Gold Code PN Source

Murtuza wrote:

Hi Ed

Can I have a look at your Gold Code source block.


The block makes use of the existing glfsr block.
Two of them are setup and XOR’ed. The “tdrss”
package containes a set of low level utilities,
including the ‘xor’ operation.

from gnuradio import gr
from gnuradio import tdrss

class gold_code_pn_source_b(gr.hier_block2):
Binary Pseudorandom Number generator based on Gold Codes.

 @param degree: Degree of generator polynomial(s)
 @type degree: integer
 @param poly0: Generator polynomial 0
 @type poly0: integer
 @param seed0: Seed value for galois pn generator 0
 @type seed0: integer
 @param poly1: Generator polynomial 1
 @type poly1: integer
 @param seed1: Seed value for galois pn generator 1
 @type seed1: integer
 def __init__(self, degree, poly0, seed0, poly1, seed1):
     gr.hier_block2.__init__(self, "gold_code_pn_source_b",
             gr.io_signature(0, 0, 0),    # Input signature
             gr.io_signature(1, 1, gr.sizeof_char)) # Input 


     repeat = True
     seq0 = gr.glfsr_source_b(degree, repeat, poly0, seed0)
     seq1 = gr.glfsr_source_b(degree, repeat, poly1, seed1)
     xor  = tdrss.xor_bb()

     self.connect(seq0, (xor,0))
     self.connect(seq1, (xor,1))
     self.connect(xor, self)

#include “config.h”

#include <tdrss_xor_bb.h>
#include <gr_io_signature.h>


  • Create a new instance of tdrss_xor_bb and return
  • a boost shared_ptr. This is effectively the public constructor.
    tdrss_make_xor_bb ()
    return tdrss_xor_bb_sptr (new tdrss_xor_bb ());


  • Specify constraints on number of input and output streams.
  • This info is used to construct the input and output signatures
  • (2nd & 3rd args to gr_block’s constructor). The input and
  • output signatures are used by the runtime system to
  • check that a valid number and type of inputs and outputs
  • are connected to this block. In this case, we accept
  • only 1 input and 1 output.
    static const int MIN_IN = 2; // mininum number of input streams
    static const int MAX_IN = 2; // maximum number of input streams
    static const int MIN_OUT = 1; // minimum number of output streams
    static const int MAX_OUT = 1; // maximum number of output streams


  • The private constructor
    tdrss_xor_bb::tdrss_xor_bb ()
    : gr_sync_block (“xor_bb”,
    gr_make_io_signature (MIN_IN, MAX_IN, sizeof (char)),
    gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (char)))
    // nothing else required in this example


  • Our virtual destructor.
    tdrss_xor_bb::~tdrss_xor_bb ()
    // nothing else required in this example

tdrss_xor_bb::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
const unsigned char *in0 = (const unsigned char *) input_items[0];
const unsigned char *in1 = (const unsigned char *) input_items[1];
unsigned char *out = (unsigned char *) output_items[0];

for (int i = 0; i < noutput_items; i++){
out[i] = in0[i] ^ in1[i];

// Tell runtime system how many output items we produced.
return noutput_items;



#include <gr_sync_block.h>

class tdrss_bpsk_bc;


  • We use boost::shared_ptr’s instead of raw pointers for all access
  • to gr_blocks (and many other data structures). The shared_ptr gets
  • us transparent reference counting, which greatly simplifies storage
  • management issues. This is especially helpful in our hybrid
  • C++ / Python system.
  • See
  • As a convention, the _sptr suffix indicates a boost::shared_ptr
    typedef boost::shared_ptr<tdrss_bpsk_bc> tdrss_bpsk_bc_sptr;


  • \brief Return a shared_ptr to a new instance of tdrss_bpsk_bc.
  • To avoid accidental use of raw pointers, tdrss_bpsk_bc’s
  • constructor is private. tdrss_make_bpsk_bc is the public
  • interface for creating new instances.
    tdrss_bpsk_bc_sptr tdrss_make_bpsk_bc ();


  • \brief bitwise xor two streams of floats.
  • \ingroup block
  • This uses the preferred technique: subclassing gr_sync_block.
    class tdrss_bpsk_bc : public gr_sync_block
    // The friend declaration allows tdrss_make_bpsk_bc to
    // access the private constructor.

friend tdrss_bpsk_bc_sptr tdrss_make_bpsk_bc ();

tdrss_bpsk_bc (); // private constructor

~tdrss_bpsk_bc (); // public destructor

// Where all the action really happens

int work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);


On Mon, Aug 18, 2008 at 7:32 AM, Ed Criscuolo
[email protected] wrote:

The “tdrss”
package containes a set of low level utilities,
including the ‘xor’ operation.

Just FYI, release 3.1.2 added a set of boolean blocks, including
gr.xor_bb, by Tim M…

Johnathan C.
Corgan Enterprises LLC