# Testing

**URL:** <https://www.ruby-forum.com/t/testing/240774>\
**Category:** GNU Radio\
**Created:** [April 30, 2014, 5:08am UTC](https://www.ruby-forum.com/t/testing/240774 "2014-04-30T05:08:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [April 30, 2014, 5:08am UTC](https://www.ruby-forum.com/t/testing/240774/1 "2014-04-30T05:08:44Z")

</div>

I am testing some blocks to understand the synchronization in ofdm . I  
edited c++ files & put std::cout for all variables in  
frequency\_modulator\_fc\_impl.cc and multiply\_cc\_impl.cc and then I  
rebuilt  
using cmake…/ then make then sudo make install . But when I run the  
python file “./top\_block.py” I got an empty output from vector sinks  
also  
I got only the values of variables in multiply\_cc\_impl.cc on terminal .  
so  
why the values of variables of frequency\_modulator\_fc\_impl.cc aren’t  
shown  
on terminal !!!

Thanks.

Here is the python file

#!/usr/bin/env python  
##################################################

# Gnuradio Python Flow Graph

# Title: Top Block

# Generated: Wed Apr 23 05:43:13 2014

##################################################

from gnuradio import blocks  
from gnuradio import eng\_notation  
from gnuradio import gr  
from gnuradio.eng\_option import eng\_option  
from gnuradio.filter import firdes  
from grc\_gnuradio import wxgui as grc\_wxgui  
from optparse import OptionParser  
import wx  
from gnuradio import digital  
from gnuradio import analog

class top\_block(grc\_wxgui.top\_block\_gui):

```
def __init__ (self):
    grc_wxgui.top_block_gui. __init__ (self, title="Top Block")

    ##################################################
    # Variables
    ##################################################
    self.samp_rate = samp_rate = 32000
    fft_len=512
    cp_len=128
    n_sync_words=1
    frame_length_tag_key = "frame_length"

    ##################################################
    # Blocks
    ##################################################
    self.blocks_vector_source_x_0 = blocks.vector_source_c((1, 1,

```

1,0,0,0,1,0,1), False, 1, [])

```
    self.sync_detect = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
    self.delay = blocks.delay(gr.sizeof_gr_complex, fft_len+cp_len)
    self.oscillator = analog.frequency_modulator_fc(-2.0 / fft_len)
    self.mixer = blocks.multiply_cc()
    self.hpd = digital.header_payload_demux(
        n_sync_words+1, # Number of OFDM symbols before 

```

payload  
(sync + 1 sym header)  
fft\_len, cp\_len, # FFT length, guard interval  
frame\_length\_tag\_key, # Frame length tag key  
“”, # We’re not using trigger tags  
True # One output item is one OFDM symbol  
(False would output complex scalars)  
)

```
    self.blocks_vector_sink_x_0 = blocks.vector_sink_b(4096)
    self.blocks_vector_sink_x_1 = blocks.vector_sink_b(4096)

    ##################################################
    # Connections
    ##################################################

    self.connect((self.blocks_vector_source_x_0, 0), 

```

(self.sync\_detect))  
self.connect((self.blocks\_vector\_source\_x\_0, 0), self.delay,  
(self.mixer, 0), (self.hpd, 0), (self.blocks\_vector\_sink\_x\_0, 0))  
self.connect((self.sync\_detect, 0), self.oscillator,  
(self.mixer,  
1))  
self.connect((self.sync\_detect, 1), (self.hpd,  
1),(self.blocks\_vector\_sink\_x\_1, 0))

```
    #if debug_log:
     # self.connect((sync_detect, 0),

```

blocks.file\_sink(gr.sizeof\_float, ‘freq-offset.dat’))  
# self.connect((sync\_detect, 1),  
blocks.file\_sink(gr.sizeof\_char, ‘sync-detect.dat’))

# QT sink close method reimplementation

```
def get_samp_rate(self):
    return self.samp_rate

def set_samp_rate(self, samp_rate):
    self.samp_rate = samp_rate

```

if **name** == ‘ **main** ’:  
import ctypes  
import sys  
if sys.platform.startswith(‘linux’):  
try:  
x11 = ctypes.cdll.LoadLibrary(‘libX11.so’)  
x11.XInitThreads()  
except:  
print “Warning: failed to XInitThreads()”  
parser = OptionParser(option\_class=eng\_option, usage="%prog:  
[options]")  
(options, args) = parser.parse\_args()  
tb = top\_block()  
tb.Start(True)  
tb.Wait()  
print tb.blocks\_vector\_sink\_x\_0.data()  
print tb.blocks\_vector\_sink\_x\_1.data()

---

<div class="post-metadata">

**Author:** ![Sara\_ChSSrif](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sara\_ChSSrif](https://www.ruby-forum.com/u/Sara_ChSSrif)\
**Post date:** [April 30, 2014, 10:39am UTC](https://www.ruby-forum.com/t/testing/240774/2 "2014-04-30T10:39:37Z")

</div>

You should attached the files where you put the std::cout.  
The std::cout should be in the work() function.

---

<div class="post-metadata">

**Author:** ![Sara\_ChSSrif](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sara\_ChSSrif](https://www.ruby-forum.com/u/Sara_ChSSrif)\
**Post date:** [May 2, 2014, 11:59am UTC](https://www.ruby-forum.com/t/testing/240774/3 "2014-05-02T11:59:07Z")

</div>

Here is the file . I wrote std::cout in the work() , why I don’t see the  
output from this file on terminal after rebuilding ?!

#ifdef HAVE\_CONFIG\_H  
#include “config.h”  
#endif

#include “frequency\_modulator\_fc\_impl.h”  
#include \<gnuradio/io\_signature.h\>  
#include \<gnuradio/fxpt.h\>  
#include \<math.h\>  
#include \<boost/math/special\_functions/trunc.hpp\>

namespace gr {  
namespace analog {

```
frequency_modulator_fc::sptr
frequency_modulator_fc::make(double sensitivity)
{
  return gnuradio::get_initial_sptr
    (new frequency_modulator_fc_impl(sensitivity));
}

frequency_modulator_fc_impl::frequency_modulator_fc_impl(double

```

sensitivity)  
: sync\_block(“frequency\_modulator\_fc”,  
io\_signature::make(1, 1, sizeof(float)),  
io\_signature::make(1, 1, sizeof(gr\_complex))),  
d\_sensitivity(sensitivity), d\_phase(0)  
{  
}

```
frequency_modulator_fc_impl::~frequency_modulator_fc_impl()
{
}

int
frequency_modulator_fc_impl::work(int noutput_items,
                                  gr_vector_const_void_star

```

&input\_items,  
gr\_vector\_void\_star &output\_items)  
{  
const float _in = (const float_)input\_items[0];  
gr\_complex _out = (gr\_complex_)output\_items[0];

```
  for(int i = 0; i < noutput_items; i++) {
    std::cout<<"d_phase "<<d_phase<<std::endl;
    d_phase = d_phase + d_sensitivity * in[i];
    std::cout<<"d_sensitivity "<<d_sensitivity<<std::endl;
    std::cout<<"in[i] "<<in[i]<<"where i] "<<i<<std::endl;
    std::cout<<"then d_phase= "<<d_phase<<std::endl;
    while(d_phase > (float)(M_PI)){
      d_phase -= (float)(2.0 * M_PI);
      std::cout<<"d_ph>MPI then d_ph= "<<d_phase<<std::endl;
      }

    while(d_phase < (float)(-M_PI)){
      d_phase += (float)(2.0 * M_PI);
      std::cout<<"d_oh<M_PI then d_ph= "<<d_phase<<std::endl;
      }

    float oi, oq;

    gr_int32 angle = gr::fxpt::float_to_fixed (d_phase);
    gr::fxpt::sincos(angle, &oq, &oi);
    std::cout<<"angle "<<angle<<" oq "<<oq<<" oi "<<oi<<std::endl;
    out[i] = gr_complex(oi, oq);
    std::cout<<" out[i] "<<out[i]<<" where i= "<<i<<std::endl;
  }

  return noutput_items;
}

```

} /\* namespace analog _/  
} /_ namespace gr \*/

2014-04-30 10:37 GMT+02:00 Activecat [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Sara\_ChSSrif](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sara\_ChSSrif](https://www.ruby-forum.com/u/Sara_ChSSrif)\
**Post date:** [May 3, 2014, 5:07am UTC](https://www.ruby-forum.com/t/testing/240774/4 "2014-05-03T05:07:18Z")

</div>

On Fri, May 2, 2014 at 8:46 AM, Activecat [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have not much idea beyond this.  
> The std::cout in work() should show something if executed.
> 
> * * *
> 
> Discuss-gnuradio mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

Did you install the file after rebuilding it? That said, I don’t know  
what you’re expecting to gain from this exercise. You’re going to see  
a bunch of numbers fly by really fast. Wouldn’t plotting the output  
with one of the waveform analysis tools be more useful?

---

<div class="post-metadata">

**Author:** ![Sara\_ChSSrif](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sara\_ChSSrif](https://www.ruby-forum.com/u/Sara_ChSSrif)\
**Post date:** [May 5, 2014, 1:17pm UTC](https://www.ruby-forum.com/t/testing/240774/5 "2014-05-05T13:17:33Z")

</div>

On 03.05.2014 05:05, West, Nathan wrote:

> Did you install the file after rebuilding it? That said, I don’t know  
> what you’re expecting to gain from this exercise. You’re going to see  
> a bunch of numbers fly by really fast. Wouldn’t plotting the output  
> with one of the waveform analysis tools be more useful?

I very much want to second this. We have all these nice plotting utils,  
it helps to use them.

M

---

<div class="post-metadata">

**Author:** ![Sara\_ChSSrif](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sara\_ChSSrif](https://www.ruby-forum.com/u/Sara_ChSSrif)\
**Post date:** [May 2, 2014, 3:49pm UTC](https://www.ruby-forum.com/t/testing/240774/6 "2014-05-02T15:49:35Z")

</div>

On Fri, May 2, 2014 at 5:57 PM, Sara Chérif [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Here is the file . I wrote std::cout in the work() , why I don’t see the  
> output from this file on terminal after rebuilding ?!

It seems like the work() function is not called at all by the scheduler.  
Probably the ofdm sync block doesn’t produce any output to feed into  
your  
custom block.  
I have not much idea beyond this.  
The std::cout in work() should show something if executed.
