def test_div_ff_2 (self): src1_data = ( 5, 9, -15, 1024) src2_data = (10, 3, -5, 64) expected_result = (0.5, 3, 3, 16) op = gr.divide_ff (2) self.help_ff ((src1_data, src2_data), expected_result, op, port_prefix='float_in_')
def __init__(self, options): self.rx = raw.ofdm_demod(options, (options.nsr is not None) and 4 or 2) self.params = self.rx.params symbol_size = self.params.data_tones * gr.sizeof_gr_complex gr.hier_block2.__init__(self, "RX", gr.io_signature(1,1, gr.sizeof_gr_complex), gr.io_signature(1,1, symbol_size)) ff = raw.fix_frame(symbol_size, options.size) self.connect(self, self.rx, (ff,0), self) self.connect((self.rx,1), (ff,1)) # noise-to-signal ratio estimate # TODO: make it a proper output from the block if options.nsr is not None: nsr = gr.divide_ff() self.connect((self.rx,2), gr.integrate_ff(options.size), (nsr,0)) self.connect((self.rx,3), gr.integrate_ff(options.size), (nsr,1)) self.connect(nsr, gr.file_sink(gr.sizeof_float, options.nsr)) # what to do with the output? acq = self.rx.ofdm_recv.frame_acq acq.set_min_symbols(options.size) if options.numpkts is not None: acq.set_num_frames(options.numpkts) self.size = options.size if options.log: self.connect((self.rx,0), gr.file_sink(symbol_size, 'rx-ofdmdemod.dat')) self.connect((self.rx,1), gr.file_sink(gr.sizeof_char, 'rx-ofdmdemod.datb')) self.connect((ff,0), gr.file_sink(symbol_size, 'rx-fixframe.dat'))
def __init__(self, fft_length, pn_weights): gr.hier_block2.__init__(self, "modified_timing_metric", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_float)) assert(len(pn_weights) == fft_length) self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.connect(self,self.input) # P(d) = sum(0 to L-1, conj(delayed(r)) * r) conj = gr.conjugate_cc() mixer = gr.multiply_cc() nominator = gr.fir_filter_ccf(1,[pn_weights[fft_length-i-1]*pn_weights[fft_length/2-i-1] for i in range(fft_length/2)]) self.connect(self.input, delay(gr.sizeof_gr_complex,fft_length/2), conj, (mixer,0)) self.connect(self.input, (mixer,1)) self.connect(mixer, nominator) # moving_avg = P(d) # R(d) denominator = schmidl_denominator(fft_length) # |P(d)| ** 2 / (R(d)) ** 2 p_mag_sqrd = gr.complex_to_mag_squared() r_sqrd = gr.multiply_ff() self.timing_metric = gr.divide_ff() self.connect(nominator, p_mag_sqrd, (self.timing_metric,0)) self.connect(self.input, denominator, (r_sqrd,0)) self.connect(denominator, (r_sqrd,1)) self.connect(r_sqrd, (self.timing_metric,1)) self.connect(self.timing_metric, self)
def test_div_ff_2 (self): src1_data = ( 5, 9, -15, 1024) src2_data = (10, 3, -5, 64) expected_result = (0.5, 3, 3, 16) op = gr.divide_ff () self.help_ff ((src1_data, src2_data), expected_result, op)
def __init__(self, fft_length): gr.hier_block2.__init__(self, "timing_metric", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_float)) self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.connect(self,self.input) # P(d) nominator = schmidl_nominator(fft_length) # R(d) denominator = schmidl_denominator(fft_length) # |P(d)| ** 2 / (R(d)) ** 2 p_mag_sqrd = gr.complex_to_mag_squared() r_sqrd = gr.multiply_ff() self.timing_metric = gr.divide_ff() self.connect(self.input, nominator, p_mag_sqrd, (self.timing_metric,0)) self.connect(self.input, denominator, (r_sqrd,0)) self.connect(denominator, (r_sqrd,1)) self.connect(r_sqrd, (self.timing_metric,1)) self.connect(self.timing_metric, self) # calculate epsilon from P(d), epsilon is normalized fractional frequency offset #angle = gr.complex_to_arg() #self.epsilon = gr.multiply_const_ff(1.0/math.pi) #self.connect(nominator, angle, self.epsilon) try: gr.hier_block.update_var_names(self, "schmidl", vars()) gr.hier_block.update_var_names(self, "schmidl", vars(self)) except: pass
def test_div_ff_1(self): src1_data = (1, 2, 4, -8) expected_result = (1, 0.5, 0.25, -.125) op = gr.divide_ff(1) self.help_ff((src1_data, ), expected_result, op, port_prefix='SINGLE_PORT')
def test_div_ff_3 (self): src1_data = ( 5, 9, -15, 1024) src2_data = (10, 3, -5, 64) src3_data = (2, 3, -.5, -4) expected_result = (0.25, 1, -6, -4) op = gr.divide_ff (3) self.help_ff ((src1_data, src2_data, src3_data), expected_result, op, port_prefix='float_in_')
def test_div_ff_2(self): src1_data = (5, 9, -15, 1024) src2_data = (10, 3, -5, 64) expected_result = (0.5, 3, 3, 16) op = gr.divide_ff(2) self.help_ff((src1_data, src2_data), expected_result, op, port_prefix='float_in_')
def test_div_ff_4 (self): src1_data = ( 5, 9, -15, 1024) src2_data = (10, 3, -5, 64) src3_data = (2, 3, -.5, -4) src4_data = (-0.5, -1 ,-3, 2) expected_result = (-0.5, -1, 2, -2) op = gr.divide_ff (4) self.help_ff ((src1_data, src2_data, src3_data, src4_data), expected_result, op, port_prefix='float_in_')
def test_div_ff_3(self): src1_data = (5, 9, -15, 1024) src2_data = (10, 3, -5, 64) src3_data = (2, 3, -.5, -4) expected_result = (0.25, 1, -6, -4) op = gr.divide_ff(3) self.help_ff((src1_data, src2_data, src3_data), expected_result, op, port_prefix='float_in_')
def test_div_ff_4(self): src1_data = (5, 9, -15, 1024) src2_data = (10, 3, -5, 64) src3_data = (2, 3, -.5, -4) src4_data = (-0.5, -1, -3, 2) expected_result = (-0.5, -1, 2, -2) op = gr.divide_ff(4) self.help_ff((src1_data, src2_data, src3_data, src4_data), expected_result, op, port_prefix='float_in_')
def __init__(self, data_tones, num_symbols, mode=0): symbol_size = data_tones * gr.sizeof_gr_complex gr.hier_block2.__init__(self, "SNR", gr.io_signature2(2,2, symbol_size, symbol_size), gr.io_signature(1,1, gr.sizeof_float)) sub = gr.sub_cc(data_tones) self.connect((self,0), (sub,0)) self.connect((self,1), (sub,1)) err = gr.complex_to_mag_squared(data_tones); self.connect(sub, err); pow = gr.complex_to_mag_squared(data_tones); self.connect((self,1), pow); if mode == 0: # one snr per symbol (num_symbols is ignored) snr = gr.divide_ff() self.connect(pow, gr.vector_to_stream(gr.sizeof_float, data_tones), gr.integrate_ff(data_tones), (snr,0)) self.connect(err, gr.vector_to_stream(gr.sizeof_float, data_tones), gr.integrate_ff(data_tones), (snr,1)) out = snr elif mode == 1: # one snr per packet snr = gr.divide_ff() self.connect(pow, gr.vector_to_stream(gr.sizeof_float, data_tones), gr.integrate_ff(data_tones*num_symbols), (snr,0)) self.connect(err, gr.vector_to_stream(gr.sizeof_float, data_tones), gr.integrate_ff(data_tones*num_symbols), (snr,1)) out = snr elif mode == 2: # one snr per frequency bin snr = gr.divide_ff(data_tones) self.connect(pow, raw.symbol_avg(data_tones, num_symbols), (snr,0)) self.connect(err, raw.symbol_avg(data_tones, num_symbols), (snr,1)) out = gr.vector_to_stream(gr.sizeof_float, data_tones) self.connect(snr, out) self.connect(out, gr.nlog10_ff(10), self)
def __init__(self, audio_rate): gr.hier_block2.__init__( self, "standard_squelch", gr.io_signature(1, 1, gr.sizeof_float), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self.input_node = gr.add_const_ff(0) # FIXME kludge self.low_iir = gr.iir_filter_ffd((0.0193, 0, -0.0193), (1, 1.9524, -0.9615)) self.low_square = gr.multiply_ff() self.low_smooth = gr.single_pole_iir_filter_ff( 1 / (0.01 * audio_rate)) # 100ms time constant self.hi_iir = gr.iir_filter_ffd((0.0193, 0, -0.0193), (1, 1.3597, -0.9615)) self.hi_square = gr.multiply_ff() self.hi_smooth = gr.single_pole_iir_filter_ff(1 / (0.01 * audio_rate)) self.sub = gr.sub_ff() self.add = gr.add_ff() self.gate = gr.threshold_ff(0.3, 0.43, 0) self.squelch_lpf = gr.single_pole_iir_filter_ff(1 / (0.01 * audio_rate)) self.div = gr.divide_ff() self.squelch_mult = gr.multiply_ff() self.connect(self, self.input_node) self.connect(self.input_node, (self.squelch_mult, 0)) self.connect(self.input_node, self.low_iir) self.connect(self.low_iir, (self.low_square, 0)) self.connect(self.low_iir, (self.low_square, 1)) self.connect(self.low_square, self.low_smooth, (self.sub, 0)) self.connect(self.low_smooth, (self.add, 0)) self.connect(self.input_node, self.hi_iir) self.connect(self.hi_iir, (self.hi_square, 0)) self.connect(self.hi_iir, (self.hi_square, 1)) self.connect(self.hi_square, self.hi_smooth, (self.sub, 1)) self.connect(self.hi_smooth, (self.add, 1)) self.connect(self.sub, (self.div, 0)) self.connect(self.add, (self.div, 1)) self.connect(self.div, self.gate, self.squelch_lpf, (self.squelch_mult, 1)) self.connect(self.squelch_mult, self)
def __init__(self, vlen): gr.hier_block2.__init__( self, "snr_estimator", gr.io_signature(2, 2, gr.sizeof_gr_complex * vlen), gr.io_signature(1, 1, gr.sizeof_float)) reference = gr.kludge_copy(gr.sizeof_gr_complex * vlen) received = gr.kludge_copy(gr.sizeof_gr_complex * vlen) self.connect((self, 0), reference) self.connect((self, 1), received) received_conjugated = gr.conjugate_cc(vlen) self.connect(received, received_conjugated) R_innerproduct = gr.multiply_vcc(vlen) self.connect(reference, R_innerproduct) self.connect(received_conjugated, (R_innerproduct, 1)) R_sum = vector_sum_vcc(vlen) self.connect(R_innerproduct, R_sum) R = gr.complex_to_mag_squared() self.connect(R_sum, R) received_magsqrd = gr.complex_to_mag_squared(vlen) reference_magsqrd = gr.complex_to_mag_squared(vlen) self.connect(received, received_magsqrd) self.connect(reference, reference_magsqrd) received_sum = vector_sum_vff(vlen) reference_sum = vector_sum_vff(vlen) self.connect(received_magsqrd, received_sum) self.connect(reference_magsqrd, reference_sum) P = gr.multiply_ff() self.connect(received_sum, (P, 0)) self.connect(reference_sum, (P, 1)) denominator = gr.sub_ff() self.connect(P, denominator) self.connect(R, (denominator, 1)) rho_hat = gr.divide_ff() self.connect(R, rho_hat) self.connect(denominator, (rho_hat, 1)) self.connect(rho_hat, self)
def __init__(self,vlen): gr.hier_block2.__init__(self,"snr_estimator", gr.io_signature(2,2,gr.sizeof_gr_complex*vlen), gr.io_signature(1,1,gr.sizeof_float)) reference = gr.kludge_copy(gr.sizeof_gr_complex*vlen) received = gr.kludge_copy(gr.sizeof_gr_complex*vlen) self.connect((self,0),reference) self.connect((self,1),received) received_conjugated = gr.conjugate_cc(vlen) self.connect(received,received_conjugated) R_innerproduct = gr.multiply_vcc(vlen) self.connect(reference,R_innerproduct) self.connect(received_conjugated,(R_innerproduct,1)) R_sum = vector_sum_vcc(vlen) self.connect(R_innerproduct,R_sum) R = gr.complex_to_mag_squared() self.connect(R_sum,R) received_magsqrd = gr.complex_to_mag_squared(vlen) reference_magsqrd = gr.complex_to_mag_squared(vlen) self.connect(received,received_magsqrd) self.connect(reference,reference_magsqrd) received_sum = vector_sum_vff(vlen) reference_sum = vector_sum_vff(vlen) self.connect(received_magsqrd,received_sum) self.connect(reference_magsqrd,reference_sum) P = gr.multiply_ff() self.connect(received_sum,(P,0)) self.connect(reference_sum,(P,1)) denominator = gr.sub_ff() self.connect(P,denominator) self.connect(R,(denominator,1)) rho_hat = gr.divide_ff() self.connect(R,rho_hat) self.connect(denominator,(rho_hat,1)) self.connect(rho_hat,self)
def __init__(self, fg): self.split = gr.multiply_const_ff(1) self.sqr = gr.multiply_ff() self.int0 = gr.iir_filter_ffd([0.004, 0], [0, 0.999]) self.offs = gr.add_const_ff(-30) self.gain = gr.multiply_const_ff(70) self.log = gr.nlog10_ff(10, 1) self.agc = gr.divide_ff() fg.connect(self.split, (self.agc, 0)) fg.connect(self.split, (self.sqr, 0)) fg.connect(self.split, (self.sqr, 1)) fg.connect(self.sqr, self.int0) fg.connect(self.int0, self.log) fg.connect(self.log, self.offs) fg.connect(self.offs, self.gain) fg.connect(self.gain, (self.agc, 1)) gr.hier_block.__init__(self, fg, self.split, self.agc)
def __init__(self, fg): self.split = gr.multiply_const_ff(1) self.sqr = gr.multiply_ff() self.int0 = gr.iir_filter_ffd([.004, 0], [0, .999]) self.offs = gr.add_const_ff(-30) self.gain = gr.multiply_const_ff(70) self.log = gr.nlog10_ff(10, 1) self.agc = gr.divide_ff() fg.connect(self.split, (self.agc, 0)) fg.connect(self.split, (self.sqr, 0)) fg.connect(self.split, (self.sqr, 1)) fg.connect(self.sqr, self.int0) fg.connect(self.int0, self.log) fg.connect(self.log, self.offs) fg.connect(self.offs, self.gain) fg.connect(self.gain, (self.agc, 1)) gr.hier_block.__init__(self, fg, self.split, self.agc)
def __init__(self, audio_rate): gr.hier_block2.__init__(self, "standard_squelch", gr.io_signature(1, 1, gr.sizeof_float), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self.input_node = gr.add_const_ff(0) # FIXME kludge self.low_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.9524,-0.9615)) self.low_square = gr.multiply_ff() self.low_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) # 100ms time constant self.hi_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.3597,-0.9615)) self.hi_square = gr.multiply_ff() self.hi_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.sub = gr.sub_ff(); self.add = gr.add_ff(); self.gate = gr.threshold_ff(0.3,0.43,0) self.squelch_lpf = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.div = gr.divide_ff() self.squelch_mult = gr.multiply_ff() self.connect (self, self.input_node) self.connect (self.input_node, (self.squelch_mult, 0)) self.connect (self.input_node,self.low_iir) self.connect (self.low_iir,(self.low_square,0)) self.connect (self.low_iir,(self.low_square,1)) self.connect (self.low_square,self.low_smooth,(self.sub,0)) self.connect (self.low_smooth, (self.add,0)) self.connect (self.input_node,self.hi_iir) self.connect (self.hi_iir,(self.hi_square,0)) self.connect (self.hi_iir,(self.hi_square,1)) self.connect (self.hi_square,self.hi_smooth,(self.sub,1)) self.connect (self.hi_smooth, (self.add,1)) self.connect (self.sub, (self.div, 0)) self.connect (self.add, (self.div, 1)) self.connect (self.div, self.gate, self.squelch_lpf, (self.squelch_mult,1)) self.connect (self.squelch_mult, self)
def __init__ ( self, fft_length ): gr.hier_block2.__init__(self, "recursive_timing_metric", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_float)) self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.connect(self, self.input) # P(d) = sum(0 to L-1, conj(delayed(r)) * r) conj = gr.conjugate_cc() mixer = gr.multiply_cc() mix_delay = delay(gr.sizeof_gr_complex,fft_length/2+1) mix_diff = gr.sub_cc() nominator = accumulator_cc() inpdelay = delay(gr.sizeof_gr_complex,fft_length/2) self.connect(self.input, inpdelay, conj, (mixer,0)) self.connect(self.input, (mixer,1)) self.connect(mixer,(mix_diff,0)) self.connect(mixer, mix_delay, (mix_diff,1)) self.connect(mix_diff,nominator) rmagsqrd = gr.complex_to_mag_squared() rm_delay = delay(gr.sizeof_float,fft_length+1) rm_diff = gr.sub_ff() denom = accumulator_ff() self.connect(self.input,rmagsqrd,rm_diff,gr.multiply_const_ff(0.5),denom) self.connect(rmagsqrd,rm_delay,(rm_diff,1)) ps = gr.complex_to_mag_squared() rs = gr.multiply_ff() self.connect(nominator,ps) self.connect(denom,rs) self.connect(denom,(rs,1)) div = gr.divide_ff() self.connect(ps,div) self.connect(rs,(div,1)) self.connect(div,self)
def __init__(self, fft_length): gr.hier_block2.__init__(self, "recursive_timing_metric", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float)) self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.connect(self, self.input) # P(d) = sum(0 to L-1, conj(delayed(r)) * r) conj = gr.conjugate_cc() mixer = gr.multiply_cc() mix_delay = delay(gr.sizeof_gr_complex, fft_length / 2 + 1) mix_diff = gr.sub_cc() nominator = accumulator_cc() inpdelay = delay(gr.sizeof_gr_complex, fft_length / 2) self.connect(self.input, inpdelay, conj, (mixer, 0)) self.connect(self.input, (mixer, 1)) self.connect(mixer, (mix_diff, 0)) self.connect(mixer, mix_delay, (mix_diff, 1)) self.connect(mix_diff, nominator) rmagsqrd = gr.complex_to_mag_squared() rm_delay = delay(gr.sizeof_float, fft_length + 1) rm_diff = gr.sub_ff() denom = accumulator_ff() self.connect(self.input, rmagsqrd, rm_diff, gr.multiply_const_ff(0.5), denom) self.connect(rmagsqrd, rm_delay, (rm_diff, 1)) ps = gr.complex_to_mag_squared() rs = gr.multiply_ff() self.connect(nominator, ps) self.connect(denom, rs) self.connect(denom, (rs, 1)) div = gr.divide_ff() self.connect(ps, div) self.connect(rs, (div, 1)) self.connect(div, self)
def __init__(self, fg, audio_rate): self.input_node = gr.add_const_ff(0) # FIXME kludge self.low_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.9524,-0.9615)) self.low_square = gr.multiply_ff() self.low_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) # 100ms time constant self.hi_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.3597,-0.9615)) self.hi_square = gr.multiply_ff() self.hi_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.sub = gr.sub_ff(); self.add = gr.add_ff(); self.gate = gr.threshold_ff(0.3,0.43,0) self.squelch_lpf = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.div = gr.divide_ff() self.squelch_mult = gr.multiply_ff() fg.connect (self.input_node, (self.squelch_mult, 0)) fg.connect (self.input_node,self.low_iir) fg.connect (self.low_iir,(self.low_square,0)) fg.connect (self.low_iir,(self.low_square,1)) fg.connect (self.low_square,self.low_smooth,(self.sub,0)) fg.connect (self.low_smooth, (self.add,0)) fg.connect (self.input_node,self.hi_iir) fg.connect (self.hi_iir,(self.hi_square,0)) fg.connect (self.hi_iir,(self.hi_square,1)) fg.connect (self.hi_square,self.hi_smooth,(self.sub,1)) fg.connect (self.hi_smooth, (self.add,1)) fg.connect (self.sub, (self.div, 0)) fg.connect (self.add, (self.div, 1)) fg.connect (self.div, self.gate, self.squelch_lpf, (self.squelch_mult,1)) gr.hier_block.__init__(self, fg, self.input_node, self.squelch_mult)
def __init__( self ): gr.hier_block2.__init__(self, "agc", gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,1,gr.sizeof_float)) self.split = gr.multiply_const_ff( 1 ) self.sqr = gr.multiply_ff( ) self.int0 = gr.iir_filter_ffd( [.004, 0], [0, .999] ) self.offs = gr.add_const_ff( -30 ) self.gain = gr.multiply_const_ff( 70 ) self.log = gr.nlog10_ff( 10, 1 ) self.agc = gr.divide_ff( ) self.connect(self, self.split) self.connect(self.split, (self.agc, 0)) self.connect(self.split, (self.sqr, 0)) self.connect(self.split, (self.sqr, 1)) self.connect(self.sqr, self.int0) self.connect(self.int0, self.log) self.connect(self.log, self.offs) self.connect(self.offs, self.gain) self.connect(self.gain, (self.agc, 1)) self.connect(self.agc, self)
def __init__(self): gr.hier_block2.__init__(self, "agc", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) self.split = gr.multiply_const_ff(1) self.sqr = gr.multiply_ff() self.int0 = gr.iir_filter_ffd([.004, 0], [0, .999]) self.offs = gr.add_const_ff(-30) self.gain = gr.multiply_const_ff(70) self.log = gr.nlog10_ff(10, 1) self.agc = gr.divide_ff() self.connect(self, self.split) self.connect(self.split, (self.agc, 0)) self.connect(self.split, (self.sqr, 0)) self.connect(self.split, (self.sqr, 1)) self.connect(self.sqr, self.int0) self.connect(self.int0, self.log) self.connect(self.log, self.offs) self.connect(self.offs, self.gain) self.connect(self.gain, (self.agc, 1)) self.connect(self.agc, self)
def __init__(self, fft_length, pn_weights): gr.hier_block2.__init__(self, "modified_timing_metric", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float)) assert (len(pn_weights) == fft_length) self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.connect(self, self.input) # P(d) = sum(0 to L-1, conj(delayed(r)) * r) conj = gr.conjugate_cc() mixer = gr.multiply_cc() nominator = gr.fir_filter_ccf(1, [ pn_weights[fft_length - i - 1] * pn_weights[fft_length / 2 - i - 1] for i in range(fft_length / 2) ]) self.connect(self.input, delay(gr.sizeof_gr_complex, fft_length / 2), conj, (mixer, 0)) self.connect(self.input, (mixer, 1)) self.connect(mixer, nominator) # moving_avg = P(d) # R(d) denominator = schmidl_denominator(fft_length) # |P(d)| ** 2 / (R(d)) ** 2 p_mag_sqrd = gr.complex_to_mag_squared() r_sqrd = gr.multiply_ff() self.timing_metric = gr.divide_ff() self.connect(nominator, p_mag_sqrd, (self.timing_metric, 0)) self.connect(self.input, denominator, (r_sqrd, 0)) self.connect(denominator, (r_sqrd, 1)) self.connect(r_sqrd, (self.timing_metric, 1)) self.connect(self.timing_metric, self)
def __init__(self, fft_length): gr.hier_block2.__init__(self, "timing_metric", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float)) self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.connect(self, self.input) # P(d) nominator = schmidl_nominator(fft_length) # R(d) denominator = schmidl_denominator(fft_length) # |P(d)| ** 2 / (R(d)) ** 2 p_mag_sqrd = gr.complex_to_mag_squared() r_sqrd = gr.multiply_ff() self.timing_metric = gr.divide_ff() self.connect(self.input, nominator, p_mag_sqrd, (self.timing_metric, 0)) self.connect(self.input, denominator, (r_sqrd, 0)) self.connect(denominator, (r_sqrd, 1)) self.connect(r_sqrd, (self.timing_metric, 1)) self.connect(self.timing_metric, self) # calculate epsilon from P(d), epsilon is normalized fractional frequency offset #angle = gr.complex_to_arg() #self.epsilon = gr.multiply_const_ff(1.0/math.pi) #self.connect(nominator, angle, self.epsilon) try: gr.hier_block.update_var_names(self, "schmidl", vars()) gr.hier_block.update_var_names(self, "schmidl", vars(self)) except: pass
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Ofdm Rx") ################################################## # Variables ################################################## self.window_size = window_size = 48 self.sync_length = sync_length = 320 - 64 self.samp_rate = samp_rate = 10e6 self.gain = gain = 0 self.freq = freq = 5.825e9 ################################################## # Blocks ################################################## self._samp_rate_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.samp_rate, callback=self.set_samp_rate, label="Sample Rate", choices=[10e6, 20e6], labels=["10 Mhz", "20 Mhz"], style=wx.RA_HORIZONTAL, ) self.Add(self._samp_rate_chooser) _gain_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, label='gain', converter=forms.float_converter(), proportion=0, ) self._gain_slider = forms.slider( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_gain_sizer) self._freq_chooser = forms.drop_down( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label="Channel", choices=[2412000000.0, 2417000000.0, 2422000000.0, 2427000000.0, 2432000000.0, 2437000000.0, 2442000000.0, 2447000000.0, 2452000000.0, 2457000000.0, 2462000000.0, 2467000000.0, 2472000000.0, 2484000000.0, 5170000000.0, 5180000000.0, 5190000000.0, 5200000000.0, 5210000000.0, 5220000000.0, 5230000000.0, 5240000000.0, 5260000000.0, 5280000000.0, 5300000000.0, 5320000000.0, 5500000000.0, 5520000000.0, 5540000000.0, 5560000000.0, 5580000000.0, 5600000000.0, 5620000000.0, 5640000000.0, 5660000000.0, 5680000000.0, 5700000000.0, 5745000000.0, 5765000000.0, 5785000000.0, 5805000000.0, 5825000000.0, 5860000000.0, 5870000000.0, 5880000000.0, 5890000000.0, 5900000000.0, 5910000000.0, 5920000000.0], labels=[' 1 | 2412.0 | 11g', ' 2 | 2417.0 | 11g', ' 3 | 2422.0 | 11g', ' 4 | 2427.0 | 11g', ' 5 | 2432.0 | 11g', ' 6 | 2437.0 | 11g', ' 7 | 2442.0 | 11g', ' 8 | 2447.0 | 11g', ' 9 | 2452.0 | 11g', ' 10 | 2457.0 | 11g', ' 11 | 2462.0 | 11g', ' 12 | 2467.0 | 11g', ' 13 | 2472.0 | 11g', ' 14 | 2484.0 | 11g', ' 34 | 5170.0 | 11a', ' 36 | 5180.0 | 11a', ' 38 | 5190.0 | 11a', ' 40 | 5200.0 | 11a', ' 42 | 5210.0 | 11a', ' 44 | 5220.0 | 11a', ' 46 | 5230.0 | 11a', ' 48 | 5240.0 | 11a', ' 52 | 5260.0 | 11a', ' 56 | 5280.0 | 11a', ' 58 | 5300.0 | 11a', ' 60 | 5320.0 | 11a', '100 | 5500.0 | 11a', '104 | 5520.0 | 11a', '108 | 5540.0 | 11a', '112 | 5560.0 | 11a', '116 | 5580.0 | 11a', '120 | 5600.0 | 11a', '124 | 5620.0 | 11a', '128 | 5640.0 | 11a', '132 | 5660.0 | 11a', '136 | 5680.0 | 11a', '140 | 5700.0 | 11a', '149 | 5745.0 | 11a', '153 | 5765.0 | 11a', '157 | 5785.0 | 11a', '161 | 5805.0 | 11a', '165 | 5825.0 | 11a', '172 | 5860.0 | 11p', '174 | 5870.0 | 11p', '176 | 5880.0 | 11p', '178 | 5890.0 | 11p', '180 | 5900.0 | 11p', '182 | 5910.0 | 11p', '184 | 5920.0 | 11p'], ) self.Add(self._freq_chooser) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(gain, 0) self.ieee802_1_ofdm_sync_short_0 = gr_ieee802_11.ofdm_sync_short(0.8, 80 * 80, 2, False) self.ieee802_1_ofdm_sync_long_0 = gr_ieee802_11.ofdm_sync_long(sync_length, 100, False) self.ieee802_1_ofdm_equalize_symbols_0 = gr_ieee802_11.ofdm_equalize_symbols(False) self.ieee802_1_ofdm_decode_signal_0 = gr_ieee802_11.ofdm_decode_signal(False) self.ieee802_1_ofdm_decode_mac_0 = gr_ieee802_11.ofdm_decode_mac(False) self.ieee802_11_ofdm_parse_mac_0 = gr_ieee802_11.ofdm_parse_mac(True) self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, 64) self.gr_socket_pdu_0 = gr.socket_pdu("UDP_SERVER", "", "12345", 10000) self.gr_skiphead_0 = gr.skiphead(gr.sizeof_gr_complex*1, 20000000) self.gr_multiply_xx_0 = gr.multiply_vcc(1) self.gr_divide_xx_0 = gr.divide_ff(1) self.gr_delay_0_0 = gr.delay(gr.sizeof_gr_complex*1, sync_length) self.gr_delay_0 = gr.delay(gr.sizeof_gr_complex*1, 16) self.gr_conjugate_cc_0 = gr.conjugate_cc() self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(1) self.gr_complex_to_mag_0 = gr.complex_to_mag(1) self.fir_filter_xxx_0_0 = filter.fir_filter_ccf(1, ([1]*window_size)) self.fir_filter_xxx_0 = filter.fir_filter_fff(1, ([1]*window_size)) self.fft_vxx_0 = fft.fft_vcc(64, True, (), True, 1) ################################################## # Connections ################################################## self.connect((self.uhd_usrp_source_0, 0), (self.gr_skiphead_0, 0)) self.connect((self.gr_skiphead_0, 0), (self.gr_complex_to_mag_squared_0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_complex_to_mag_squared_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.gr_skiphead_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.gr_conjugate_cc_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_complex_to_mag_0, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.fir_filter_xxx_0_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.gr_complex_to_mag_0, 0)) self.connect((self.gr_skiphead_0, 0), (self.gr_delay_0, 0)) self.connect((self.gr_delay_0, 0), (self.gr_conjugate_cc_0, 0)) self.connect((self.fft_vxx_0, 0), (self.ieee802_1_ofdm_equalize_symbols_0, 0)) self.connect((self.ieee802_1_ofdm_equalize_symbols_0, 0), (self.ieee802_1_ofdm_decode_signal_0, 0)) self.connect((self.ieee802_1_ofdm_decode_signal_0, 0), (self.ieee802_1_ofdm_decode_mac_0, 0)) self.connect((self.ieee802_1_ofdm_sync_short_0, 0), (self.gr_delay_0_0, 0)) self.connect((self.gr_delay_0, 0), (self.ieee802_1_ofdm_sync_short_0, 0)) self.connect((self.gr_divide_xx_0, 0), (self.ieee802_1_ofdm_sync_short_0, 1)) self.connect((self.gr_delay_0_0, 0), (self.ieee802_1_ofdm_sync_long_0, 1)) self.connect((self.ieee802_1_ofdm_sync_short_0, 0), (self.ieee802_1_ofdm_sync_long_0, 0)) self.connect((self.ieee802_1_ofdm_sync_long_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self.ieee802_1_ofdm_decode_mac_0, "out", self.ieee802_11_ofdm_parse_mac_0, "in") self.msg_connect(self.ieee802_11_ofdm_parse_mac_0, "out", self.gr_socket_pdu_0, "pdus")
def test_div_ff_1 (self): src1_data = (1, 2, 4, -8) expected_result = (1, 0.5, 0.25, -.125) op = gr.divide_ff (1) self.help_ff ((src1_data,), expected_result, op, port_prefix='SINGLE_PORT')
def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.frame_1_menubar = wx.MenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wx.Menu() self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.frame_1_menubar.Append(wxglade_tmp_menu, "File") # Menu Bar end self.panel_1 = wx.Panel(self, -1) self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB") self.button_2 = wx.Button(self, ID_BUTTON_2, "USB") self.button_3 = wx.Button(self, ID_BUTTON_3, "AM") self.button_4 = wx.Button(self, ID_BUTTON_4, "CW") self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper") self.slider_fcutoff_hi = wx.Slider(self, ID_SLIDER_1, 0, -15798, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower") self.slider_fcutoff_lo = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15798, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_5 = wx.Panel(self, -1) self.label_1 = wx.StaticText(self, -1, " Band\nCenter") self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "") self.panel_6 = wx.Panel(self, -1) self.panel_7 = wx.Panel(self, -1) self.panel_2 = wx.Panel(self, -1) self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq") self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000) self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100) self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol") self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500) self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20) self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time") self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew") self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd") self.panel_3 = wx.Panel(self, -1) self.label_2 = wx.StaticText(self, -1, "PGA ") self.panel_4 = wx.Panel(self, -1) self.panel_8 = wx.Panel(self, -1) self.panel_9 = wx.Panel(self, -1) self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier") self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.label_4 = wx.StaticText(self, -1, "Antenna Tune") self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_10 = wx.Panel(self, -1) self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune") self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate") self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset") self.panel_11 = wx.Panel(self, -1) self.panel_12 = wx.Panel(self, -1) self.__set_properties() self.__do_layout() # end wxGlade parser = OptionParser(option_class=eng_option) parser.add_option("", "--address", type="string", default="addr=192.168.10.2", help="Address of UHD device, [default=%default]") parser.add_option("-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ") parser.add_option( "-s", "--samp-rate", type="eng_float", default=256e3, help="set sample rate (bandwidth) [default=%default]") parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE") parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option( "-O", "--audio-output", type="string", default="", help="audio output device name. E.g., hw:0,0, /dev/dsp, or pulse") (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq input_rate = options.samp_rate self.slider_range = input_rate * 0.9375 self.f_lo = self.usrp_center - (self.slider_range / 2) self.f_hi = self.usrp_center + (self.slider_range / 2) self.af_sample_rate = 32000 fir_decim = long(input_rate / self.af_sample_rate) # data point arrays for antenna tuner self.xdata = [] self.ydata = [] self.tb = gr.top_block() # radio variables, initial conditions self.frequency = self.usrp_center # these map the frequency slider (0-6000) to the actual range self.f_slider_offset = self.f_lo self.f_slider_scale = 10000 self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi) self.text_ctrl_1.SetValue(str(int(self.usrp_center))) self.slider_5.SetValue(0) self.AM_mode = False self.slider_3.SetValue( (self.frequency - self.f_slider_offset) / self.f_slider_scale) self.spin_ctrl_1.SetValue(int(self.frequency)) POWERMATE = True try: self.pm = powermate.powermate(self) except: sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n") POWERMATE = False if POWERMATE: powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate) powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton) self.active_button = 7 # command line options if options.audio_file == "": SAVE_AUDIO_TO_FILE = False else: SAVE_AUDIO_TO_FILE = True if options.radio_file == "": SAVE_RADIO_TO_FILE = False else: SAVE_RADIO_TO_FILE = True if options.input_file == "": self.PLAY_FROM_USRP = True else: self.PLAY_FROM_USRP = False if self.PLAY_FROM_USRP: self.src = uhd.usrp_source(device_addr=options.address, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) self.src.set_samp_rate(input_rate) input_rate = self.src.get_samp_rate() self.src.set_center_freq(self.usrp_center, 0) self.tune_offset = 0 else: self.src = gr.file_source(gr.sizeof_short, options.input_file) self.tune_offset = 2200 # 2200 works for 3.5-4Mhz band # convert rf data in interleaved short int form to complex s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src_f2c = gr.float_to_complex() self.tb.connect(self.src, s2ss) self.tb.connect((s2ss, 0), s2f1) self.tb.connect((s2ss, 1), s2f2) self.tb.connect(s2f1, (src_f2c, 0)) self.tb.connect(s2f2, (src_f2c, 1)) # save radio data to a file if SAVE_RADIO_TO_FILE: radio_file = gr.file_sink(gr.sizeof_short, options.radio_file) self.tb.connect(self.src, radio_file) # 2nd DDC xlate_taps = gr.firdes.low_pass ( \ 1.0, input_rate, 16e3, 4e3, gr.firdes.WIN_HAMMING ) self.xlate = gr.freq_xlating_fir_filter_ccf ( \ fir_decim, xlate_taps, self.tune_offset, input_rate ) # Complex Audio filter audio_coeffs = gr.firdes.complex_band_pass( 1.0, # gain self.af_sample_rate, # sample rate -3000, # low cutoff 0, # high cutoff 100, # transition gr.firdes.WIN_HAMMING) # window self.slider_fcutoff_hi.SetValue(0) self.slider_fcutoff_lo.SetValue(-3000) self.audio_filter = gr.fir_filter_ccc(1, audio_coeffs) # Main +/- 16Khz spectrum display self.fft = fftsink2.fft_sink_c(self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)) # AM Sync carrier if AM_SYNC_DISPLAY: self.fft2 = fftsink.fft_sink_c(self.tb, self.panel_9, y_per_div=20, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)) c2f = gr.complex_to_float() # AM branch self.sel_am = gr.multiply_const_cc(0) # the following frequencies turn out to be in radians/sample # gr.pll_refout_cc(alpha,beta,min_freq,max_freq) # suggested alpha = X, beta = .25 * X * X pll = gr.pll_refout_cc(.5, .0625, (2. * math.pi * 7.5e3 / self.af_sample_rate), (2. * math.pi * 6.5e3 / self.af_sample_rate)) self.pll_carrier_scale = gr.multiply_const_cc(complex(10, 0)) am_det = gr.multiply_cc() # these are for converting +7.5kHz to -7.5kHz # for some reason gr.conjugate_cc() adds noise ?? c2f2 = gr.complex_to_float() c2f3 = gr.complex_to_float() f2c = gr.float_to_complex() phaser1 = gr.multiply_const_ff(1) phaser2 = gr.multiply_const_ff(-1) # filter for pll generated carrier pll_carrier_coeffs = gr.firdes.complex_band_pass( 2.0, # gain self.af_sample_rate, # sample rate 7400, # low cutoff 7600, # high cutoff 100, # transition gr.firdes.WIN_HAMMING) # window self.pll_carrier_filter = gr.fir_filter_ccc(1, pll_carrier_coeffs) self.sel_sb = gr.multiply_const_ff(1) combine = gr.add_ff() #AGC sqr1 = gr.multiply_ff() intr = gr.iir_filter_ffd([.004, 0], [0, .999]) offset = gr.add_const_ff(1) agc = gr.divide_ff() self.scale = gr.multiply_const_ff(0.00001) dst = audio.sink(long(self.af_sample_rate), options.audio_output) if self.PLAY_FROM_USRP: self.tb.connect(self.src, self.xlate, self.fft) else: self.tb.connect(src_f2c, self.xlate, self.fft) self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0)) self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3) self.tb.connect((c2f3, 0), phaser1, (f2c, 0)) self.tb.connect((c2f3, 1), phaser2, (f2c, 1)) self.tb.connect(f2c, (am_det, 1)) self.tb.connect(am_det, c2f2, (combine, 0)) self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1)) if AM_SYNC_DISPLAY: self.tb.connect(self.pll_carrier_filter, self.fft2) self.tb.connect(combine, self.scale) self.tb.connect(self.scale, (sqr1, 0)) self.tb.connect(self.scale, (sqr1, 1)) self.tb.connect(sqr1, intr, offset, (agc, 1)) self.tb.connect(self.scale, (agc, 0)) self.tb.connect(agc, dst) if SAVE_AUDIO_TO_FILE: f_out = gr.file_sink(gr.sizeof_short, options.audio_file) sc1 = gr.multiply_const_ff(64000) f2s1 = gr.float_to_short() self.tb.connect(agc, sc1, f2s1, f_out) self.tb.start() # for mouse position reporting on fft display self.fft.win.Bind(wx.EVT_LEFT_UP, self.Mouse) # and left click to re-tune self.fft.win.Bind(wx.EVT_LEFT_DOWN, self.Click) # start a timer to check for web commands if WEB_CONTROL: self.timer = UpdateTimer(self, 1000) # every 1000 mSec, 1 Sec wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb) wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb) wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am) wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw) wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd) wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew) wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate) wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button) wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune) wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume) wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga) wx.EVT_SLIDER(self, ID_SLIDER_6, self.am_carrier) wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune) wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune) wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def __init__(self, vlen): gr.hier_block2.__init__(self, "snr_estimator", gr.io_signature2(2,2,gr.sizeof_gr_complex,gr.sizeof_char), gr.io_signature (1,1,gr.sizeof_float)) data_in = (self,0) trig_in = (self,1) snr_out = (self,0) ## Preamble Extraction sampler = vector_sampler(gr.sizeof_gr_complex,vlen) self.connect(data_in,sampler) self.connect(trig_in,(sampler,1)) ## Algorithm implementation estim = sc_snr_estimator(vlen) self.connect(sampler,estim) self.connect(estim,snr_out) return ## Split block into two parts splitter = gr.vector_to_streams(gr.sizeof_gr_complex*vlen/2,2) self.connect(sampler,splitter) ## Conjugate first half block conj = gr.conjugate_cc(vlen/2) self.connect(splitter,conj) ## Vector multiplication of both half blocks vmult = gr.multiply_vcc(vlen/2) self.connect(conj,vmult) self.connect((splitter,1),(vmult,1)) ## Sum of Products psum = vector_sum_vcc(vlen/2) self.connect(vmult,psum) ## Magnitude of P(d) p_mag = gr.complex_to_mag() self.connect(psum,p_mag) ## Squared Magnitude of block r_magsqrd = gr.complex_to_mag_squared(vlen) self.connect(sampler,r_magsqrd) ## Sum of squared second half block r_sum = vector_sum_vff(vlen) self.connect(r_magsqrd,r_sum) ## Square Root of Metric m_sqrt = gr.divide_ff() self.connect(p_mag,(m_sqrt,0)) self.connect(r_sum,gr.multiply_const_ff(0.5),(m_sqrt,1)) ## Denominator of SNR estimate denom = gr.add_const_ff(1) neg_m_sqrt = gr.multiply_const_ff(-1.0) self.connect(m_sqrt,limit_vff(1,1-2e-5,-1000),neg_m_sqrt,denom) ## SNR estimate snr_est = gr.divide_ff() self.connect(m_sqrt,(snr_est,0)) self.connect(denom,(snr_est,1)) ## Setup Output Connections self.connect(snr_est,self)
def __init__(self, freq_corr=0, N_id_1=134, avg_frames=1, N_id_2=0, decim=16): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr2 Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq_corr = freq_corr self.N_id_1 = N_id_1 self.avg_frames = avg_frames self.N_id_2 = N_id_2 self.decim = decim ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720*5/decim self.samp_rate = samp_rate = 30720e3/decim self.rot = rot = 0 self.noise_level = noise_level = 0 self.fft_size = fft_size = 2048/decim ################################################## # Blocks ################################################## _rot_sizer = wx.BoxSizer(wx.VERTICAL) self._rot_text_box = forms.text_box( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, label='rot', converter=forms.float_converter(), proportion=0, ) self._rot_slider = forms.slider( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rot_sizer) _noise_level_sizer = wx.BoxSizer(wx.VERTICAL) self._noise_level_text_box = forms.text_box( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, label='noise_level', converter=forms.float_converter(), proportion=0, ) self._noise_level_slider = forms.slider( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_noise_level_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.gr_vector_to_stream_1 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_to_stream_0_2 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_to_stream_0_1 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_to_stream_0_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_float*1, fft_size) self.gr_vector_source_x_0_0_0 = gr.vector_source_c((gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0_0 = gr.vector_source_c((gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0 = gr.vector_source_c((gen_sss_fd( N_id_1, N_id_2, fft_size).get_sss(True)), True, fft_size) self.gr_stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.gr_repeat_0 = gr.repeat(gr.sizeof_float*1, fft_size) self.gr_null_sink_0_0 = gr.null_sink(gr.sizeof_gr_complex*1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0) self.gr_multiply_xx_1 = gr.multiply_vcc(1) self.gr_multiply_xx_0 = gr.multiply_vcc(fft_size) self.gr_multiply_const_vxx_1 = gr.multiply_const_vcc((1/1500., )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((exp(rot*2*numpy.pi*1j), )) self.gr_interleave_0 = gr.interleave(gr.sizeof_gr_complex*fft_size) self.gr_integrate_xx_0 = gr.integrate_ff(fft_size) self.gr_float_to_complex_0_0 = gr.float_to_complex(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/home/user/git/gr-lte/gr-lte/test/foo_pss0_sss_in.cfile", True) self.gr_fft_vxx_1 = gr.fft_vcc(fft_size, False, (window.blackmanharris(1024)), True, 1) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) self.gr_divide_xx_0_1 = gr.divide_cc(1) self.gr_divide_xx_0_0 = gr.divide_ff(1) self.gr_divide_xx_0 = gr.divide_cc(1) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex*fft_size) self.gr_conjugate_cc_1 = gr.conjugate_cc() self.gr_conjugate_cc_0 = gr.conjugate_cc() self.gr_complex_to_mag_squared_0_0 = gr.complex_to_mag_squared(1) self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(fft_size) self.gr_add_xx_0 = gr.add_vcc(1) self.gr_add_const_vxx_0 = gr.add_const_vff((1, )) self.const_source_x_0_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_conjugate_cc_0, 0), (self.gr_stream_to_vector_0_0, 0)) self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_complex_to_mag_squared_0, 0)) self.connect((self.gr_complex_to_mag_squared_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_integrate_xx_0, 0)) self.connect((self.gr_integrate_xx_0, 0), (self.gr_repeat_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_vector_to_stream_0_0, 0)) self.connect((self.gr_vector_to_stream_0_1, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_divide_xx_0, 0), (self.gr_multiply_xx_1, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_conjugate_cc_1, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_vector_to_stream_0_1, 0)) self.connect((self.gr_repeat_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.const_source_x_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.gr_conjugate_cc_1, 0)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.gr_complex_to_mag_squared_0_0, 0)) self.connect((self.gr_complex_to_mag_squared_0_0, 0), (self.gr_divide_xx_0_0, 0)) self.connect((self.gr_repeat_0, 0), (self.gr_divide_xx_0_0, 1)) self.connect((self.gr_divide_xx_0_0, 0), (self.gr_add_const_vxx_0, 0)) self.connect((self.gr_add_const_vxx_0, 0), (self.gr_float_to_complex_0_0, 0)) self.connect((self.const_source_x_0_0, 0), (self.gr_float_to_complex_0_0, 1)) self.connect((self.gr_float_to_complex_0_0, 0), (self.gr_divide_xx_0_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_divide_xx_0_1, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_vector_to_stream_0_2, 0), (self.gr_conjugate_cc_0, 0)) self.connect((self.gr_divide_xx_0_1, 0), (self.gr_null_sink_0, 0)) self.connect((self.gr_vector_source_x_0, 0), (self.gr_interleave_0, 1)) self.connect((self.gr_interleave_0, 0), (self.gr_fft_vxx_1, 0)) self.connect((self.gr_fft_vxx_1, 0), (self.gr_vector_to_stream_1, 0)) self.connect((self.gr_vector_source_x_0_0, 0), (self.gr_interleave_0, 0)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_2, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_vector_to_stream_1, 0), (self.gr_add_xx_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_vector_to_stream_0_1, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_null_sink_0_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.gr_divide_xx_0_1, 0), (self.wxgui_scopesink2_0, 0))
def __init__(self, fft_length, cp_length, half_sync, logging=False): gr.hier_block2.__init__(self, "ofdm_sync_pn", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature3(3, 3, # Output signature gr.sizeof_gr_complex, # delayed input gr.sizeof_float, # fine frequency offset gr.sizeof_char # timing indicator )) if half_sync: period = fft_length/2 window = fft_length/2 else: # full symbol period = fft_length + cp_length window = fft_length # makes the plateau cp_length long # Calculate the frequency offset from the correlation of the preamble x_corr = gr.multiply_cc() self.connect(self, gr.conjugate_cc(), (x_corr, 0)) self.connect(self, gr.delay(gr.sizeof_gr_complex, period), (x_corr, 1)) P_d = gr.moving_average_cc(window, 1.0) self.connect(x_corr, P_d) P_d_angle = gr.complex_to_arg() self.connect(P_d, P_d_angle) # Get the power of the input signal to normalize the output of the correlation R_d = gr.moving_average_ff(window, 1.0) self.connect(self, gr.complex_to_mag_squared(), R_d) R_d_squared = gr.multiply_ff() # this is retarded self.connect(R_d, (R_d_squared, 0)) self.connect(R_d, (R_d_squared, 1)) M_d = gr.divide_ff() self.connect(P_d, gr.complex_to_mag_squared(), (M_d, 0)) self.connect(R_d_squared, (M_d, 1)) # Now we need to detect peak of M_d # NOTE: replaced fir_filter with moving_average for clarity # the peak is up to cp_length long, but noisy, so average it out #matched_filter_taps = [1.0/cp_length for i in range(cp_length)] #matched_filter = gr.fir_filter_fff(1, matched_filter_taps) matched_filter = gr.moving_average_ff(cp_length, 1.0/cp_length) # NOTE: the look_ahead parameter doesn't do anything # these parameters are kind of magic, increase 1 and 2 (==) to be more tolerant #peak_detect = raw.peak_detector_fb(0.55, 0.55, 30, 0.001) peak_detect = raw.peak_detector_fb(0.25, 0.25, 30, 0.001) # NOTE: gr.peak_detector_fb is broken! #peak_detect = gr.peak_detector_fb(0.55, 0.55, 30, 0.001) #peak_detect = gr.peak_detector_fb(0.45, 0.45, 30, 0.001) #peak_detect = gr.peak_detector_fb(0.30, 0.30, 30, 0.001) # offset by -1 self.connect(M_d, matched_filter, gr.add_const_ff(-1), peak_detect) # peak_detect indicates the time M_d is highest, which is the end of the symbol. # We should try to sample in the middle of the plateau!! # FIXME until we figure out how to do this, just offset by cp_length/2 offset = 6 #cp_length/2 # nco(t) = P_d_angle(t-offset) sampled at peak_detect(t) # modulate input(t - fft_length) by nco(t) # signal to sample input(t) at t-offset # # We can't delay by < 0 so instead: # input is delayed by fft_length # P_d_angle is delayed by offset # signal to sample is delayed by fft_length - offset # phi = gr.sample_and_hold_ff() self.connect(peak_detect, (phi,1)) self.connect(P_d_angle, gr.delay(gr.sizeof_float, offset), (phi,0)) #self.connect(P_d_angle, matched_filter2, (phi,0)) # why isn't this better?!? # FIXME: we add fft_length delay so that the preamble is nco corrected too # BUT is this buffering worth it? consider implementing sync as a proper block # delay the input signal to follow the frequency offset signal self.connect(self, gr.delay(gr.sizeof_gr_complex, (fft_length+offset)), (self,0)) self.connect(phi, (self,1)) self.connect(peak_detect, (self,2)) if logging: self.connect(matched_filter, gr.file_sink(gr.sizeof_float, "sync-mf.dat")) self.connect(M_d, gr.file_sink(gr.sizeof_float, "sync-M.dat")) self.connect(P_d_angle, gr.file_sink(gr.sizeof_float, "sync-angle.dat")) self.connect(peak_detect, gr.file_sink(gr.sizeof_char, "sync-peaks.datb")) self.connect(phi, gr.file_sink(gr.sizeof_float, "sync-phi.dat"))
def test_div_ff_1 (self): src1_data = (1, 2, 4, -8) expected_result = (1, 0.5, 0.25, -.125) op = gr.divide_ff () self.help_ff ((src1_data,), expected_result, op)
def __init__(self, fft_length, cp_length, logging=False): """ OFDM synchronization using PN Correlation: T. M. Schmidl and D. C. Cox, "Robust Frequency and Timing Synchonization for OFDM," IEEE Trans. Communications, vol. 45, no. 12, 1997. """ gr.hier_block2.__init__(self, "ofdm_sync_pn", 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) # PN Sync # Create a delay line self.delay = gr.delay(gr.sizeof_gr_complex, fft_length/2) # Correlation from ML Sync self.conjg = gr.conjugate_cc(); self.corr = gr.multiply_cc(); # Create a moving sum filter for the corr output if 1: moving_sum_taps = [1.0 for i in range(fft_length//2)] self.moving_sum_filter = gr.fir_filter_ccf(1,moving_sum_taps) else: moving_sum_taps = [complex(1.0,0.0) for i in range(fft_length//2)] self.moving_sum_filter = gr.fft_filter_ccc(1,moving_sum_taps) # Create a moving sum filter for the input self.inputmag2 = gr.complex_to_mag_squared() movingsum2_taps = [1.0 for i in range(fft_length//2)] if 1: self.inputmovingsum = gr.fir_filter_fff(1,movingsum2_taps) else: self.inputmovingsum = gr.fft_filter_fff(1,movingsum2_taps) self.square = gr.multiply_ff() self.normalize = gr.divide_ff() # Get magnitude (peaks) and angle (phase/freq error) self.c2mag = gr.complex_to_mag_squared() self.angle = gr.complex_to_arg() self.sample_and_hold = gr.sample_and_hold_ff() #ML measurements input to sampler block and detect #self.sub1 = gr.add_const_ff(-1) self.sub1 = gr.add_const_ff(0) self.pk_detect = gr.peak_detector_fb(0.20, 0.20, 30, 0.001) #self.pk_detect = gr.peak_detector2_fb(9) self.connect(self, self.input) # Calculate the frequency offset from the correlation of the preamble self.connect(self.input, self.delay) self.connect(self.input, (self.corr,0)) self.connect(self.delay, self.conjg) self.connect(self.conjg, (self.corr,1)) self.connect(self.corr, self.moving_sum_filter) self.connect(self.moving_sum_filter, self.c2mag) self.connect(self.moving_sum_filter, self.angle) self.connect(self.angle, (self.sample_and_hold,0)) # Get the power of the input signal to normalize the output of the correlation self.connect(self.input, self.inputmag2, self.inputmovingsum) self.connect(self.inputmovingsum, (self.square,0)) self.connect(self.inputmovingsum, (self.square,1)) self.connect(self.square, (self.normalize,1)) self.connect(self.c2mag, (self.normalize,0)) # Create a moving sum filter for the corr output matched_filter_taps = [1.0/cp_length for i in range(cp_length)] self.matched_filter = gr.fir_filter_fff(1,matched_filter_taps) self.connect(self.normalize, self.matched_filter) self.connect(self.matched_filter, self.sub1, self.pk_detect) #self.connect(self.matched_filter, self.pk_detect) self.connect(self.pk_detect, (self.sample_and_hold,1)) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) self.connect(self.pk_detect, (self,1)) if logging: self.connect(self.matched_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-mf_f.dat")) self.connect(self.normalize, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-theta_f.dat")) self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat")) self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat")) self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat")) self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))
def __init__(self, fft_length, cp_length, half_sync, kstime, ks1time, threshold, logging=False): gr.hier_block2.__init__( self, "ofdm_sync_pn", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature3( 3, 3, # Output signature gr.sizeof_gr_complex, # delayed input gr.sizeof_float, # fine frequency offset gr.sizeof_char, # timing indicator ), ) if half_sync: period = fft_length / 2 window = fft_length / 2 else: # full symbol period = fft_length + cp_length window = fft_length # makes the plateau cp_length long # Calculate the frequency offset from the correlation of the preamble x_corr = gr.multiply_cc() self.connect(self, gr.conjugate_cc(), (x_corr, 0)) self.connect(self, gr.delay(gr.sizeof_gr_complex, period), (x_corr, 1)) P_d = gr.moving_average_cc(window, 1.0) self.connect(x_corr, P_d) # offset by -1 phi = gr.sample_and_hold_ff() self.corrmag = gr.complex_to_mag_squared() P_d_angle = gr.complex_to_arg() self.connect(P_d, P_d_angle, (phi, 0)) cross_correlate = 1 if cross_correlate == 1: # cross-correlate with the known symbol kstime = [k.conjugate() for k in kstime] kstime.reverse() self.crosscorr_filter = gr.fir_filter_ccc(1, kstime) """ self.f2b = gr.float_to_char() self.slice = gr.threshold_ff(threshold, threshold, 0, fft_length) #self.connect(self, self.crosscorr_filter, self.corrmag, self.slice, self.f2b) self.connect(self.f2b, (phi,1)) self.connect(self.f2b, (self,2)) self.connect(self.f2b, gr.file_sink(gr.sizeof_char, "ofdm_f2b.dat")) """ # new method starts here - only crosscorrelate and use peak_detect block # peak_detect = gr.peak_detector_fb(100, 100, 30, 0.001) self.corrmag1 = gr.complex_to_mag_squared() self.connect(self, self.crosscorr_filter, self.corrmag, peak_detect) self.connect(peak_detect, (phi, 1)) self.connect(peak_detect, (self, 2)) self.connect(peak_detect, gr.file_sink(gr.sizeof_char, "sync-peaks_b.dat")) self.connect(self.corrmag, gr.file_sink(gr.sizeof_float, "ofdm_corrmag.dat")) self.connect(self, gr.delay(gr.sizeof_gr_complex, (fft_length)), (self, 0)) else: # Get the power of the input signal to normalize the output of the correlation R_d = gr.moving_average_ff(window, 1.0) self.connect(self, gr.complex_to_mag_squared(), R_d) R_d_squared = gr.multiply_ff() # this is retarded self.connect(R_d, (R_d_squared, 0)) self.connect(R_d, (R_d_squared, 1)) M_d = gr.divide_ff() self.connect(P_d, gr.complex_to_mag_squared(), (M_d, 0)) self.connect(R_d_squared, (M_d, 1)) # Now we need to detect peak of M_d matched_filter = gr.moving_average_ff(cp_length, 1.0 / cp_length) peak_detect = gr.peak_detector_fb(0.25, 0.25, 30, 0.001) self.connect(M_d, matched_filter, gr.add_const_ff(-1), peak_detect) offset = cp_length / 2 # cp_length/2 self.connect(peak_detect, (phi, 1)) self.connect(peak_detect, (self, 2)) self.connect(P_d_angle, gr.delay(gr.sizeof_float, offset), (phi, 0)) self.connect( self, gr.delay(gr.sizeof_gr_complex, (fft_length + offset)), (self, 0) ) # delay the input to follow the freq offset self.connect(peak_detect, gr.delay(gr.sizeof_char, (fft_length + offset)), (self, 2)) self.connect(peak_detect, gr.file_sink(gr.sizeof_char, "sync-peaks_b.dat")) self.connect(matched_filter, gr.file_sink(gr.sizeof_float, "sync-mf.dat")) self.connect(phi, (self, 1)) if logging: self.connect(matched_filter, gr.file_sink(gr.sizeof_float, "sync-mf.dat")) self.connect(M_d, gr.file_sink(gr.sizeof_float, "sync-M.dat")) self.connect(P_d_angle, gr.file_sink(gr.sizeof_float, "sync-angle.dat")) self.connect(peak_detect, gr.file_sink(gr.sizeof_char, "sync-peaks.datb")) self.connect(phi, gr.file_sink(gr.sizeof_float, "sync-phi.dat"))
def __init__(self, subc, vlen, ss): gr.hier_block2.__init__( self, "new_snr_estimator", gr.io_signature(2, 2, gr.sizeof_gr_complex * vlen), #gr.io_signature2(2,2,gr.sizeof_float*vlen,gr.sizeof_float*vlen/ss*(ss-1))) gr.io_signature2(2, 2, gr.sizeof_float * vlen, gr.sizeof_float)) print "Created Milan's SINR estimator" trigger = [0] * vlen trigger[0] = 1 v = range(vlen / ss) ones_ind = map(lambda z: z * ss, v) skip2_pr0 = skip(gr.sizeof_gr_complex, vlen) skip2_pr1 = skip(gr.sizeof_gr_complex, vlen) for x in ones_ind: skip2_pr0.skip(x) skip2_pr1.skip(x) #print "skipped ones",ones_ind v2s_pr0 = gr.vector_to_stream(gr.sizeof_gr_complex, vlen) v2s_pr1 = gr.vector_to_stream(gr.sizeof_gr_complex, vlen) s2v2_pr0 = gr.stream_to_vector(gr.sizeof_gr_complex, vlen / ss * (ss - 1)) trigger_src_2_pr0 = gr.vector_source_b(trigger, True) s2v2_pr1 = gr.stream_to_vector(gr.sizeof_gr_complex, vlen / ss * (ss - 1)) trigger_src_2_pr1 = gr.vector_source_b(trigger, True) mag_sq_zeros_pr0 = gr.complex_to_mag_squared(vlen / ss * (ss - 1)) mag_sq_zeros_pr1 = gr.complex_to_mag_squared(vlen / ss * (ss - 1)) filt_zeros_pr0 = gr.single_pole_iir_filter_ff(0.01, vlen / ss * (ss - 1)) filt_zeros_pr1 = gr.single_pole_iir_filter_ff(0.01, vlen / ss * (ss - 1)) v1 = vlen / ss * (ss - 1) vevc1 = [-1] * v1 neg_nomin_z = gr.multiply_const_vff(vevc1) div_z = gr.divide_ff(vlen / ss * (ss - 1)) on_zeros = gr.add_const_vff(vevc1) sum_zeros = add_vff(vlen / ss * (ss - 1)) # For average sum_all = vector_sum_vff(vlen) mult = gr.multiply_const_ff(1. / vlen) scsnr_db_av = gr.nlog10_ff(10, 1, 0) filt_end_av = gr.single_pole_iir_filter_ff(0.1) self.connect((self, 0), v2s_pr0, skip2_pr0, s2v2_pr0, mag_sq_zeros_pr0, filt_zeros_pr0) self.connect(trigger_src_2_pr0, (skip2_pr0, 1)) self.connect((self, 1), v2s_pr1, skip2_pr1, s2v2_pr1, mag_sq_zeros_pr1, filt_zeros_pr1) self.connect(trigger_src_2_pr1, (skip2_pr1, 1)) # On zeros self.connect(filt_zeros_pr1, (sum_zeros, 0)) self.connect(filt_zeros_pr0, neg_nomin_z, (sum_zeros, 1)) self.connect(sum_zeros, div_z) self.connect(filt_zeros_pr0, (div_z, 1)) scsnr_db = gr.nlog10_ff(10, vlen, 0) filt_end = gr.single_pole_iir_filter_ff(0.1, vlen) dd = [] for i in range(vlen / ss): dd.extend([i * ss]) #print dd interpolator = sinr_interpolator(vlen, ss, dd) self.connect(div_z, interpolator, filt_end, scsnr_db, self) self.connect(interpolator, sum_all, mult, scsnr_db_av, filt_end_av, (self, 1))
def __init__(self, fft_length, cp_length, snr, kstime, logging): ''' Maximum Likelihood OFDM synchronizer: J. van de Beek, M. Sandell, and P. O. Borjesson, "ML Estimation of Time and Frequency Offset in OFDM Systems," IEEE Trans. Signal Processing, vol. 45, no. 7, pp. 1800-1805, 1997. ''' gr.hier_block2.__init__(self, "ofdm_sync_ml", 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) SNR = 10.0**(snr/10.0) rho = SNR / (SNR + 1.0) symbol_length = fft_length + cp_length # ML Sync # Energy Detection from ML Sync self.connect(self, self.input) # Create a delay line self.delay = gr.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() moving_sum_taps = [rho/2 for i in range(cp_length)] self.moving_sum_filter = gr.fir_filter_fff(1,moving_sum_taps) self.connect(self.input,self.magsqrd1) self.connect(self.delay,self.magsqrd2) self.connect(self.magsqrd1,(self.adder,0)) self.connect(self.magsqrd2,(self.adder,1)) self.connect(self.adder,self.moving_sum_filter) # Correlation from ML Sync self.conjg = gr.conjugate_cc(); self.mixer = gr.multiply_cc(); movingsum2_taps = [1.0 for i in range(cp_length)] self.movingsum2 = gr.fir_filter_ccf(1,movingsum2_taps) # Correlator data handler self.c2mag = gr.complex_to_mag() self.angle = gr.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.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() # use the sync loop values to set the sampler and the NCO # self.diff = theta # self.angle = epsilon self.connect(self.diff, self.pk_detect) # The DPLL corrects for timing differences between CP correlations use_dpll = 0 if use_dpll: self.dpll = gr.dpll_bb(float(symbol_length),0.01) self.connect(self.pk_detect, self.dpll) self.connect(self.dpll, (self.sample_and_hold,1)) else: self.connect(self.pk_detect, (self.sample_and_hold,1)) self.connect(self.angle, (self.sample_and_hold,0)) ################################ # correlate against known symbol # This gives us the same timing signal as the PN sync block only on the preamble # we don't use the signal generated from the CP correlation because we don't want # 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() # 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 # anyone wants to use this against a WiMAX-like signal since it, too, repeats. # 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() # 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. # if this is removed, the threshold value needs adjustment. self.connect(self.input, self.kscorr, self.corrmag, (self.div,0)) self.connect(self.moving_sum_filter, (self.div,1)) self.connect(self.div, (self.mul,0)) self.connect(self.pk_detect, self.b2f, (self.mul,1)) self.connect(self.mul, self.slice) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) self.connect(self.slice, self.f2b, (self,1)) 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")) if use_dpll: self.connect(self.dpll, gr.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"))
def __init__(self, devid="type=b100", rdsfile="rds_fifo", gain=35.0, freq=101.1e6, xmlport=13777, arate=int(48e3), mute=-15.0, ftune=0, ant="J1", subdev="A:0", ahw="pulse", deemph=75.0e-6, prenames='["UWRF","89.3","950","WEVR"]', prefreqs="[88.715e6,89.3e6,950.735e6,106.317e6]", volume=1.0): grc_wxgui.top_block_gui.__init__(self, title="Simple FM (Stereo) Receiver") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.devid = devid self.rdsfile = rdsfile self.gain = gain self.freq = freq self.xmlport = xmlport self.arate = arate self.mute = mute self.ftune = ftune self.ant = ant self.subdev = subdev self.ahw = ahw self.deemph = deemph self.prenames = prenames self.prefreqs = prefreqs self.volume = volume ################################################## # Variables ################################################## self.pthresh = pthresh = 350 self.preselect = preselect = eval(prefreqs)[0] self.pilot_level = pilot_level = 0 self.ifreq = ifreq = freq self.stpilotdet = stpilotdet = True if (pilot_level > pthresh) else False self.stereo = stereo = True self.rf_pwr_lvl = rf_pwr_lvl = 0 self.cur_freq = cur_freq = simple_fm_helper.freq_select(ifreq,preselect) self.vol = vol = volume self.variable_static_text_0 = variable_static_text_0 = 10.0*math.log(rf_pwr_lvl+1.0e-11)/math.log(10) self.tone_med = tone_med = 5 self.tone_low = tone_low = 5 self.tone_high = tone_high = 5 self.stereo_0 = stereo_0 = stpilotdet self.st_enabled = st_enabled = 1 if (stereo == True and pilot_level > pthresh) else 0 self.squelch_probe = squelch_probe = 0 self.sq_thresh = sq_thresh = mute self.samp_rate = samp_rate = 250e3 self.rtext_0 = rtext_0 = cur_freq self.record = record = False self.rdsrate = rdsrate = 25e3 self.osmo_taps = osmo_taps = firdes.low_pass(1.0,1.00e6,95e3,20e3,firdes.WIN_HAMMING,6.76) self.mod_reset = mod_reset = 0 self.igain = igain = gain self.fine = fine = ftune self.farate = farate = arate self.dm = dm = deemph self.discrim_dc = discrim_dc = 0 self.capture_file = capture_file = "capture.wav" self.asrate = asrate = 125e3 ################################################## # Blocks ################################################## _sq_thresh_sizer = wx.BoxSizer(wx.VERTICAL) self._sq_thresh_text_box = forms.text_box( parent=self.GetWin(), sizer=_sq_thresh_sizer, value=self.sq_thresh, callback=self.set_sq_thresh, label="Mute Level", converter=forms.float_converter(), proportion=0, ) self._sq_thresh_slider = forms.slider( parent=self.GetWin(), sizer=_sq_thresh_sizer, value=self.sq_thresh, callback=self.set_sq_thresh, minimum=-30.0, maximum=-5.0, num_steps=40, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_sq_thresh_sizer, 1, 5, 1, 1) self.input_power = gr.probe_avg_mag_sqrd_c(sq_thresh, 1.0/(samp_rate/10)) self.dc_level = gr.probe_signal_f() _vol_sizer = wx.BoxSizer(wx.VERTICAL) self._vol_text_box = forms.text_box( parent=self.GetWin(), sizer=_vol_sizer, value=self.vol, callback=self.set_vol, label="Volume", converter=forms.float_converter(), proportion=0, ) self._vol_slider = forms.slider( parent=self.GetWin(), sizer=_vol_sizer, value=self.vol, callback=self.set_vol, minimum=0, maximum=11, num_steps=110, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_vol_sizer, 0, 3, 1, 1) _tone_med_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_med_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_med_sizer, value=self.tone_med, callback=self.set_tone_med, label="1Khz-4Khz", converter=forms.float_converter(), proportion=0, ) self._tone_med_slider = forms.slider( parent=self.GetWin(), sizer=_tone_med_sizer, value=self.tone_med, callback=self.set_tone_med, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_med_sizer, 1, 3, 1, 1) _tone_low_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_low_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_low_sizer, value=self.tone_low, callback=self.set_tone_low, label="0-1Khz", converter=forms.float_converter(), proportion=0, ) self._tone_low_slider = forms.slider( parent=self.GetWin(), sizer=_tone_low_sizer, value=self.tone_low, callback=self.set_tone_low, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_low_sizer, 1, 2, 1, 1) _tone_high_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_high_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_high_sizer, value=self.tone_high, callback=self.set_tone_high, label="4Khz-15Khz", converter=forms.float_converter(), proportion=0, ) self._tone_high_slider = forms.slider( parent=self.GetWin(), sizer=_tone_high_sizer, value=self.tone_high, callback=self.set_tone_high, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_high_sizer, 1, 4, 1, 1) def _squelch_probe_probe(): while True: val = self.input_power.unmuted() try: self.set_squelch_probe(val) except AttributeError, e: pass time.sleep(1.0/(10)) _squelch_probe_thread = threading.Thread(target=_squelch_probe_probe) _squelch_probe_thread.daemon = True _squelch_probe_thread.start() self._record_check_box = forms.check_box( parent=self.GetWin(), value=self.record, callback=self.set_record, label="Record Audio", true=True, false=False, ) self.GridAdd(self._record_check_box, 2, 2, 1, 1) self.pilot_probe = gr.probe_signal_f() _fine_sizer = wx.BoxSizer(wx.VERTICAL) self._fine_text_box = forms.text_box( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, label="Fine Tuning", converter=forms.float_converter(), proportion=0, ) self._fine_slider = forms.slider( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, minimum=-50.0e3, maximum=50.e03, num_steps=400, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_fine_sizer, 1, 0, 1, 1) def _discrim_dc_probe(): while True: val = self.dc_level.level() try: self.set_discrim_dc(val) except AttributeError, e: pass time.sleep(1.0/(2.5)) _discrim_dc_thread = threading.Thread(target=_discrim_dc_probe) _discrim_dc_thread.daemon = True _discrim_dc_thread.start() self._capture_file_text_box = forms.text_box( parent=self.GetWin(), value=self.capture_file, callback=self.set_capture_file, label="Record Filename", converter=forms.str_converter(), ) self.GridAdd(self._capture_file_text_box, 2, 0, 1, 2) self.Main = self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.Main.AddPage(grc_wxgui.Panel(self.Main), "L/R") self.Main.AddPage(grc_wxgui.Panel(self.Main), "FM Demod Spectrum") self.Add(self.Main) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.Add(self.wxgui_waterfallsink2_0.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.Main.GetPage(0).GetWin(), title="Audio Channels (L and R)", sample_rate=farate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Rel. Audio Level", ) self.Main.GetPage(0).Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.Main.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=asrate, fft_size=1024, fft_rate=6, average=True, avg_alpha=0.1, title="FM Demod Spectrum", peak_hold=False, ) self.Main.GetPage(1).Add(self.wxgui_fftsink2_0.win) self._variable_static_text_0_static_text = forms.static_text( parent=self.GetWin(), value=self.variable_static_text_0, callback=self.set_variable_static_text_0, label="RF Power ", converter=forms.float_converter(formatter=lambda x: "%4.1f" % x), ) self.GridAdd(self._variable_static_text_0_static_text, 0, 2, 1, 1) self._stereo_0_check_box = forms.check_box( parent=self.GetWin(), value=self.stereo_0, callback=self.set_stereo_0, label="Stereo Detect", true=True, false=False, ) self.GridAdd(self._stereo_0_check_box, 2, 5, 1, 1) self._stereo_check_box = forms.check_box( parent=self.GetWin(), value=self.stereo, callback=self.set_stereo, label="Stereo", true=True, false=False, ) self.GridAdd(self._stereo_check_box, 2, 4, 1, 1) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_sample_rate(1.0e6) self.rtl2832_source_0.set_frequency(cur_freq+200e3) self.rtl2832_source_0.set_auto_gain_mode(False) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(gain) self._rtext_0_static_text = forms.static_text( parent=self.GetWin(), value=self.rtext_0, callback=self.set_rtext_0, label="CURRENT FREQUENCY>>", converter=forms.float_converter(), ) self.GridAdd(self._rtext_0_static_text, 0, 1, 1, 1) def _rf_pwr_lvl_probe(): while True: val = self.input_power.level() try: self.set_rf_pwr_lvl(val) except AttributeError, e: pass time.sleep(1.0/(2)) _rf_pwr_lvl_thread = threading.Thread(target=_rf_pwr_lvl_probe) _rf_pwr_lvl_thread.daemon = True _rf_pwr_lvl_thread.start() self._preselect_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.preselect, callback=self.set_preselect, label='preselect', choices=eval(prefreqs), labels=eval(prenames), style=wx.RA_HORIZONTAL, ) self.GridAdd(self._preselect_chooser, 0, 4, 1, 1) def _pilot_level_probe(): while True: val = self.pilot_probe.level() try: self.set_pilot_level(val) except AttributeError, e: pass time.sleep(1.0/(5)) _pilot_level_thread = threading.Thread(target=_pilot_level_probe) _pilot_level_thread.daemon = True _pilot_level_thread.start() self.low_pass_filter_3 = gr.fir_filter_fff(1, firdes.low_pass( 3, asrate/500, 10, 3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2 = gr.fir_filter_fff(10, firdes.low_pass( 3, asrate/50, 100, 30, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1 = gr.fir_filter_fff(10, firdes.low_pass( 3, asrate/5, 1e3, 200, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = gr.fir_filter_fff(5, firdes.low_pass( 3, asrate, 10e3, 2e3, firdes.WIN_HAMMING, 6.76)) _igain_sizer = wx.BoxSizer(wx.VERTICAL) self._igain_text_box = forms.text_box( parent=self.GetWin(), sizer=_igain_sizer, value=self.igain, callback=self.set_igain, label="RF Gain", converter=forms.float_converter(), proportion=0, ) self._igain_slider = forms.slider( parent=self.GetWin(), sizer=_igain_sizer, value=self.igain, callback=self.set_igain, minimum=0, maximum=50, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_igain_sizer, 1, 1, 1, 1) _ifreq_sizer = wx.BoxSizer(wx.VERTICAL) self._ifreq_text_box = forms.text_box( parent=self.GetWin(), sizer=_ifreq_sizer, value=self.ifreq, callback=self.set_ifreq, label="Center Frequency", converter=forms.float_converter(), proportion=0, ) self._ifreq_slider = forms.slider( parent=self.GetWin(), sizer=_ifreq_sizer, value=self.ifreq, callback=self.set_ifreq, minimum=88.1e6, maximum=108.1e6, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_ifreq_sizer, 0, 0, 1, 1) self.gr_wavfile_sink_0 = gr.wavfile_sink("/dev/null" if record == False else capture_file, 2, int(farate), 16) self.gr_sub_xx_0 = gr.sub_ff(1) self.gr_single_pole_iir_filter_xx_1 = gr.single_pole_iir_filter_ff(2.5/(asrate/500), 1) self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff(1.0/(asrate/3), 1) self.gr_multiply_xx_1 = gr.multiply_vff(1) self.gr_multiply_xx_0_0 = gr.multiply_vff(1) self.gr_multiply_xx_0 = gr.multiply_vff(1) self.gr_multiply_const_vxx_3 = gr.multiply_const_vff((3.16e3 if st_enabled else 0, )) self.gr_multiply_const_vxx_2 = gr.multiply_const_vff((1.0 if st_enabled else 1.414, )) self.gr_multiply_const_vxx_1_0 = gr.multiply_const_vff((0 if st_enabled else 1, )) self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((0 if squelch_probe == 0 else 1.0, )) self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vff((vol*1.5*10.0, )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((vol*1.5*10.0 if st_enabled else 0, )) self.gr_keep_one_in_n_0 = gr.keep_one_in_n(gr.sizeof_float*1, int(asrate/3)) self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(4, (osmo_taps), 200e3+fine+(-12e3*discrim_dc), 1.0e6) self.gr_fractional_interpolator_xx_0_0 = gr.fractional_interpolator_ff(0, asrate/farate) self.gr_fractional_interpolator_xx_0 = gr.fractional_interpolator_ff(0, asrate/farate) self.gr_fft_filter_xxx_1_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_high/10.0,asrate,3.5e3,15.0e3,5.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_1_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_med/10.0,asrate,1.0e3,4.0e3,2.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_1 = gr.fft_filter_fff(1, (firdes.low_pass(tone_low/10.0,asrate,1.2e3,500,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_high/10.0,asrate,3.5e3,13.5e3,3.5e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_med/10.0,asrate,1.0e3,4.0e3,2.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0 = gr.fft_filter_fff(1, (firdes.low_pass(tone_low/10.0,asrate,1.2e3,500,firdes.WIN_HAMMING)), 1) self.gr_divide_xx_0 = gr.divide_ff(1) self.gr_agc_xx_1 = gr.agc_cc(1e-2, 0.35, 1.0, 5000) self.gr_add_xx_2_0 = gr.add_vff(1) self.gr_add_xx_2 = gr.add_vff(1) self.gr_add_xx_1 = gr.add_vff(1) self.gr_add_xx_0 = gr.add_vff(1) self.gr_add_const_vxx_0 = gr.add_const_vff((1.0e-7, )) self._dm_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.dm, callback=self.set_dm, label="FM Deemphasis", choices=[75.0e-6, 50.0e-6], labels=["NA", "EU"], style=wx.RA_HORIZONTAL, ) self.GridAdd(self._dm_chooser, 0, 5, 1, 1) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate, audio_decimation=2, ) self.blks2_fm_deemph_0_0 = blks2.fm_deemph(fs=farate, tau=deemph) self.blks2_fm_deemph_0 = blks2.fm_deemph(fs=farate, tau=deemph) self.band_pass_filter_2_0 = gr.fir_filter_fff(1, firdes.band_pass( 20, asrate, 17.5e3, 17.9e3, 250, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_2 = gr.fir_filter_fff(1, firdes.band_pass( 10, asrate, 18.8e3, 19.2e3, 350, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0_0 = gr.fir_filter_fff(1, firdes.band_pass( 1, asrate, 38e3-(15e3), 38e3+(15e3), 4.0e3, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0 = audio.sink(int(farate), "" if ahw == "Default" else ahw, True) ################################################## # Connections ################################################## self.connect((self.gr_add_xx_1, 0), (self.gr_fractional_interpolator_xx_0, 0)) self.connect((self.gr_sub_xx_0, 0), (self.gr_fractional_interpolator_xx_0_0, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.gr_multiply_xx_1, 0)) self.connect((self.gr_multiply_const_vxx_1_0, 0), (self.gr_add_xx_0, 0)) self.connect((self.band_pass_filter_2_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.band_pass_filter_2_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_multiply_xx_0_0, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_divide_xx_0, 0), (self.gr_single_pole_iir_filter_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_add_const_vxx_0, 0)) self.connect((self.gr_add_const_vxx_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_keep_one_in_n_0, 0)) self.connect((self.gr_keep_one_in_n_0, 0), (self.pilot_probe, 0)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_1, 2)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_0_0, 0)) self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_add_xx_1, 0)) self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_sub_xx_0, 0)) self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_sub_xx_0, 1)) self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_add_xx_1, 1)) self.connect((self.gr_fractional_interpolator_xx_0, 0), (self.gr_multiply_const_vxx_0_0, 0)) self.connect((self.gr_fractional_interpolator_xx_0_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0, 0)) self.connect((self.gr_fft_filter_xxx_1, 0), (self.gr_add_xx_2, 0)) self.connect((self.gr_fft_filter_xxx_1_0, 0), (self.gr_add_xx_2, 1)) self.connect((self.gr_fft_filter_xxx_1_0_0, 0), (self.gr_add_xx_2, 2)) self.connect((self.gr_add_xx_2, 0), (self.gr_multiply_const_vxx_2, 0)) self.connect((self.gr_add_xx_2_0, 0), (self.gr_multiply_const_vxx_3, 0)) self.connect((self.gr_fft_filter_xxx_0, 0), (self.gr_add_xx_2_0, 0)) self.connect((self.gr_fft_filter_xxx_0_0, 0), (self.gr_add_xx_2_0, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0_0, 0)) self.connect((self.gr_fft_filter_xxx_0_0_0, 0), (self.gr_add_xx_2_0, 2)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0_0_0, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.gr_multiply_const_vxx_1_0, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1_0_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.blks2_fm_deemph_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.audio_sink_0, 1)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_fm_deemph_0_0, 0)) self.connect((self.blks2_fm_deemph_0_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_0_0, 1)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_2, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.audio_sink_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_2_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_wavfile_sink_0, 1)) self.connect((self.blks2_fm_deemph_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.blks2_wfm_rcv_0, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_agc_xx_1, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.gr_agc_xx_1, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.input_power, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.low_pass_filter_1, 0), (self.low_pass_filter_2, 0)) self.connect((self.low_pass_filter_2, 0), (self.low_pass_filter_3, 0)) self.connect((self.gr_single_pole_iir_filter_xx_1, 0), (self.dc_level, 0)) self.connect((self.low_pass_filter_3, 0), (self.gr_single_pole_iir_filter_xx_1, 0)) self.connect((self.rtl2832_source_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_waterfallsink2_0, 0))
def __init__(self, subc, vlen, ss): gr.hier_block2.__init__(self, "new_snr_estimator", gr.io_signature(2,2,gr.sizeof_gr_complex*vlen), #gr.io_signature2(2,2,gr.sizeof_float*vlen,gr.sizeof_float*vlen/ss*(ss-1))) gr.io_signature2(2,2,gr.sizeof_float*vlen,gr.sizeof_float)) print "Created Milan's SINR estimator" trigger = [0]*vlen trigger[0] = 1 v = range (vlen/ss) ones_ind= map(lambda z: z*ss,v) skip2_pr0 = skip(gr.sizeof_gr_complex,vlen) skip2_pr1 = skip(gr.sizeof_gr_complex,vlen) for x in ones_ind: skip2_pr0.skip(x) skip2_pr1.skip(x) #print "skipped ones",ones_ind v2s_pr0 = gr.vector_to_stream(gr.sizeof_gr_complex,vlen) v2s_pr1 = gr.vector_to_stream(gr.sizeof_gr_complex,vlen) s2v2_pr0 = gr.stream_to_vector(gr.sizeof_gr_complex,vlen/ss*(ss-1)) trigger_src_2_pr0 = gr.vector_source_b(trigger,True) s2v2_pr1 = gr.stream_to_vector(gr.sizeof_gr_complex,vlen/ss*(ss-1)) trigger_src_2_pr1 = gr.vector_source_b(trigger,True) mag_sq_zeros_pr0 = gr.complex_to_mag_squared(vlen/ss*(ss-1)) mag_sq_zeros_pr1 = gr.complex_to_mag_squared(vlen/ss*(ss-1)) filt_zeros_pr0 = gr.single_pole_iir_filter_ff(0.01,vlen/ss*(ss-1)) filt_zeros_pr1 = gr.single_pole_iir_filter_ff(0.01,vlen/ss*(ss-1)) v1 = vlen/ss*(ss-1) vevc1 =[-1]*v1 neg_nomin_z = gr.multiply_const_vff(vevc1) div_z=gr.divide_ff(vlen/ss*(ss-1)) on_zeros = gr.add_const_vff(vevc1) sum_zeros = add_vff(vlen/ss*(ss-1)) # For average sum_all = vector_sum_vff(vlen) mult = gr.multiply_const_ff(1./vlen) scsnr_db_av = gr.nlog10_ff(10,1,0) filt_end_av = gr.single_pole_iir_filter_ff(0.1) self.connect((self,0),v2s_pr0,skip2_pr0,s2v2_pr0,mag_sq_zeros_pr0,filt_zeros_pr0) self.connect(trigger_src_2_pr0,(skip2_pr0,1)) self.connect((self,1),v2s_pr1,skip2_pr1,s2v2_pr1,mag_sq_zeros_pr1,filt_zeros_pr1) self.connect(trigger_src_2_pr1,(skip2_pr1,1)) # On zeros self.connect(filt_zeros_pr1,(sum_zeros,0)) self.connect(filt_zeros_pr0,neg_nomin_z,(sum_zeros,1)) self.connect(sum_zeros,div_z) self.connect(filt_zeros_pr0,(div_z,1)) scsnr_db = gr.nlog10_ff(10,vlen,0) filt_end = gr.single_pole_iir_filter_ff(0.1,vlen) dd = [] for i in range (vlen/ss): dd.extend([i*ss]) #print dd interpolator = sinr_interpolator(vlen, ss,dd) self.connect(div_z,interpolator,filt_end,scsnr_db,self) self.connect(interpolator,sum_all,mult,scsnr_db_av,filt_end_av,(self,1))
def __init__(self, fft_length, cp_length, kstime, threshold, threshold_type, threshold_gap, logging=False): """ OFDM synchronization using PN Correlation: T. M. Schmidl and D. C. Cox, "Robust Frequency and Timing Synchonization for OFDM," IEEE Trans. Communications, vol. 45, no. 12, 1997. """ gr.hier_block2.__init__(self, "ofdm_sync_pn", 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) # PN Sync # Create a delay line self.delay = gr.delay(gr.sizeof_gr_complex, fft_length/2) # Correlation from ML Sync self.conjg = gr.conjugate_cc(); self.corr = gr.multiply_cc(); # Create a moving sum filter for the corr output if 1: moving_sum_taps = [1.0 for i in range(fft_length//2)] self.moving_sum_filter = gr.fir_filter_ccf(1,moving_sum_taps) else: moving_sum_taps = [complex(1.0,0.0) for i in range(fft_length//2)] self.moving_sum_filter = gr.fft_filter_ccc(1,moving_sum_taps) # Create a moving sum filter for the input self.inputmag2 = gr.complex_to_mag_squared() movingsum2_taps = [1.0 for i in range(fft_length//2)] #movingsum2_taps = [0.5 for i in range(fft_length*4)] #apurv - implementing Veljo's suggestion, when pause b/w packets if 1: self.inputmovingsum = gr.fir_filter_fff(1,movingsum2_taps) else: self.inputmovingsum = gr.fft_filter_fff(1,movingsum2_taps) self.square = gr.multiply_ff() self.normalize = gr.divide_ff() # Get magnitude (peaks) and angle (phase/freq error) self.c2mag = gr.complex_to_mag_squared() self.angle = gr.complex_to_arg() self.sample_and_hold = gr.sample_and_hold_ff() #ML measurements input to sampler block and detect self.sub1 = gr.add_const_ff(-1) self.pk_detect = gr.peak_detector_fb(0.20, 0.20, 30, 0.001) #apurv - implementing Veljo's suggestion, when pause b/w packets self.connect(self, self.input) # Calculate the frequency offset from the correlation of the preamble self.connect(self.input, self.delay) self.connect(self.input, (self.corr,0)) self.connect(self.delay, self.conjg) self.connect(self.conjg, (self.corr,1)) self.connect(self.corr, self.moving_sum_filter) #self.connect(self.moving_sum_filter, self.c2mag) self.connect(self.moving_sum_filter, self.angle) self.connect(self.angle, (self.sample_and_hold,0)) # apurv-- #self.connect(self.angle, gr.delay(gr.sizeof_float, offset), (self.sample_and_hold, 0)) #apurv++ cross_correlate = 1 if cross_correlate==1: # cross-correlate with the known symbol kstime = [k.conjugate() for k in kstime] kstime.reverse() self.crosscorr_filter = gr.fir_filter_ccc(1, kstime) # get the magnitude # self.corrmag = gr.complex_to_mag_squared() self.f2b = gr.float_to_char() self.threshold_factor = threshold #0.0012 #0.012 #0.0015 if 0: self.slice = gr.threshold_ff(self.threshold_factor, self.threshold_factor, 0, fft_length) else: #thresholds = [self.threshold_factor, 9e-5] self.slice = gr.threshold_ff(threshold, threshold, 0, fft_length, threshold_type, threshold_gap) self.connect(self.input, self.crosscorr_filter, self.corrmag, self.slice, self.f2b) # some debug dump # self.connect(self.corrmag, gr.file_sink(gr.sizeof_float, "ofdm_corrmag.dat")) #self.connect(self.f2b, gr.file_sink(gr.sizeof_char, "ofdm_f2b.dat")) self.connect(self.f2b, (self.sample_and_hold,1)) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) #self.connect(self.pk_detect, (self,1)) #removed #self.connect(self.f2b, gr.delay(gr.sizeof_char, 1), (self, 1)) self.connect(self.f2b, (self, 1)) if logging: self.connect(self.matched_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-mf_f.dat")) self.connect(self.normalize, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-theta_f.dat")) self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat")) self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat")) self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat")) self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))
def __init__(self, vlen): gr.hier_block2.__init__( self, "snr_estimator", gr.io_signature2(2, 2, gr.sizeof_gr_complex, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_float)) data_in = (self, 0) trig_in = (self, 1) snr_out = (self, 0) ## Preamble Extraction sampler = vector_sampler(gr.sizeof_gr_complex, vlen) self.connect(data_in, sampler) self.connect(trig_in, (sampler, 1)) ## Algorithm implementation estim = sc_snr_estimator(vlen) self.connect(sampler, estim) self.connect(estim, snr_out) return ## Split block into two parts splitter = gr.vector_to_streams(gr.sizeof_gr_complex * vlen / 2, 2) self.connect(sampler, splitter) ## Conjugate first half block conj = gr.conjugate_cc(vlen / 2) self.connect(splitter, conj) ## Vector multiplication of both half blocks vmult = gr.multiply_vcc(vlen / 2) self.connect(conj, vmult) self.connect((splitter, 1), (vmult, 1)) ## Sum of Products psum = vector_sum_vcc(vlen / 2) self.connect(vmult, psum) ## Magnitude of P(d) p_mag = gr.complex_to_mag() self.connect(psum, p_mag) ## Squared Magnitude of block r_magsqrd = gr.complex_to_mag_squared(vlen) self.connect(sampler, r_magsqrd) ## Sum of squared second half block r_sum = vector_sum_vff(vlen) self.connect(r_magsqrd, r_sum) ## Square Root of Metric m_sqrt = gr.divide_ff() self.connect(p_mag, (m_sqrt, 0)) self.connect(r_sum, gr.multiply_const_ff(0.5), (m_sqrt, 1)) ## Denominator of SNR estimate denom = gr.add_const_ff(1) neg_m_sqrt = gr.multiply_const_ff(-1.0) self.connect(m_sqrt, limit_vff(1, 1 - 2e-5, -1000), neg_m_sqrt, denom) ## SNR estimate snr_est = gr.divide_ff() self.connect(m_sqrt, (snr_est, 0)) self.connect(denom, (snr_est, 1)) ## Setup Output Connections self.connect(snr_est, self)
def __init__(self, fft_length, cp_length, half_sync, logging=False): gr.hier_block2.__init__( self, "ofdm_sync_pn", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature3( 3, 3, # Output signature gr.sizeof_gr_complex, # delayed input gr.sizeof_float, # fine frequency offset gr.sizeof_char # timing indicator )) if half_sync: period = fft_length / 2 window = fft_length / 2 else: # full symbol period = fft_length + cp_length window = fft_length # makes the plateau cp_length long # Calculate the frequency offset from the correlation of the preamble x_corr = gr.multiply_cc() self.connect(self, gr.conjugate_cc(), (x_corr, 0)) self.connect(self, gr.delay(gr.sizeof_gr_complex, period), (x_corr, 1)) P_d = gr.moving_average_cc(window, 1.0) self.connect(x_corr, P_d) P_d_angle = gr.complex_to_arg() self.connect(P_d, P_d_angle) # Get the power of the input signal to normalize the output of the correlation R_d = gr.moving_average_ff(window, 1.0) self.connect(self, gr.complex_to_mag_squared(), R_d) R_d_squared = gr.multiply_ff() # this is retarded self.connect(R_d, (R_d_squared, 0)) self.connect(R_d, (R_d_squared, 1)) M_d = gr.divide_ff() self.connect(P_d, gr.complex_to_mag_squared(), (M_d, 0)) self.connect(R_d_squared, (M_d, 1)) # Now we need to detect peak of M_d # NOTE: replaced fir_filter with moving_average for clarity # the peak is up to cp_length long, but noisy, so average it out #matched_filter_taps = [1.0/cp_length for i in range(cp_length)] #matched_filter = gr.fir_filter_fff(1, matched_filter_taps) matched_filter = gr.moving_average_ff(cp_length, 1.0 / cp_length) # NOTE: the look_ahead parameter doesn't do anything # these parameters are kind of magic, increase 1 and 2 (==) to be more tolerant #peak_detect = raw.peak_detector_fb(0.55, 0.55, 30, 0.001) peak_detect = raw.peak_detector_fb(0.25, 0.25, 30, 0.001) # NOTE: gr.peak_detector_fb is broken! #peak_detect = gr.peak_detector_fb(0.55, 0.55, 30, 0.001) #peak_detect = gr.peak_detector_fb(0.45, 0.45, 30, 0.001) #peak_detect = gr.peak_detector_fb(0.30, 0.30, 30, 0.001) # offset by -1 self.connect(M_d, matched_filter, gr.add_const_ff(-1), peak_detect) # peak_detect indicates the time M_d is highest, which is the end of the symbol. # We should try to sample in the middle of the plateau!! # FIXME until we figure out how to do this, just offset by cp_length/2 offset = 6 #cp_length/2 # nco(t) = P_d_angle(t-offset) sampled at peak_detect(t) # modulate input(t - fft_length) by nco(t) # signal to sample input(t) at t-offset # # We can't delay by < 0 so instead: # input is delayed by fft_length # P_d_angle is delayed by offset # signal to sample is delayed by fft_length - offset # phi = gr.sample_and_hold_ff() self.connect(peak_detect, (phi, 1)) self.connect(P_d_angle, gr.delay(gr.sizeof_float, offset), (phi, 0)) #self.connect(P_d_angle, matched_filter2, (phi,0)) # why isn't this better?!? # FIXME: we add fft_length delay so that the preamble is nco corrected too # BUT is this buffering worth it? consider implementing sync as a proper block # delay the input signal to follow the frequency offset signal self.connect(self, gr.delay(gr.sizeof_gr_complex, (fft_length + offset)), (self, 0)) self.connect(phi, (self, 1)) self.connect(peak_detect, (self, 2)) if logging: self.connect(matched_filter, gr.file_sink(gr.sizeof_float, "sync-mf.dat")) self.connect(M_d, gr.file_sink(gr.sizeof_float, "sync-M.dat")) self.connect(P_d_angle, gr.file_sink(gr.sizeof_float, "sync-angle.dat")) self.connect(peak_detect, gr.file_sink(gr.sizeof_char, "sync-peaks.datb")) self.connect(phi, gr.file_sink(gr.sizeof_float, "sync-phi.dat"))
def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.frame_1_menubar = wx.MenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wx.Menu() self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.frame_1_menubar.Append(wxglade_tmp_menu, "File") # Menu Bar end self.panel_1 = wx.Panel(self, -1) self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB") self.button_2 = wx.Button(self, ID_BUTTON_2, "USB") self.button_3 = wx.Button(self, ID_BUTTON_3, "AM") self.button_4 = wx.Button(self, ID_BUTTON_4, "CW") self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper") self.slider_1 = wx.Slider(self, ID_SLIDER_1, 0, -15799, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower") self.slider_2 = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_5 = wx.Panel(self, -1) self.label_1 = wx.StaticText(self, -1, " Band\nCenter") self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "") self.panel_6 = wx.Panel(self, -1) self.panel_7 = wx.Panel(self, -1) self.panel_2 = wx.Panel(self, -1) self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq") self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000) self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100) self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol") self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500) self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20) self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time") self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew") self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd") self.panel_3 = wx.Panel(self, -1) self.label_2 = wx.StaticText(self, -1, "PGA ") self.panel_4 = wx.Panel(self, -1) self.panel_8 = wx.Panel(self, -1) self.panel_9 = wx.Panel(self, -1) self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier") self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.label_4 = wx.StaticText(self, -1, "Antenna Tune") self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_10 = wx.Panel(self, -1) self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune") self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate") self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset") self.panel_11 = wx.Panel(self, -1) self.panel_12 = wx.Panel(self, -1) self.__set_properties() self.__do_layout() # end wxGlade parser = OptionParser(option_class=eng_option) parser.add_option( "-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ" ) parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE") parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option("-d", "--decim", type="int", default=250, help="USRP decimation") parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=first one with a daughterboard)", ) (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq usb_rate = 64e6 / options.decim self.slider_range = usb_rate * 0.9375 self.f_lo = self.usrp_center - (self.slider_range / 2) self.f_hi = self.usrp_center + (self.slider_range / 2) self.af_sample_rate = 32000 fir_decim = long(usb_rate / self.af_sample_rate) # data point arrays for antenna tuner self.xdata = [] self.ydata = [] self.tb = gr.top_block() # radio variables, initial conditions self.frequency = self.usrp_center # these map the frequency slider (0-6000) to the actual range self.f_slider_offset = self.f_lo self.f_slider_scale = 10000 / options.decim self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi) self.text_ctrl_1.SetValue(str(int(self.usrp_center))) self.slider_5.SetValue(0) self.AM_mode = False self.slider_3.SetValue((self.frequency - self.f_slider_offset) / self.f_slider_scale) self.spin_ctrl_1.SetValue(int(self.frequency)) POWERMATE = True try: self.pm = powermate.powermate(self) except: sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n") POWERMATE = False if POWERMATE: powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate) powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton) self.active_button = 7 # command line options if options.audio_file == "": SAVE_AUDIO_TO_FILE = False else: SAVE_AUDIO_TO_FILE = True if options.radio_file == "": SAVE_RADIO_TO_FILE = False else: SAVE_RADIO_TO_FILE = True if options.input_file == "": self.PLAY_FROM_USRP = True else: self.PLAY_FROM_USRP = False if self.PLAY_FROM_USRP: self.src = usrp.source_s(decim_rate=options.decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.src) self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.src, options.rx_subdev_spec) self.src.tune(0, self.subdev, self.usrp_center) self.tune_offset = 0 # -self.usrp_center - self.src.rx_freq(0) else: self.src = gr.file_source(gr.sizeof_short, options.input_file) self.tune_offset = 2200 # 2200 works for 3.5-4Mhz band # save radio data to a file if SAVE_RADIO_TO_FILE: file = gr.file_sink(gr.sizeof_short, options.radio_file) self.tb.connect(self.src, file) # 2nd DDC xlate_taps = gr.firdes.low_pass(1.0, usb_rate, 16e3, 4e3, gr.firdes.WIN_HAMMING) self.xlate = gr.freq_xlating_fir_filter_ccf(fir_decim, xlate_taps, self.tune_offset, usb_rate) # convert rf data in interleaved short int form to complex s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src_f2c = gr.float_to_complex() self.tb.connect(self.src, s2ss) self.tb.connect((s2ss, 0), s2f1) self.tb.connect((s2ss, 1), s2f2) self.tb.connect(s2f1, (src_f2c, 0)) self.tb.connect(s2f2, (src_f2c, 1)) # Complex Audio filter audio_coeffs = gr.firdes.complex_band_pass( 1.0, # gain self.af_sample_rate, # sample rate -3000, # low cutoff 0, # high cutoff 100, # transition gr.firdes.WIN_HAMMING, ) # window self.slider_1.SetValue(0) self.slider_2.SetValue(-3000) self.audio_filter = gr.fir_filter_ccc(1, audio_coeffs) # Main +/- 16Khz spectrum display self.fft = fftsink2.fft_sink_c( self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240) ) # AM Sync carrier if AM_SYNC_DISPLAY: self.fft2 = fftsink.fft_sink_c( self.tb, self.panel_9, y_per_div=20, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240), ) c2f = gr.complex_to_float() # AM branch self.sel_am = gr.multiply_const_cc(0) # the following frequencies turn out to be in radians/sample # gr.pll_refout_cc(alpha,beta,min_freq,max_freq) # suggested alpha = X, beta = .25 * X * X pll = gr.pll_refout_cc( 0.5, 0.0625, (2.0 * math.pi * 7.5e3 / self.af_sample_rate), (2.0 * math.pi * 6.5e3 / self.af_sample_rate) ) self.pll_carrier_scale = gr.multiply_const_cc(complex(10, 0)) am_det = gr.multiply_cc() # these are for converting +7.5kHz to -7.5kHz # for some reason gr.conjugate_cc() adds noise ?? c2f2 = gr.complex_to_float() c2f3 = gr.complex_to_float() f2c = gr.float_to_complex() phaser1 = gr.multiply_const_ff(1) phaser2 = gr.multiply_const_ff(-1) # filter for pll generated carrier pll_carrier_coeffs = gr.firdes.complex_band_pass( 2.0, # gain self.af_sample_rate, # sample rate 7400, # low cutoff 7600, # high cutoff 100, # transition gr.firdes.WIN_HAMMING, ) # window self.pll_carrier_filter = gr.fir_filter_ccc(1, pll_carrier_coeffs) self.sel_sb = gr.multiply_const_ff(1) combine = gr.add_ff() # AGC sqr1 = gr.multiply_ff() intr = gr.iir_filter_ffd([0.004, 0], [0, 0.999]) offset = gr.add_const_ff(1) agc = gr.divide_ff() self.scale = gr.multiply_const_ff(0.00001) dst = audio.sink(long(self.af_sample_rate)) self.tb.connect(src_f2c, self.xlate, self.fft) self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0)) self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3) self.tb.connect((c2f3, 0), phaser1, (f2c, 0)) self.tb.connect((c2f3, 1), phaser2, (f2c, 1)) self.tb.connect(f2c, (am_det, 1)) self.tb.connect(am_det, c2f2, (combine, 0)) self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1)) if AM_SYNC_DISPLAY: self.tb.connect(self.pll_carrier_filter, self.fft2) self.tb.connect(combine, self.scale) self.tb.connect(self.scale, (sqr1, 0)) self.tb.connect(self.scale, (sqr1, 1)) self.tb.connect(sqr1, intr, offset, (agc, 1)) self.tb.connect(self.scale, (agc, 0)) self.tb.connect(agc, dst) if SAVE_AUDIO_TO_FILE: f_out = gr.file_sink(gr.sizeof_short, options.audio_file) sc1 = gr.multiply_const_ff(64000) f2s1 = gr.float_to_short() self.tb.connect(agc, sc1, f2s1, f_out) self.tb.start() # for mouse position reporting on fft display em.eventManager.Register(self.Mouse, wx.EVT_MOTION, self.fft.win) # and left click to re-tune em.eventManager.Register(self.Click, wx.EVT_LEFT_DOWN, self.fft.win) # start a timer to check for web commands if WEB_CONTROL: self.timer = UpdateTimer(self, 1000) # every 1000 mSec, 1 Sec wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb) wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb) wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am) wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw) wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd) wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew) wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate) wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button) wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune) wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume) wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga) wx.EVT_SLIDER(self, ID_SLIDER_6, self.am_carrier) wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune) wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune) wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def __init__(self, fft_length, cp_length, kstime, threshold, threshold_type, threshold_gap, logging=False): """ OFDM synchronization using PN Correlation: T. M. Schmidl and D. C. Cox, "Robust Frequency and Timing Synchonization for OFDM," IEEE Trans. Communications, vol. 45, no. 12, 1997. """ gr.hier_block2.__init__( self, "ofdm_sync_pn", 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) # PN Sync # Create a delay line self.delay = gr.delay(gr.sizeof_gr_complex, fft_length / 2) # Correlation from ML Sync self.conjg = gr.conjugate_cc() self.corr = gr.multiply_cc() # Create a moving sum filter for the corr output if 1: moving_sum_taps = [1.0 for i in range(fft_length // 2)] self.moving_sum_filter = gr.fir_filter_ccf(1, moving_sum_taps) else: moving_sum_taps = [ complex(1.0, 0.0) for i in range(fft_length // 2) ] self.moving_sum_filter = gr.fft_filter_ccc(1, moving_sum_taps) # Create a moving sum filter for the input self.inputmag2 = gr.complex_to_mag_squared() movingsum2_taps = [1.0 for i in range(fft_length // 2)] #movingsum2_taps = [0.5 for i in range(fft_length*4)] #apurv - implementing Veljo's suggestion, when pause b/w packets if 1: self.inputmovingsum = gr.fir_filter_fff(1, movingsum2_taps) else: self.inputmovingsum = gr.fft_filter_fff(1, movingsum2_taps) self.square = gr.multiply_ff() self.normalize = gr.divide_ff() # Get magnitude (peaks) and angle (phase/freq error) self.c2mag = gr.complex_to_mag_squared() self.angle = gr.complex_to_arg() self.sample_and_hold = gr.sample_and_hold_ff() #ML measurements input to sampler block and detect self.sub1 = gr.add_const_ff(-1) self.pk_detect = gr.peak_detector_fb( 0.20, 0.20, 30, 0.001 ) #apurv - implementing Veljo's suggestion, when pause b/w packets self.connect(self, self.input) # Calculate the frequency offset from the correlation of the preamble self.connect(self.input, self.delay) self.connect(self.input, (self.corr, 0)) self.connect(self.delay, self.conjg) self.connect(self.conjg, (self.corr, 1)) self.connect(self.corr, self.moving_sum_filter) #self.connect(self.moving_sum_filter, self.c2mag) self.connect(self.moving_sum_filter, self.angle) self.connect(self.angle, (self.sample_and_hold, 0)) # apurv-- #self.connect(self.angle, gr.delay(gr.sizeof_float, offset), (self.sample_and_hold, 0)) #apurv++ cross_correlate = 1 if cross_correlate == 1: # cross-correlate with the known symbol kstime = [k.conjugate() for k in kstime] kstime.reverse() self.crosscorr_filter = gr.fir_filter_ccc(1, kstime) # get the magnitude # self.corrmag = gr.complex_to_mag_squared() self.f2b = gr.float_to_char() self.threshold_factor = threshold #0.0012 #0.012 #0.0015 if 0: self.slice = gr.threshold_ff(self.threshold_factor, self.threshold_factor, 0, fft_length) else: #thresholds = [self.threshold_factor, 9e-5] self.slice = gr.threshold_ff(threshold, threshold, 0, fft_length, threshold_type, threshold_gap) self.connect(self.input, self.crosscorr_filter, self.corrmag, self.slice, self.f2b) # some debug dump # self.connect(self.corrmag, gr.file_sink(gr.sizeof_float, "ofdm_corrmag.dat")) #self.connect(self.f2b, gr.file_sink(gr.sizeof_char, "ofdm_f2b.dat")) self.connect(self.f2b, (self.sample_and_hold, 1)) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self, 0)) #self.connect(self.pk_detect, (self,1)) #removed #self.connect(self.f2b, gr.delay(gr.sizeof_char, 1), (self, 1)) self.connect(self.f2b, (self, 1)) if logging: self.connect( self.matched_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-mf_f.dat")) self.connect( self.normalize, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-theta_f.dat")) self.connect( self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat")) self.connect( self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat")) self.connect( self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat")) self.connect( self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))
def __init__(self, fft_length, cp_length, logging=False): """ OFDM synchronization using PN Correlation: T. M. Schmidl and D. C. Cox, "Robust Frequency and Timing Synchonization for OFDM," IEEE Trans. Communications, vol. 45, no. 12, 1997. """ gr.hier_block2.__init__(self, "ofdm_sync_pn", 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) # PN Sync # Create a delay line self.delay = gr.delay(gr.sizeof_gr_complex, fft_length/2) # Correlation from ML Sync self.conjg = gr.conjugate_cc(); self.corr = gr.multiply_cc(); # Create a moving sum filter for the corr output if 1: moving_sum_taps = [1.0 for i in range(fft_length//2)] self.moving_sum_filter = gr.fir_filter_ccf(1,moving_sum_taps) else: moving_sum_taps = [complex(1.0,0.0) for i in range(fft_length//2)] self.moving_sum_filter = gr.fft_filter_ccc(1,moving_sum_taps) # Create a moving sum filter for the input self.inputmag2 = gr.complex_to_mag_squared() # Modified by Yong (12.06.27) #movingsum2_taps = [1.0 for i in range(fft_length//2)] movingsum2_taps = [0.5 for i in range(fft_length)] if 1: self.inputmovingsum = gr.fir_filter_fff(1,movingsum2_taps) else: self.inputmovingsum = gr.fft_filter_fff(1,movingsum2_taps) self.square = gr.multiply_ff() self.normalize = gr.divide_ff() # Get magnitude (peaks) and angle (phase/freq error) self.c2mag = gr.complex_to_mag_squared() self.angle = gr.complex_to_arg() self.sample_and_hold = gr.sample_and_hold_ff() #ML measurements input to sampler block and detect self.sub1 = gr.add_const_ff(-1) self.pk_detect = gr.peak_detector_fb(0.20, 0.20, 30, 0.001) #self.pk_detect = gr.peak_detector2_fb(9) self.connect(self, self.input) # Calculate the frequency offset from the correlation of the preamble self.connect(self.input, self.delay) self.connect(self.input, (self.corr,0)) self.connect(self.delay, self.conjg) self.connect(self.conjg, (self.corr,1)) self.connect(self.corr, self.moving_sum_filter) self.connect(self.moving_sum_filter, self.c2mag) self.connect(self.moving_sum_filter, self.angle) self.connect(self.angle, (self.sample_and_hold,0)) # Get the power of the input signal to normalize the output of the correlation self.connect(self.input, self.inputmag2, self.inputmovingsum) self.connect(self.inputmovingsum, (self.square,0)) self.connect(self.inputmovingsum, (self.square,1)) self.connect(self.square, (self.normalize,1)) self.connect(self.c2mag, (self.normalize,0)) # Create a moving sum filter for the corr output matched_filter_taps = [1.0/cp_length for i in range(cp_length)] self.matched_filter = gr.fir_filter_fff(1,matched_filter_taps) self.connect(self.normalize, self.matched_filter) self.connect(self.matched_filter, self.sub1, self.pk_detect) #self.connect(self.matched_filter, self.pk_detect) self.connect(self.pk_detect, (self.sample_and_hold,1)) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) self.connect(self.pk_detect, (self,1)) if logging: self.connect(self.matched_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-mf_f.dat")) self.connect(self.c2mag, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-nominator_f.dat")) self.connect(self.square, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-denominator_f.dat")) self.connect(self.normalize, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-theta_f.dat")) self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat")) self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat")) self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat")) self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))
def __init__(self, options, hostname): gr.top_block.__init__(self) ################################################## # Variables ################################################## window_size = options.window_size sync_length = options.sync_length gain = options.gain freq = options.freq samp_rate = options.bandwidth self.uhd_usrp_source_0 = uhd.usrp_source(device_addr="", stream_args=uhd.stream_args(cpu_format="fc32", channels=range(1))) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(gain, 0) self.ieee802_1_ofdm_sync_short_0 = gr_ieee802_11.ofdm_sync_short(0.8, 80 * 80, 2, False) self.ieee802_1_ofdm_sync_long_0 = gr_ieee802_11.ofdm_sync_long(sync_length, 100, False) self.ieee802_1_ofdm_equalize_symbols_0 = gr_ieee802_11.ofdm_equalize_symbols(False) self.ieee802_1_ofdm_decode_signal_0 = gr_ieee802_11.ofdm_decode_signal(False) self.ieee802_1_ofdm_decode_mac_0 = gr_ieee802_11.ofdm_decode_mac(False) self.ieee802_11_ofdm_parse_mac_0 = gr_ieee802_11.ofdm_parse_mac(True) self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, 64) self.gr_socket_pdu_0 = gr.socket_pdu("TCP_SERVER", hostname, str(options.PHYRXport), 10000) self.gr_skiphead_0 = gr.skiphead(gr.sizeof_gr_complex*1, 20000000) self.gr_multiply_xx_0 = gr.multiply_vcc(1) self.gr_divide_xx_0 = gr.divide_ff(1) self.gr_delay_0_0 = gr.delay(gr.sizeof_gr_complex*1, sync_length) self.gr_delay_0 = gr.delay(gr.sizeof_gr_complex*1, 16) self.gr_conjugate_cc_0 = gr.conjugate_cc() self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(1) self.gr_complex_to_mag_0 = gr.complex_to_mag(1) self.fir_filter_xxx_0_0 = filter.fir_filter_ccf(1, ([1]*window_size)) self.fir_filter_xxx_0 = filter.fir_filter_fff(1, ([1]*window_size)) self.fft_vxx_0 = fft.fft_vcc(64, True, (), True, 1) self.message_debug = gr.message_debug() ################################################## # Connections ################################################## self.connect((self.uhd_usrp_source_0, 0), (self.gr_skiphead_0, 0)) self.connect((self.gr_skiphead_0, 0), (self.gr_complex_to_mag_squared_0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_complex_to_mag_squared_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.gr_skiphead_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.gr_conjugate_cc_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_complex_to_mag_0, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.fir_filter_xxx_0_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.gr_complex_to_mag_0, 0)) self.connect((self.gr_skiphead_0, 0), (self.gr_delay_0, 0)) self.connect((self.gr_delay_0, 0), (self.gr_conjugate_cc_0, 0)) self.connect((self.fft_vxx_0, 0), (self.ieee802_1_ofdm_equalize_symbols_0, 0)) self.connect((self.ieee802_1_ofdm_equalize_symbols_0, 0), (self.ieee802_1_ofdm_decode_signal_0, 0)) self.connect((self.ieee802_1_ofdm_decode_signal_0, 0), (self.ieee802_1_ofdm_decode_mac_0, 0)) self.connect((self.ieee802_1_ofdm_sync_short_0, 0), (self.gr_delay_0_0, 0)) self.connect((self.gr_delay_0, 0), (self.ieee802_1_ofdm_sync_short_0, 0)) self.connect((self.gr_divide_xx_0, 0), (self.ieee802_1_ofdm_sync_short_0, 1)) self.connect((self.gr_delay_0_0, 0), (self.ieee802_1_ofdm_sync_long_0, 1)) self.connect((self.ieee802_1_ofdm_sync_short_0, 0), (self.ieee802_1_ofdm_sync_long_0, 0)) self.connect((self.ieee802_1_ofdm_sync_long_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self.ieee802_1_ofdm_decode_mac_0, "out", self.ieee802_11_ofdm_parse_mac_0, "in") self.msg_connect(self.ieee802_11_ofdm_parse_mac_0, "out", self.gr_socket_pdu_0, "pdus")
def __init__(self, subc, vlen, ss): gr.hier_block2.__init__(self, "new_snr_estimator", gr.io_signature(1,1,gr.sizeof_gr_complex*vlen), gr.io_signature(1,1,gr.sizeof_float)) print "Created Milan's SNR estimator" trigger = [0]*vlen trigger[0] = 1 u = range (vlen/ss*(ss-1)) zeros_ind= map(lambda z: z+1+z/(ss-1),u) skip1 = skip(gr.sizeof_gr_complex,vlen) for x in zeros_ind: skip1.skip(x) #print "skipped zeros",zeros_ind v = range (vlen/ss) ones_ind= map(lambda z: z*ss,v) skip2 = skip(gr.sizeof_gr_complex,vlen) for x in ones_ind: skip2.skip(x) #print "skipped ones",ones_ind v2s = gr.vector_to_stream(gr.sizeof_gr_complex,vlen) s2v1 = gr.stream_to_vector(gr.sizeof_gr_complex,vlen/ss) trigger_src_1 = gr.vector_source_b(trigger,True) s2v2 = gr.stream_to_vector(gr.sizeof_gr_complex,vlen/ss*(ss-1)) trigger_src_2 = gr.vector_source_b(trigger,True) mag_sq_ones = gr.complex_to_mag_squared(vlen/ss) mag_sq_zeros = gr.complex_to_mag_squared(vlen/ss*(ss-1)) filt_ones = gr.single_pole_iir_filter_ff(0.1,vlen/ss) filt_zeros = gr.single_pole_iir_filter_ff(0.1,vlen/ss*(ss-1)) sum_ones = vector_sum_vff(vlen/ss) sum_zeros = vector_sum_vff(vlen/ss*(ss-1)) D = gr.divide_ff() P = gr.multiply_ff() mult1 = gr.multiply_const_ff(ss-1.0) add1 = gr.add_const_ff(-1.0) mult2 = gr.multiply_const_ff(1./ss) scsnrdb = gr.nlog10_ff(10,1,0) filt_end = gr.single_pole_iir_filter_ff(0.1) self.connect(self,v2s,skip1,s2v1,mag_sq_ones,filt_ones,sum_ones) self.connect(trigger_src_1,(skip1,1)) self.connect(v2s,skip2,s2v2,mag_sq_zeros,filt_zeros,sum_zeros) self.connect(trigger_src_2,(skip2,1)) self.connect(sum_ones,D) self.connect(sum_zeros,(D,1)) self.connect(D,mult1,add1,mult2) self.connect(mult2,scsnrdb,filt_end,self)
def test_div_ff_1(self): src1_data = (1, 2, 4, -8) expected_result = (1, 0.5, 0.25, -.125) op = gr.divide_ff() self.help_ff((src1_data, ), expected_result, op)
def __init__(self, freq_corr=0, N_id_1=134, avg_frames=1, N_id_2=0, decim=16): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr2 Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq_corr = freq_corr self.N_id_1 = N_id_1 self.avg_frames = avg_frames self.N_id_2 = N_id_2 self.decim = decim ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720 * 5 / decim self.samp_rate = samp_rate = 30720e3 / decim self.rot = rot = 0 self.noise_level = noise_level = 0 self.fft_size = fft_size = 2048 / decim ################################################## # Blocks ################################################## _rot_sizer = wx.BoxSizer(wx.VERTICAL) self._rot_text_box = forms.text_box( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, label='rot', converter=forms.float_converter(), proportion=0, ) self._rot_slider = forms.slider( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rot_sizer) _noise_level_sizer = wx.BoxSizer(wx.VERTICAL) self._noise_level_text_box = forms.text_box( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, label='noise_level', converter=forms.float_converter(), proportion=0, ) self._noise_level_slider = forms.slider( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_noise_level_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.gr_vector_to_stream_1 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_to_stream_0_2 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_to_stream_0_1 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_to_stream_0_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_to_stream_0 = gr.vector_to_stream( gr.sizeof_float * 1, fft_size) self.gr_vector_source_x_0_0_0 = gr.vector_source_c( (gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0_0 = gr.vector_source_c( (gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0 = gr.vector_source_c( (gen_sss_fd(N_id_1, N_id_2, fft_size).get_sss(True)), True, fft_size) self.gr_stream_to_vector_0_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.gr_stream_to_vector_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.gr_repeat_0 = gr.repeat(gr.sizeof_float * 1, fft_size) self.gr_null_sink_0_0 = gr.null_sink(gr.sizeof_gr_complex * 1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex * 1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0) self.gr_multiply_xx_1 = gr.multiply_vcc(1) self.gr_multiply_xx_0 = gr.multiply_vcc(fft_size) self.gr_multiply_const_vxx_1 = gr.multiply_const_vcc((1 / 1500., )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc( (exp(rot * 2 * numpy.pi * 1j), )) self.gr_interleave_0 = gr.interleave(gr.sizeof_gr_complex * fft_size) self.gr_integrate_xx_0 = gr.integrate_ff(fft_size) self.gr_float_to_complex_0_0 = gr.float_to_complex(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.gr_file_source_0 = gr.file_source( gr.sizeof_gr_complex * 1, "/home/user/git/gr-lte/gr-lte/test/foo_pss0_sss_in.cfile", True) self.gr_fft_vxx_1 = gr.fft_vcc(fft_size, False, (window.blackmanharris(1024)), True, 1) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) self.gr_divide_xx_0_1 = gr.divide_cc(1) self.gr_divide_xx_0_0 = gr.divide_ff(1) self.gr_divide_xx_0 = gr.divide_cc(1) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * fft_size) self.gr_conjugate_cc_1 = gr.conjugate_cc() self.gr_conjugate_cc_0 = gr.conjugate_cc() self.gr_complex_to_mag_squared_0_0 = gr.complex_to_mag_squared(1) self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(fft_size) self.gr_add_xx_0 = gr.add_vcc(1) self.gr_add_const_vxx_0 = gr.add_const_vff((1, )) self.const_source_x_0_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_conjugate_cc_0, 0), (self.gr_stream_to_vector_0_0, 0)) self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_complex_to_mag_squared_0, 0)) self.connect((self.gr_complex_to_mag_squared_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_integrate_xx_0, 0)) self.connect((self.gr_integrate_xx_0, 0), (self.gr_repeat_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_vector_to_stream_0_0, 0)) self.connect((self.gr_vector_to_stream_0_1, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_divide_xx_0, 0), (self.gr_multiply_xx_1, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_conjugate_cc_1, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_vector_to_stream_0_1, 0)) self.connect((self.gr_repeat_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.const_source_x_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.gr_conjugate_cc_1, 0)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.gr_complex_to_mag_squared_0_0, 0)) self.connect((self.gr_complex_to_mag_squared_0_0, 0), (self.gr_divide_xx_0_0, 0)) self.connect((self.gr_repeat_0, 0), (self.gr_divide_xx_0_0, 1)) self.connect((self.gr_divide_xx_0_0, 0), (self.gr_add_const_vxx_0, 0)) self.connect((self.gr_add_const_vxx_0, 0), (self.gr_float_to_complex_0_0, 0)) self.connect((self.const_source_x_0_0, 0), (self.gr_float_to_complex_0_0, 1)) self.connect((self.gr_float_to_complex_0_0, 0), (self.gr_divide_xx_0_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_divide_xx_0_1, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_vector_to_stream_0_2, 0), (self.gr_conjugate_cc_0, 0)) self.connect((self.gr_divide_xx_0_1, 0), (self.gr_null_sink_0, 0)) self.connect((self.gr_vector_source_x_0, 0), (self.gr_interleave_0, 1)) self.connect((self.gr_interleave_0, 0), (self.gr_fft_vxx_1, 0)) self.connect((self.gr_fft_vxx_1, 0), (self.gr_vector_to_stream_1, 0)) self.connect((self.gr_vector_source_x_0_0, 0), (self.gr_interleave_0, 0)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_2, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_vector_to_stream_1, 0), (self.gr_add_xx_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_vector_to_stream_0_1, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_null_sink_0_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.gr_divide_xx_0_1, 0), (self.wxgui_scopesink2_0, 0))
def test_div_ff_2(self): src1_data = (5, 9, -15, 1024) src2_data = (10, 3, -5, 64) expected_result = (0.5, 3, 3, 16) op = gr.divide_ff() self.help_ff((src1_data, src2_data), expected_result, op)
def __init__(self, subc, vlen, ss): gr.hier_block2.__init__( self, "new_snr_estimator", gr.io_signature(1, 1, gr.sizeof_gr_complex * vlen), gr.io_signature(1, 1, gr.sizeof_float)) print "Created Milan's SNR estimator" trigger = [0] * vlen trigger[0] = 1 u = range(vlen / ss * (ss - 1)) zeros_ind = map(lambda z: z + 1 + z / (ss - 1), u) skip1 = skip(gr.sizeof_gr_complex, vlen) for x in zeros_ind: skip1.skip(x) #print "skipped zeros",zeros_ind v = range(vlen / ss) ones_ind = map(lambda z: z * ss, v) skip2 = skip(gr.sizeof_gr_complex, vlen) for x in ones_ind: skip2.skip(x) #print "skipped ones",ones_ind v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen) s2v1 = gr.stream_to_vector(gr.sizeof_gr_complex, vlen / ss) trigger_src_1 = gr.vector_source_b(trigger, True) s2v2 = gr.stream_to_vector(gr.sizeof_gr_complex, vlen / ss * (ss - 1)) trigger_src_2 = gr.vector_source_b(trigger, True) mag_sq_ones = gr.complex_to_mag_squared(vlen / ss) mag_sq_zeros = gr.complex_to_mag_squared(vlen / ss * (ss - 1)) filt_ones = gr.single_pole_iir_filter_ff(0.1, vlen / ss) filt_zeros = gr.single_pole_iir_filter_ff(0.1, vlen / ss * (ss - 1)) sum_ones = vector_sum_vff(vlen / ss) sum_zeros = vector_sum_vff(vlen / ss * (ss - 1)) D = gr.divide_ff() P = gr.multiply_ff() mult1 = gr.multiply_const_ff(ss - 1.0) add1 = gr.add_const_ff(-1.0) mult2 = gr.multiply_const_ff(1. / ss) scsnrdb = gr.nlog10_ff(10, 1, 0) filt_end = gr.single_pole_iir_filter_ff(0.1) self.connect(self, v2s, skip1, s2v1, mag_sq_ones, filt_ones, sum_ones) self.connect(trigger_src_1, (skip1, 1)) self.connect(v2s, skip2, s2v2, mag_sq_zeros, filt_zeros, sum_zeros) self.connect(trigger_src_2, (skip2, 1)) self.connect(sum_ones, D) self.connect(sum_zeros, (D, 1)) self.connect(D, mult1, add1, mult2) self.connect(mult2, scsnrdb, filt_end, self)
def __init__(self, fft_length, cp_length, logging=False): """ OFDM synchronization using PN Correlation: T. M. Schmidl and D. C. Cox, "Robust Frequency and Timing Synchonization for OFDM," IEEE Trans. Communications, vol. 45, no. 12, 1997. Improved with averaging over the whole FFT and peak averaging over cp_length. """ gr.hier_block2.__init__(self, "ofdm_sync_pn", 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.delay = gr.delay(gr.sizeof_gr_complex, fft_length/2) self.conjg = gr.conjugate_cc(); self.corr = gr.multiply_cc(); moving_sum_taps = [1.0 for i in range(fft_length//2)] self.moving_sum_filter = gr.fir_filter_ccf(1,moving_sum_taps) self.inputmag2 = gr.complex_to_mag_squared() #movingsum2_taps = [0.125 for i in range(fft_length*4)] movingsum2_taps = [0.5 for i in range(fft_length*4)] self.inputmovingsum = gr.fir_filter_fff(1,movingsum2_taps) self.square = gr.multiply_ff() self.normalize = gr.divide_ff() self.c2mag = gr.complex_to_mag_squared() self.angle = gr.complex_to_arg() self.sample_and_hold = flex.sample_and_hold_ff() self.sub1 = gr.add_const_ff(-1) # linklab, change peak detector parameters: use higher threshold to detect rise/fall of peak #self.pk_detect = gr.peak_detector_fb(0.20, 0.20, 30, 0.001) self.pk_detect = flex.peak_detector_fb(0.7, 0.7, 30, 0.001) # linklab #self.pk_detect = gr.peak_detector2_fb(9) self.connect(self, self.input) # Lower branch: self.connect(self.input, self.delay) self.connect(self.input, (self.corr,0)) self.connect(self.delay, self.conjg) self.connect(self.conjg, (self.corr,1)) self.connect(self.corr, self.moving_sum_filter) self.connect(self.moving_sum_filter, self.c2mag) self.connect(self.moving_sum_filter, self.angle) self.connect(self.angle, (self.sample_and_hold,0)) self.connect(self.c2mag, (self.normalize,0)) # Upper branch self.connect(self.input, self.inputmag2, self.inputmovingsum) self.connect(self.inputmovingsum, (self.square,0)) self.connect(self.inputmovingsum, (self.square,1)) self.connect(self.square, (self.normalize,1)) matched_filter_taps = [1.0/cp_length for i in range(cp_length)] self.matched_filter = gr.fir_filter_fff(1,matched_filter_taps) self.connect(self.normalize, self.matched_filter) # linklab, provide the signal power into peak detector, linklab self.connect(self.square, (self.pk_detect,1)) self.connect(self.matched_filter, self.sub1, (self.pk_detect, 0)) self.connect(self.pk_detect, (self.sample_and_hold,1)) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) self.connect(self.pk_detect, (self,1)) if logging: self.connect(self.square, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-square.dat")) self.connect(self.c2mag, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-c2mag.dat")) self.connect(self.matched_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-mf_f.dat")) self.connect(self.sub1, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-sub1.dat")) self.connect(self.normalize, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-theta_f.dat")) self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat")) self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat")) self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat")) self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))