From 381253a1d24f1273fad2f4e0d57d75d3ac6e518d Mon Sep 17 00:00:00 2001 From: ptrkrysik Date: Wed, 19 Nov 2014 11:30:53 +0100 Subject: [PATCH] Changes in clock offset corrector and gsm_input - the previous version wasn't working well when samp_rate_in was different from samp_rate_out. Now resampling is done outside of clock offset corrector. --- grc/misc_utils/gsm_clock_offset_corrector.xml | 18 +- grc/receiver/gsm_input.xml | 33 +- .../misc_utils/gsm_clock_offset_corrector.grc | 502 +++++++++-------- hier_blocks/receiver/gsm_input.grc | 517 ++++++++++-------- python/misc_utils/clock_offset_corrector.py | 44 +- python/receiver/gsm_input.py | 28 +- 6 files changed, 628 insertions(+), 514 deletions(-) diff --git a/grc/misc_utils/gsm_clock_offset_corrector.xml b/grc/misc_utils/gsm_clock_offset_corrector.xml index c541054..0740f17 100644 --- a/grc/misc_utils/gsm_clock_offset_corrector.xml +++ b/grc/misc_utils/gsm_clock_offset_corrector.xml @@ -1,4 +1,3 @@ - Clock offset corrector gsm_clock_offset_corrector @@ -7,34 +6,26 @@ fc=$fc, ppm=$ppm, samp_rate_in=$samp_rate_in, - samp_rate_out=$samp_rate_out, ) set_fc($fc) set_ppm($ppm) set_samp_rate_in($samp_rate_in) - set_samp_rate_out($samp_rate_out) fc fc - 936.6e6 + fc float ppm ppm - 0 - int + ppm + float samp_rate_in samp_rate_in - 1625000.0/6.0*4.0 - float - - - samp_rate_out - samp_rate_out - 1625000.0/6.0*4.0 + samp_rate_in float @@ -53,5 +44,4 @@ 1 Piotr Krysik - diff --git a/grc/receiver/gsm_input.xml b/grc/receiver/gsm_input.xml index df86a3f..2892103 100644 --- a/grc/receiver/gsm_input.xml +++ b/grc/receiver/gsm_input.xml @@ -1,4 +1,3 @@ - GSM input adaptor gsm_input @@ -6,40 +5,40 @@ import gsm gsm.gsm_input( ppm=$ppm, - fc=$fc, osr=$osr, + fc=$fc, samp_rate_in=$samp_rate_in, ) set_ppm($ppm) - set_fc($fc) set_osr($osr) + set_fc($fc) set_samp_rate_in($samp_rate_in) ppm ppm - 0 - raw + ppm + float + part + + + OSR + osr + osr + int part fc fc fc - raw - part - - - OSR - osr - 4 - raw + float part samp_rate_in samp_rate_in - samp_rate - raw + samp_rate_in + float part @@ -58,7 +57,5 @@ 1 Piotr Krysik -Adaptor of input stream for the GSM receiver. Contains frequency ofset corrector doing also resampling to integer multiplies of GSM sample rate and LP filter filtering GSM channel. -/home/piotr/.grc_gnuradio/gsm_input.py - /home/piotr/Odbiornik_gsm/Dodanie_wielokanalowosci/demonstration (without data)/gsminput.grc +Adaptor of input stream for the GSM receiver. Contains frequency offset corrector and resampler to correct carrier frequency and sampling frequency offsets. At the end it has LP filter for filtering of a GSM channel. diff --git a/hier_blocks/misc_utils/gsm_clock_offset_corrector.grc b/hier_blocks/misc_utils/gsm_clock_offset_corrector.grc index efc1275..99d8e15 100644 --- a/hier_blocks/misc_utils/gsm_clock_offset_corrector.grc +++ b/hier_blocks/misc_utils/gsm_clock_offset_corrector.grc @@ -1,4 +1,5 @@ + Thu Nov 6 10:22:20 2014 @@ -28,6 +29,33 @@ 0 + + variable + + id + samp_rate_out + + + _enabled + True + + + value + samp_rate_in + + + alias + + + + _coordinate + (736, 19) + + + _rotation + 0 + + parameter @@ -67,6 +95,84 @@ 0 + + pad_source + + id + pad_source_0 + + + _enabled + True + + + label + in + + + type + complex + + + vlen + 1 + + + num_streams + 1 + + + optional + False + + + _coordinate + (14, 299) + + + _rotation + 0 + + + + parameter + + id + ppm + + + _enabled + True + + + label + ppm + + + value + 0 + + + type + eng_float + + + short_id + + + + alias + + + + _coordinate + (496, 19) + + + _rotation + 0 + + parameter @@ -114,7 +220,7 @@ _enabled - True + False label @@ -146,10 +252,10 @@ - pad_sink + pad_source id - pad_sink_1 + ppm_in _enabled @@ -157,11 +263,11 @@ label - out + ppm_in type - complex + message vlen @@ -173,11 +279,11 @@ optional - False + True _coordinate - (1184, 333) + (16, 219) _rotation @@ -188,15 +294,15 @@ fractional_resampler_xx id - fractional_resampler_xx_0 + fractional_resampler_xx_0_0 _enabled - True + False type - complex + float phase_shift @@ -224,89 +330,7 @@ _coordinate - (721, 303) - - - _rotation - 0 - - - - pad_source - - id - pad_source_0 - - - _enabled - True - - - label - in - - - type - complex - - - vlen - 1 - - - num_streams - 1 - - - optional - False - - - _coordinate - (14, 299) - - - _rotation - 0 - - - - gsm_controlled_rotator_cc - - id - gsm_controlled_rotator_cc_0 - - - _enabled - True - - - phase_inc - 0 - - - samp_rate - samp_rate_out - - - alias - - - - affinity - - - - minoutbuf - 0 - - - maxoutbuf - 0 - - - _coordinate - (968, 320) + (712, 144) _rotation @@ -353,7 +377,7 @@ _coordinate - (435, 216) + (416, 219) _rotation @@ -364,7 +388,7 @@ fractional_resampler_xx id - fractional_resampler_xx_0_0 + fractional_resampler_xx_0 _enabled @@ -372,7 +396,7 @@ type - float + complex phase_shift @@ -400,124 +424,7 @@ _coordinate - (721, 220) - - - _rotation - 0 - - - - gsm_controlled_const_source_f - - id - gsm_controlled_const_source_f_0 - - - _enabled - True - - - constant - ppm - - - alias - - - - affinity - - - - minoutbuf - 0 - - - maxoutbuf - 0 - - - _coordinate - (182, 216) - - - _rotation - 0 - - - - pad_source - - id - ppm_in - - - _enabled - True - - - label - ppm_in - - - type - message - - - vlen - 1 - - - num_streams - 1 - - - optional - True - - - _coordinate - (13, 216) - - - _rotation - 0 - - - - parameter - - id - ppm - - - _enabled - True - - - label - ppm - - - value - 0 - - - type - eng_float - - - short_id - - - - alias - - - - _coordinate - (496, 19) + (704, 304) _rotation @@ -564,7 +471,128 @@ _coordinate - (410, 333) + (392, 331) + + + _rotation + 0 + + + + pad_sink + + id + pad_sink_1 + + + _enabled + True + + + label + out + + + type + complex + + + vlen + 1 + + + num_streams + 1 + + + optional + False + + + _coordinate + (1112, 331) + + + _rotation + 0 + + + + gsm_controlled_rotator_cc + + id + gsm_controlled_rotator_cc_0 + + + _enabled + True + + + phase_inc + 0 + + + samp_rate + samp_rate_out + + + alias + + + + affinity + + + + minoutbuf + 0 + + + maxoutbuf + 0 + + + _coordinate + (928, 320) + + + _rotation + 0 + + + + gsm_controlled_const_source_f + + id + gsm_controlled_const_source_f_0 + + + _enabled + True + + + constant + ppm + + + alias + + + + affinity + + + + minoutbuf + 0 + + + maxoutbuf + 0 + + + _coordinate + (168, 219) _rotation @@ -611,7 +639,7 @@ _coordinate - (571, 333) + (552, 331) _rotation @@ -687,12 +715,6 @@ 0 constant_msg - - gsm_controlled_const_source_f_0 - blocks_multiply_const_vxx_0 - 0 - 0 - pad_source_0 fractional_resampler_xx_0 @@ -711,12 +733,6 @@ 0 1 - - gsm_controlled_rotator_cc_0 - pad_sink_1 - 0 - 0 - fractional_resampler_xx_0 gsm_controlled_rotator_cc_0 @@ -729,12 +745,6 @@ 0 1 - - gsm_controlled_const_source_f_0 - blocks_multiply_const_vxx_0_0 - 0 - 0 - blocks_multiply_const_vxx_0_0 blocks_add_const_vxx_0 @@ -747,4 +757,28 @@ 0 1 + + blocks_multiply_const_vxx_0 + gsm_controlled_rotator_cc_0 + 0 + 1 + + + gsm_controlled_rotator_cc_0 + pad_sink_1 + 0 + 0 + + + gsm_controlled_const_source_f_0 + blocks_multiply_const_vxx_0_0 + 0 + 0 + + + gsm_controlled_const_source_f_0 + blocks_multiply_const_vxx_0 + 0 + 0 + diff --git a/hier_blocks/receiver/gsm_input.grc b/hier_blocks/receiver/gsm_input.grc index 8d99640..685f0b2 100644 --- a/hier_blocks/receiver/gsm_input.grc +++ b/hier_blocks/receiver/gsm_input.grc @@ -1,4 +1,5 @@ + Thu Nov 6 14:41:06 2014 @@ -65,38 +66,26 @@ - pad_sink + variable id - pad_sink_0 + samp_rate_out _enabled True - label - out + value + 1625000.0/6.0*osr - type - complex - - - vlen - 1 - - - num_streams - 1 - - - optional - False + alias + _coordinate - (706, 213) + (632, 19) _rotation @@ -181,206 +170,6 @@ 0 - - low_pass_filter - - id - low_pass_filter_0_0 - - - _enabled - True - - - type - fir_filter_ccf - - - decim - 1 - - - interp - 1 - - - gain - 1 - - - samp_rate - 1625000.0/6.0*osr - - - cutoff_freq - 125e3 - - - width - 5e3 - - - win - firdes.WIN_HAMMING - - - beta - 6.76 - - - alias - - - - affinity - - - - minoutbuf - 0 - - - maxoutbuf - 0 - - - _coordinate - (502, 165) - - - _rotation - 0 - - - - pad_source - - id - ppm_in - - - _enabled - True - - - label - ppm_in - - - type - message - - - vlen - 1 - - - num_streams - 1 - - - optional - True - - - _coordinate - (91, 242) - - - _rotation - 0 - - - - gsm_clock_offset_corrector - - id - gsm_clock_offset_corrector_0 - - - _enabled - True - - - fc - fc - - - ppm - 0 - - - samp_rate_in - samp_rate_in - - - samp_rate_out - 1625000.0/6.0*4.0 - - - alias - - - - affinity - - - - minoutbuf - 0 - - - maxoutbuf - 0 - - - _coordinate - (279, 190) - - - _rotation - 0 - - - - pad_source - - id - pad_source_0 - - - _enabled - True - - - label - in - - - type - complex - - - vlen - 1 - - - num_streams - 1 - - - optional - False - - - _coordinate - (88, 197) - - - _rotation - 0 - - parameter @@ -459,6 +248,288 @@ 0 + + low_pass_filter + + id + low_pass_filter_0_0 + + + _enabled + True + + + type + fir_filter_ccf + + + decim + 1 + + + interp + 1 + + + gain + 1 + + + samp_rate + samp_rate_out + + + cutoff_freq + 125e3 + + + width + 5e3 + + + win + firdes.WIN_HAMMING + + + beta + 6.76 + + + alias + + + + affinity + + + + minoutbuf + 0 + + + maxoutbuf + 0 + + + _coordinate + (704, 179) + + + _rotation + 0 + + + + pad_sink + + id + pad_sink_0 + + + _enabled + True + + + label + out + + + type + complex + + + vlen + 1 + + + num_streams + 1 + + + optional + False + + + _coordinate + (904, 227) + + + _rotation + 0 + + + + fractional_resampler_xx + + id + fractional_resampler_xx_0 + + + _enabled + True + + + type + complex + + + phase_shift + 0 + + + resamp_ratio + samp_rate_in/samp_rate_out + + + alias + + + + affinity + + + + minoutbuf + 0 + + + maxoutbuf + 0 + + + _coordinate + (488, 216) + + + _rotation + 0 + + + + pad_source + + id + pad_source_0 + + + _enabled + True + + + label + in + + + type + complex + + + vlen + 1 + + + num_streams + 1 + + + optional + False + + + _coordinate + (56, 179) + + + _rotation + 0 + + + + pad_source + + id + ppm_in + + + _enabled + True + + + label + ppm_in + + + type + message + + + vlen + 1 + + + num_streams + 1 + + + optional + True + + + _coordinate + (56, 243) + + + _rotation + 0 + + + + gsm_clock_offset_corrector + + id + gsm_clock_offset_corrector_0 + + + _enabled + True + + + fc + fc + + + ppm + ppm + + + samp_rate_in + samp_rate_in + + + alias + + + + affinity + + + + minoutbuf + 0 + + + maxoutbuf + 0 + + + _coordinate + (280, 195) + + + _rotation + 0 + + low_pass_filter_0_0 pad_sink_0 @@ -466,11 +537,17 @@ 0 - gsm_clock_offset_corrector_0 + fractional_resampler_xx_0 low_pass_filter_0_0 0 0 + + gsm_clock_offset_corrector_0 + fractional_resampler_xx_0 + 0 + 0 + pad_source_0 gsm_clock_offset_corrector_0 diff --git a/python/misc_utils/clock_offset_corrector.py b/python/misc_utils/clock_offset_corrector.py index 0633ae5..9063082 100644 --- a/python/misc_utils/clock_offset_corrector.py +++ b/python/misc_utils/clock_offset_corrector.py @@ -3,7 +3,7 @@ # Gnuradio Python Flow Graph # Title: Clock offset corrector # Author: Piotr Krysik -# Generated: Thu Nov 6 10:22:24 2014 +# Generated: Wed Nov 19 08:38:40 2014 ################################################## from gnuradio import blocks @@ -15,7 +15,7 @@ import math class clock_offset_corrector(gr.hier_block2): - def __init__(self, fc=936.6e6, samp_rate_in=1625000.0/6.0*4.0, samp_rate_out=1625000.0/6.0*4.0, ppm=0): + def __init__(self, fc=936.6e6, ppm=0, samp_rate_in=1625000.0/6.0*4.0): gr.hier_block2.__init__( self, "Clock offset corrector", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), @@ -26,9 +26,13 @@ class clock_offset_corrector(gr.hier_block2): # Parameters ################################################## self.fc = fc - self.samp_rate_in = samp_rate_in - self.samp_rate_out = samp_rate_out self.ppm = ppm + self.samp_rate_in = samp_rate_in + + ################################################## + # Variables + ################################################## + self.samp_rate_out = samp_rate_out = samp_rate_in ################################################## # Blocks @@ -36,7 +40,6 @@ class clock_offset_corrector(gr.hier_block2): self.ppm_in = None;self.message_port_register_hier_out("ppm_in") self.gsm_controlled_rotator_cc_0 = gsm.controlled_rotator_cc(0,samp_rate_out) self.gsm_controlled_const_source_f_0 = gsm.controlled_const_source_f(ppm) - self.fractional_resampler_xx_0_0 = filter.fractional_resampler_ff(0, samp_rate_in/samp_rate_out) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((1.0e-6*samp_rate_in/samp_rate_out, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((fc/samp_rate_out*(2*math.pi)/1e6, )) @@ -45,16 +48,14 @@ class clock_offset_corrector(gr.hier_block2): ################################################## # Connections ################################################## - self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 0), (self.fractional_resampler_xx_0, 0)) - self.connect((self.blocks_multiply_const_vxx_0, 0), (self.fractional_resampler_xx_0_0, 0)) - self.connect((self.blocks_add_const_vxx_0, 0), (self.fractional_resampler_xx_0_0, 1)) - self.connect((self.gsm_controlled_rotator_cc_0, 0), (self, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.gsm_controlled_rotator_cc_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.fractional_resampler_xx_0, 1)) - self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_const_vxx_0, 0)) - self.connect((self.fractional_resampler_xx_0_0, 0), (self.gsm_controlled_rotator_cc_0, 1)) + self.connect((self.blocks_multiply_const_vxx_0, 0), (self.gsm_controlled_rotator_cc_0, 1)) + self.connect((self.gsm_controlled_rotator_cc_0, 0), (self, 0)) + self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) + self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0, 0)) ################################################## # Asynch Message Connections @@ -69,13 +70,20 @@ class clock_offset_corrector(gr.hier_block2): self.fc = fc self.blocks_multiply_const_vxx_0.set_k((self.fc/self.samp_rate_out*(2*math.pi)/1e6, )) + def get_ppm(self): + return self.ppm + + def set_ppm(self, ppm): + self.ppm = ppm + self.gsm_controlled_const_source_f_0.set_constant(self.ppm) + def get_samp_rate_in(self): return self.samp_rate_in def set_samp_rate_in(self, samp_rate_in): self.samp_rate_in = samp_rate_in + self.set_samp_rate_out(self.samp_rate_in) self.fractional_resampler_xx_0.set_resamp_ratio(self.samp_rate_in/self.samp_rate_out) - self.fractional_resampler_xx_0_0.set_resamp_ratio(self.samp_rate_in/self.samp_rate_out) self.blocks_multiply_const_vxx_0_0.set_k((1.0e-6*self.samp_rate_in/self.samp_rate_out, )) self.blocks_add_const_vxx_0.set_k((self.samp_rate_in/self.samp_rate_out, )) @@ -84,17 +92,9 @@ class clock_offset_corrector(gr.hier_block2): def set_samp_rate_out(self, samp_rate_out): self.samp_rate_out = samp_rate_out - self.fractional_resampler_xx_0.set_resamp_ratio(self.samp_rate_in/self.samp_rate_out) - self.gsm_controlled_rotator_cc_0.set_samp_rate(self.samp_rate_out) self.blocks_multiply_const_vxx_0.set_k((self.fc/self.samp_rate_out*(2*math.pi)/1e6, )) - self.fractional_resampler_xx_0_0.set_resamp_ratio(self.samp_rate_in/self.samp_rate_out) + self.fractional_resampler_xx_0.set_resamp_ratio(self.samp_rate_in/self.samp_rate_out) self.blocks_multiply_const_vxx_0_0.set_k((1.0e-6*self.samp_rate_in/self.samp_rate_out, )) + self.gsm_controlled_rotator_cc_0.set_samp_rate(self.samp_rate_out) self.blocks_add_const_vxx_0.set_k((self.samp_rate_in/self.samp_rate_out, )) - def get_ppm(self): - return self.ppm - - def set_ppm(self, ppm): - self.ppm = ppm - self.gsm_controlled_const_source_f_0.set_constant(self.ppm) - diff --git a/python/receiver/gsm_input.py b/python/receiver/gsm_input.py index e1a51b0..ffc7782 100644 --- a/python/receiver/gsm_input.py +++ b/python/receiver/gsm_input.py @@ -4,7 +4,7 @@ # Title: GSM input adaptor # Author: Piotr Krysik # Description: Adaptor of input stream for the GSM receiver. Contains frequency ofset corrector doing also resampling to integer multiplies of GSM sample rate and LP filter filtering GSM channel. -# Generated: Thu Nov 6 14:41:06 2014 +# Generated: Wed Nov 19 08:23:52 2014 ################################################## from gnuradio import filter @@ -29,24 +29,30 @@ class gsm_input(gr.hier_block2): self.fc = fc self.samp_rate_in = samp_rate_in + ################################################## + # Variables + ################################################## + self.samp_rate_out = samp_rate_out = 1625000.0/6.0*osr + ################################################## # Blocks ################################################## self.ppm_in = None;self.message_port_register_hier_out("ppm_in") self.low_pass_filter_0_0 = filter.fir_filter_ccf(1, firdes.low_pass( - 1, 1625000.0/6.0*osr, 125e3, 5e3, firdes.WIN_HAMMING, 6.76)) + 1, samp_rate_out, 125e3, 5e3, firdes.WIN_HAMMING, 6.76)) self.gsm_clock_offset_corrector_0 = gsm.clock_offset_corrector( - fc=fc, + fc=936.6e6, ppm=0, samp_rate_in=samp_rate_in, - samp_rate_out=1625000.0/6.0*4.0, ) + self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0_0, 0), (self, 0)) - self.connect((self.gsm_clock_offset_corrector_0, 0), (self.low_pass_filter_0_0, 0)) + self.connect((self.fractional_resampler_xx_0, 0), (self.low_pass_filter_0_0, 0)) + self.connect((self.gsm_clock_offset_corrector_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self, 0), (self.gsm_clock_offset_corrector_0, 0)) ################################################## @@ -60,13 +66,14 @@ class gsm_input(gr.hier_block2): def set_ppm(self, ppm): self.ppm = ppm + self.gsm_clock_offset_corrector_0.set_ppm(self.ppm) def get_osr(self): return self.osr def set_osr(self, osr): self.osr = osr - self.low_pass_filter_0_0.set_taps(firdes.low_pass(1, 1625000.0/6.0*self.osr, 125e3, 5e3, firdes.WIN_HAMMING, 6.76)) + self.set_samp_rate_out(1625000.0/6.0*self.osr) def get_fc(self): return self.fc @@ -80,5 +87,14 @@ class gsm_input(gr.hier_block2): def set_samp_rate_in(self, samp_rate_in): self.samp_rate_in = samp_rate_in + self.fractional_resampler_xx_0.set_resamp_ratio(self.samp_rate_in/self.samp_rate_out) self.gsm_clock_offset_corrector_0.set_samp_rate_in(self.samp_rate_in) + def get_samp_rate_out(self): + return self.samp_rate_out + + def set_samp_rate_out(self, samp_rate_out): + self.samp_rate_out = samp_rate_out + self.low_pass_filter_0_0.set_taps(firdes.low_pass(1, self.samp_rate_out, 125e3, 5e3, firdes.WIN_HAMMING, 6.76)) + self.fractional_resampler_xx_0.set_resamp_ratio(self.samp_rate_in/self.samp_rate_out) +