diff options
Diffstat (limited to 'gr-digital/python/qa_constellation_receiver.py')
-rwxr-xr-x | gr-digital/python/qa_constellation_receiver.py | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/gr-digital/python/qa_constellation_receiver.py b/gr-digital/python/qa_constellation_receiver.py index 2d25433b92..6da3fc1066 100755 --- a/gr-digital/python/qa_constellation_receiver.py +++ b/gr-digital/python/qa_constellation_receiver.py @@ -22,9 +22,11 @@ import random -from gnuradio import gr, blks2, gr_unittest +from gnuradio import gr, gr_unittest from utils import mod_codes, alignment -import digital_swig, packet_utils +import packet_utils +import filter_swig as filter +import analog_swig as analog from generic_mod_demod import generic_mod, generic_demod from qa_constellation import tested_constellations, twod_constell @@ -37,7 +39,7 @@ SEED = 1239 # TESTING PARAMETERS # The number of symbols to test with. # We need this many to let the frequency recovery block converge. -DATA_LENGTH = 2000 +DATA_LENGTH = 1000 # Test fails if fraction of output that is correct is less than this. REQ_CORRECT = 0.7 @@ -50,8 +52,30 @@ TIMING_OFFSET = 1.0 FREQ_BW = 2*math.pi/100.0 PHASE_BW = 2*math.pi/100.0 +class channel_model(gr.hier_block2): + def __init__(self, noise_voltage, freq, timing): + gr.hier_block2.__init__(self, "channel_model", + gr.io_signature(1, 1, gr.sizeof_gr_complex), + gr.io_signature(1, 1, gr.sizeof_gr_complex)) + -class test_constellation_receiver (gr_unittest.TestCase): + timing_offset = filter.fractional_interpolator_cc(0, timing) + noise_adder = gr.add_cc() + noise = analog.noise_source_c(analog.GR_GAUSSIAN, + noise_voltage, 0) + freq_offset = analog.sig_source_c(1, analog.GR_SIN_WAVE, + freq, 1.0, 0.0) + mixer_offset = gr.multiply_cc(); + + self.connect(self, timing_offset) + self.connect(timing_offset, (mixer_offset,0)) + self.connect(freq_offset, (mixer_offset,1)) + self.connect(mixer_offset, (noise_adder,1)) + self.connect(noise, (noise_adder,0)) + self.connect(noise_adder, self) + + +class test_constellation_receiver(gr_unittest.TestCase): # We ignore the first half of the output data since often it takes # a while for the receiver to lock on. @@ -85,11 +109,16 @@ class test_constellation_receiver (gr_unittest.TestCase): # That is not implemented since the receiver has no way of # knowing where the beginning of a symbol is. # It also doesn't work for non-differential modulation. - if constellation.dimensionality() != 1 or not differential: + if constellation.dimensionality() != 1: continue data_length = DATA_LENGTH * constellation.bits_per_symbol() + if differential: + freq_offset=True + else: + freq_offset=False tb = rec_test_tb(constellation, differential, - src_data=self.src_data[:data_length]) + src_data=self.src_data[:data_length], + freq_offset=freq_offset) tb.run() data = tb.dst.data() d1 = tb.src_data[:int(len(tb.src_data)*self.ignore_fraction)] @@ -99,18 +128,20 @@ class test_constellation_receiver (gr_unittest.TestCase): self.assertTrue(correct > REQ_CORRECT) -class rec_test_tb (gr.top_block): +class rec_test_tb(gr.top_block): """ Takes a constellation an runs a generic modulation, channel, and generic demodulation. """ def __init__(self, constellation, differential, - data_length=None, src_data=None): + data_length=None, src_data=None, freq_offset=True): """ - constellation -- a constellation object - differential -- whether differential encoding is used - data_length -- the number of bits of data to use - src_data -- a list of the bits to use + Args: + constellation: a constellation object + differential: whether differential encoding is used + data_length: the number of bits of data to use + src_data: a list of the bits to use + freq_offset: whether to use a frequency offset in the channel """ super(rec_test_tb, self).__init__() # Transmission Blocks @@ -122,11 +153,18 @@ class rec_test_tb (gr.top_block): src = gr.vector_source_b(self.src_data) mod = generic_mod(constellation, differential=differential) # Channel - channel = gr.channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET) + if freq_offset: + channel = channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET) + else: + channel = channel_model(NOISE_VOLTAGE, 0, TIMING_OFFSET) # Receiver Blocks - demod = generic_demod(constellation, differential=differential, - freq_bw=FREQ_BW, - phase_bw=PHASE_BW) + if freq_offset: + demod = generic_demod(constellation, differential=differential, + freq_bw=FREQ_BW, + phase_bw=PHASE_BW) + else: + demod = generic_demod(constellation, differential=differential, + freq_bw=0, phase_bw=0) self.dst = gr.vector_sink_b() self.connect(src, packer, mod, channel, demod, self.dst) |