[Top][All Lists]

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

[Patch-gnuradio] gr_pack_k_bits_bb

From: Mattias Kjellsson
Subject: [Patch-gnuradio] gr_pack_k_bits_bb
Date: Thu, 27 Aug 2009 12:50:55 +0200
User-agent: Thunderbird (X11/20090817)

Hi people,

In an effort to write a c++ qpsk mapper/demapper i found that the quite useful block "gr_unpack_k_bits", but I couldn't find the "inverse", so I wrote it.

I have tested it using the following flow- graph:

file_source -> bit- packer -> constellation- mapper -> constellation- demapper -> bit- unpacker -> file_sink

file_source contains random bits generated in matlab.
packer packs two consecutive bits together
constellation- mapper is a qpsk- mapper
constellation- demapper is the inverse
unpacker is a gr_unpack_k_bits_bb

I have tested it for "gr_pack_k_bits_bb(2)" and "gr_unpack_k_bits_bb(2)".

Hope this can be incorporated into the tree.
Best regards
//Mattias Kjellsson
#include "gr_pack_k_bits_bb.h"
#include <gr_io_signature.h>
#include <stdexcept>
#include <iostream>

gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb(unsigned k){
  return gr_pack_k_bits_bb_sptr (new gr_pack_k_bits_bb(k));

gr_pack_k_bits_bb::gr_pack_k_bits_bb(unsigned k)
  : gr_sync_decimator("pack_k_bits_bb",
                          gr_make_io_signature (1, 1, sizeof (unsigned char)),
                          gr_make_io_signature (1, 1, sizeof (unsigned char)),
  if (d_k == 0)
    throw std::out_of_range ("decimation must be > 0");


int gr_pack_k_bits_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];

        int n = 0;
        for(unsigned int i=0;i<noutput_items * d_k ;i=i+d_k){
                /* Working for two...           
                char t1 = in[i];
                char t2 = in[i+1];
                out[n] = ( (t1<<1) + t2 ) & 0x3;
                //printf("i: %d\t t1: 0x%0x\t t2: 0x%0x\t out[%d] = 0x%0x\n",
                //                              i, t1, t2, n, out[n]);
                /*Trying for more */
                int c = 0;
                for(int j=(d_k-1);j>=0;j--){
                        char t = in[i+c++];
                        out[n] = out[n] + (t<<j);
                out[n] = out[n] & (d_k+1);
  //assert(n == noutput_items);
  return noutput_items;

#include <gr_sync_decimator.h>

class gr_pack_k_bits_bb;

typedef boost::shared_ptr<gr_pack_k_bits_bb> gr_pack_k_bits_bb_sptr;

gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb(unsigned k);

class gr_pack_k_bits_bb : public gr_sync_decimator{
  friend gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb(unsigned k);
  gr_pack_k_bits_bb(unsigned k);
  unsigned int d_k;

  ~gr_pack_k_bits_bb ();
  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]