def __init__(self, length, debug=False): """ Hierarchical block to detect Null symbols @param length length of the Null symbol (in samples) @param debug whether to write signals out to files """ gr.hier_block2.__init__(self,"detect_null", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_char)) # output signature # get the magnitude squared self.ns_c2magsquared = blocks.complex_to_mag_squared() # this wastes cpu cycles: # ns_detect_taps = [1]*length # self.ns_moving_sum = gr.fir_filter_fff(1,ns_detect_taps) # this isn't better: #self.ns_filter = gr.iir_filter_ffd([1]+[0]*(length-1)+[-1],[0,1]) # this does the same again, but is actually faster (outsourced to an independent block ..): self.ns_moving_sum = dab.moving_sum_ff(length) self.ns_invert = blocks.multiply_const_ff(-1) # peak detector on the inverted, summed up signal -> we get the nulls (i.e. the position of the start of a frame) self.ns_peak_detect = blocks.peak_detector_fb(0.6,0.7,10,0.0001) # mostly found by try and error -> remember that the values are negative! # connect it all self.connect(self, self.ns_c2magsquared, self.ns_moving_sum, self.ns_invert, self.ns_peak_detect, self) if debug: self.connect(self.ns_invert, blocks.file_sink(gr.sizeof_float, "debug/ofdm_sync_dab_ns_filter_inv_f.dat")) self.connect(self.ns_peak_detect,blocks.file_sink(gr.sizeof_char, "debug/ofdm_sync_dab_peak_detect_b.dat"))
def test_001_moving_sum_ff(self): src_data = (0, 1, 3, 3, -3.5, -7.7, 2, 2, 3) expected_result = (0, 1, 4, 7, 2.5, -8.2, -9.2, -3.7, 7) src = blocks.vector_source_f(src_data) moving_sum = dab.moving_sum_ff(3) dst = blocks.vector_sink_f() self.tb.connect(src, moving_sum) self.tb.connect(moving_sum, dst) self.tb.run() result_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
def test_002_moving_sum_ff(self): src_data = [float(i ** 3) * (7 ** -2) for i in range(-20, 20)] expected_result = [src_data[0]] + [src_data[i] + src_data[i - 1] for i in range(1, 40)] src = blocks.vector_source_f(src_data) moving_sum = dab.moving_sum_ff(2) dst = blocks.vector_sink_f() self.tb.connect(src, moving_sum) self.tb.connect(moving_sum, dst) self.tb.run() result_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4)
def test_002_moving_sum_ff(self): src_data = [float(i**3) * (7**-2) for i in range(-20, 20)] expected_result = [src_data[0]] + [ src_data[i] + src_data[i - 1] for i in range(1, 40) ] src = blocks.vector_source_f(src_data) moving_sum = dab.moving_sum_ff(2) dst = blocks.vector_sink_f() self.tb.connect(src, moving_sum) self.tb.connect(moving_sum, dst) self.tb.run() result_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4)
def __init__(self, length, debug=False): """ Hierarchical block to detect Null symbols @param length length of the Null symbol (in samples) @param debug whether to write signals out to files """ gr.hier_block2.__init__( self, "detect_null", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_char)) # output signature # get the magnitude squared self.ns_c2magsquared = blocks.complex_to_mag_squared() # this wastes cpu cycles: # ns_detect_taps = [1]*length # self.ns_moving_sum = gr.fir_filter_fff(1,ns_detect_taps) # this isn't better: #self.ns_filter = gr.iir_filter_ffd([1]+[0]*(length-1)+[-1],[0,1]) # this does the same again, but is actually faster (outsourced to an independent block ..): self.ns_moving_sum = dab.moving_sum_ff(length) self.ns_invert = blocks.multiply_const_ff(-1) # peak detector on the inverted, summed up signal -> we get the nulls (i.e. the position of the start of a frame) self.ns_peak_detect = blocks.peak_detector_fb( 0.6, 0.7, 10, 0.0001 ) # mostly found by try and error -> remember that the values are negative! # connect it all self.connect(self, self.ns_c2magsquared, self.ns_moving_sum, self.ns_invert, self.ns_peak_detect, self) if debug: self.connect( self.ns_invert, blocks.file_sink(gr.sizeof_float, "debug/ofdm_sync_dab_ns_filter_inv_f.dat")) self.connect( self.ns_peak_detect, blocks.file_sink(gr.sizeof_char, "debug/ofdm_sync_dab_peak_detect_b.dat"))