[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Gold Code PN Source

From: Ed Criscuolo
Subject: [Discuss-gnuradio] Gold Code PN Source
Date: Mon, 18 Aug 2008 10:32:21 -0400
User-agent: Thunderbird (Macintosh/20071031)

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 signature

        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 http://www.boost.org/libs/smart_ptr/smart_ptr.htm
 * 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);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]