discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] gnuradio block for boolean operations


From: Ed Criscuolo
Subject: Re: [Discuss-gnuradio] gnuradio block for boolean operations
Date: Mon, 18 Feb 2008 10:43:04 -0500
User-agent: Thunderbird 2.0.0.9 (Macintosh/20071031)

Tim Meehan wrote:

Hello all,

I want to perform some simple boolean operations on a stream of data.
For example invert the bits from the output of the demodulators or convert
from NRZ to NRZI

I was thinking something like
 1) gr_xor_bb, gr_and_bb, gr_or_bb, br_not_bb ...
or
 2) maybe gr_boolean("xor") , gr_boolean("and") ...

Is this something someone has started?


I have written both  xor_bb and nrzi_to_nrz_bb and used them
on 2 different projects.

Is there another way I should go about this?

If this is something that should be done can someone give me an idea of the desired format (1 or 2 or something else)


Purely from the point of view of "cohesion" I would recommend
the "gr_xor_bb" form instead of passing in a selector that
determines the behavior.  Although I must admit, I wrestled
for quite a while with writing so much infrastructure code
for something as simple an an "xor".


Here's the code for gr_nrzi_to_nrz_bb.  The code for xor
is similar.

@(^.^)@  Ed


/* -*- c++ -*- */
/*
 * Copyright 2006 Free Software Foundation, Inc.
 *
 * This file is part of GNU Radio
 *
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gr_nrzi_to_nrz_bb.h>
#include <gr_io_signature.h>
#include <stdexcept>

gr_nrzi_to_nrz_bb_sptr
gr_make_nrzi_to_nrz_bb (bool preload)
{
  return gr_nrzi_to_nrz_bb_sptr (new gr_nrzi_to_nrz_bb (preload));
}

gr_nrzi_to_nrz_bb::gr_nrzi_to_nrz_bb (bool preload)
  : gr_sync_block ("nrzi_to_nrz_bb",
           gr_make_io_signature (1, 1, sizeof (unsigned char)),
           gr_make_io_signature (1, 1, sizeof (unsigned char))),
           d_prev_nrzi_bit(preload)
{
}

int
gr_nrzi_to_nrz_bb::work (int                       noutput_items,
                         gr_vector_const_void_star &input_items,
                         gr_vector_void_star       &output_items)
{
  const unsigned char* in  = (const unsigned char *) input_items[0];
  unsigned char*       out = (unsigned char *) output_items[0];
  unsigned char        nrzi_bit;
  unsigned char        nrz_bit;

  for (int i = 0; i < noutput_items; i++)
    {
        nrzi_bit = in[i];
        // Convert NRZI to NRZ.
        if(nrzi_bit != d_prev_nrzi_bit)
          {
            nrz_bit = 0;
          }
        else
          {
            nrz_bit = 1;
          }
        out[i] = nrz_bit;
        d_prev_nrzi_bit = nrzi_bit;
    }
  return noutput_items;
}






reply via email to

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