[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Discuss-gnuradio] Gnuradio block behaves strange.....please have a look
From: |
Murtuza |
Subject: |
[Discuss-gnuradio] Gnuradio block behaves strange.....please have a look at this |
Date: |
Tue, 30 Sep 2008 23:19:54 -0500 |
Hi friends,
I wrote a gnuradio block that has 2 input streams.
1. The first stream is the stream of PN sequence data coming out of an gr.xor_bb block. (It is a gold sequence generated by XOR two M-seq generated using gr.glfsr_source_b).
2. The second stream is the data read from a file. I use a test data "0xAA " stored in a file and read it using gr.file_source(gr.sizeof_char,"datafile",True).
The output is written to a file. The output written to the file always has some data missing. I tested the spreading block by printing its output to "stdout" and found that the output is alright, but when I write it to the file I always see some data missing. Any ideas why this might be happening ?
Below is the code for the block that spreads the data. I spread each bit of every byte read to the lenth of PN sequence. e.g. If PN sequence is 7 bit long, the output of the block will be 7*8 bits for each byte read from the file. The PN sequence bit is the LSB of every byte that output out of the XOR block.
I suspect something is wrong with the way I call the "consume" function.
Any kind of help will be greatly appreciated.
Thanks
Ali.
The code.
// dsss_spreading_blk_b.h
/* -*- c++ -*- */
/*
* Copyright 2004 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 3, 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.
*/
#ifndef INCLUDED_DSSS_SPREADING_BLK_B_H
#define INCLUDED_DSSS_SPREADING_BLK_B_H
#include <gr_block.h>
class dsss_spreading_blk_b;
typedef boost::shared_ptr<dsss_spreading_blk_b> dsss_spreading_blk_b_sptr;
dsss_spreading_blk_b_sptr dsss_make_spreading_blk_b (int degree_PN);
class dsss_spreading_blk_b : public gr_block
{
int d_length_PN;
friend dsss_spreading_blk_b_sptr dsss_make_spreading_blk_b(int degree_PN);
dsss_spreading_blk_b(int degree_PN);
public:
void forecast(int noutput_items,gr_vector_int &ninput_items_required);
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
#endif /* INCLUDED_DSSS_SPREADING_BLK_B_H */
//***********************************************************************************
// dsss_spreading_blk_b.cc
/* -*- c++ -*- */
/*
* Copyright 2004 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 3, 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 <dsss_spreading_blk_b.h>
#include <gr_io_signature.h>
#include <assert.h>
#include <stdexcept>
#include <iostream>
dsss_spreading_blk_b_sptr
dsss_make_spreading_blk_b (int degree_PN)
{
return dsss_spreading_blk_b_sptr (new dsss_spreading_blk_b (degree_PN));
}
/*
Input_stream_2 = data_source to be spread. The input data size is 1 byte.(1 item is needed to produce 1 output item)
Input_stream_1 = PN_sequence_generator. The input data size is 1 byte.(length_PN items are needed to produce 1 output item)
*/
dsss_spreading_blk_b::dsss_spreading_blk_b(int degree_PN):gr_block("spreading_blk",
gr_make_io_signature(2,2,sizeof(unsigned char)),
gr_make_io_signature(1,1,sizeof(unsigned char))),
d_length_PN((int)(pow(2,degree_PN)-1))
{
set_output_multiple(8*d_length_PN); // noutput_items == multiple of length of PN sequence
}
void
dsss_spreading_blk_b::forecast(int noutput_items,gr_vector_int &ninput_items_required){
assert(noutput_items % d_length_PN==0);
//unsigned int ninputs = ninput_items_required.size();
int items_on_first_input_stream = noutput_items; // the first_stream is the PN sequence stream
int items_on_data_input_stream = noutput_items/(8*d_length_PN);
ninput_items_required[0]=items_on_first_input_stream;
ninput_items_required[1]=items_on_data_input_stream;
}
int
dsss_spreading_blk_b::general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
//std::cout << d_length_PN << std::endl;
const unsigned char *in_1 = (const unsigned char *)input_items[0];// PN
const unsigned char *in_2 = (const unsigned char *)input_items[1];// data
unsigned char *out = (unsigned char *)output_items[0];
int pn_input_cnt=0;
int items_on_1 = ninput_items[0];
int items_on_2 = ninput_items[1];
int i=0;
int data_cnt=0;
int cc=0;
for(i=0;(i<noutput_items)&&(data_cnt<items_on_2);i++){
data_cnt=data_cnt+1;
//pn_input_cnt=0;
unsigned char temp = in_2[data_cnt-1];
//std::cout << "int_2=" << (int)temp << std::endl;
//std::cout << " in \t" << " out" << std::endl;
for(int j=0;j<8;j++){
pn_input_cnt=0;
if((temp>>j)&0x01){
while(pn_input_cnt<d_length_PN){
//std::cout << " "<< (int)in_1[i] << "\t";
out[i]=in_1[i];
// std::cout << " \t"<< (int)out[i] << std::endl;
i=i+1;
pn_input_cnt=pn_input_cnt+1;
}
}else{
while(pn_input_cnt<d_length_PN){
//std::cout << " "<< (int)in_1[i] << "\t";
out[i]=in_1[i] ^ 0x01;
// std::cout << " \t"<< (int)out[i] << std::endl;
i=i+1;
pn_input_cnt=pn_input_cnt+1;
}
}
}
//cc++;
//if(cc==1)
//exit(0);
}
consume(0,i);
consume(1,data_cnt);
}
//***************************************************************
//spread.i
/* -*- c++ -*- */
/*
* Copyright 2007 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 3, 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.
*/
%feature("autodoc", "1"); // generate python docstrings
%include "exception.i"
%import "gnuradio.i"
// the common stuff
%{
#include "gnuradio_swig_bug_workaround.h" // mandatory bug fix
#include "dsss_spreading_blk_b.h"
#include <stdexcept>
%}
GR_SWIG_BLOCK_MAGIC(dsss,spreading_blk_b);
dsss_spreading_blk_b_sptr
dsss_make_spreading_blk_b(int degree_PN)
throw (std::runtime_error);
class dsss_spreading_blk_b:public gr_block
{
protected:
dsss_spreading_blk_b(int degree_PN);
};
--
Mir Murtuza Ali
Graduate Student
Center for Wireless Communications
University of Mississippi
University, MS 38677
- [Discuss-gnuradio] Gnuradio block behaves strange.....please have a look at this,
Murtuza <=