diff options
Diffstat (limited to 'gr-digital/python/ofdm_sync_ml.py')
-rw-r--r-- | gr-digital/python/ofdm_sync_ml.py | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/gr-digital/python/ofdm_sync_ml.py b/gr-digital/python/ofdm_sync_ml.py index 7c75d7f1d4..3afd647098 100644 --- a/gr-digital/python/ofdm_sync_ml.py +++ b/gr-digital/python/ofdm_sync_ml.py @@ -23,6 +23,16 @@ import math from gnuradio import gr +try: + from gnuradio import filter +except ImportError: + import filter_swig as filter + +try: + from gnuradio import blocks +except ImportError: + import blocks_swig as blocks + class ofdm_sync_ml(gr.hier_block2): def __init__(self, fft_length, cp_length, snr, kstime, logging): ''' Maximum Likelihood OFDM synchronizer: @@ -35,7 +45,7 @@ class ofdm_sync_ml(gr.hier_block2): gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature - self.input = gr.add_const_cc(0) + self.input = blocks.add_const_cc(0) SNR = 10.0**(snr/10.0) rho = SNR / (SNR + 1.0) @@ -48,16 +58,16 @@ class ofdm_sync_ml(gr.hier_block2): self.connect(self, self.input) # Create a delay line - self.delay = gr.delay(gr.sizeof_gr_complex, fft_length) + self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length) self.connect(self.input, self.delay) # magnitude squared blocks - self.magsqrd1 = gr.complex_to_mag_squared() - self.magsqrd2 = gr.complex_to_mag_squared() - self.adder = gr.add_ff() + self.magsqrd1 = blocks.complex_to_mag_squared() + self.magsqrd2 = blocks.complex_to_mag_squared() + self.adder = blocks.add_ff() moving_sum_taps = [rho/2 for i in range(cp_length)] - self.moving_sum_filter = gr.fir_filter_fff(1,moving_sum_taps) + self.moving_sum_filter = filter.fir_filter_fff(1,moving_sum_taps) self.connect(self.input,self.magsqrd1) self.connect(self.delay,self.magsqrd2) @@ -67,29 +77,29 @@ class ofdm_sync_ml(gr.hier_block2): # Correlation from ML Sync - self.conjg = gr.conjugate_cc(); - self.mixer = gr.multiply_cc(); + self.conjg = blocks.conjugate_cc(); + self.mixer = blocks.multiply_cc(); movingsum2_taps = [1.0 for i in range(cp_length)] - self.movingsum2 = gr.fir_filter_ccf(1,movingsum2_taps) + self.movingsum2 = filter.fir_filter_ccf(1,movingsum2_taps) # Correlator data handler - self.c2mag = gr.complex_to_mag() - self.angle = gr.complex_to_arg() + self.c2mag = blocks.complex_to_mag() + self.angle = blocks.complex_to_arg() self.connect(self.input,(self.mixer,1)) self.connect(self.delay,self.conjg,(self.mixer,0)) self.connect(self.mixer,self.movingsum2,self.c2mag) self.connect(self.movingsum2,self.angle) # ML Sync output arg, need to find maximum point of this - self.diff = gr.sub_ff() + self.diff = blocks.sub_ff() self.connect(self.c2mag,(self.diff,0)) self.connect(self.moving_sum_filter,(self.diff,1)) #ML measurements input to sampler block and detect - self.f2c = gr.float_to_complex() - self.pk_detect = gr.peak_detector_fb(0.2, 0.25, 30, 0.0005) - self.sample_and_hold = gr.sample_and_hold_ff() + self.f2c = blocks.float_to_complex() + self.pk_detect = blocks.peak_detector_fb(0.2, 0.25, 30, 0.0005) + self.sample_and_hold = blocks.sample_and_hold_ff() # use the sync loop values to set the sampler and the NCO # self.diff = theta @@ -115,9 +125,9 @@ class ofdm_sync_ml(gr.hier_block2): # to readjust the timing in the middle of the packet or we ruin the equalizer settings. kstime = [k.conjugate() for k in kstime] kstime.reverse() - self.kscorr = gr.fir_filter_ccc(1, kstime) - self.corrmag = gr.complex_to_mag_squared() - self.div = gr.divide_ff() + self.kscorr = filter.fir_filter_ccc(1, kstime) + self.corrmag = blocks.complex_to_mag_squared() + self.div = blocks.divide_ff() # The output signature of the correlation has a few spikes because the rest of the # system uses the repeated preamble symbol. It needs to work that generically if @@ -125,10 +135,10 @@ class ofdm_sync_ml(gr.hier_block2): # The output theta of the correlator above is multiplied with this correlation to # identify the proper peak and remove other products in this cross-correlation self.threshold_factor = 0.1 - self.slice = gr.threshold_ff(self.threshold_factor, self.threshold_factor, 0) - self.f2b = gr.float_to_char() - self.b2f = gr.char_to_float() - self.mul = gr.multiply_ff() + self.slice = blocks.threshold_ff(self.threshold_factor, self.threshold_factor, 0) + self.f2b = blocks.float_to_char() + self.b2f = blocks.char_to_float() + self.mul = blocks.multiply_ff() # Normalize the power of the corr output by the energy. This is not really needed # and could be removed for performance, but it makes for a cleaner signal. @@ -148,18 +158,18 @@ class ofdm_sync_ml(gr.hier_block2): if logging: - self.connect(self.moving_sum_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat")) - self.connect(self.diff, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat")) - self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat")) - self.connect(self.corrmag, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat")) - self.connect(self.kscorr, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat")) - self.connect(self.div, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat")) - self.connect(self.mul, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat")) - self.connect(self.slice, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat")) - self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat")) + self.connect(self.moving_sum_filter, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat")) + self.connect(self.diff, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat")) + self.connect(self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat")) + self.connect(self.corrmag, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat")) + self.connect(self.kscorr, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat")) + self.connect(self.div, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat")) + self.connect(self.mul, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat")) + self.connect(self.slice, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat")) + self.connect(self.pk_detect, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat")) if use_dpll: - self.connect(self.dpll, gr.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat")) + self.connect(self.dpll, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat")) - self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat")) - self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat")) + self.connect(self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat")) + self.connect(self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat")) |