def test_002_t (self): """test_002_t: with a input sine without noise in the boundary BW of PLL""" tb = self.tb data_tar = namedtuple('data_tar', 'phase_source phase_output time tar') ################################################## # Variables ################################################## samp_rate = 1000000 ################################################## # Blocks ################################################## flaress_sine_debug_0 = flaress.sine_debug() flaress_sine_debug_1 = flaress.sine_debug() blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) blocks_throttle_1 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, '../python/test_files/validation_test_output', False) blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) blocks_file_source_1 = blocks.file_source(gr.sizeof_gr_complex*1, '../python/test_files/validation_test_source', False) blocks_file_source_1.set_begin_tag(pmt.PMT_NIL) blocks_complex_to_arg_1 = blocks.complex_to_arg(1) blocks_complex_to_arg_0 = blocks.complex_to_arg(1) blocks_divide = blocks.divide_ff(1) dst_source = blocks.vector_sink_f() dst_output = blocks.vector_sink_f() dst_tar = blocks.vector_sink_f() ################################################## # Connections ################################################## tb.connect((blocks_file_source_0, 0), (blocks_throttle_0, 0)) tb.connect((blocks_file_source_1, 0), (blocks_throttle_1, 0)) tb.connect((blocks_throttle_0, 0), (blocks_complex_to_arg_0, 0)) tb.connect((blocks_throttle_0, 0), (flaress_sine_debug_0, 0)) tb.connect((blocks_throttle_1, 0), (blocks_complex_to_arg_1, 0)) tb.connect((blocks_throttle_1, 0), (flaress_sine_debug_1, 0)) tb.connect((flaress_sine_debug_0, 0), (blocks_divide, 0)) tb.connect((flaress_sine_debug_1, 0), (blocks_divide, 1)) tb.connect((blocks_divide, 0), (dst_tar, 0)) tb.connect((blocks_complex_to_arg_1, 0), (dst_source, 0)) tb.connect((blocks_complex_to_arg_0, 0), (dst_output, 0)) self.tb.run() data_tar.phase_source = dst_source.data() data_tar.phase_output = dst_output.data() data_tar.tar = dst_tar.data() data_tar.time = np.linspace(0, (len(data_tar.phase_output) * 1.0 / samp_rate), len(data_tar.phase_output), endpoint=False) print len(data_tar.phase_output), len(data_tar.phase_source) # for i in range(len(data_tar.phase_output)): # if data_tar.phase_output[i] != 0: # print i # break plot(self, data_tar)
def __init__(self, num_ports=2, n_skip_ahead=8192): gr.hier_block2.__init__( self, "TwinRx Phase Offset Estimate", gr.io_signaturev(num_ports, num_ports, gen_sig_io(num_ports,gr.sizeof_gr_complex)), gr.io_signaturev(num_ports-1, num_ports-1, gen_sig_io(num_ports-1,gr.sizeof_float)), ) ################################################## # Parameters ################################################## self.n_skip_ahead = n_skip_ahead self.num_ports = num_ports # Create skip head blocks and connect them to the inputs self.skiphead = [] for p in range(0, num_ports): object_name_skiphead = 'blocks_skiphead_'+str(p) self.skiphead.append(blocks.skiphead(gr.sizeof_gr_complex*1, n_skip_ahead)) self.connect((self, p), (self.skiphead[p], 0)) #Create blocks computing subtracted phases and connect the results to the outputs self.multiply_conjugate = [] self.complex_to_arg = [] for p in range(0, num_ports-1): self.multiply_conjugate.append(blocks.multiply_conjugate_cc(1)) self.complex_to_arg.append(blocks.complex_to_arg(1)) self.connect((self.skiphead[0], 0), (self.multiply_conjugate[p], 0)) self.connect((self.skiphead[p+1], 0), (self.multiply_conjugate[p], 1)) self.connect((self.multiply_conjugate[p], 0), (self.complex_to_arg[p], 0)) self.connect((self.complex_to_arg[p], 0), (self, p))
def test_complex_to_arg(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) arg = blocks.complex_to_arg() probe = blocks.probe_rate(gr.sizeof_float) top.connect(src, arg, probe) return top, probe
def test_complex_to_arg(self): src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j) expected_data = (atan2(2, 1), atan2(-4,3), atan2(6, 5), atan2(-8, 7), atan2(10,-9)) src = blocks.vector_source_c(src_data) op = blocks.complex_to_arg() dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 2)
def __init__(self): gr.top_block.__init__(self, "Scanner Grc") ################################################## # Variables ################################################## self.f_symb = f_symb = 1625000.0/6.0 self.f_900_b = f_900_b = 921.2e6 self.samp_rate = samp_rate = f_symb*4 self.fs = fs = f_900_b self.f_900_e = f_900_e = 959.8e6 self.f_1800_e = f_1800_e = 1879.8e6 self.f_1800_b = f_1800_b = 1805.2e6 self.OSR = OSR = 4 ################################################## # Blocks ################################################## self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "bladerf=0" ) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(fs, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0.set_iq_balance_mode(2, 0) self.osmosdr_source_0.set_gain_mode(True, 0) self.osmosdr_source_0.set_gain(30, 0) self.osmosdr_source_0.set_if_gain(30, 0) self.osmosdr_source_0.set_bb_gain(30, 0) self.osmosdr_source_0.set_antenna("", 0) self.osmosdr_source_0.set_bandwidth(200000, 0) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 200e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.threshold_result = blocks.threshold_ff(0, 0.2, 0) self.blocks_threshold_ff_0_0 = blocks.threshold_ff(0, 0, 0) self.blocks_threshold_ff_0 = blocks.threshold_ff(int((138)*samp_rate/f_symb), int((138)*samp_rate/f_symb), 0) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_moving_average_xx_0 = blocks.moving_average_ff(int((142)*samp_rate/f_symb), 1, int(1e6)) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, int(OSR)) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_threshold_ff_0_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.threshold_result, 0)) self.connect((self.blocks_threshold_ff_0_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.threshold_result, 0), (self.blocks_null_sink_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blocks_delay_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.low_pass_filter_0, 0))
def __init__(self, OSR=4): grgsm.hier_block.__init__( self, "FCCH bursts detector", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) ################################################## # Parameters ################################################## self.OSR = OSR ################################################## # Variables ################################################## self.f_symb = f_symb = 1625000.0 / 6.0 self.samp_rate = samp_rate = f_symb * OSR ################################################## # Blocks ################################################## self.gsm_fcch_burst_tagger_0 = grgsm.fcch_burst_tagger(OSR) self.blocks_threshold_ff_0_0 = blocks.threshold_ff(0, 0, 0) self.blocks_threshold_ff_0 = blocks.threshold_ff( int((138) * samp_rate / f_symb), int((138) * samp_rate / f_symb), 0) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_moving_average_xx_0 = blocks.moving_average_ff( int((142) * samp_rate / f_symb), 1, int(1e6)) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, int(OSR)) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) ################################################## # Connections ################################################## self.connect((self, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_threshold_ff_0_0, 0)) self.connect((self, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_threshold_ff_0_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.gsm_fcch_burst_tagger_0, 0), (self, 0)) self.connect((self, 0), (self.gsm_fcch_burst_tagger_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.gsm_fcch_burst_tagger_0, 1))
def __init__(self): gr.hier_block2.__init__(self, "CORDIC from I,Q floats", gr.io_signature(2,2,gr.sizeof_float), gr.io_signature(2,2,gr.sizeof_float)) ftc = blocks.float_to_complex() mag = blocks.complex_to_mag() arg = blocks.complex_to_arg() self.connect((self,0), (ftc,0)) self.connect((self,1), (ftc,1)) self.connect(ftc,mag,(self,0)) self.connect(ftc,arg,(self,1))
def __init__(self): gr.top_block.__init__(self, "Ornl 1") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.blocks_magphase_to_complex_1 = blocks.magphase_to_complex(1) self.blocks_magphase_to_complex_0 = blocks.magphase_to_complex(1) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex * 1, 50 * samp_rate) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1, 'ornl_1.bin', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_magphase_0 = blocks.complex_to_magphase(1) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_magphase_to_complex_1, 1)) self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_magphase_to_complex_1, 0)) self.connect((self.blocks_complex_to_magphase_0, 1), (self.blocks_magphase_to_complex_0, 1)) self.connect((self.blocks_complex_to_magphase_0, 0), (self.blocks_magphase_to_complex_0, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_complex_to_magphase_0, 0)) self.connect((self.blocks_magphase_to_complex_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_magphase_to_complex_0, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.blocks_magphase_to_complex_1, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_head_0, 0))
def __init__(self): gr.hier_block2.__init__( self, "phase_calc_ccf", gr.io_signature(2, 2, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self.block = dict() self.block['mult_conj'] = blocks.multiply_conjugate_cc() self.block['arg'] = blocks.complex_to_arg() self.block['mult_const'] = blocks.multiply_const_ff(180.0 / np.pi) self.connect((self, 0), (self.block['mult_conj'], 0)) self.connect((self, 1), (self.block['mult_conj'], 1)) self.connect((self.block['mult_conj'], 0), (self.block['arg'], 0)) self.connect((self.block['arg'], 0), (self.block['mult_const'], 0)) self.connect((self.block['mult_const'], 0), (self, 0))
def BuildConjMult(self,scope=True): ## Compute angle difference #self.conj = blocks.conjugate_cc() self.mult = blocks.multiply_conjugate_cc() self.connect(self.rx0, blocks.multiply_const_cc(10000), (self.mult,0)) self.connect(self.rx1, blocks.multiply_const_cc(10000), (self.mult,1)) self.histo = qtgui.histogram_sink_f(1000,360,-179,180,"Histogram") #self.histo.enable_autoscale(False) self.histo.enable_accumulate(True) self.histo.enable_grid(True) #self.histo.enable_menu(True) self.connect(self.mult,blocks.complex_to_arg(), blocks.multiply_const_ff(180.0/np.pi),self.histo) self.pyobj = sip.wrapinstance(self.histo.pyqwidget(), QtGui.QWidget) self.pyobj.show()
def do_check_phase_shift(self, type, name): sps = 2 L = 1 in_bits = (1,) * 20 src = blocks.vector_source_b(in_bits, False) cpm = digital.cpmmod_bc(type, 0.5, sps, L) arg = blocks.complex_to_arg() sink = blocks.vector_sink_f() self.tb.connect(src, cpm, arg, sink) self.tb.run() symbol_phases = numpy.array(sink.data()[sps*L-1::sps]) phase_diff = numpy.mod(numpy.subtract(symbol_phases[1:], symbol_phases[:-1]), (2*numpy.pi,) * (len(symbol_phases)-1)) self.assertFloatTuplesAlmostEqual(tuple(phase_diff), (0.5 * numpy.pi,) * len(phase_diff), 5, msg="Phase shift was not correct for CPM method " + name)
def __init__(self, OSR=4): gr.hier_block2.__init__( self, "FCCH bursts detector", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) ################################################## # Parameters ################################################## self.OSR = OSR ################################################## # Variables ################################################## self.f_symb = f_symb = 1625000.0 / 6.0 self.samp_rate = samp_rate = f_symb * OSR ################################################## # Blocks ################################################## self.gsm_fcch_burst_tagger_0 = grgsm.fcch_burst_tagger(OSR) self.blocks_threshold_ff_0_0 = blocks.threshold_ff(0, 0, 0) self.blocks_threshold_ff_0 = blocks.threshold_ff( int((138) * samp_rate / f_symb), int((138) * samp_rate / f_symb), 0 ) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_moving_average_xx_0 = blocks.moving_average_ff(int((142) * samp_rate / f_symb), 1, int(1e6)) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, int(OSR)) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) ################################################## # Connections ################################################## self.connect((self, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_threshold_ff_0_0, 0)) self.connect((self, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_threshold_ff_0_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.gsm_fcch_burst_tagger_0, 0), (self, 0)) self.connect((self, 0), (self.gsm_fcch_burst_tagger_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.gsm_fcch_burst_tagger_0, 1))
def test_001_lgmsk(self): sps = 2 L = 5 bt = 0.3 in_bits = (1,) * 20 src = blocks.vector_source_b(in_bits, False) gmsk = digital.gmskmod_bc(sps, L, bt) arg = blocks.complex_to_arg() sink = blocks.vector_sink_f() self.tb.connect(src, gmsk, arg, sink) self.tb.run() symbol_phases = numpy.array(sink.data()[sps*L-1::sps]) phase_diff = numpy.mod(numpy.subtract(symbol_phases[1:], symbol_phases[:-1]), (2*numpy.pi,) * (len(symbol_phases)-1)) self.assertFloatTuplesAlmostEqual(tuple(phase_diff), (0.5 * numpy.pi,) * len(phase_diff), 5, msg="Phase shift was not correct for GMSK")
def __init__(self, costas_alpha=0.04, gain_mu=0.025, input_rate=48000, output_rate=4800): gr.hier_block2.__init__( self, "CQPSK Demodulator", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_float*1), ) ################################################## # Parameters ################################################## self.costas_alpha = costas_alpha self.gain_mu = gain_mu self.input_rate = input_rate self.output_rate = output_rate ################################################## # Variables ################################################## self.alpha = alpha = costas_alpha self.omega = omega = float(input_rate) / float(output_rate) self.gain_omega = gain_omega = 0.1 * gain_mu * gain_mu self.fmax = fmax = 2 * math.pi * 2400 / float(input_rate) self.beta = beta = 0.125 * alpha * alpha ################################################## # Blocks ################################################## self.to_float = blocks.complex_to_arg(1) self.rescale = blocks.multiply_const_vff((1 / (math.pi / 4), )) self.diffdec = digital.diff_phasor_cc() self.clock = op25_repeater.gardner_costas_cc(omega, gain_mu, gain_omega, alpha, beta, fmax, -fmax) self.agc = analog.feedforward_agc_cc(16, 1.0) ################################################## # Connections ################################################## self.connect((self.agc, 0), (self.clock, 0)) self.connect((self.clock, 0), (self.diffdec, 0)) self.connect((self.diffdec, 0), (self.to_float, 0)) self.connect((self, 0), (self.agc, 0)) self.connect((self.rescale, 0), (self, 0)) self.connect((self.to_float, 0), (self.rescale, 0))
def __init__(self, input_rate=None, demod_type='cqpsk', relative_freq=0, offset=0, if_rate=_def_if_rate, gain_mu=_def_gain_mu, costas_alpha=_def_costas_alpha, symbol_rate=_def_symbol_rate): """ Hierarchical block for P25 demodulation. The complex input is tuned, decimated and demodulated @param input_rate: sample rate of complex input channel @type input_rate: int """ gr.hier_block2.__init__( self, "p25_demod_cb", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature # gr.io_signature(0, 0, 0)) # Output signature p25_demod_base.__init__(self, if_rate=if_rate, symbol_rate=symbol_rate) self.input_rate = input_rate self.if_rate = if_rate self.symbol_rate = symbol_rate self.connect_state = None self.offset = 0 self.sps = 0.0 self.lo_freq = 0 self.float_sink = None self.complex_sink = None # local osc self.lo = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, 0, 1.0, 0) self.mixer = blocks.multiply_cc() lpf_coeffs = filter.firdes.low_pass(1.0, input_rate, 7250, 725, filter.firdes.WIN_HANN) decimation = int(input_rate / if_rate) self.lpf = filter.fir_filter_ccf(decimation, lpf_coeffs) resampled_rate = float(input_rate) / float( decimation) # rate at output of self.lpf self.arb_resampler = filter.pfb.arb_resampler_ccf( float(self.if_rate) / resampled_rate) self.connect(self, (self.mixer, 0)) self.connect(self.lo, (self.mixer, 1)) self.connect(self.mixer, self.lpf, self.arb_resampler) levels = [-2.0, 0.0, 2.0, 4.0] self.slicer = op25_repeater.fsk4_slicer_fb(levels) omega = float(self.if_rate) / float(self.symbol_rate) gain_omega = 0.1 * gain_mu * gain_mu alpha = costas_alpha beta = 0.125 * alpha * alpha fmax = 2400 # Hz fmax = 2 * pi * fmax / float(self.if_rate) self.clock = op25_repeater.gardner_costas_cc(omega, gain_mu, gain_omega, alpha, beta, fmax, -fmax) self.agc = analog.feedforward_agc_cc(16, 1.0) # Perform Differential decoding on the constellation self.diffdec = digital.diff_phasor_cc() # take angle of the difference (in radians) self.to_float = blocks.complex_to_arg() # convert from radians such that signal is in -3/-1/+1/+3 self.rescale = blocks.multiply_const_ff((1 / (pi / 4))) # fm demodulator (needed in fsk4 case) fm_demod_gain = if_rate / (2.0 * pi * _def_symbol_deviation) self.fm_demod = analog.quadrature_demod_cf(fm_demod_gain) self.connect_chain(demod_type) self.connect(self.slicer, self) self.set_relative_frequency(relative_freq)
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, costas_alpha=_def_costas_alpha, gain_mu=_def_gain_mu, mu=_def_mu, omega_relative_limit=_def_omega_relative_limit, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered CQPSK demodulation The input is the complex modulated signal at baseband. The output is a stream of floats in [ -3 / -1 / +1 / +3 ] @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: float @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param costas_alpha: loop filter gain @type costas_alphas: float @param gain_mu: for M&M block @type gain_mu: float @param mu: for M&M block @type mu: float @param omega_relative_limit: for M&M block @type omega_relative_limit: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__(self, "cqpsk_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._costas_alpha = costas_alpha self._mm_gain_mu = gain_mu self._mm_mu = mu self._mm_omega_relative_limit = omega_relative_limit self._gray_code = gray_code if samples_per_symbol < 2: raise TypeError, "sbp must be >= 2, is %d" % samples_per_symbol arity = pow(2,self.bits_per_symbol()) # Automatic gain control scale = (1.0/16384.0) self.pre_scaler = blocks.multiply_const_cc(scale) # scale the signal from full-range to +-1 #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100) self.agc = analog.feedforward_agc_cc(16, 2.0) # RRC data filter ntaps = 11 * samples_per_symbol self.rrc_taps = filter.firdes.root_raised_cosine( 1.0, # gain self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter=filter.interp_fir_filter_ccf(1, self.rrc_taps) if not self._mm_gain_mu: sbs_to_mm = {2: 0.050, 3: 0.075, 4: 0.11, 5: 0.125, 6: 0.15, 7: 0.15} self._mm_gain_mu = sbs_to_mm[samples_per_symbol] self._mm_omega = self._samples_per_symbol self._mm_gain_omega = .25 * self._mm_gain_mu * self._mm_gain_mu self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha fmin = -0.025 fmax = 0.025 self.receiver=digital.mpsk_receiver_cc(arity, pi/4.0, 2*pi/150, fmin, fmax, self._mm_mu, self._mm_gain_mu, self._mm_omega, self._mm_gain_omega, self._mm_omega_relative_limit) self.receiver.set_alpha(self._costas_alpha) self.receiver.set_beta(self._costas_beta) # Perform Differential decoding on the constellation self.diffdec = digital.diff_phasor_cc() # take angle of the difference (in radians) self.to_float = blocks.complex_to_arg() # convert from radians such that signal is in -3/-1/+1/+3 self.rescale = blocks.multiply_const_ff( 1 / (pi / 4) ) if verbose: self._print_verbage() if log: self._setup_logging() # Connect & Initialize base class self.connect(self, self.pre_scaler, self.agc, self.rrc_filter, self.receiver, self.diffdec, self.to_float, self.rescale, self)
def __init__(self, input_rate = None, demod_type = 'cqpsk', filter_type = None, excess_bw = _def_excess_bw, relative_freq = 0, offset = 0, if_rate = _def_if_rate, gain_mu = _def_gain_mu, costas_alpha = _def_costas_alpha, symbol_rate = _def_symbol_rate): """ Hierarchical block for P25 demodulation. The complex input is tuned, decimated and demodulated @param input_rate: sample rate of complex input channel @type input_rate: int """ gr.hier_block2.__init__(self, "p25_demod_cb", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature # gr.io_signature(0, 0, 0)) # Output signature p25_demod_base.__init__(self, if_rate=if_rate, symbol_rate=symbol_rate, filter_type=filter_type) self.input_rate = input_rate self.if_rate = if_rate self.symbol_rate = symbol_rate self.connect_state = None self.aux_fm_connected = False self.offset = 0 self.sps = 0.0 self.lo_freq = 0 self.float_sink = None self.complex_sink = None self.if1 = 0 self.if2 = 0 self.t_cache = {} if filter_type == 'rrc': self.set_baseband_gain(0.61) # local osc self.lo = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, 0, 1.0, 0) self.mixer = blocks.multiply_cc() decimator_values = get_decim(input_rate) if decimator_values: self.decim, self.decim2 = decimator_values self.if1 = input_rate / self.decim self.if2 = self.if1 / self.decim2 sys.stderr.write( 'Using two-stage decimator for speed=%d, decim=%d/%d if1=%d if2=%d\n' % (input_rate, self.decim, self.decim2, self.if1, self.if2)) bpf_coeffs = filter.firdes.complex_band_pass(1.0, input_rate, -self.if1/2, self.if1/2, self.if1/2, filter.firdes.WIN_HAMMING) self.t_cache[0] = bpf_coeffs fa = 6250 fb = self.if2 / 2 lpf_coeffs = filter.firdes.low_pass(1.0, self.if1, (fb+fa)/2, fb-fa, filter.firdes.WIN_HAMMING) self.bpf = filter.fir_filter_ccc(self.decim, bpf_coeffs) self.lpf = filter.fir_filter_ccf(self.decim2, lpf_coeffs) resampled_rate = self.if2 self.bfo = analog.sig_source_c (self.if1, analog.GR_SIN_WAVE, 0, 1.0, 0) self.connect(self, self.bpf, (self.mixer, 0)) self.connect(self.bfo, (self.mixer, 1)) else: sys.stderr.write( 'Unable to use two-stage decimator for speed=%d\n' % (input_rate)) # local osc self.lo = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, 0, 1.0, 0) lpf_coeffs = filter.firdes.low_pass(1.0, input_rate, 7250, 1450, filter.firdes.WIN_HANN) decimation = int(input_rate / if_rate) self.lpf = filter.fir_filter_ccf(decimation, lpf_coeffs) resampled_rate = float(input_rate) / float(decimation) # rate at output of self.lpf self.connect(self, (self.mixer, 0)) self.connect(self.lo, (self.mixer, 1)) self.connect(self.mixer, self.lpf) if self.if_rate != resampled_rate: self.if_out = filter.pfb.arb_resampler_ccf(float(self.if_rate) / resampled_rate) self.connect(self.lpf, self.if_out) else: self.if_out = self.lpf fa = 6250 fb = fa + 625 cutoff_coeffs = filter.firdes.low_pass(1.0, self.if_rate, (fb+fa)/2, fb-fa, filter.firdes.WIN_HANN) self.cutoff = filter.fir_filter_ccf(1, cutoff_coeffs) omega = float(self.if_rate) / float(self.symbol_rate) gain_omega = 0.1 * gain_mu * gain_mu alpha = costas_alpha beta = 0.125 * alpha * alpha fmax = 2400 # Hz fmax = 2*pi * fmax / float(self.if_rate) self.clock = op25_repeater.gardner_costas_cc(omega, gain_mu, gain_omega, alpha, beta, fmax, -fmax) self.agc = analog.feedforward_agc_cc(16, 1.0) # Perform Differential decoding on the constellation self.diffdec = digital.diff_phasor_cc() # take angle of the difference (in radians) self.to_float = blocks.complex_to_arg() # convert from radians such that signal is in -3/-1/+1/+3 self.rescale = blocks.multiply_const_ff( (1 / (pi / 4)) ) # fm demodulator (needed in fsk4 case) fm_demod_gain = if_rate / (2.0 * pi * _def_symbol_deviation) self.fm_demod = analog.quadrature_demod_cf(fm_demod_gain) self.connect_chain(demod_type) self.connect(self.slicer, self) self.set_relative_frequency(relative_freq)
def __init__(self, input_rate = None, demod_type = 'cqpsk', relative_freq = 0, offset = 0, if_rate = _def_if_rate, gain_mu = _def_gain_mu, costas_alpha = _def_costas_alpha, symbol_rate = _def_symbol_rate): """ Hierarchical block for P25 demodulation. The complex input is tuned, decimated and demodulated @param input_rate: sample rate of complex input channel @type input_rate: int """ gr.hier_block2.__init__(self, "p25_demod_cb", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature # gr.io_signature(0, 0, 0)) # Output signature p25_demod_base.__init__(self, if_rate=if_rate, symbol_rate=symbol_rate) self.input_rate = input_rate self.if_rate = if_rate self.symbol_rate = symbol_rate self.connect_state = None self.offset = 0 self.sps = 0.0 self.lo_freq = 0 self.float_sink = None self.complex_sink = None # local osc self.lo = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, 0, 1.0, 0) self.mixer = blocks.multiply_cc() lpf_coeffs = filter.firdes.low_pass(1.0, input_rate, 7250, 725, filter.firdes.WIN_HANN) decimation = int(input_rate / if_rate) self.lpf = filter.fir_filter_ccf(decimation, lpf_coeffs) resampled_rate = float(input_rate) / float(decimation) # rate at output of self.lpf self.arb_resampler = filter.pfb.arb_resampler_ccf( float(self.if_rate) / resampled_rate) self.connect(self, (self.mixer, 0)) self.connect(self.lo, (self.mixer, 1)) self.connect(self.mixer, self.lpf, self.arb_resampler) levels = [ -2.0, 0.0, 2.0, 4.0 ] self.slicer = op25_repeater.fsk4_slicer_fb(levels) omega = float(self.if_rate) / float(self.symbol_rate) gain_omega = 0.1 * gain_mu * gain_mu alpha = costas_alpha beta = 0.125 * alpha * alpha fmax = 2400 # Hz fmax = 2*pi * fmax / float(self.if_rate) self.clock = op25_repeater.gardner_costas_cc(omega, gain_mu, gain_omega, alpha, beta, fmax, -fmax) self.agc = analog.feedforward_agc_cc(16, 1.0) # Perform Differential decoding on the constellation self.diffdec = digital.diff_phasor_cc() # take angle of the difference (in radians) self.to_float = blocks.complex_to_arg() # convert from radians such that signal is in -3/-1/+1/+3 self.rescale = blocks.multiply_const_ff( (1 / (pi / 4)) ) # fm demodulator (needed in fsk4 case) fm_demod_gain = if_rate / (2.0 * pi * _def_symbol_deviation) self.fm_demod = analog.quadrature_demod_cf(fm_demod_gain) self.connect_chain(demod_type) self.connect(self.slicer, self) self.set_relative_frequency(relative_freq)
def __init__(self, fm_subcarrier=9960, zero_point=-5): grc_wxgui.top_block_gui.__init__(self, title="VOR Receiver") ################################################## # Parameters ################################################## self.fm_subcarrier = fm_subcarrier self.zero_point = zero_point ################################################## # Variables ################################################## self.rf_rate = rf_rate = 1000000 self.dir_rate = dir_rate = 10 self.channel_rate = channel_rate = 40000 self.audio_rate = audio_rate = 10000 self.vor_freq = vor_freq = 113.9e6 self.volume = volume = 0 self.rf_scale = rf_scale = int(rf_rate/channel_rate) + rf_rate % channel_rate self.offset = offset = fm_subcarrier + 4000 self.dir_scale = dir_scale = int(audio_rate/dir_rate) + audio_rate % dir_rate self.channel = channel = 113.9e6 self.audio_scale = audio_scale = int(channel_rate/audio_rate) + channel_rate % audio_rate ################################################## # Blocks ################################################## _volume_sizer = wx.BoxSizer(wx.VERTICAL) self._volume_text_box = forms.text_box( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, label='volume', converter=forms.float_converter(), proportion=0, ) self._volume_slider = forms.slider( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, minimum=-10, maximum=10, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_volume_sizer) self._channel_text_box = forms.text_box( parent=self.GetWin(), value=self.channel, callback=self.set_channel, label="Channel (Hz)", converter=forms.float_converter(), ) self.Add(self._channel_text_box) self.zeroer = blocks.add_const_vff((zero_point*(math.pi/180), )) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="deg", minval=-180, maxval=180, factor=180/math.acos(-1), decimal_places=2, ref_level=0, sample_rate=dir_rate, number_rate=dir_rate, average=True, avg_alpha=.25, label="Direction", peak_hold=False, show_gauge=True, ) self.Add(self.wxgui_numbersink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=channel, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=channel_rate, fft_size=1024, fft_rate=15, average=True, avg_alpha=0.25, title="Channel", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self._vor_freq_text_box = forms.text_box( parent=self.GetWin(), value=self.vor_freq, callback=self.set_vor_freq, label='vor_freq', converter=forms.float_converter(), ) self.Add(self._vor_freq_text_box) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=40, decimation=1, taps=None, fractional_bw=None, ) self.low_pass_filter_1 = filter.fir_filter_ccf(1, firdes.low_pass( 1, dir_rate, 1, 2, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, channel_rate, 10000, 4000, firdes.WIN_HAMMING, 6.76)) self.goertzel_fc_0_0 = fft.goertzel_fc(channel_rate, dir_scale*audio_scale, 30) self.goertzel_fc_0 = fft.goertzel_fc(audio_rate, dir_scale, 30) self.freq_xlating_fir_filter_xxx_0_0 = filter.freq_xlating_fir_filter_ccc(1, (firdes.low_pass(1.0, channel_rate, 500, 100, firdes.WIN_HAMMING)), fm_subcarrier, channel_rate) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(rf_scale, (firdes.low_pass(1.0, rf_rate, channel_rate, channel_rate/2, firdes.WIN_HAMMING)), 900, rf_rate) self.dc_blocker_xx_0 = filter.dc_blocker_ff(128, True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, 1e6) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((10**(volume/10), )) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, "/home/john/apps/aviation_rx/woodside_vor25.dat", True) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, int(channel_rate/30*0.0)) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.audio_sink_0 = audio.sink(audio_rate, "", True) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(1) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=40e3, audio_decim=4, audio_pass=5000, audio_stop=5500, ) self.analog_agc2_xx_1 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_1.set_max_gain(65536) self.analog_agc2_xx_0_1_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0_1_0.set_max_gain(100) self.analog_agc2_xx_0_1 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0_1.set_max_gain(100) ################################################## # Connections ################################################## self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blocks_delay_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.goertzel_fc_0_0, 0)) self.connect((self.goertzel_fc_0, 0), (self.analog_agc2_xx_0_1, 0)) self.connect((self.goertzel_fc_0_0, 0), (self.analog_agc2_xx_0_1_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_delay_0, 0), (self.freq_xlating_fir_filter_xxx_0_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.zeroer, 0)) self.connect((self.zeroer, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.analog_agc2_xx_0_1, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.analog_agc2_xx_0_1_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.goertzel_fc_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.dc_blocker_xx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.analog_agc2_xx_1, 0)) self.connect((self.analog_agc2_xx_1, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Prr Fd Gui") Qt.QWidget.__init__(self) self.setWindowTitle("Prr Fd Gui") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "prr_fd_gui") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.occupied_carriers = occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) self.sync_word_zeros = sync_word_zeros = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.sync_word = sync_word = [0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 0, 0, 0, 0, 0] self.pilot_symbols = pilot_symbols = ((1, 1, 1, -1,),) self.pilot_carriers = pilot_carriers = ((-21, -7, 7, 21,),) self.packet_len = packet_len = 32 self.occupied_carriers_len = occupied_carriers_len = len(occupied_carriers[0]) self.variable_function_probe_0_2 = variable_function_probe_0_2 = 0 self.variable_function_probe_0_1_0 = variable_function_probe_0_1_0 = 0 self.variable_function_probe_0_0_1 = variable_function_probe_0_0_1 = 0 self.variable_function_probe_0_0_0_0 = variable_function_probe_0_0_0_0 = 0 self.usrp_source_addr = usrp_source_addr = "addr0=192.168.30.3, addr1=192.168.30.4" self.usrp_sink_addr = usrp_sink_addr = "addr0=192.168.30.3, addr1=192.168.30.4" self.tx_gain = tx_gain = 20 self.sync_word_zero_len = sync_word_zero_len = len(sync_word_zeros) self.sync_word_len = sync_word_len = len(sync_word) self.sync_word2 = sync_word2 = [0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 0, 0, 0, 0, 0] self.sync_word1 = sync_word1 = [0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 0., 0., 0., 0., 0.] self.symbols_num = symbols_num = (packet_len + 4)*8/2 /occupied_carriers_len + 3 self.samp_rate = samp_rate = 5e6 self.premultiply = premultiply = 1 self.pilot_symbols_len = pilot_symbols_len = len(pilot_symbols[0]) self.pilot_carriers_len = pilot_carriers_len = len(pilot_carriers[0]) self.pad_tail_len = pad_tail_len = 1000 self.pad_front_len = pad_front_len = 320000 self.out_buf_size = out_buf_size = 1000000 self.len_tag_key = len_tag_key = "packet_len" self.freq = freq = 915e6 self.frame_len = frame_len = ((packet_len+4)/12+3+2 + 2 + 2*2)*80 + 0*80 self.fft_len = fft_len = 64 self.delay_tx2rx = delay_tx2rx = 40 self.bb_gain = bb_gain = -21.5 ################################################## # Blocks ################################################## self._tx_gain_range = Range(0, 25, 1, 20, 200) self._tx_gain_win = RangeWidget(self._tx_gain_range, self.set_tx_gain, 'Tx Gain', "counter_slider", int) self.top_grid_layout.addWidget(self._tx_gain_win, 5, 0, 1, 6) for r in range(5, 6): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 6): self.top_grid_layout.setColumnStretch(c, 1) self.uhd_usrp_source = uhd.usrp_source( ",".join((usrp_source_addr, "")), uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) self.uhd_usrp_source.set_clock_source('mimo', 1) self.uhd_usrp_source.set_time_source('mimo', 1) self.uhd_usrp_source.set_samp_rate(samp_rate) self.uhd_usrp_source.set_center_freq(freq, 0) self.uhd_usrp_source.set_gain(10, 0) self.uhd_usrp_source.set_antenna('RX2', 0) self.uhd_usrp_source.set_auto_dc_offset(True, 0) self.uhd_usrp_source.set_auto_iq_balance(True, 0) self.uhd_usrp_source.set_center_freq(freq, 1) self.uhd_usrp_source.set_gain(10, 1) self.uhd_usrp_source.set_antenna('RX2', 1) self.uhd_usrp_source.set_auto_dc_offset(True, 1) self.uhd_usrp_source.set_auto_iq_balance(True, 1) self.uhd_usrp_sink = uhd.usrp_sink( ",".join((usrp_sink_addr, "")), uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) self.uhd_usrp_sink.set_clock_source('mimo', 1) self.uhd_usrp_sink.set_time_source('mimo', 1) self.uhd_usrp_sink.set_samp_rate(samp_rate) self.uhd_usrp_sink.set_center_freq(freq, 0) self.uhd_usrp_sink.set_gain(0, 0) self.uhd_usrp_sink.set_antenna('TX/RX', 0) self.uhd_usrp_sink.set_center_freq(freq, 1) self.uhd_usrp_sink.set_gain(tx_gain, 1) self.uhd_usrp_sink.set_antenna('TX/RX', 1) def _variable_function_probe_0_2_probe(): while True: val = self.uhd_usrp_sink.set_time_now(uhd.time_spec_t(0.0)) try: self.set_variable_function_probe_0_2(val) except AttributeError: pass time.sleep(1.0 / (1e-9)) _variable_function_probe_0_2_thread = threading.Thread(target=_variable_function_probe_0_2_probe) _variable_function_probe_0_2_thread.daemon = True _variable_function_probe_0_2_thread.start() def _variable_function_probe_0_1_0_probe(): while True: val = self.uhd_usrp_source.set_time_now(uhd.time_spec_t(0.0)) try: self.set_variable_function_probe_0_1_0(val) except AttributeError: pass time.sleep(1.0 / (1e-9)) _variable_function_probe_0_1_0_thread = threading.Thread(target=_variable_function_probe_0_1_0_probe) _variable_function_probe_0_1_0_thread.daemon = True _variable_function_probe_0_1_0_thread.start() def _variable_function_probe_0_0_1_probe(): while True: val = self.uhd_usrp_sink.set_start_time(uhd.time_spec_t(0.5)) try: self.set_variable_function_probe_0_0_1(val) except AttributeError: pass time.sleep(1.0 / (1e-9)) _variable_function_probe_0_0_1_thread = threading.Thread(target=_variable_function_probe_0_0_1_probe) _variable_function_probe_0_0_1_thread.daemon = True _variable_function_probe_0_0_1_thread.start() def _variable_function_probe_0_0_0_0_probe(): while True: val = self.uhd_usrp_source.set_start_time(uhd.time_spec_t(0.5)) try: self.set_variable_function_probe_0_0_0_0(val) except AttributeError: pass time.sleep(1.0 / (1e-9)) _variable_function_probe_0_0_0_0_thread = threading.Thread(target=_variable_function_probe_0_0_0_0_probe) _variable_function_probe_0_0_0_0_thread.daemon = True _variable_function_probe_0_0_0_0_thread.start() self.qtgui_time_sink_x_0 = qtgui.time_sink_c( frame_len, #size samp_rate, #samp_rate "", #name 2 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(True) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ["After RF SIC, I", "After RF SIC, Q", "After Digital SIC, I", "After Digital SIC, Q", '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(4): if len(labels[i]) == 0: if(i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 0, 0, 3, 6) for r in range(0, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 6): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_number_sink_0_0_0_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1 ) self.qtgui_number_sink_0_0_0_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0_0_0_0.set_title("Measured PRR") labels = ["Packet Reception Ratio", '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0_0_0_0.set_min(i, 0) self.qtgui_number_sink_0_0_0_0_0.set_max(i, 1) self.qtgui_number_sink_0_0_0_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0_0_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0_0_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0_0_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0_0_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0_0_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_0_0_0_win = sip.wrapinstance(self.qtgui_number_sink_0_0_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_0_0_0_win, 4, 0, 1, 6) for r in range(4, 5): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 6): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_number_sink_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1 ) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title("Measured SNR") labels = ["Signal-to-Noise Ratio", '', '', '', '', '', '', '', '', ''] units = ["dB", '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0.set_min(i, 0) self.qtgui_number_sink_0.set_max(i, 35) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(False) self._qtgui_number_sink_0_win = sip.wrapinstance(self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_win, 3, 0, 1, 6) for r in range(3, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 6): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 3*48, #size "Constellation after RF SIC", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "red", "red", "red", "red", "red", "red", "red", "red"] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_0_win, 0, 7, 3, 3) for r in range(0, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(7, 10): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 3*48, #size "Constellation after Digital SIC", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0.enable_autoscale(False) self.qtgui_const_sink_x_0.enable_grid(False) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "red", "red", "red", "red", "red", "red", "red", "red"] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win, 3, 7, 3, 3) for r in range(3, 6): self.top_grid_layout.setRowStretch(r, 1) for c in range(7, 10): self.top_grid_layout.setColumnStretch(c, 1) self.fullduplex_snr_calc_0 = fullduplex.snr_calc(False, 0, -20, 6, 0, 140) self.fullduplex_packet_encap2_0_0 = fullduplex.packet_encap2(False, False, 0.001, pad_front_len, pad_tail_len, 1, 0.2, 2) (self.fullduplex_packet_encap2_0_0).set_min_output_buffer(1000000) self.fullduplex_packet_encap2_0 = fullduplex.packet_encap2(False, False, 0.001, pad_front_len, pad_tail_len, 0, premultiply, 2) (self.fullduplex_packet_encap2_0).set_min_output_buffer(1000000) self.fullduplex_ofdm_constellation_0_0 = fullduplex.ofdm_constellation(False, 8, -20, frame_len) (self.fullduplex_ofdm_constellation_0_0).set_min_output_buffer(1000000) self.fullduplex_ofdm_constellation_0 = fullduplex.ofdm_constellation(False, 0, -20, frame_len) (self.fullduplex_ofdm_constellation_0).set_min_output_buffer(1000000) self.fullduplex_digital_sic_0_0 = fullduplex.digital_sic(False, delay_tx2rx, pad_front_len, 0, frame_len, 10, 1, premultiply) (self.fullduplex_digital_sic_0_0).set_min_output_buffer(1000000) self.fullduplex_count_packets_0_0 = fullduplex.count_packets(False) self.fullduplex_count_packets_0 = fullduplex.count_packets(False) self.fullduplex_async_divide_0 = fullduplex.async_divide() self.digital_ofdm_tx_0_0_0 = digital.ofdm_tx( fft_len=fft_len, cp_len=fft_len/4, packet_length_tag_key=len_tag_key, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, sync_word1=sync_word1, sync_word2=sync_word2, bps_header=1, bps_payload=2, rolloff=0, debug_log=False, scramble_bits=False ) self.digital_ofdm_tx_0_0 = digital.ofdm_tx( fft_len=fft_len, cp_len=fft_len/4, packet_length_tag_key=len_tag_key, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, sync_word1=sync_word1, sync_word2=sync_word2, bps_header=1, bps_payload=2, rolloff=0, debug_log=False, scramble_bits=False ) self.digital_ofdm_rx_0_0_0 = digital.ofdm_rx( fft_len=fft_len, cp_len=fft_len/4, frame_length_tag_key='frame_'+"rx_len_tag_key", packet_length_tag_key="rx_len_tag_key", occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, sync_word1=sync_word1, sync_word2=sync_word2, bps_header=1, bps_payload=2, debug_log=False, scramble_bits=False ) (self.digital_ofdm_rx_0_0_0).set_min_output_buffer(1000000) self.blocks_stream_to_tagged_stream_1 = blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, frame_len + pad_front_len + pad_tail_len, "packet_len") (self.blocks_stream_to_tagged_stream_1).set_min_output_buffer(1000000) self.blocks_stream_to_tagged_stream_0_0_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, len_tag_key) self.blocks_stream_to_tagged_stream_0_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, len_tag_key) self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, len_tag_key) self.blocks_null_sink_3_1_1 = blocks.null_sink(gr.sizeof_float*1) self.blocks_null_sink_3_1_0 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_null_sink_3_1 = blocks.null_sink(gr.sizeof_float*1) self.blocks_null_sink_3 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vcc((0.01*2.23 * 0.56 * 1.4 * 1.4 * premultiply * 10**(bb_gain/20.0), )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((0.01*2.23 * 0.56 * 1.4 * 1.4 * premultiply * 10 ** (-5.0/20), )) self.blocks_float_to_uchar_0 = blocks.float_to_uchar() self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.analog_random_source_x_0_0 = blocks.vector_source_b(map(int, numpy.random.randint(51, 100, 50)), True) self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 50, 50)), True) ################################################## # Connections ################################################## self.msg_connect((self.fullduplex_count_packets_0, 'out_msg'), (self.fullduplex_async_divide_0, 'in1')) self.msg_connect((self.fullduplex_count_packets_0_0, 'out_msg'), (self.fullduplex_async_divide_0, 'in2')) self.connect((self.analog_random_source_x_0, 0), (self.blocks_stream_to_tagged_stream_0, 0)) self.connect((self.analog_random_source_x_0_0, 0), (self.blocks_stream_to_tagged_stream_0_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_float_to_uchar_0, 0)) self.connect((self.blocks_float_to_uchar_0, 0), (self.fullduplex_count_packets_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.fullduplex_packet_encap2_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.fullduplex_packet_encap2_0_0, 0)) self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.digital_ofdm_tx_0_0, 0)) self.connect((self.blocks_stream_to_tagged_stream_0_0, 0), (self.digital_ofdm_tx_0_0_0, 0)) self.connect((self.blocks_stream_to_tagged_stream_0_0_0, 0), (self.fullduplex_count_packets_0, 0)) self.connect((self.blocks_stream_to_tagged_stream_1, 0), (self.fullduplex_digital_sic_0_0, 1)) self.connect((self.digital_ofdm_rx_0_0_0, 0), (self.blocks_stream_to_tagged_stream_0_0_0, 0)) self.connect((self.digital_ofdm_tx_0_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.digital_ofdm_tx_0_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.fullduplex_async_divide_0, 0), (self.qtgui_number_sink_0_0_0_0_0, 0)) self.connect((self.fullduplex_count_packets_0, 0), (self.blocks_null_sink_3_1_1, 1)) self.connect((self.fullduplex_count_packets_0_0, 0), (self.blocks_null_sink_3_1_1, 0)) self.connect((self.fullduplex_digital_sic_0_0, 1), (self.blocks_complex_to_arg_0, 0)) self.connect((self.fullduplex_digital_sic_0_0, 2), (self.blocks_null_sink_3, 0)) self.connect((self.fullduplex_digital_sic_0_0, 0), (self.blocks_null_sink_3_1_0, 0)) self.connect((self.fullduplex_digital_sic_0_0, 1), (self.digital_ofdm_rx_0_0_0, 0)) self.connect((self.fullduplex_digital_sic_0_0, 1), (self.fullduplex_ofdm_constellation_0, 0)) self.connect((self.fullduplex_digital_sic_0_0, 0), (self.fullduplex_ofdm_constellation_0_0, 0)) self.connect((self.fullduplex_digital_sic_0_0, 1), (self.fullduplex_snr_calc_0, 0)) self.connect((self.fullduplex_digital_sic_0_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.fullduplex_digital_sic_0_0, 1), (self.qtgui_time_sink_x_0, 1)) self.connect((self.fullduplex_ofdm_constellation_0, 1), (self.blocks_null_sink_3_1, 1)) self.connect((self.fullduplex_ofdm_constellation_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.fullduplex_ofdm_constellation_0_0, 1), (self.blocks_null_sink_3_1, 0)) self.connect((self.fullduplex_ofdm_constellation_0_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.fullduplex_packet_encap2_0, 0), (self.fullduplex_digital_sic_0_0, 0)) self.connect((self.fullduplex_packet_encap2_0, 0), (self.uhd_usrp_sink, 0)) self.connect((self.fullduplex_packet_encap2_0_0, 0), (self.uhd_usrp_sink, 1)) self.connect((self.fullduplex_snr_calc_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.uhd_usrp_source, 1), (self.blocks_null_sink_1, 0)) self.connect((self.uhd_usrp_source, 0), (self.blocks_stream_to_tagged_stream_1, 0))
def __init__(self, fft_length, cp_length, kstime, logging=False): """ OFDM synchronization using PN Correlation and initial cross-correlation: F. Tufvesson, O. Edfors, and M. Faulkner, "Time and Frequency Synchronization for OFDM using PN-Sequency Preambles," IEEE Proc. VTC, 1999, pp. 2203-2207. This implementation is meant to be a more robust version of the Schmidl and Cox receiver design. By correlating against the preamble and using that as the input to the time-delayed correlation, this circuit produces a very clean timing signal at the end of the preamble. The timing is more accurate and does not have the problem associated with determining the timing from the plateau structure in the Schmidl and Cox. This implementation appears to require that the signal is received with a normalized power or signal scaling factor to reduce ambiguities introduced from partial correlation of the cyclic prefix and the peak detection. A better peak detection block might fix this. Also, the cross-correlation falls apart as the frequency offset gets larger and completely fails when an integer offset is introduced. Another thing to look at. """ gr.hier_block2.__init__(self, "ofdm_sync_pnac", 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 = blocks.add_const_cc(0) symbol_length = fft_length + cp_length # PN Sync with cross-correlation input # cross-correlate with the known symbol kstime = [k.conjugate() for k in kstime[0:fft_length//2]] kstime.reverse() self.crosscorr_filter = filter.fir_filter_ccc(1, kstime) # Create a delay line self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length/2) # Correlation from ML Sync self.conjg = blocks.conjugate_cc(); self.corr = blocks.multiply_cc(); # Create a moving sum filter for the input self.mag = blocks.complex_to_mag_squared() self.power = filter.fir_filter_fff(1, [1.0] * int(fft_length)) # Get magnitude (peaks) and angle (phase/freq error) self.c2mag = blocks.complex_to_mag_squared() self.angle = blocks.complex_to_arg() self.compare = blocks.sub_ff() self.sample_and_hold = blocks.sample_and_hold_ff() #ML measurements input to sampler block and detect self.threshold = blocks.threshold_ff(0,0,0) # threshold detection might need to be tweaked self.peaks = blocks.float_to_char() self.connect(self, self.input) # Cross-correlate input signal with known preamble self.connect(self.input, self.crosscorr_filter) # use the output of the cross-correlation as input time-shifted correlation self.connect(self.crosscorr_filter, self.delay) self.connect(self.crosscorr_filter, (self.corr,0)) self.connect(self.delay, self.conjg) self.connect(self.conjg, (self.corr,1)) self.connect(self.corr, self.c2mag) self.connect(self.corr, self.angle) self.connect(self.angle, (self.sample_and_hold,0)) # Get the power of the input signal to compare against the correlation self.connect(self.crosscorr_filter, self.mag, self.power) # Compare the power to the correlator output to determine timing peak # When the peak occurs, it peaks above zero, so the thresholder detects this self.connect(self.c2mag, (self.compare,0)) self.connect(self.power, (self.compare,1)) self.connect(self.compare, self.threshold) self.connect(self.threshold, self.peaks, (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.peaks, (self,1)) if logging: self.connect(self.compare, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-compare_f.dat")) self.connect(self.c2mag, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-theta_f.dat")) self.connect(self.power, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-inputpower_f.dat")) self.connect(self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-epsilon_f.dat")) self.connect(self.threshold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-threshold_f.dat")) self.connect(self.peaks, blocks.file_sink(gr.sizeof_char, "ofdm_sync_pnac-peaks_b.dat")) self.connect(self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-sample_and_hold_f.dat")) self.connect(self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pnac-input_c.dat"))
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() self.src = blocks.file_source(gr.sizeof_gr_complex*1, "/tmp/myout1.ch", False) ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 15 self.afc_gain = 0.01 self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 10 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) self.channels = 10 ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.blocks_deinterleave_0 = blocks.deinterleave(gr.sizeof_gr_complex*1, 1) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): mpsk = digital.mpsk_receiver_cc( 4, math.pi/4, math.pi/100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2./math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) brmchannels = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71] #brmchannels = [11,4,3,64,45,47,53,8,68,6,56,49,17,54,65,5,71,22,48,7,50] # itds kancl #brmchannels = [23,13,40,69,59,7,42,54,5,14,4,56,45,46,67,55,66,44,71,49,31,57,0,65,70] # doma - dole #brmchannels = [23,13,59,40,69,7,49,60,42,70,4,50,66,67,3,14,57,33,46,22,68,32,39,24,6,12,43,58,48,17,5,56,65,29,54,30,16,52,53,41,47,2,34,44,8] # doma - strecha #brmchannels = [67, 7, 23, 70] # doma - strecha - SDS #brmchannels = [67, 7, 23, 70,9,71,64,63,62,61,55,51,45,38,37,36,35,31,28,27,26,25,21,20,19,18,15,11,10,1,0] # doma - strecha - komplement if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port)+ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) print "connect %i"%ch if ch in brmchannels: self.connect((self.blocks_deinterleave_0, ch), #(squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect( (self.src, 0), (self.blocks_deinterleave_0, 0)) ################################################## # signal strenght identification ################################################## ''' self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./self.srate_channel) self.pwr_probes.append(pwr_probe) print "connect %i"%ch self.connect((self.blocks_deinterleave_0, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "power threshold target %f"%pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in []: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread(target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ''' ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel/(2*math.pi)) samp_afc = self.srate_channel*self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1./samp_afc*self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): rt = 0.0 while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() freq = err * self.afc_gain print "err: %f\tfreq: %f\trt %f" % (err, freq, rt) changed = False if err < -1: rt += 0.1 changed = True elif err > 1: rt -= 0.1 changed = True if changed: os.system("echo \"setrot %f\" | nc localhost 3333"%rt) self.afc_channel = 0 self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): print "connect %i"%ch self.connect((self.blocks_deinterleave_0, ch), (self.afc_selector, ch)) self.connect( (self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-1", "--one-channel", action="store_true", default=False, help="software synthesized Q channel") parser.add_option("-a", "--agc", action="store_true", default=False, help="automatic gain control (overrides --gain)") parser.add_option("-c", "--calibration", type="eng_float", default=0, help="freq offset") parser.add_option("-d", "--debug", action="store_true", default=False, help="allow time at init to attach gdb") parser.add_option("-C", "--costas-alpha", type="eng_float", default=0.125, help="Costas alpha") parser.add_option("-g", "--gain", type="eng_float", default=1.0) parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file") parser.add_option("-I", "--imbe", action="store_true", default=False, help="output IMBE codewords") parser.add_option("-L", "--low-pass", type="eng_float", default=6.5e3, help="low pass cut-off", metavar="Hz") parser.add_option("-o", "--output-file", type="string", default="out.dat", help="specify the output file") parser.add_option("-p", "--polarity", action="store_true", default=False, help="use reversed polarity") parser.add_option("-r", "--raw-symbols", type="string", default=None, help="dump decoded symbols to file") parser.add_option("-s", "--sample-rate", type="int", default=96000, help="input sample rate") parser.add_option("-t", "--tone-detect", action="store_true", default=False, help="use experimental tone detect algorithm") parser.add_option("-v", "--verbose", action="store_true", default=False, help="additional output") parser.add_option("-6", "--k6k", action="store_true", default=False, help="use 6K symbol rate") (options, args) = parser.parse_args() sample_rate = options.sample_rate if options.k6k: symbol_rate = 6000 else: symbol_rate = 4800 samples_per_symbol = sample_rate // symbol_rate IN = blocks.file_source(gr.sizeof_gr_complex, options.input_file) if options.one_channel: C2F = blocks.complex_to_float() F2C = blocks.float_to_complex() # osc./mixer for mixing signal down to approx. zero IF LO = analog.sig_source_c (sample_rate, analog.GR_COS_WAVE, options.calibration, 1.0, 0) MIXER = blocks.multiply_cc() # get signal into normalized range (-1.0 - +1.0) if options.agc: AMP = analog.feedforward_agc_cc(16, 1.0) else: AMP = blocks.multiply_const_cc(options.gain) lpf_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) decim_amt = 1 if options.tone_detect: if sample_rate != 96000: print "warning, only 96K has been tested." print "other rates may require theta to be reviewed/adjusted." step_size = 7.5e-8 theta = -4 # optimum timing sampling point cic_length = 48 DEMOD = op25_repeater.tdetect_cc(samples_per_symbol, step_size, theta, cic_length) else: # decim by 2 to get 48k rate samples_per_symbol /= 2 # for DECIM sample_rate /= 2 # for DECIM decim_amt = 2 # create Gardner/Costas loop # the loop will not work if the sample levels aren't normalized (above) timing_error_gain = 0.025 # loop error gain gain_omega = 0.25 * timing_error_gain * timing_error_gain alpha = options.costas_alpha beta = 0.125 * alpha * alpha fmin = -0.025 # fmin and fmax are in radians/s fmax = 0.025 DEMOD = op25_repeater.gardner_costas_cc(samples_per_symbol, timing_error_gain, gain_omega, alpha, beta, fmax, fmin) DECIM = filter.fir_filter_ccf (decim_amt, lpf_taps) # probably too much phase noise etc to attempt coherent demodulation # so we use differential DIFF = digital.diff_phasor_cc() # take angle of the phase difference (in radians) TOFLOAT = blocks.complex_to_arg() # convert from radians such that signal is in [-3, -1, +1, +3] RESCALE = blocks.multiply_const_ff(1 / (pi / 4.0)) # optional polarity reversal (should be unnec. - now autodetected) p = 1.0 if options.polarity: p = -1.0 POLARITY = blocks.multiply_const_ff(p) # hard decision at specified points levels = [-2.0, 0.0, 2.0, 4.0 ] SLICER = op25_repeater.fsk4_slicer_fb(levels) # assemble received frames and route to Wireshark via UDP hostname = "127.0.0.1" port = 23456 debug = 0 if options.verbose: debug = 255 do_imbe = False if options.imbe: do_imbe = True do_output = True # enable block's output stream do_msgq = False # msgq output not yet implemented msgq = gr.msg_queue(2) DECODER = op25_repeater.p25_frame_assembler(hostname, port, debug, do_imbe, do_output, do_msgq, msgq, False, False) OUT = blocks.file_sink(gr.sizeof_char, options.output_file) if options.one_channel: self.connect(IN, C2F, F2C, (MIXER, 0)) else: self.connect(IN, (MIXER, 0)) self.connect(LO, (MIXER, 1)) self.connect(MIXER, AMP, DECIM, DEMOD, DIFF, TOFLOAT, RESCALE, POLARITY, SLICER, DECODER, OUT) if options.raw_symbols: SINKC = blocks.file_sink(gr.sizeof_char, options.raw_symbols) self.connect(SLICER, SINKC) if options.debug: print 'Ready for GDB to attach (pid = %d)' % (os.getpid(),) raw_input("Press 'Enter' to continue...")
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 960e3 ################################################## # Blocks ################################################## self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.rational_resampler_xxx_1 = filter.rational_resampler_fff( interpolation=1, decimation=30, taps=None, fractional_bw=None, ) self.iir_filter_xxx_2 = filter.iir_filter_ffd((10, ), (1, .95), True) self.iir_filter_xxx_1 = filter.iir_filter_ffd((1/(5e3), ), ([1,1]), True) self.iir_filter_xxx_0 = filter.iir_filter_ffd(([1,0.95]), ([1,0]), False) self.hilbert_fc_0 = filter.hilbert_fc(65, firdes.WIN_HAMMING, 6.76) self.dc_blocker_xx_0 = filter.dc_blocker_ff(8192, True) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.blocks_add_xx_2 = blocks.add_vff(1) self.blocks_add_xx_1_0 = blocks.add_vff(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.audio_sink_0 = audio.sink(32000, "", True) self.analog_sig_source_x_3 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0) self.analog_sig_source_x_2_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 10000, 1, 0) self.analog_sig_source_x_1_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 5000, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 300000, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -300000, 1, 0) self.analog_phase_modulator_fc_0 = analog.phase_modulator_fc(5e-6) self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 0.01, 0) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_phase_modulator_fc_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.analog_sig_source_x_1_0, 0), (self.blocks_add_xx_1_0, 1)) self.connect((self.analog_sig_source_x_2_0, 0), (self.blocks_add_xx_2, 1)) self.connect((self.analog_sig_source_x_3, 0), (self.blocks_add_xx_1_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.blocks_add_xx_1_0, 0), (self.blocks_add_xx_2, 0)) self.connect((self.blocks_add_xx_2, 0), (self.iir_filter_xxx_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.iir_filter_xxx_2, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.hilbert_fc_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.audio_sink_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.hilbert_fc_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.iir_filter_xxx_0, 0), (self.iir_filter_xxx_1, 0)) self.connect((self.iir_filter_xxx_1, 0), (self.analog_phase_modulator_fc_0, 0)) self.connect((self.iir_filter_xxx_2, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.dc_blocker_xx_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Mono FM Radio") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.xlate_tune = xlate_tune = 0 self.usrp_freq = usrp_freq = 101.8e6 self.samp_rate = samp_rate = 2500e3 self.rx_freq = rx_freq = usrp_freq + xlate_tune self.rf_gain = rf_gain = 7 self.if_gain = if_gain = 7 self.filter_taps = filter_taps = firdes.low_pass( 1, samp_rate, 250000, 20000, firdes.WIN_HAMMING, 6.76) self.bb_gain = bb_gain = 7 self.af_gain = af_gain = 0.3 ################################################## # Blocks ################################################## _xlate_tune_sizer = wx.BoxSizer(wx.VERTICAL) self._xlate_tune_text_box = forms.text_box( parent=self.GetWin(), sizer=_xlate_tune_sizer, value=self.xlate_tune, callback=self.set_xlate_tune, label='Fine frequency', converter=forms.float_converter(), proportion=0, ) self._xlate_tune_slider = forms.slider( parent=self.GetWin(), sizer=_xlate_tune_sizer, value=self.xlate_tune, callback=self.set_xlate_tune, minimum=-250e3, maximum=250e3, num_steps=500, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_xlate_tune_sizer, 7, 0, 1, 5) _usrp_freq_sizer = wx.BoxSizer(wx.VERTICAL) self._usrp_freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_usrp_freq_sizer, value=self.usrp_freq, callback=self.set_usrp_freq, label='USRP frequency', converter=forms.float_converter(), proportion=0, ) self._usrp_freq_slider = forms.slider( parent=self.GetWin(), sizer=_usrp_freq_sizer, value=self.usrp_freq, callback=self.set_usrp_freq, minimum=88e6, maximum=108e6, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_usrp_freq_sizer, 6, 0, 1, 5) _rf_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._rf_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rf_gain_sizer, value=self.rf_gain, callback=self.set_rf_gain, label='RF', converter=forms.float_converter(), proportion=0, ) self._rf_gain_slider = forms.slider( parent=self.GetWin(), sizer=_rf_gain_sizer, value=self.rf_gain, callback=self.set_rf_gain, minimum=0, maximum=90, num_steps=90, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rf_gain_sizer, 9, 2, 1, 1) self.nbook = self.nbook = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.nbook.AddPage(grc_wxgui.Panel(self.nbook), "Receiver") self.nbook.AddPage(grc_wxgui.Panel(self.nbook), "Audio") self.GridAdd(self.nbook, 0, 0, 5, 5) _if_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._if_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_if_gain_sizer, value=self.if_gain, callback=self.set_if_gain, label='IF', converter=forms.float_converter(), proportion=0, ) self._if_gain_slider = forms.slider( parent=self.GetWin(), sizer=_if_gain_sizer, value=self.if_gain, callback=self.set_if_gain, minimum=0, maximum=60, num_steps=60, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_if_gain_sizer, 9, 1, 1, 1) _bb_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._bb_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_bb_gain_sizer, value=self.bb_gain, callback=self.set_bb_gain, label='BB', converter=forms.float_converter(), proportion=0, ) self._bb_gain_slider = forms.slider( parent=self.GetWin(), sizer=_bb_gain_sizer, value=self.bb_gain, callback=self.set_bb_gain, minimum=0, maximum=90, num_steps=90, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_bb_gain_sizer, 9, 3, 1, 1) _af_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._af_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, label='AF', converter=forms.float_converter(), proportion=0, ) self._af_gain_slider = forms.slider( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_af_gain_sizer, 9, 0, 1, 1) self.xlating_fir_filter = filter.freq_xlating_fir_filter_ccc( 1, (filter_taps), -xlate_tune, samp_rate) self._rx_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.rx_freq, callback=self.set_rx_freq, label='Receive', converter=forms.float_converter(), ) self.GridAdd(self._rx_freq_static_text, 5, 3, 1, 1) self.rr_stereo_right = filter.rational_resampler_fff( interpolation=48, decimation=2500, taps=None, fractional_bw=None, ) self.osmosdr_source_1 = osmosdr.source(args="numchan=" + str(1) + " " + 'airspy') self.osmosdr_source_1.set_sample_rate(samp_rate) self.osmosdr_source_1.set_center_freq(usrp_freq, 0) self.osmosdr_source_1.set_freq_corr(0, 0) self.osmosdr_source_1.set_dc_offset_mode(0, 0) self.osmosdr_source_1.set_iq_balance_mode(0, 0) self.osmosdr_source_1.set_gain_mode(False, 0) self.osmosdr_source_1.set_gain(rf_gain, 0) self.osmosdr_source_1.set_if_gain(if_gain, 0) self.osmosdr_source_1.set_bb_gain(bb_gain, 0) self.osmosdr_source_1.set_antenna('', 0) self.osmosdr_source_1.set_bandwidth(0, 0) self.fftsink_rf = fftsink2.fft_sink_c( self.nbook.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=-30, ref_scale=1.0, sample_rate=samp_rate / 2, fft_size=512, fft_rate=10, average=True, avg_alpha=0.5, title='Baseband', peak_hold=False, ) self.nbook.GetPage(0).Add(self.fftsink_rf.win) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, 1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.audio_sink = audio.sink(48000, '', True) self.af_gain_stereo_left = blocks.multiply_const_vff((af_gain, )) ################################################## # Connections ################################################## self.connect((self.af_gain_stereo_left, 0), (self.audio_sink, 0)) self.connect((self.af_gain_stereo_left, 0), (self.audio_sink, 1)) self.connect((self.blocks_complex_to_arg_0, 0), (self.rr_stereo_right, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.osmosdr_source_1, 0), (self.xlating_fir_filter, 0)) self.connect((self.rr_stereo_right, 0), (self.af_gain_stereo_left, 0)) self.connect((self.xlating_fir_filter, 0), (self.blocks_delay_0, 0)) self.connect((self.xlating_fir_filter, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.xlating_fir_filter, 0), (self.fftsink_rf, 0))
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 5 self.afc_gain = 1. self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 1 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## self.src = osmosdr.source(args=options.args) self.src.set_sample_rate(srate_rx) self.src.set_center_freq(options.frequency, 0) self.src.set_freq_corr(options.ppm, 0) self.src.set_dc_offset_mode(0, 0) self.src.set_iq_balance_mode(0, 0) if options.gain is not None: self.src.set_gain_mode(False, 0) self.src.set_gain(36, 0) else: self.src.set_gain_mode(True, 0) out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, srate_rx) self.channelizer = pfb.channelizer_ccf( self.channels, (firdes.root_raised_cosine(1, srate_rx, 18000, 0.35, 1024)), 36. / 25., 100) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): squelch = analog.pwr_squelch_cc(0, 0.001, 0, True) mpsk = digital.mpsk_receiver_cc(4, math.pi / 4, math.pi / 100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2. / math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port) + ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) self.connect((self.channelizer, ch), (squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.squelch.append(squelch) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect((self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) ################################################## # signal strenght identification ################################################## self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1. / self.srate_channel) self.pwr_probes.append(pwr_probe) self.connect((self.channelizer, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [ self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels ] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "Power level for squelch % 5.1f" % pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in self.squelch: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread( target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel / (2 * math.pi)) samp_afc = self.srate_channel * self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1. / samp_afc * self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_step: continue freq = self.freq_xlating.center_freq + err * self.afc_gain if self.debug: print "err: %f\tfreq: %f" % ( err, freq, ) self.freq_xlating.set_center_freq(freq) self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): self.connect((self.channelizer, ch), (self.afc_selector, ch)) self.connect((self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self, fft_size=128): gr.top_block.__init__(self, "Holo RX") Qt.QWidget.__init__(self) self.setWindowTitle("Holo RX") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "holorx_host") self.restoreGeometry( self.settings.value("geometry", type=QtCore.QByteArray)) ################################################## # Parameters ################################################## self.fft_size = fft_size ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1000 self.seconds_record = seconds_record = 7200 self.label_results_per_second = label_results_per_second = samp_rate / fft_size self.label_fftsize = label_fftsize = fft_size self.label_binwidth_hz = label_binwidth_hz = samp_rate / fft_size self.label_baseband_samp_freq = label_baseband_samp_freq = samp_rate self.gui_update_sec = gui_update_sec = 0.2 self.gain_rxb = gain_rxb = 0 self.gain_rxa = gain_rxa = 0 self.freq_rftune = freq_rftune = 70e6 self.client_address = client_address = "192.168.10.184" ################################################## # Blocks ################################################## self.tabs = Qt.QTabWidget() self.tabs_widget_0 = Qt.QWidget() self.tabs_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_0) self.tabs_grid_layout_0 = Qt.QGridLayout() self.tabs_layout_0.addLayout(self.tabs_grid_layout_0) self.tabs.addTab(self.tabs_widget_0, 'RX 2 Channels') self.top_grid_layout.addWidget(self.tabs, 0, 0, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.zeromq_pull_source_1 = zeromq.pull_source( gr.sizeof_gr_complex, 1, 'tcp://192.168.10.184:9998', 100, False, -1) self.zeromq_pull_source_0 = zeromq.pull_source( gr.sizeof_gr_complex, 1, 'tcp://192.168.10.184:9999', 100, False, -1) self.xmlrpc_client1 = xmlrpclib.Server('http://192.168.10.184:30000') self.xmlrpc_client0_0 = xmlrpclib.Server('http://192.168.10.184:30000') self.xmlrpc_client0 = xmlrpclib.Server('http://192.168.10.184:30000') self.to_mag_db_0_3 = to_mag_db() self.to_mag_db_0_1 = to_mag_db() self.to_mag_db_0_0 = to_mag_db() self.qtgui_number_sink_0_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_NONE, 2) self.qtgui_number_sink_0_0_0.set_update_time(gui_update_sec) self.qtgui_number_sink_0_0_0.set_title('Difference A-B') labels = [ 'Magnitude (dB)', 'Phase (deg)', 'A - B', '', '', '', '', '', '', '' ] units = ['dB', 'degrees', 'dB', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(2): self.qtgui_number_sink_0_0_0.set_min(i, -1) self.qtgui_number_sink_0_0_0.set_max(i, 1) self.qtgui_number_sink_0_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0_0.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_0.addWidget(self._qtgui_number_sink_0_0_0_win, 3, 1, 2, 1) for r in range(3, 5): self.tabs_grid_layout_0.setRowStretch(r, 1) for c in range(1, 2): self.tabs_grid_layout_0.setColumnStretch(c, 1) self.qtgui_number_sink_0_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_NONE, 2) self.qtgui_number_sink_0_0.set_update_time(gui_update_sec) self.qtgui_number_sink_0_0.set_title('Magnitude (dB)') labels = ['RXA', 'RXB', 'RXB', '', '', '', '', '', '', ''] units = ['dB', 'dB', 'dB', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(2): self.qtgui_number_sink_0_0.set_min(i, -1) self.qtgui_number_sink_0_0.set_max(i, 1) self.qtgui_number_sink_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_0.addWidget(self._qtgui_number_sink_0_0_win, 1, 1, 2, 1) for r in range(1, 3): self.tabs_grid_layout_0.setRowStretch(r, 1) for c in range(1, 2): self.tabs_grid_layout_0.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( fft_size, #size firdes.WIN_HANN, #wintype 0, #fc samp_rate, #bw "", #name 2 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(gui_update_sec) self.qtgui_freq_sink_x_0.set_y_axis(-160, 0) self.qtgui_freq_sink_x_0.set_y_label('FFT Amplitude', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['RXA', 'RXB', 'RXB', '', '', '', '', '', '', ''] widths = [1, 1, 2, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 0, 0, 1, 2) for r in range(0, 1): self.tabs_grid_layout_0.setRowStretch(r, 1) for c in range(0, 2): self.tabs_grid_layout_0.setColumnStretch(c, 1) self._label_results_per_second_tool_bar = Qt.QToolBar(self) if None: self._label_results_per_second_formatter = None else: self._label_results_per_second_formatter = lambda x: eng_notation.num_to_str( x) self._label_results_per_second_tool_bar.addWidget( Qt.QLabel('FFT Results Per Second ' + ": ")) self._label_results_per_second_label = Qt.QLabel( str( self._label_results_per_second_formatter( self.label_results_per_second))) self._label_results_per_second_tool_bar.addWidget( self._label_results_per_second_label) self.top_grid_layout.addWidget(self._label_results_per_second_tool_bar, 4, 0, 1, 1) for r in range(4, 5): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._label_fftsize_tool_bar = Qt.QToolBar(self) if None: self._label_fftsize_formatter = None else: self._label_fftsize_formatter = lambda x: str(x) self._label_fftsize_tool_bar.addWidget(Qt.QLabel('FFT Size' + ": ")) self._label_fftsize_label = Qt.QLabel( str(self._label_fftsize_formatter(self.label_fftsize))) self._label_fftsize_tool_bar.addWidget(self._label_fftsize_label) self.top_grid_layout.addWidget(self._label_fftsize_tool_bar, 2, 0, 1, 1) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._label_binwidth_hz_tool_bar = Qt.QToolBar(self) if None: self._label_binwidth_hz_formatter = None else: self._label_binwidth_hz_formatter = lambda x: eng_notation.num_to_str( x) self._label_binwidth_hz_tool_bar.addWidget( Qt.QLabel('FFT Bin Width (Hz) ' + ": ")) self._label_binwidth_hz_label = Qt.QLabel( str(self._label_binwidth_hz_formatter(self.label_binwidth_hz))) self._label_binwidth_hz_tool_bar.addWidget( self._label_binwidth_hz_label) self.top_grid_layout.addWidget(self._label_binwidth_hz_tool_bar, 3, 0, 1, 1) for r in range(3, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._label_baseband_samp_freq_tool_bar = Qt.QToolBar(self) if None: self._label_baseband_samp_freq_formatter = None else: self._label_baseband_samp_freq_formatter = lambda x: eng_notation.num_to_str( x) self._label_baseband_samp_freq_tool_bar.addWidget( Qt.QLabel('Baseband Sample Frequency (Hz)' + ": ")) self._label_baseband_samp_freq_label = Qt.QLabel( str( self._label_baseband_samp_freq_formatter( self.label_baseband_samp_freq))) self._label_baseband_samp_freq_tool_bar.addWidget( self._label_baseband_samp_freq_label) self.top_grid_layout.addWidget(self._label_baseband_samp_freq_tool_bar, 1, 0, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._gain_rxb_range = Range(0, 80, 1, 0, 1) self._gain_rxb_win = RangeWidget(self._gain_rxb_range, self.set_gain_rxb, 'Gain RXB', "counter", float) self.tabs_grid_layout_0.addWidget(self._gain_rxb_win, 2, 0, 1, 1) for r in range(2, 3): self.tabs_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tabs_grid_layout_0.setColumnStretch(c, 1) self._gain_rxa_range = Range(0, 80, 1, 0, 1) self._gain_rxa_win = RangeWidget(self._gain_rxa_range, self.set_gain_rxa, 'Gain RXA', "counter", float) self.tabs_grid_layout_0.addWidget(self._gain_rxa_win, 1, 0, 1, 1) for r in range(1, 2): self.tabs_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tabs_grid_layout_0.setColumnStretch(c, 1) self._freq_rftune_range = Range(10e6, 6e9, 1, 70e6, 1) self._freq_rftune_win = RangeWidget(self._freq_rftune_range, self.set_freq_rftune, 'Freq RF Tune', "counter", float) self.tabs_grid_layout_0.addWidget(self._freq_rftune_win, 3, 0, 1, 1) for r in range(3, 4): self.tabs_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tabs_grid_layout_0.setColumnStretch(c, 1) self.fft_bin_select_B = fft_bin_select( fft_size=fft_size, nskip=1, ) self.fft_bin_select_A = fft_bin_select( fft_size=fft_size, nskip=1, ) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (180 / np.pi, )) self.blocks_head_0 = blocks.head( gr.sizeof_gr_complex * 1, int(seconds_record * samp_rate / fft_size)) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1, 'test2hrs.iq', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_divide_xx_0 = blocks.divide_cc(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_divide_xx_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_divide_xx_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_divide_xx_0, 0), (self.to_mag_db_0_3, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_number_sink_0_0_0, 1)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.fft_bin_select_A, 0), (self.blocks_divide_xx_0, 0)) self.connect((self.fft_bin_select_A, 0), (self.to_mag_db_0_0, 0)) self.connect((self.fft_bin_select_B, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.fft_bin_select_B, 0), (self.to_mag_db_0_1, 0)) self.connect((self.to_mag_db_0_0, 0), (self.qtgui_number_sink_0_0, 0)) self.connect((self.to_mag_db_0_1, 0), (self.qtgui_number_sink_0_0, 1)) self.connect((self.to_mag_db_0_3, 0), (self.qtgui_number_sink_0_0_0, 0)) self.connect((self.zeromq_pull_source_0, 0), (self.fft_bin_select_B, 0)) self.connect((self.zeromq_pull_source_0, 0), (self.qtgui_freq_sink_x_0, 1)) self.connect((self.zeromq_pull_source_1, 0), (self.blocks_throttle_0, 0)) self.connect((self.zeromq_pull_source_1, 0), (self.fft_bin_select_A, 0))
def __init__(self): gr.top_block.__init__(self, "Fm Recv") Qt.QWidget.__init__(self) self.setWindowTitle("Fm Recv") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "FM_RECV") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate_ursp = samp_rate_ursp = 200000 self.samp_rate = samp_rate = 48000 self.gain = gain = 120 self.fc = fc = 15000 self.f_cut_off = f_cut_off = 15000 self.beta = beta = 4 ################################################## # Blocks ################################################## self._gain_range = Range(0, 200, 10, 120, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, "Gain", "counter_slider", float) self.top_layout.addWidget(self._gain_win) self._fc_range = Range(0, 15000, 1000, 15000, 200) self._fc_win = RangeWidget(self._fc_range, self.set_fc, "Carrier Frequency", "counter_slider", float) self.top_layout.addWidget(self._fc_win) self._f_cut_off_range = Range(0, 15000, 1000, 15000, 200) self._f_cut_off_win = RangeWidget(self._f_cut_off_range, self.set_f_cut_off, "f_cut_off", "counter_slider", float) self.top_layout.addWidget(self._f_cut_off_win) self._beta_range = Range(0, 4, 1, 4, 200) self._beta_win = RangeWidget(self._beta_range, self.set_beta, "beta", "counter_slider", float) self.top_layout.addWidget(self._beta_win) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("addr=192.168.10.2", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate_ursp) self.uhd_usrp_source_0.set_center_freq(1340e6, 0) self.uhd_usrp_source_0.set_gain(gain, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.uhd_usrp_source_0.set_bandwidth(200e6, 0) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=samp_rate, decimation=samp_rate_ursp, taps=None, fractional_bw=None, ) self.qtgui_freq_sink_x_1 = qtgui.freq_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "Recieved Wave Signal", #name 1 #number of inputs ) self.qtgui_freq_sink_x_1.set_update_time(0.10) self.qtgui_freq_sink_x_1.set_y_axis(-140, 10) self.qtgui_freq_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_1.enable_autoscale(True) self.qtgui_freq_sink_x_1.enable_grid(False) self.qtgui_freq_sink_x_1.set_fft_average(1.0) self.qtgui_freq_sink_x_1.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_1.disable_legend() if "float" == "float" or "float" == "msg_float": self.qtgui_freq_sink_x_1.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_1.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_1.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_1.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_1_win = sip.wrapinstance( self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_1_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "Complex Wave Signal", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.low_pass_filter_1_0 = filter.fir_filter_fff( 1, firdes.low_pass(1, samp_rate, f_cut_off, 100, firdes.WIN_HAMMING, beta)) self.low_pass_filter_1 = filter.fir_filter_fff( 1, firdes.low_pass(1, samp_rate, f_cut_off, 100, firdes.WIN_HAMMING, beta)) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( 62.8e-3, 4, False) self.blocks_wavfile_sink_0 = blocks.wavfile_sink( "/root/SDR_Class/Lab3/test.wav", 1, samp_rate, 8) self.blocks_multiply_xx_1 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, 1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.analog_sig_source_x_1 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, fc, 700e-3, 0) self.analog_sig_source_x_0 = analog.sig_source_f( samp_rate, analog.GR_SIN_WAVE, fc, 700e-3, 0) self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc( -70, 1e-4, 0, True) ################################################## # Connections ################################################## self.connect((self.analog_pwr_squelch_xx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_wavfile_sink_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.qtgui_freq_sink_x_1, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_1_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.low_pass_filter_1, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.analog_pwr_squelch_xx_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.low_pass_filter_1_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.digital_costas_loop_cc_0, 0))
def __init__(self): gr.top_block.__init__(self, "vor_record_sigmf") Qt.QWidget.__init__(self) self.setWindowTitle("vor_record_sigmf") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "vor_playback_sigmf") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.throttle_rate = throttle_rate = 1 self.samp_rate = samp_rate = 250e3 self.fine = fine = 0 self.decim = decim = 5 self.audio_gain_30hz = audio_gain_30hz = 1 self.alpha = alpha = .02 ################################################## # Blocks ################################################## self._throttle_rate_tool_bar = Qt.QToolBar(self) self._throttle_rate_tool_bar.addWidget( Qt.QLabel("throttle_rate" + ": ")) self._throttle_rate_line_edit = Qt.QLineEdit(str(self.throttle_rate)) self._throttle_rate_tool_bar.addWidget(self._throttle_rate_line_edit) self._throttle_rate_line_edit.returnPressed.connect( lambda: self.set_throttle_rate( eng_notation.str_to_num( str(self._throttle_rate_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._throttle_rate_tool_bar, 0, 6, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(6, 8): self.top_grid_layout.setColumnStretch(c, 1) self._samp_rate_tool_bar = Qt.QToolBar(self) self._samp_rate_tool_bar.addWidget(Qt.QLabel("samp_rate" + ": ")) self._samp_rate_line_edit = Qt.QLineEdit(str(self.samp_rate)) self._samp_rate_tool_bar.addWidget(self._samp_rate_line_edit) self._samp_rate_line_edit.returnPressed.connect( lambda: self.set_samp_rate( eng_notation.str_to_num( str(self._samp_rate_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._samp_rate_tool_bar, 0, 4, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 6): self.top_grid_layout.setColumnStretch(c, 1) self._fine_tool_bar = Qt.QToolBar(self) self._fine_tool_bar.addWidget(Qt.QLabel('Fine [Hz]' + ": ")) self._fine_line_edit = Qt.QLineEdit(str(self.fine)) self._fine_tool_bar.addWidget(self._fine_line_edit) self._fine_line_edit.returnPressed.connect(lambda: self.set_fine( eng_notation.str_to_num(str(self._fine_line_edit.text().toAscii())) )) self.top_grid_layout.addWidget(self._fine_tool_bar, 1, 4, 1, 2) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 6): self.top_grid_layout.setColumnStretch(c, 1) self.sigmf_source_0 = gr_sigmf.source( '/captures/20191216/VOR_2019-12-16T18:51:17Z.sigmf-data', "cf32" + ("_le" if sys.byteorder == "little" else "_be"), False) self.rational_resampler_xxx_2 = filter.rational_resampler_fff( interpolation=66, decimation=1, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_1 = filter.rational_resampler_fff( interpolation=66, decimation=1, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0_0_0 = filter.rational_resampler_ccc( interpolation=24, decimation=25, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=decim, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.010) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 4, 0, 4, 4) for r in range(4, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 1024, #size samp_rate / decim / 25 * 24, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.0010) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_NORM, qtgui.TRIG_SLOPE_POS, 0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(False) self.qtgui_time_sink_x_0_0.enable_grid(True) self.qtgui_time_sink_x_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_0_0.enable_control_panel(False) self.qtgui_time_sink_x_0_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win, 6, 4, 2, 4) for r in range(6, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 8192, #size samp_rate / decim / 25 * 24, #samp_rate "30 Hz Variable", #name 2 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.0010) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_NORM, qtgui.TRIG_SLOPE_POS, 0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(True) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 4, 4, 2, 4) for r in range(4, 6): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_1 = qtgui.freq_sink_f( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim / 25 * 24, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_1.set_update_time(0.10) self.qtgui_freq_sink_x_1.set_y_axis(-140, 10) self.qtgui_freq_sink_x_1.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_1.enable_autoscale(False) self.qtgui_freq_sink_x_1.enable_grid(False) self.qtgui_freq_sink_x_1.set_fft_average(1.0) self.qtgui_freq_sink_x_1.enable_axis_labels(True) self.qtgui_freq_sink_x_1.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_1.disable_legend() if "float" == "float" or "float" == "msg_float": self.qtgui_freq_sink_x_1.set_plot_pos_half(not False) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_1.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_1.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_1.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_1_win = sip.wrapinstance( self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_1_win, 0, 0, 4, 4) for r in range(0, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.low_pass_filter_0_0 = filter.fir_filter_fff( 1, firdes.low_pass(10, samp_rate / decim / 25 * 24, 1e3, 500, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_fff( 1, firdes.low_pass(1, 48e3, 1, 1, firdes.WIN_HAMMING, 6.76)) self.dc_blocker_xx_0_0 = filter.dc_blocker_ff(1024, True) self.dc_blocker_xx_0 = filter.dc_blocker_ff(1024, True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate * throttle_rate, True) self.blocks_multiply_xx_3 = blocks.multiply_vff(1) self.blocks_multiply_xx_2 = blocks.multiply_vff(1) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_integrate_xx_2 = blocks.integrate_ff(66, 1) self.blocks_integrate_xx_0 = blocks.integrate_ff(66, 1) self.blocks_float_to_complex_2 = blocks.float_to_complex(1) self.blocks_float_to_complex_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_divide_xx_0_0 = blocks.divide_ff(1) self.blocks_divide_xx_0 = blocks.divide_ff(1) self.blocks_delay_1 = blocks.delay(gr.sizeof_float * 1, 0) self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, 0) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.band_pass_filter_0_0 = filter.fir_filter_fff( 1, firdes.band_pass(1, samp_rate / decim / 25 * 24, 25, 35, 5, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0 = filter.fir_filter_fff( 1, firdes.band_pass(1, samp_rate / decim / 25 * 24, 25, 35, 5, firdes.WIN_HAMMING, 6.76)) self._audio_gain_30hz_tool_bar = Qt.QToolBar(self) self._audio_gain_30hz_tool_bar.addWidget(Qt.QLabel('vol30' + ": ")) self._audio_gain_30hz_line_edit = Qt.QLineEdit( str(self.audio_gain_30hz)) self._audio_gain_30hz_tool_bar.addWidget( self._audio_gain_30hz_line_edit) self._audio_gain_30hz_line_edit.returnPressed.connect( lambda: self.set_audio_gain_30hz( eng_notation.str_to_num( str(self._audio_gain_30hz_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._audio_gain_30hz_tool_bar, 1, 7, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(7, 8): self.top_grid_layout.setColumnStretch(c, 1) self.analog_sig_source_x_1 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 9960, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -1 * fine, 1, 0) self.analog_pll_carriertracking_cc_0 = analog.pll_carriertracking_cc( math.pi / 200, math.pi / 10, -math.pi / 10) self.analog_fm_demod_cf_0 = analog.fm_demod_cf( channel_rate=samp_rate / decim / 25 * 24, audio_decim=1, deviation=1e3, audio_pass=100, audio_stop=200, gain=1.0, tau=75e-6, ) self.analog_const_source_x_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=48e3, audio_decim=1, audio_pass=12000, audio_stop=13000, ) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) self._alpha_tool_bar = Qt.QToolBar(self) self._alpha_tool_bar.addWidget(Qt.QLabel('alpha' + ": ")) self._alpha_line_edit = Qt.QLineEdit(str(self.alpha)) self._alpha_tool_bar.addWidget(self._alpha_line_edit) self._alpha_line_edit.returnPressed.connect(lambda: self.set_alpha( eng_notation.str_to_num(str(self._alpha_line_edit.text().toAscii()) ))) self.top_grid_layout.addWidget(self._alpha_tool_bar, 1, 6, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(6, 7): self.top_grid_layout.setColumnStretch(c, 1) ################################################## # Connections ################################################## self.connect((self.analog_agc2_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.qtgui_freq_sink_x_1, 0)) self.connect((self.analog_const_source_x_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.analog_fm_demod_cf_0, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.analog_pll_carriertracking_cc_0, 0), (self.rational_resampler_xxx_0_0_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.band_pass_filter_0, 0), (self.dc_blocker_xx_0, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.dc_blocker_xx_0_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_divide_xx_0_0, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_3, 0)) self.connect((self.blocks_delay_1, 0), (self.blocks_multiply_xx_2, 1)) self.connect((self.blocks_divide_xx_0, 0), (self.blocks_float_to_complex_2, 0)) self.connect((self.blocks_divide_xx_0_0, 0), (self.blocks_float_to_complex_2, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_float_to_complex_2, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.blocks_integrate_xx_2, 0), (self.rational_resampler_xxx_2, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.analog_fm_demod_cf_0, 0)) self.connect((self.blocks_multiply_xx_2, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_multiply_xx_3, 0), (self.blocks_integrate_xx_2, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_delay_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_multiply_xx_2, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.dc_blocker_xx_0_0, 0), (self.blocks_delay_1, 0)) self.connect((self.dc_blocker_xx_0_0, 0), (self.blocks_multiply_xx_3, 1)) self.connect((self.dc_blocker_xx_0_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_pll_carriertracking_cc_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_divide_xx_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_float_to_complex_1, 0)) self.connect((self.rational_resampler_xxx_2, 0), (self.blocks_divide_xx_0_0, 0)) self.connect((self.rational_resampler_xxx_2, 0), (self.blocks_float_to_complex_1, 1)) self.connect((self.sigmf_source_0, 0), (self.blocks_throttle_0, 0))
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, costas_alpha=_def_costas_alpha, gain_mu=_def_gain_mu, mu=_def_mu, omega_relative_limit=_def_omega_relative_limit, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered CQPSK demodulation The input is the complex modulated signal at baseband. The output is a stream of floats in [ -3 / -1 / +1 / +3 ] @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: float @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param costas_alpha: loop filter gain @type costas_alphas: float @param gain_mu: for M&M block @type gain_mu: float @param mu: for M&M block @type mu: float @param omega_relative_limit: for M&M block @type omega_relative_limit: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__(self, "cqpsk_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._costas_alpha = costas_alpha self._mm_gain_mu = gain_mu self._mm_mu = mu self._mm_omega_relative_limit = omega_relative_limit self._gray_code = gray_code if samples_per_symbol < 2: raise TypeError, "sbp must be >= 2, is %d" % samples_per_symbol arity = pow(2,self.bits_per_symbol()) # Automatic gain control scale = (1.0/16384.0) self.pre_scaler = blocks.multiply_const_cc(scale) # scale the signal from full-range to +-1 #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100) self.agc = analog.feedforward_agc_cc(16, 2.0) # RRC data filter ntaps = 11 * samples_per_symbol self.rrc_taps = firdes.root_raised_cosine( 1.0, # gain self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter=filter.interp_fir_filter_ccf(1, self.rrc_taps) if not self._mm_gain_mu: sbs_to_mm = {2: 0.050, 3: 0.075, 4: 0.11, 5: 0.125, 6: 0.15, 7: 0.15} self._mm_gain_mu = sbs_to_mm[samples_per_symbol] self._mm_omega = self._samples_per_symbol self._mm_gain_omega = .25 * self._mm_gain_mu * self._mm_gain_mu self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha fmin = -0.025 fmax = 0.025 if not _def_has_gr_digital: self.receiver=gr.mpsk_receiver_cc(arity, pi/4.0, self._costas_alpha, self._costas_beta, fmin, fmax, self._mm_mu, self._mm_gain_mu, self._mm_omega, self._mm_gain_omega, self._mm_omega_relative_limit) else: self.receiver=digital.mpsk_receiver_cc(arity, pi/4.0, 2*pi/150, fmin, fmax, self._mm_mu, self._mm_gain_mu, self._mm_omega, self._mm_gain_omega, self._mm_omega_relative_limit) #self.receiver.set_alpha(self._costas_alpha) #self.receiver.set_beta(self._costas_beta) # Perform Differential decoding on the constellation self.diffdec = digital.diff_phasor_cc() # take angle of the difference (in radians) self.to_float = blocks.complex_to_arg() # convert from radians such that signal is in -3/-1/+1/+3 self.rescale = blocks.multiply_const_ff( 1 / (pi / 4) ) if verbose: self._print_verbage() if log: self._setup_logging() # Connect & Initialize base class self.connect(self, self.pre_scaler, self.agc, self.rrc_filter, self.receiver, self.diffdec, self.to_float, self.rescale, self)
def __init__(self, system, site_uuid, overseer_uuid): gr.top_block.__init__(self, "p25 receiver") #set globals self.is_locked = False self.system = system self.instance_uuid = '%s' % uuid.uuid4() self.log = logging.getLogger('overseer.p25_control_demod.%s' % self.instance_uuid) self.protocol_log = logging.getLogger('protocol.%s' % self.instance_uuid) self.log.info('Initializing instance: %s site: %s overseer: %s' % (self.instance_uuid, site_uuid, overseer_uuid)) self.site_uuid = site_uuid self.overseer_uuid = overseer_uuid self.control_channel = system['channels'][ system['default_control_channel']] self.control_channel_i = system['default_control_channel'] self.channel_identifier_table = {} try: self.modulation = system['modulation'] except: self.modulation = 'C4FM' self.channel_rate = 12500 symbol_rate = 4800 self.site_detail = {} self.site_detail['WACN ID'] = None self.site_detail['System ID'] = None self.site_detail['Control Channel'] = None self.site_detail['System Service Class'] = None self.site_detail['Site ID'] = None self.site_detail['RF Sub-system ID'] = None self.site_detail['RFSS Network Connection'] = None self.bad_messages = 0 self.total_messages = 0 self.quality = [] self.keep_running = True self.source = None # channel filter channel_rate = self.channel_rate * 2 self.control_prefilter = filter.freq_xlating_fir_filter_ccc( 1, (1, ), 0, channel_rate) # power squelch #power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True) #self.connect(self.channel_filter, power_squelch) autotuneq = gr.msg_queue(2) self.demod_watcher = demod_watcher(self) self.symbol_deviation = 600.0 if self.modulation == 'C4FM': # FM demodulator fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation) self.fm_demod = fm_demod = analog.quadrature_demod_cf( fm_demod_gain) moving_sum = blocks.moving_average_ff(10000, 1, 40000) subtract = blocks.sub_ff(1) divide_const = blocks.multiply_const_vff((0.0001, )) self.probe = blocks.probe_signal_f() self.connect(self.fm_demod, moving_sum, divide_const, self.probe) # symbol filter symbol_decim = 1 samples_per_symbol = channel_rate // symbol_rate symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol symbol_filter = filter.fir_filter_fff(symbol_decim, symbol_coeffs) demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate) elif self.modulation == 'CQPSK': # FM demodulator fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation) self.fm_demod = fm_demod = analog.quadrature_demod_cf( fm_demod_gain) moving_sum = blocks.moving_average_ff(10000, 1, 40000) subtract = blocks.sub_ff(1) divide_const = blocks.multiply_const_vff((0.0001, )) self.probe = blocks.probe_signal_f() self.connect(fm_demod, moving_sum, divide_const, self.probe) #self.resampler = filter.pfb.arb_resampler_ccf(float(48000)/float(channel_rate)) self.resampler = blocks.multiply_const_cc(1.0) self.agc = analog.feedforward_agc_cc(1024, 1.0) self.symbol_filter_c = blocks.multiply_const_cc(1.0) gain_mu = 0.025 omega = float(channel_rate) / float(symbol_rate) gain_omega = 0.1 * gain_mu * gain_mu alpha = 0.04 beta = 0.125 * alpha * alpha fmax = 1200 # Hz fmax = 2 * pi * fmax / float(channel_rate) self.clock = repeater.gardner_costas_cc(omega, gain_mu, gain_omega, alpha, beta, fmax, -fmax) self.diffdec = digital.diff_phasor_cc() self.to_float = blocks.complex_to_arg() self.rescale = blocks.multiply_const_ff((1 / (pi / 4))) # symbol slicer levels = [-2.0, 0.0, 2.0, 4.0] slicer = op25.fsk4_slicer_fb(levels) # frame decoder self.decodequeue = decodequeue = gr.msg_queue(1000) qsink = blocks.message_sink(gr.sizeof_char, self.decodequeue, False) self.decoder = decoder = repeater.p25_frame_assembler( '', 0, 0, False, True, True, autotuneq, False, False) if self.modulation == 'C4FM': self.connect(self.control_prefilter, fm_demod, symbol_filter, demod_fsk4, slicer, decoder, qsink) elif self.modulation == 'CQPSK': self.connect(self.resampler, self.agc, self.symbol_filter_c, self.clock, self.diffdec, self.to_float, self.rescale, slicer, decoder, qsink) ################################################## # Threads ################################################## self.connector = frontend_connector() self.client_redis = client_redis() self.redis_demod_publisher = redis_demod_publisher(parent_demod=self) quality_check_0 = threading.Thread(target=self.quality_check) quality_check_0.daemon = True quality_check_0.start() # Adjust the channel offset # self.tune_next_control_channel() #self.receive_engine() receive_engine = threading.Thread(target=self.receive_engine) receive_engine.daemon = True receive_engine.start()
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.vol = vol = 100 self.tau = tau = 50e-6 self.samp_rate = samp_rate = 1000000 self.rx_gain = rx_gain = 20 self.freq = freq = 107.2e6 self.decim = decim = 80 self.b_signal = b_signal = 50e3 ################################################## # Blocks ################################################## _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 L", 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=300, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_vol_sizer, 2, 0, 1, 1) _tau_sizer = wx.BoxSizer(wx.VERTICAL) self._tau_text_box = forms.text_box( parent=self.GetWin(), sizer=_tau_sizer, value=self.tau, callback=self.set_tau, label="Zeitkonstante (Tau)", converter=forms.float_converter(), proportion=0, ) self._tau_slider = forms.slider( parent=self.GetWin(), sizer=_tau_sizer, value=self.tau, callback=self.set_tau, minimum=0, maximum=100e-6, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tau_sizer, 0, 1, 1, 1) self._samp_rate_text_box = forms.text_box( parent=self.GetWin(), value=self.samp_rate, callback=self.set_samp_rate, label="Sampling Rate", converter=forms.float_converter(), ) self.GridAdd(self._samp_rate_text_box, 1, 0, 1, 1) _rx_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, label="Receiver Gain", converter=forms.float_converter(), proportion=0, ) self._rx_gain_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, minimum=0, maximum=50, num_steps=50, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rx_gain_sizer, 2, 2, 1, 1) _freq_sizer = wx.BoxSizer(wx.VERTICAL) self._freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, label="Frequenz (UKW)", converter=forms.float_converter(), proportion=0, ) self._freq_slider = forms.slider( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, minimum=80e6, maximum=230e6, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_freq_sizer, 0, 0, 1, 1) _b_signal_sizer = wx.BoxSizer(wx.VERTICAL) self._b_signal_text_box = forms.text_box( parent=self.GetWin(), sizer=_b_signal_sizer, value=self.b_signal, callback=self.set_b_signal, label="Signalbandbreite", converter=forms.float_converter(), proportion=0, ) self._b_signal_slider = forms.slider( parent=self.GetWin(), sizer=_b_signal_sizer, value=self.b_signal, callback=self.set_b_signal, minimum=1e3, maximum=400e3, num_steps=399, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_b_signal_sizer, 1, 1, 1, 1) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=500, decimation=480, taps=None, fractional_bw=None, ) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(freq, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0.set_iq_balance_mode(2, 0) self.osmosdr_source_0.set_gain_mode(True, 0) self.osmosdr_source_0.set_gain(rx_gain, 0) self.osmosdr_source_0.set_if_gain(20, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna("", 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio L (FFT)") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio R (FFT)") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio L (Scope)") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio R (Scope)") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "MPX-Signal (FFT)") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RX FFT") self.GridAdd(self.notebook_0, 3, 0, 1, 3) self.low_pass_filter_2_1_0_0 = filter.fir_filter_fff(20, firdes.low_pass( 1, samp_rate, 15000, 500, firdes.WIN_HANN, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, b_signal, 2000, firdes.WIN_HANN, 6.76)) self.iir_filter_xxx_0 = filter.iir_filter_ffd(((1.0/(1+tau*2*samp_rate), 1.0/(1+tau*2*samp_rate))), ((1, -(1-tau*2*samp_rate)/(1+tau*2*samp_rate))), True) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((vol/100, )) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.audio_sink_0 = audio.sink(48000, "", True) ################################################## # Connections ################################################## self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.low_pass_filter_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.low_pass_filter_2_1_0_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blocks_delay_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.iir_filter_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.iir_filter_xxx_0, 0), (self.low_pass_filter_2_1_0_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self, dab_params, rx_params, verbose=False, debug=False): """ Hierarchical block for OFDM demodulation @param dab_params DAB parameter object (grdab.parameters.dab_parameters) @param rx_params RX parameter object (grdab.parameters.receiver_parameters) @param debug enables debug output to files @param verbose whether to produce verbose messages """ self.dp = dp = dab_params self.rp = rp = rx_params self.verbose = verbose if self.rp.softbits: gr.hier_block2.__init__( self, "ofdm_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_float * self.dp.num_carriers * 2)) # output signature else: gr.hier_block2.__init__( self, "ofdm_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_char * self.dp.num_carriers / 4)) # output signature # workaround for a problem that prevents connecting more than one block directly (see trac ticket #161) #self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.input = blocks.multiply_const_cc(1.0) # FIXME self.connect(self, self.input) # input filtering if self.rp.input_fft_filter: if verbose: print("--> RX filter enabled") lowpass_taps = filter.firdes_low_pass( 1.0, # gain dp.sample_rate, # sampling rate rp.filt_bw, # cutoff frequency rp.filt_tb, # width of transition band filter.firdes.WIN_HAMMING) # Hamming window self.fft_filter = filter.fft_filter_ccc(1, lowpass_taps) # correct sample rate offset, if enabled if self.rp.autocorrect_sample_rate: if verbose: print("--> dynamic sample rate correction enabled") self.rate_detect_ns = grdab.detect_null(dp.ns_length, False) self.rate_estimator = grdab.estimate_sample_rate_bf( dp.sample_rate, dp.frame_length) self.rate_prober = blocks.probe_signal_f() self.connect(self.input, self.rate_detect_ns, self.rate_estimator, self.rate_prober) # self.resample = gr.fractional_interpolator_cc(0, 1) self.resample = grdab.fractional_interpolator_triggered_update_cc( 0, 1) self.connect(self.rate_detect_ns, (self.resample, 1)) self.updater = Timer(0.1, self.update_correction) # self.updater = threading.Thread(target=self.update_correction) self.run_interpolater_update_thread = True self.updater.setDaemon(True) self.updater.start() else: self.run_interpolater_update_thread = False if self.rp.sample_rate_correction_factor != 1 or self.rp.always_include_resample: if verbose: print("--> static sample rate correction enabled") self.resample = filter.mmse_resampler_cc( 0, self.rp.sample_rate_correction_factor) # timing and fine frequency synchronisation self.sync = grdab.ofdm_sync_dab2(self.dp, self.rp, debug) # ofdm symbol sampler self.sampler = grdab.ofdm_sampler(dp.fft_length, dp.cp_length, dp.symbols_per_frame, rp.cp_gap) # fft for symbol vectors self.fft = fft.fft_vcc(dp.fft_length, True, [], True) # coarse frequency synchronisation self.cfs = grdab.ofdm_coarse_frequency_correct(dp.fft_length, dp.num_carriers, dp.cp_length) # diff phasor self.phase_diff = grdab.diff_phasor_vcc(dp.num_carriers) # remove pilot symbol self.remove_pilot = grdab.ofdm_remove_first_symbol_vcc(dp.num_carriers) # magnitude equalisation if self.rp.equalize_magnitude: if verbose: print("--> magnitude equalization enabled") self.equalizer = grdab.magnitude_equalizer_vcc( dp.num_carriers, rp.symbols_for_magnitude_equalization) # frequency deinterleaving self.deinterleave = grdab.frequency_interleaver_vcc( dp.frequency_deinterleaving_sequence_array) # symbol demapping self.demapper = grdab.qpsk_demapper_vcb(dp.num_carriers) # # connect everything # if self.rp.autocorrect_sample_rate or self.rp.sample_rate_correction_factor != 1 or self.rp.always_include_resample: self.connect(self.input, self.resample) self.input2 = self.resample else: self.input2 = self.input if self.rp.input_fft_filter: self.connect(self.input2, self.fft_filter, self.sync) else: self.connect(self.input2, self.sync) # data stream self.connect(self.sync, self.sampler, self.fft, self.cfs, self.phase_diff, self.remove_pilot) if self.rp.equalize_magnitude: self.connect(self.remove_pilot, self.equalizer, self.deinterleave) else: self.connect(self.remove_pilot, self.deinterleave) if self.rp.softbits: if verbose: print("--> using soft bits") self.softbit_interleaver = grdab.complex_to_interleaved_float_vcf( self.dp.num_carriers) self.connect(self.deinterleave, self.softbit_interleaver, (self, 0)) else: self.connect(self.deinterleave, self.demapper, (self, 0)) # calculate an estimate of the SNR self.phase_var_decim = blocks.keep_one_in_n( gr.sizeof_gr_complex * self.dp.num_carriers, self.rp.phase_var_estimate_downsample) self.phase_var_arg = blocks.complex_to_arg(dp.num_carriers) self.phase_var_v2s = blocks.vector_to_stream(gr.sizeof_float, dp.num_carriers) self.phase_var_mod = grdab.modulo_ff(pi / 2) self.phase_var_avg_mod = filter.iir_filter_ffd( [rp.phase_var_estimate_alpha], [0, 1 - rp.phase_var_estimate_alpha]) self.phase_var_sub_avg = blocks.sub_ff() self.phase_var_sqr = blocks.multiply_ff() self.phase_var_avg = filter.iir_filter_ffd( [rp.phase_var_estimate_alpha], [0, 1 - rp.phase_var_estimate_alpha]) self.probe_phase_var = blocks.probe_signal_f() self.connect((self.remove_pilot, 0), self.phase_var_decim, self.phase_var_arg, self.phase_var_v2s, self.phase_var_mod, (self.phase_var_sub_avg, 0), (self.phase_var_sqr, 0)) self.connect(self.phase_var_mod, self.phase_var_avg_mod, (self.phase_var_sub_avg, 1)) self.connect(self.phase_var_sub_avg, (self.phase_var_sqr, 1)) self.connect(self.phase_var_sqr, self.phase_var_avg, self.probe_phase_var) # measure processing rate self.measure_rate = grdab.measure_processing_rate( gr.sizeof_gr_complex, 2000000) self.connect(self.input, self.measure_rate) # debugging if debug: self.connect( self.fft, blocks.file_sink(gr.sizeof_gr_complex * dp.fft_length, "debug/ofdm_after_fft.dat")) self.connect( (self.cfs, 0), blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_after_cfs.dat")) self.connect( self.phase_diff, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_diff_phasor.dat")) self.connect( (self.remove_pilot, 0), blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_pilot_removed.dat")) self.connect((self.remove_pilot, 1), blocks.file_sink(gr.sizeof_char, "debug/ofdm_after_cfs_trigger.dat")) self.connect( self.deinterleave, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_deinterleaved.dat")) if self.rp.equalize_magnitude: self.connect( self.equalizer, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_equalizer.dat")) if self.rp.softbits: self.connect( self.softbit_interleaver, blocks.file_sink(gr.sizeof_float * dp.num_carriers * 2, "debug/softbits.dat"))
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-1", "--one-channel", action="store_true", default=False, help="software synthesized Q channel") parser.add_option("-a", "--agc", action="store_true", default=False, help="automatic gain control (overrides --gain)") parser.add_option("-c", "--calibration", type="eng_float", default=0, help="freq offset") parser.add_option("-d", "--debug", action="store_true", default=False, help="allow time at init to attach gdb") parser.add_option("-C", "--costas-alpha", type="eng_float", default=0.125, help="Costas alpha") parser.add_option("-g", "--gain", type="eng_float", default=1.0) parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file") parser.add_option("-I", "--imbe", action="store_true", default=False, help="output IMBE codewords") parser.add_option("-L", "--low-pass", type="eng_float", default=6.5e3, help="low pass cut-off", metavar="Hz") parser.add_option("-o", "--output-file", type="string", default="out.dat", help="specify the output file") parser.add_option("-p", "--polarity", action="store_true", default=False, help="use reversed polarity") parser.add_option("-r", "--raw-symbols", type="string", default=None, help="dump decoded symbols to file") parser.add_option("-s", "--sample-rate", type="int", default=96000, help="input sample rate") parser.add_option("-t", "--tone-detect", action="store_true", default=False, help="use experimental tone detect algorithm") parser.add_option("-v", "--verbose", action="store_true", default=False, help="additional output") parser.add_option("-6", "--k6k", action="store_true", default=False, help="use 6K symbol rate") (options, args) = parser.parse_args() sample_rate = options.sample_rate if options.k6k: symbol_rate = 6000 else: symbol_rate = 4800 samples_per_symbol = sample_rate // symbol_rate IN = blocks.file_source(gr.sizeof_gr_complex, options.input_file) if options.one_channel: C2F = blocks.complex_to_float() F2C = blocks.float_to_complex() # osc./mixer for mixing signal down to approx. zero IF LO = analog.sig_source_c(sample_rate, analog.GR_COS_WAVE, options.calibration, 1.0, 0) MIXER = blocks.multiply_cc() # get signal into normalized range (-1.0 - +1.0) if options.agc: AMP = analog.feedforward_agc_cc(16, 1.0) else: AMP = blocks.multiply_const_cc(options.gain) lpf_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) decim_amt = 1 if options.tone_detect: if sample_rate != 96000: print "warning, only 96K has been tested." print "other rates may require theta to be reviewed/adjusted." step_size = 7.5e-8 theta = -4 # optimum timing sampling point cic_length = 48 DEMOD = op25_repeater.tdetect_cc(samples_per_symbol, step_size, theta, cic_length) else: # decim by 2 to get 48k rate samples_per_symbol /= 2 # for DECIM sample_rate /= 2 # for DECIM decim_amt = 2 # create Gardner/Costas loop # the loop will not work if the sample levels aren't normalized (above) timing_error_gain = 0.025 # loop error gain gain_omega = 0.25 * timing_error_gain * timing_error_gain alpha = options.costas_alpha beta = 0.125 * alpha * alpha fmin = -0.025 # fmin and fmax are in radians/s fmax = 0.025 DEMOD = op25_repeater.gardner_costas_cc(samples_per_symbol, timing_error_gain, gain_omega, alpha, beta, fmax, fmin) DECIM = filter.fir_filter_ccf(decim_amt, lpf_taps) # probably too much phase noise etc to attempt coherent demodulation # so we use differential DIFF = digital.diff_phasor_cc() # take angle of the phase difference (in radians) TOFLOAT = blocks.complex_to_arg() # convert from radians such that signal is in [-3, -1, +1, +3] RESCALE = blocks.multiply_const_ff(1 / (pi / 4.0)) # optional polarity reversal (should be unnec. - now autodetected) p = 1.0 if options.polarity: p = -1.0 POLARITY = blocks.multiply_const_ff(p) # hard decision at specified points levels = [-2.0, 0.0, 2.0, 4.0] SLICER = op25_repeater.fsk4_slicer_fb(levels) # assemble received frames and route to Wireshark via UDP hostname = "127.0.0.1" port = 23456 debug = 0 if options.verbose: debug = 255 do_imbe = False if options.imbe: do_imbe = True do_output = True # enable block's output stream do_msgq = False # msgq output not yet implemented msgq = gr.msg_queue(2) DECODER = op25_repeater.p25_frame_assembler(hostname, port, debug, do_imbe, do_output, do_msgq, msgq, False, False) OUT = blocks.file_sink(gr.sizeof_char, options.output_file) if options.one_channel: self.connect(IN, C2F, F2C, (MIXER, 0)) else: self.connect(IN, (MIXER, 0)) self.connect(LO, (MIXER, 1)) self.connect(MIXER, AMP, DECIM, DEMOD, DIFF, TOFLOAT, RESCALE, POLARITY, SLICER, DECODER, OUT) if options.raw_symbols: SINKC = blocks.file_sink(gr.sizeof_char, options.raw_symbols) self.connect(SLICER, SINKC) if options.debug: print 'Ready for GDB to attach (pid = %d)' % (os.getpid(), ) raw_input("Press 'Enter' to continue...")
def __init__(self, mode='VOR', zero_point=59, **kwargs): self.channel_rate = channel_rate = 40000 internal_audio_rate = 20000 # TODO over spec'd self.zero_point = zero_point transition = 5000 SimpleAudioDemodulator.__init__(self, mode=mode, audio_rate=internal_audio_rate, demod_rate=channel_rate, band_filter=fm_subcarrier * 1.25 + fm_deviation + transition / 2, band_filter_transition=transition, **kwargs) self.dir_rate = dir_rate = 10 if internal_audio_rate % dir_rate != 0: raise ValueError('Audio rate %s is not a multiple of direction-finding rate %s' % (internal_audio_rate, dir_rate)) self.dir_scale = dir_scale = internal_audio_rate // dir_rate self.audio_scale = audio_scale = channel_rate // internal_audio_rate self.zeroer = blocks.add_const_vff((zero_point * (math.pi / 180), )) self.dir_vector_filter = grfilter.fir_filter_ccf(1, firdes.low_pass( 1, dir_rate, 1, 2, firdes.WIN_HAMMING, 6.76)) self.am_channel_filter_block = grfilter.fir_filter_ccf(1, firdes.low_pass( 1, channel_rate, 5000, 5000, firdes.WIN_HAMMING, 6.76)) self.goertzel_fm = fft.goertzel_fc(channel_rate, dir_scale * audio_scale, 30) self.goertzel_am = fft.goertzel_fc(internal_audio_rate, dir_scale, 30) self.fm_channel_filter_block = grfilter.freq_xlating_fir_filter_ccc(1, (firdes.low_pass(1.0, channel_rate, fm_subcarrier / 2, fm_subcarrier / 2, firdes.WIN_HAMMING)), fm_subcarrier, channel_rate) self.multiply_conjugate_block = blocks.multiply_conjugate_cc(1) self.complex_to_arg_block = blocks.complex_to_arg(1) self.am_agc_block = analog.feedforward_agc_cc(1024, 1.0) self.am_demod_block = analog.am_demod_cf( channel_rate=channel_rate, audio_decim=audio_scale, audio_pass=5000, audio_stop=5500, ) self.fm_demod_block = analog.quadrature_demod_cf(1) self.phase_agc_fm = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.phase_agc_am = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.probe = blocks.probe_signal_f() self.audio_filter_block = grfilter.fir_filter_fff(1, design_lofi_audio_filter(internal_audio_rate, False)) ################################################## # Connections ################################################## # Input self.connect( self, self.band_filter_block) # AM chain self.connect( self.band_filter_block, self.am_channel_filter_block, self.am_agc_block, self.am_demod_block) # AM audio self.connect( self.am_demod_block, blocks.multiply_const_ff(1.0 / audio_modulation_index * 0.5), self.audio_filter_block) self.connect_audio_output(self.audio_filter_block) # AM phase self.connect( self.am_demod_block, self.goertzel_am, self.phase_agc_am, (self.multiply_conjugate_block, 0)) # FM phase self.connect( self.band_filter_block, self.fm_channel_filter_block, self.fm_demod_block, self.goertzel_fm, self.phase_agc_fm, (self.multiply_conjugate_block, 1)) # Phase comparison and output self.connect( self.multiply_conjugate_block, self.dir_vector_filter, self.complex_to_arg_block, blocks.multiply_const_ff(-1), # opposite angle conventions self.zeroer, self.probe)
def __init__(self): gr.top_block.__init__(self, "Lab 2 Task 4") Qt.QWidget.__init__(self) self.setWindowTitle("Lab 2 Task 4") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "lab2_task4") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.samp_rate = samp_rate = 960000 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=32000, decimation=960000, taps=None, fractional_bw=None) self.low_pass_filter_0 = filter.fir_filter_fff( 1, firdes.low_pass(1, samp_rate, 15000, 1000, firdes.WIN_KAISER, 6.76)) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_ff(1 / 6.28) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(1) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_gr_complex * 1, '/home/ipsit/Documents/EE 340/Lab 2/lab2_task4.dat', True, 0, 0) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, 1) self.blocks_conjugate_cc_0 = blocks.conjugate_cc() self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.audio_sink_0_0 = audio.sink(32000, '', True) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_conjugate_cc_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_conjugate_cc_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
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 Synchronization 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 = blocks.add_const_cc(0) # PN Sync # Create a delay line self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length/2) # Correlation from ML Sync self.conjg = blocks.conjugate_cc(); self.corr = blocks.multiply_cc(); # Create a moving sum filter for the corr output self.moving_sum_filter = filter.fir_filter_ccf(1, [1.0] * (fft_length//2)) # Create a moving sum filter for the input self.inputmag2 = blocks.complex_to_mag_squared() self.inputmovingsum = filter.fir_filter_fff(1, [1.0] * (fft_length//2)) self.square = blocks.multiply_ff() self.normalize = blocks.divide_ff() # Get magnitude (peaks) and angle (phase/freq error) self.c2mag = blocks.complex_to_mag_squared() self.angle = blocks.complex_to_arg() self.sample_and_hold = blocks.sample_and_hold_ff() #ML measurements input to sampler block and detect self.sub1 = blocks.add_const_ff(-1) self.pk_detect = blocks.peak_detector_fb(0.20, 0.20, 30, 0.001) 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 = filter.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, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-mf_f.dat")) self.connect(self.normalize, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-theta_f.dat")) self.connect(self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat")) self.connect(self.pk_detect, blocks.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat")) self.connect(self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat")) self.connect(self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 40000 ################################################## # Blocks ################################################## self.lab5_part2 = self.lab5_part2 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.lab5_part2.AddPage(grc_wxgui.Panel(self.lab5_part2), "scope") self.lab5_part2.AddPage(grc_wxgui.Panel(self.lab5_part2), "fft") self.Add(self.lab5_part2) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.lab5_part2.GetPage(0).GetWin(), title="Scope Plot", sample_rate=40000, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.lab5_part2.GetPage(0).Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.lab5_part2.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=40000, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.lab5_part2.GetPage(1).Add(self.wxgui_fftsink2_0.win) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=16, decimation=1, taps=None, fractional_bw=None, ) self.low_pass_filter_0 = filter.fir_filter_fff( 16, firdes.low_pass(1, 640000, 20000, 4000, firdes.WIN_HAMMING, 6.76)) self.iir_filter_xxx_2 = filter.iir_filter_ffd((1, -0.95), (1, ), True) self.iir_filter_xxx_1 = filter.iir_filter_ffd((1, ), (1, 0.95), True) self.iir_filter_xxx_0 = filter.iir_filter_ffd((1 / 40e3, ), (1, 1), True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, 640000, True) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (1 / 640e3, )) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, 1) self.blocks_conjugate_cc_0 = blocks.conjugate_cc() self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.blocks_add_xx_1 = blocks.add_vcc(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.analog_sig_source_x_2 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, 11000, 0.5, 0) self.analog_sig_source_x_1 = analog.sig_source_c( 640000, analog.GR_COS_WAVE, 100000, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, 1100, 0.5, 0) self.analog_phase_modulator_fc_0 = analog.phase_modulator_fc(471000) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, 0.2, 0) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_1, 1)) self.connect((self.analog_phase_modulator_fc_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_2, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.iir_filter_xxx_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_conjugate_cc_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_conjugate_cc_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_add_xx_1, 0)) self.connect((self.iir_filter_xxx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.iir_filter_xxx_1, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.iir_filter_xxx_1, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.iir_filter_xxx_2, 0), (self.analog_phase_modulator_fc_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.iir_filter_xxx_1, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.iir_filter_xxx_2, 0))
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 5 self.afc_gain = 1. self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 1 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## self.src = osmosdr.source( args=options.args ) self.src.set_sample_rate(srate_rx) self.src.set_center_freq(options.frequency, 0) self.src.set_freq_corr(options.ppm, 0) self.src.set_dc_offset_mode(0, 0) self.src.set_iq_balance_mode(0, 0) if options.gain is not None: self.src.set_gain_mode(False, 0) self.src.set_gain(36, 0) else: self.src.set_gain_mode(True, 0) out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, srate_rx) self.channelizer = pfb.channelizer_ccf( self.channels, (firdes.root_raised_cosine(1, srate_rx, 18000, 0.35, 1024)), 36./25., 100) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): squelch = analog.pwr_squelch_cc(0, 0.001, 0, True) mpsk = digital.mpsk_receiver_cc( 4, math.pi/4, math.pi/100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2./math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port)+ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) self.connect((self.channelizer, ch), (squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.squelch.append(squelch) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect( (self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) ################################################## # signal strenght identification ################################################## self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./self.srate_channel) self.pwr_probes.append(pwr_probe) self.connect((self.channelizer, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "Power level for squelch % 5.1f" % pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in self.squelch: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread(target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel/(2*math.pi)) samp_afc = self.srate_channel*self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1./samp_afc*self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_step: continue freq = self.freq_xlating.center_freq + err * self.afc_gain if self.debug: print "err: %f\tfreq: %f" % (err, freq, ) self.freq_xlating.set_center_freq(freq) self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): self.connect((self.channelizer, ch), (self.afc_selector, ch)) self.connect( (self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self, antenna="TX/RX", vor_freq_1=111e6, com_freq_1=135.275e6, vor_freq_2=111e6, rx_gain=30, gain=20): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Parameters ################################################## self.antenna = antenna self.vor_freq_1 = vor_freq_1 self.com_freq_1 = com_freq_1 self.vor_freq_2 = vor_freq_2 self.rx_gain = rx_gain self.gain = gain ################################################## # Variables ################################################## self.obs_decimation = obs_decimation = 25 self.ils_decimation = ils_decimation = 50 self.am_sample_rate = am_sample_rate = 12.5e3 self.vor_samp_rate = vor_samp_rate = 250e3 self.vor_freq_entry_2 = vor_freq_entry_2 = vor_freq_2 self.vor_freq_entry_1 = vor_freq_entry_1 = vor_freq_1 self.vor_center_freq_0 = vor_center_freq_0 = (117.95e6 - 108.00e6) / 2 + 117.95e6 self.vor_center_freq = vor_center_freq = (117.95e6 - 108.00e6) / 2 + 117.95e6 self.squelch_slider = squelch_slider = -110 self.rxgain = rxgain = 15 self.phase_correction = phase_correction = 5 self.obs_sample_rate = obs_sample_rate = am_sample_rate / obs_decimation self.ils_sample_rate = ils_sample_rate = am_sample_rate / ils_decimation self.gain_slider = gain_slider = gain self.com_freq_entry_1 = com_freq_entry_1 = com_freq_1 self.band_center_freq = band_center_freq = (136.975e6 - 108.0e6) / 2 + 108.0e6 self.audio_select = audio_select = 0 self.audio_sample_rate = audio_sample_rate = 48e3 self.am_decimation = am_decimation = 1 ################################################## # Blocks ################################################## self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF Analyzer") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Channel FFT") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Demod Audio FFT") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Ref and Phase Scope") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Manipulated Ref and Phase") self.Add(self.notebook_0) self._vor_freq_entry_1_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), value=self.vor_freq_entry_1, callback=self.set_vor_freq_entry_1, label='vor_freq_entry_1', converter=forms.float_converter(), ) self.notebook_0.GetPage(0).Add(self._vor_freq_entry_1_text_box) _gain_slider_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_slider_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), sizer=_gain_slider_sizer, value=self.gain_slider, callback=self.set_gain_slider, label='gain_slider', converter=forms.float_converter(), proportion=0, ) self._gain_slider_slider = forms.slider( parent=self.notebook_0.GetPage(0).GetWin(), sizer=_gain_slider_sizer, value=self.gain_slider, callback=self.set_gain_slider, minimum=0, maximum=30, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.notebook_0.GetPage(0).Add(_gain_slider_sizer) self._com_freq_entry_1_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), value=self.com_freq_entry_1, callback=self.set_com_freq_entry_1, label='com_freq_entry_1', converter=forms.float_converter(), ) self.notebook_0.GetPage(0).Add(self._com_freq_entry_1_text_box) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.notebook_0.GetPage(1).GetWin(), title="Scope Plot", sample_rate=10e3, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0.win) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="Units", minval=-100, maxval=100, factor=1.0, decimal_places=10, ref_level=0, sample_rate=10, number_rate=15, average=False, avg_alpha=None, label="Number Plot", peak_hold=False, show_gauge=True, ) self.Add(self.wxgui_numbersink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=12.5e3, fft_size=1024, fft_rate=5, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self._vor_freq_entry_2_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), value=self.vor_freq_entry_2, callback=self.set_vor_freq_entry_2, label='vor_freq_entry_2', converter=forms.float_converter(), ) self.notebook_0.GetPage(0).Add(self._vor_freq_entry_2_text_box) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) self.uhd_usrp_source_0.set_subdev_spec("A:0 A:0", 0) self.uhd_usrp_source_0.set_samp_rate(vor_samp_rate) self.uhd_usrp_source_0.set_center_freq( uhd.tune_request(com_freq_entry_1, rf_freq=band_center_freq, rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 0) self.uhd_usrp_source_0.set_gain(gain_slider, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.uhd_usrp_source_0.set_center_freq( uhd.tune_request(vor_freq_entry_1, rf_freq=band_center_freq, rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 1) self.uhd_usrp_source_0.set_gain(gain_slider, 1) self.uhd_usrp_source_0.set_antenna("TX/RX", 1) self.uhd_usrp_sink_0 = uhd.usrp_sink( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0.set_samp_rate(250e3) self.uhd_usrp_sink_0.set_center_freq( uhd.tune_request(com_freq_entry_1, 20e6), 0) self.uhd_usrp_sink_0.set_gain(15, 0) self.uhd_usrp_sink_0.set_antenna("TX/RX", 0) _squelch_slider_sizer = wx.BoxSizer(wx.VERTICAL) self._squelch_slider_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), sizer=_squelch_slider_sizer, value=self.squelch_slider, callback=self.set_squelch_slider, label='squelch_slider', converter=forms.float_converter(), proportion=0, ) self._squelch_slider_slider = forms.slider( parent=self.notebook_0.GetPage(0).GetWin(), sizer=_squelch_slider_sizer, value=self.squelch_slider, callback=self.set_squelch_slider, minimum=-110, maximum=0, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.notebook_0.GetPage(0).Add(_squelch_slider_sizer) self.squelch = analog.pwr_squelch_cc(squelch_slider, 0.01, 20, True) self.rational_resampler_xxx_2 = filter.rational_resampler_fff( interpolation=250, decimation=48, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_1 = filter.rational_resampler_fff( interpolation=480, decimation=125, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=4, decimation=5, taps=None, fractional_bw=None, ) self.openavionics_joystick_interface_0 = openavionics.joystick_interface( ) self.openavionics_audio_ptt_0 = openavionics.audio_ptt() self.null_sink_0_0_0 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.null_sink_0_0 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.multiply_xx_0_0_0 = blocks.multiply_vcc(1) self.multiply_xx_0_0 = blocks.multiply_vff(1) self.low_pass_filter_3 = filter.fir_filter_ccf( 1, firdes.low_pass(1, 10e3, 1, 2, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2_0_0 = filter.fir_filter_ccf( 5, firdes.low_pass(1, 40e3, 2e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2_0 = filter.fir_filter_ccf( 5, firdes.low_pass(1, 40e3, 2e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2 = filter.fir_filter_ccf( 5, firdes.low_pass(1, vor_samp_rate, 15e3, 5e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1 = filter.interp_fir_filter_fff( 1, firdes.low_pass(1, 12.5e3, 3e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf( int(250e3 / 12.5e3), firdes.low_pass(1, vor_samp_rate, 10e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.goertzel_fc_0_0 = fft.goertzel_fc(10000, 1000, 30) self.goertzel_fc_0 = fft.goertzel_fc(40000, 4000, 30) self.float_to_complex_0_0 = blocks.float_to_complex(1) self.const_source_x_0_0_0 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, 0.450) self.const_source_x_0_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0.550) self.const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0.450) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-87.2665e-3, )) self.band_pass_filter_0_0 = filter.fir_filter_fff( 4, firdes.band_pass(1, 40e3, 20, 40, 20, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0 = filter.fir_filter_fff( 1, firdes.band_pass(1, 10e3, 20, 40, 20, firdes.WIN_HAMMING, 6.76)) self.audio_source_0 = audio.source(48000, "", True) self.audio_sink_0 = audio.sink(int(audio_sample_rate), "", True) self._audio_select_chooser = forms.drop_down( parent=self.GetWin(), value=self.audio_select, callback=self.set_audio_select, label='audio_select', choices=[0, 1], labels=['AM Voice', 'VOR Subcarrier'], ) self.Add(self._audio_select_chooser) self.analog_sig_source_x_0 = analog.sig_source_c( 40e3, analog.GR_COS_WAVE, -9.96e3, 1, 0) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(1) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=40e3, audio_decim=4, audio_pass=5000, audio_stop=5500, ) self.analog_agc2_xx_0_1_0 = analog.agc2_ff(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0_1_0.set_max_gain(100) self.analog_agc2_xx_0_1 = analog.agc2_ff(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0_1.set_max_gain(100) self.analog_agc2_xx_0_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0_0.set_max_gain(100) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(100) self.am_demod_cf_0 = analog.am_demod_cf( channel_rate=am_sample_rate, audio_decim=am_decimation, audio_pass=3e3, audio_stop=4e3, ) self.agc2_xx_0 = analog.agc2_cc(1, 1, 0.75, 1.0) self.agc2_xx_0.set_max_gain(0.0) self.add_xx_0_0 = blocks.add_vff(1) ################################################## # Connections ################################################## self.connect((self.agc2_xx_0, 0), (self.am_demod_cf_0, 0)) self.connect((self.am_demod_cf_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.agc2_xx_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.multiply_xx_0_0, 0), (self.add_xx_0_0, 0)) self.connect((self.const_source_x_0, 0), (self.multiply_xx_0_0, 1)) self.connect((self.const_source_x_0_0, 0), (self.add_xx_0_0, 1)) self.connect((self.multiply_xx_0_0_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.add_xx_0_0, 0), (self.float_to_complex_0_0, 0)) self.connect((self.add_xx_0_0, 0), (self.float_to_complex_0_0, 1)) self.connect((self.float_to_complex_0_0, 0), (self.multiply_xx_0_0_0, 0)) self.connect((self.const_source_x_0_0_0, 0), (self.multiply_xx_0_0_0, 1)) self.connect((self.uhd_usrp_source_0, 0), (self.null_sink_0_0_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.audio_sink_0, 0)) self.connect((self.analog_agc2_xx_0_1_0, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.analog_agc2_xx_0_1, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_agc2_xx_0_1, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.analog_agc2_xx_0_1_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.goertzel_fc_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.low_pass_filter_3, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.low_pass_filter_3, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.analog_agc2_xx_0_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.goertzel_fc_0_0, 0), (self.analog_agc2_xx_0_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.goertzel_fc_0_0, 0)) self.connect((self.goertzel_fc_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.low_pass_filter_2_0_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.low_pass_filter_2_0_0, 0)) self.connect((self.low_pass_filter_2_0, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_2_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.uhd_usrp_source_0, 1), (self.null_sink_0_0, 0)) self.connect((self.low_pass_filter_2, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.audio_source_0, 0), (self.openavionics_audio_ptt_0, 0)) self.connect((self.openavionics_audio_ptt_0, 0), (self.rational_resampler_xxx_2, 0)) self.connect((self.rational_resampler_xxx_2, 0), (self.multiply_xx_0_0, 0)) self.connect((self.squelch, 0), (self.agc2_xx_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.squelch, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_2, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self.openavionics_joystick_interface_0, "out", self.openavionics_audio_ptt_0, "in2")
def __init__(self, dab_params, rx_params, verbose=False, debug=False): """ Hierarchical block for OFDM demodulation @param dab_params DAB parameter object (dab.parameters.dab_parameters) @param rx_params RX parameter object (dab.parameters.receiver_parameters) @param debug enables debug output to files @param verbose whether to produce verbose messages """ self.dp = dp = dab_params self.rp = rp = rx_params self.verbose = verbose if self.rp.softbits: gr.hier_block2.__init__(self,"ofdm_demod", gr.io_signature (1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature2(2, 2, gr.sizeof_float*self.dp.num_carriers*2, gr.sizeof_char)) # output signature else: gr.hier_block2.__init__(self,"ofdm_demod", gr.io_signature (1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature2(2, 2, gr.sizeof_char*self.dp.num_carriers/4, gr.sizeof_char)) # output signature # workaround for a problem that prevents connecting more than one block directly (see trac ticket #161) #self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.input = blocks.multiply_const_cc(1.0) # FIXME self.connect(self, self.input) # input filtering if self.rp.input_fft_filter: if verbose: print "--> RX filter enabled" lowpass_taps = filter.firdes_low_pass(1.0, # gain dp.sample_rate, # sampling rate rp.filt_bw, # cutoff frequency rp.filt_tb, # width of transition band filter.firdes.WIN_HAMMING) # Hamming window self.fft_filter = filter.fft_filter_ccc(1, lowpass_taps) # correct sample rate offset, if enabled if self.rp.autocorrect_sample_rate: if verbose: print "--> dynamic sample rate correction enabled" self.rate_detect_ns = dab.detect_null(dp.ns_length, False) self.rate_estimator = dab.estimate_sample_rate_bf(dp.sample_rate, dp.frame_length) self.rate_prober = blocks.probe_signal_f() self.connect(self.input, self.rate_detect_ns, self.rate_estimator, self.rate_prober) # self.resample = gr.fractional_interpolator_cc(0, 1) self.resample = dab.fractional_interpolator_triggered_update_cc(0,1) self.connect(self.rate_detect_ns, (self.resample,1)) self.updater = Timer(0.1,self.update_correction) # self.updater = threading.Thread(target=self.update_correction) self.run_interpolater_update_thread = True self.updater.setDaemon(True) self.updater.start() else: self.run_interpolater_update_thread = False if self.rp.sample_rate_correction_factor != 1: if verbose: print "--> static sample rate correction enabled" self.resample = gr.fractional_interpolator_cc(0, self.rp.sample_rate_correction_factor) # timing and fine frequency synchronisation self.sync = dab.ofdm_sync_dab2(self.dp, self.rp, debug) # ofdm symbol sampler self.sampler = dab.ofdm_sampler(dp.fft_length, dp.cp_length, dp.symbols_per_frame, rp.cp_gap) # fft for symbol vectors self.fft = fft.fft_vcc(dp.fft_length, True, [], True) # coarse frequency synchronisation self.cfs = dab.ofdm_coarse_frequency_correct(dp.fft_length, dp.num_carriers, dp.cp_length) # diff phasor self.phase_diff = dab.diff_phasor_vcc(dp.num_carriers) # remove pilot symbol self.remove_pilot = dab.ofdm_remove_first_symbol_vcc(dp.num_carriers) # magnitude equalisation if self.rp.equalize_magnitude: if verbose: print "--> magnitude equalization enabled" self.equalizer = dab.magnitude_equalizer_vcc(dp.num_carriers, rp.symbols_for_magnitude_equalization) # frequency deinterleaving self.deinterleave = dab.frequency_interleaver_vcc(dp.frequency_deinterleaving_sequence_array) # symbol demapping self.demapper = dab.qpsk_demapper_vcb(dp.num_carriers) # # connect everything # if self.rp.autocorrect_sample_rate or self.rp.sample_rate_correction_factor != 1: self.connect(self.input, self.resample) self.input2 = self.resample else: self.input2 = self.input if self.rp.input_fft_filter: self.connect(self.input2, self.fft_filter, self.sync) else: self.connect(self.input2, self.sync) # data stream self.connect((self.sync, 0), (self.sampler, 0), self.fft, (self.cfs, 0), self.phase_diff, (self.remove_pilot,0)) if self.rp.equalize_magnitude: self.connect((self.remove_pilot,0), (self.equalizer,0), self.deinterleave) else: self.connect((self.remove_pilot,0), self.deinterleave) if self.rp.softbits: if verbose: print "--> using soft bits" self.softbit_interleaver = dab.complex_to_interleaved_float_vcf(self.dp.num_carriers) self.connect(self.deinterleave, self.softbit_interleaver, (self,0)) else: self.connect(self.deinterleave, self.demapper, (self,0)) # control stream self.connect((self.sync, 1), (self.sampler, 1), (self.cfs, 1), (self.remove_pilot,1)) if self.rp.equalize_magnitude: self.connect((self.remove_pilot,1), (self.equalizer,1), (self,1)) else: self.connect((self.remove_pilot,1), (self,1)) # calculate an estimate of the SNR self.phase_var_decim = blocks.keep_one_in_n(gr.sizeof_gr_complex*self.dp.num_carriers, self.rp.phase_var_estimate_downsample) self.phase_var_arg = blocks.complex_to_arg(dp.num_carriers) self.phase_var_v2s = blocks.vector_to_stream(gr.sizeof_float, dp.num_carriers) self.phase_var_mod = dab.modulo_ff(pi/2) self.phase_var_avg_mod = filter.iir_filter_ffd([rp.phase_var_estimate_alpha], [0,1-rp.phase_var_estimate_alpha]) self.phase_var_sub_avg = blocks.sub_ff() self.phase_var_sqr = blocks.multiply_ff() self.phase_var_avg = filter.iir_filter_ffd([rp.phase_var_estimate_alpha], [0,1-rp.phase_var_estimate_alpha]) self.probe_phase_var = blocks.probe_signal_f() self.connect((self.remove_pilot,0), self.phase_var_decim, self.phase_var_arg, self.phase_var_v2s, self.phase_var_mod, (self.phase_var_sub_avg,0), (self.phase_var_sqr,0)) self.connect(self.phase_var_mod, self.phase_var_avg_mod, (self.phase_var_sub_avg,1)) self.connect(self.phase_var_sub_avg, (self.phase_var_sqr,1)) self.connect(self.phase_var_sqr, self.phase_var_avg, self.probe_phase_var) # measure processing rate self.measure_rate = dab.measure_processing_rate(gr.sizeof_gr_complex, 2000000) self.connect(self.input, self.measure_rate) # debugging if debug: self.connect(self.fft, blocks.file_sink(gr.sizeof_gr_complex*dp.fft_length, "debug/ofdm_after_fft.dat")) self.connect((self.cfs,0), blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_after_cfs.dat")) self.connect(self.phase_diff, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_diff_phasor.dat")) self.connect((self.remove_pilot,0), blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_pilot_removed.dat")) self.connect((self.remove_pilot,1), blocks.file_sink(gr.sizeof_char, "debug/ofdm_after_cfs_trigger.dat")) self.connect(self.deinterleave, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_deinterleaved.dat")) if self.rp.equalize_magnitude: self.connect(self.equalizer, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_equalizer.dat")) if self.rp.softbits: self.connect(self.softbit_interleaver, blocks.file_sink(gr.sizeof_float*dp.num_carriers*2, "debug/softbits.dat"))
def __init__(self, antenna="TX/RX", vor_freq_1=111e6, com_freq_1=135.275e6, vor_freq_2=111e6, rx_gain=30, gain=20): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Parameters ################################################## self.antenna = antenna self.vor_freq_1 = vor_freq_1 self.com_freq_1 = com_freq_1 self.vor_freq_2 = vor_freq_2 self.rx_gain = rx_gain self.gain = gain ################################################## # Variables ################################################## self.obs_decimation = obs_decimation = 25 self.ils_decimation = ils_decimation = 50 self.am_sample_rate = am_sample_rate = 12.5e3 self.vor_samp_rate = vor_samp_rate = 250e3 self.vor_freq_entry_2 = vor_freq_entry_2 = vor_freq_2 self.vor_freq_entry_1 = vor_freq_entry_1 = vor_freq_1 self.vor_center_freq_0 = vor_center_freq_0 = (117.95e6-108.00e6)/2+117.95e6 self.vor_center_freq = vor_center_freq = (117.95e6-108.00e6)/2+117.95e6 self.squelch_slider = squelch_slider = -110 self.rxgain = rxgain = 15 self.phase_correction = phase_correction = 5 self.obs_sample_rate = obs_sample_rate = am_sample_rate/obs_decimation self.ils_sample_rate = ils_sample_rate = am_sample_rate/ils_decimation self.gain_slider = gain_slider = gain self.com_freq_entry_1 = com_freq_entry_1 = com_freq_1 self.band_center_freq = band_center_freq = (136.975e6-108.0e6)/2+108.0e6 self.audio_select = audio_select = 0 self.audio_sample_rate = audio_sample_rate = 48e3 self.am_decimation = am_decimation = 1 ################################################## # Blocks ################################################## self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF Analyzer") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Channel FFT") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Demod Audio FFT") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Ref and Phase Scope") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Manipulated Ref and Phase") self.Add(self.notebook_0) self._vor_freq_entry_1_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), value=self.vor_freq_entry_1, callback=self.set_vor_freq_entry_1, label='vor_freq_entry_1', converter=forms.float_converter(), ) self.notebook_0.GetPage(0).Add(self._vor_freq_entry_1_text_box) _gain_slider_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_slider_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), sizer=_gain_slider_sizer, value=self.gain_slider, callback=self.set_gain_slider, label='gain_slider', converter=forms.float_converter(), proportion=0, ) self._gain_slider_slider = forms.slider( parent=self.notebook_0.GetPage(0).GetWin(), sizer=_gain_slider_sizer, value=self.gain_slider, callback=self.set_gain_slider, minimum=0, maximum=30, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.notebook_0.GetPage(0).Add(_gain_slider_sizer) self._com_freq_entry_1_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), value=self.com_freq_entry_1, callback=self.set_com_freq_entry_1, label='com_freq_entry_1', converter=forms.float_converter(), ) self.notebook_0.GetPage(0).Add(self._com_freq_entry_1_text_box) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.notebook_0.GetPage(1).GetWin(), title="Scope Plot", sample_rate=10e3, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0.win) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="Units", minval=-100, maxval=100, factor=1.0, decimal_places=10, ref_level=0, sample_rate=10, number_rate=15, average=False, avg_alpha=None, label="Number Plot", peak_hold=False, show_gauge=True, ) self.Add(self.wxgui_numbersink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=12.5e3, fft_size=1024, fft_rate=5, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self._vor_freq_entry_2_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), value=self.vor_freq_entry_2, callback=self.set_vor_freq_entry_2, label='vor_freq_entry_2', converter=forms.float_converter(), ) self.notebook_0.GetPage(0).Add(self._vor_freq_entry_2_text_box) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) self.uhd_usrp_source_0.set_subdev_spec("A:0 A:0", 0) self.uhd_usrp_source_0.set_samp_rate(vor_samp_rate) self.uhd_usrp_source_0.set_center_freq(uhd.tune_request(com_freq_entry_1,rf_freq=band_center_freq, rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 0) self.uhd_usrp_source_0.set_gain(gain_slider, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.uhd_usrp_source_0.set_center_freq(uhd.tune_request(vor_freq_entry_1, rf_freq=band_center_freq, rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 1) self.uhd_usrp_source_0.set_gain(gain_slider, 1) self.uhd_usrp_source_0.set_antenna("TX/RX", 1) self.uhd_usrp_sink_0 = uhd.usrp_sink( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0.set_samp_rate(250e3) self.uhd_usrp_sink_0.set_center_freq(uhd.tune_request(com_freq_entry_1,20e6), 0) self.uhd_usrp_sink_0.set_gain(15, 0) self.uhd_usrp_sink_0.set_antenna("TX/RX", 0) _squelch_slider_sizer = wx.BoxSizer(wx.VERTICAL) self._squelch_slider_text_box = forms.text_box( parent=self.notebook_0.GetPage(0).GetWin(), sizer=_squelch_slider_sizer, value=self.squelch_slider, callback=self.set_squelch_slider, label='squelch_slider', converter=forms.float_converter(), proportion=0, ) self._squelch_slider_slider = forms.slider( parent=self.notebook_0.GetPage(0).GetWin(), sizer=_squelch_slider_sizer, value=self.squelch_slider, callback=self.set_squelch_slider, minimum=-110, maximum=0, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.notebook_0.GetPage(0).Add(_squelch_slider_sizer) self.squelch = analog.pwr_squelch_cc(squelch_slider, 0.01, 20, True) self.rational_resampler_xxx_2 = filter.rational_resampler_fff( interpolation=250, decimation=48, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_1 = filter.rational_resampler_fff( interpolation=480, decimation=125, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=4, decimation=5, taps=None, fractional_bw=None, ) self.openavionics_joystick_interface_0 = openavionics.joystick_interface() self.openavionics_audio_ptt_0 = openavionics.audio_ptt() self.null_sink_0_0_0 = blocks.null_sink(gr.sizeof_gr_complex*1) self.null_sink_0_0 = blocks.null_sink(gr.sizeof_gr_complex*1) self.multiply_xx_0_0_0 = blocks.multiply_vcc(1) self.multiply_xx_0_0 = blocks.multiply_vff(1) self.low_pass_filter_3 = filter.fir_filter_ccf(1, firdes.low_pass( 1, 10e3, 1, 2, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2_0_0 = filter.fir_filter_ccf(5, firdes.low_pass( 1, 40e3, 2e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2_0 = filter.fir_filter_ccf(5, firdes.low_pass( 1, 40e3, 2e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2 = filter.fir_filter_ccf(5, firdes.low_pass( 1, vor_samp_rate, 15e3, 5e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1 = filter.interp_fir_filter_fff(1, firdes.low_pass( 1, 12.5e3, 3e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(int(250e3/12.5e3), firdes.low_pass( 1, vor_samp_rate, 10e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.goertzel_fc_0_0 = fft.goertzel_fc(10000, 1000, 30) self.goertzel_fc_0 = fft.goertzel_fc(40000, 4000, 30) self.float_to_complex_0_0 = blocks.float_to_complex(1) self.const_source_x_0_0_0 = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 0.450) self.const_source_x_0_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0.550) self.const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0.450) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-87.2665e-3, )) self.band_pass_filter_0_0 = filter.fir_filter_fff(4, firdes.band_pass( 1, 40e3, 20, 40, 20, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0 = filter.fir_filter_fff(1, firdes.band_pass( 1, 10e3, 20, 40, 20, firdes.WIN_HAMMING, 6.76)) self.audio_source_0 = audio.source(48000, "", True) self.audio_sink_0 = audio.sink(int(audio_sample_rate), "", True) self._audio_select_chooser = forms.drop_down( parent=self.GetWin(), value=self.audio_select, callback=self.set_audio_select, label='audio_select', choices=[0, 1], labels=['AM Voice','VOR Subcarrier'], ) self.Add(self._audio_select_chooser) self.analog_sig_source_x_0 = analog.sig_source_c(40e3, analog.GR_COS_WAVE, -9.96e3, 1, 0) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(1) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=40e3, audio_decim=4, audio_pass=5000, audio_stop=5500, ) self.analog_agc2_xx_0_1_0 = analog.agc2_ff(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0_1_0.set_max_gain(100) self.analog_agc2_xx_0_1 = analog.agc2_ff(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0_1.set_max_gain(100) self.analog_agc2_xx_0_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0_0.set_max_gain(100) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(100) self.am_demod_cf_0 = analog.am_demod_cf( channel_rate=am_sample_rate, audio_decim=am_decimation, audio_pass=3e3, audio_stop=4e3, ) self.agc2_xx_0 = analog.agc2_cc(1, 1, 0.75, 1.0) self.agc2_xx_0.set_max_gain(0.0) self.add_xx_0_0 = blocks.add_vff(1) ################################################## # Connections ################################################## self.connect((self.agc2_xx_0, 0), (self.am_demod_cf_0, 0)) self.connect((self.am_demod_cf_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.agc2_xx_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.multiply_xx_0_0, 0), (self.add_xx_0_0, 0)) self.connect((self.const_source_x_0, 0), (self.multiply_xx_0_0, 1)) self.connect((self.const_source_x_0_0, 0), (self.add_xx_0_0, 1)) self.connect((self.multiply_xx_0_0_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.add_xx_0_0, 0), (self.float_to_complex_0_0, 0)) self.connect((self.add_xx_0_0, 0), (self.float_to_complex_0_0, 1)) self.connect((self.float_to_complex_0_0, 0), (self.multiply_xx_0_0_0, 0)) self.connect((self.const_source_x_0_0_0, 0), (self.multiply_xx_0_0_0, 1)) self.connect((self.uhd_usrp_source_0, 0), (self.null_sink_0_0_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.audio_sink_0, 0)) self.connect((self.analog_agc2_xx_0_1_0, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.analog_agc2_xx_0_1, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_agc2_xx_0_1, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.analog_agc2_xx_0_1_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.goertzel_fc_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.low_pass_filter_3, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.low_pass_filter_3, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.analog_agc2_xx_0_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.goertzel_fc_0_0, 0), (self.analog_agc2_xx_0_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.goertzel_fc_0_0, 0)) self.connect((self.goertzel_fc_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.low_pass_filter_2_0_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.low_pass_filter_2_0_0, 0)) self.connect((self.low_pass_filter_2_0, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_2_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.uhd_usrp_source_0, 1), (self.null_sink_0_0, 0)) self.connect((self.low_pass_filter_2, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.audio_source_0, 0), (self.openavionics_audio_ptt_0, 0)) self.connect((self.openavionics_audio_ptt_0, 0), (self.rational_resampler_xxx_2, 0)) self.connect((self.rational_resampler_xxx_2, 0), (self.multiply_xx_0_0, 0)) self.connect((self.squelch, 0), (self.agc2_xx_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.squelch, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_2, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self.openavionics_joystick_interface_0, "out", self.openavionics_audio_ptt_0, "in2")
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1e6 self.m = m = 50 self.kf = kf = 17 self.fm = fm = 1.1e3 ################################################## # Blocks ################################################## _kf_sizer = wx.BoxSizer(wx.VERTICAL) self._kf_text_box = forms.text_box( parent=self.GetWin(), sizer=_kf_sizer, value=self.kf, callback=self.set_kf, label='kf', converter=forms.float_converter(), proportion=0, ) self._kf_slider = forms.slider( parent=self.GetWin(), sizer=_kf_sizer, value=self.kf, callback=self.set_kf, minimum=0, maximum=25, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_kf_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( 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=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.message_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 11e3, 0.5, 0) self.message = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1.1e3, 0.5, 0) _m_sizer = wx.BoxSizer(wx.VERTICAL) self._m_text_box = forms.text_box( parent=self.GetWin(), sizer=_m_sizer, value=self.m, callback=self.set_m, label='m', converter=forms.float_converter(), proportion=0, ) self._m_slider = forms.slider( parent=self.GetWin(), sizer=_m_sizer, value=self.m, callback=self.set_m, minimum=1, maximum=80, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_m_sizer) self.iir_filter_xxx_0 = filter.iir_filter_ffd(([1.0/samp_rate]), ([1,1]), True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((10e3, )) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 1) self.blocks_conjugate_cc_0 = blocks.conjugate_cc() self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.blocks_add_xx_1 = blocks.add_vcc(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 100e3, 1, 0) self.analog_phase_modulator_fc_0 = analog.phase_modulator_fc(kf) self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_1, 1)) self.connect((self.analog_phase_modulator_fc_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.iir_filter_xxx_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.blocks_conjugate_cc_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_conjugate_cc_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.analog_phase_modulator_fc_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_add_xx_1, 0)) self.connect((self.iir_filter_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.message, 0), (self.blocks_add_xx_0, 0)) self.connect((self.message_0, 0), (self.blocks_add_xx_0, 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 = blocks.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 = blocks.delay(gr.sizeof_gr_complex, fft_length) self.connect(self.input, self.delay) # magnitude squared blocks self.magsqrd1 = blocks.complex_to_mag_squared() self.magsqrd2 = blocks.complex_to_mag_squared() self.adder = blocks.add_ff() moving_sum_taps = [rho / 2 for i in range(cp_length)] self.moving_sum_filter = filter.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 = blocks.conjugate_cc() self.mixer = blocks.multiply_cc() movingsum2_taps = [1.0 for i in range(cp_length)] self.movingsum2 = filter.fir_filter_ccf(1, movingsum2_taps) # Correlator data handler self.c2mag = blocks.complex_to_mag() self.angle = blocks.complex_to_arg() self.connect(self.input, (self.mixer, 1)) self.connect(self.delay, self.conjg, (self.mixer, 0)) self.connect(self.mixer, self.movingsum2, self.c2mag) self.connect(self.movingsum2, self.angle) # ML Sync output arg, need to find maximum point of this self.diff = blocks.sub_ff() self.connect(self.c2mag, (self.diff, 0)) self.connect(self.moving_sum_filter, (self.diff, 1)) #ML measurements input to sampler block and detect self.f2c = blocks.float_to_complex() self.pk_detect = blocks.peak_detector_fb(0.2, 0.25, 30, 0.0005) self.sample_and_hold = blocks.sample_and_hold_ff() # use the sync loop values to set the sampler and the NCO # self.diff = theta # 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 = filter.fir_filter_ccc(1, kstime) self.corrmag = blocks.complex_to_mag_squared() self.div = blocks.divide_ff() # The output signature of the correlation has a few spikes because the rest of the # system uses the repeated preamble symbol. It needs to work that generically if # 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 = blocks.threshold_ff(self.threshold_factor, self.threshold_factor, 0) self.f2b = blocks.float_to_char() self.b2f = blocks.char_to_float() self.mul = blocks.multiply_ff() # Normalize the power of the corr output by the energy. This is not really needed # and could be removed for performance, but it makes for a cleaner signal. # 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, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat")) self.connect( self.diff, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat")) self.connect( self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat")) self.connect( self.corrmag, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat")) self.connect( self.kscorr, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat")) self.connect( self.div, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat")) self.connect( self.mul, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat")) self.connect( self.slice, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat")) self.connect( self.pk_detect, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat")) if use_dpll: self.connect( self.dpll, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat")) self.connect( self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat")) self.connect( self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat"))
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 = blocks.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 = blocks.delay(gr.sizeof_gr_complex, fft_length) self.connect(self.input, self.delay) # magnitude squared blocks self.magsqrd1 = blocks.complex_to_mag_squared() self.magsqrd2 = blocks.complex_to_mag_squared() self.adder = blocks.add_ff() moving_sum_taps = [rho / 2 for i in range(cp_length)] self.moving_sum_filter = filter.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 = blocks.conjugate_cc(); self.mixer = blocks.multiply_cc(); movingsum2_taps = [1.0 for i in range(cp_length)] self.movingsum2 = filter.fir_filter_ccf(1,movingsum2_taps) # Correlator data handler self.c2mag = blocks.complex_to_mag() self.angle = blocks.complex_to_arg() self.connect(self.input,(self.mixer,1)) self.connect(self.delay,self.conjg,(self.mixer,0)) self.connect(self.mixer,self.movingsum2,self.c2mag) self.connect(self.movingsum2,self.angle) # ML Sync output arg, need to find maximum point of this self.diff = blocks.sub_ff() self.connect(self.c2mag,(self.diff,0)) self.connect(self.moving_sum_filter,(self.diff,1)) #ML measurements input to sampler block and detect self.f2c = blocks.float_to_complex() self.pk_detect = blocks.peak_detector_fb(0.2, 0.25, 30, 0.0005) self.sample_and_hold = blocks.sample_and_hold_ff() # use the sync loop values to set the sampler and the NCO # self.diff = theta # 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 = filter.fir_filter_ccc(1, kstime) self.corrmag = blocks.complex_to_mag_squared() self.div = blocks.divide_ff() # The output signature of the correlation has a few spikes because the rest of the # system uses the repeated preamble symbol. It needs to work that generically if # 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 = blocks.threshold_ff(self.threshold_factor, self.threshold_factor, 0) self.f2b = blocks.float_to_char() self.b2f = blocks.char_to_float() self.mul = blocks.multiply_ff() # Normalize the power of the corr output by the energy. This is not really needed # and could be removed for performance, but it makes for a cleaner signal. # 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, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat")) self.connect(self.diff, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat")) self.connect(self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat")) self.connect(self.corrmag, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat")) self.connect(self.kscorr, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat")) self.connect(self.div, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat")) self.connect(self.mul, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat")) self.connect(self.slice, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat")) self.connect(self.pk_detect, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat")) if use_dpll: self.connect(self.dpll, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat")) self.connect(self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat")) self.connect(self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat"))
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() self.src = blocks.file_source(gr.sizeof_gr_complex * 1, "/tmp/myout1.ch", False) ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 15 self.afc_gain = 0.01 self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 10 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) self.channels = 10 ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.blocks_deinterleave_0 = blocks.deinterleave( gr.sizeof_gr_complex * 1, 1) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): mpsk = digital.mpsk_receiver_cc(4, math.pi / 4, math.pi / 100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2. / math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) brmchannels = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 ] #brmchannels = [11,4,3,64,45,47,53,8,68,6,56,49,17,54,65,5,71,22,48,7,50] # itds kancl #brmchannels = [23,13,40,69,59,7,42,54,5,14,4,56,45,46,67,55,66,44,71,49,31,57,0,65,70] # doma - dole #brmchannels = [23,13,59,40,69,7,49,60,42,70,4,50,66,67,3,14,57,33,46,22,68,32,39,24,6,12,43,58,48,17,5,56,65,29,54,30,16,52,53,41,47,2,34,44,8] # doma - strecha #brmchannels = [67, 7, 23, 70] # doma - strecha - SDS #brmchannels = [67, 7, 23, 70,9,71,64,63,62,61,55,51,45,38,37,36,35,31,28,27,26,25,21,20,19,18,15,11,10,1,0] # doma - strecha - komplement if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port) + ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) print "connect %i" % ch if ch in brmchannels: self.connect( (self.blocks_deinterleave_0, ch), #(squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect((self.src, 0), (self.blocks_deinterleave_0, 0)) ################################################## # signal strenght identification ################################################## ''' self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./self.srate_channel) self.pwr_probes.append(pwr_probe) print "connect %i"%ch self.connect((self.blocks_deinterleave_0, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "power threshold target %f"%pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in []: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread(target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ''' ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel / (2 * math.pi)) samp_afc = self.srate_channel * self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1. / samp_afc * self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): rt = 0.0 while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() freq = err * self.afc_gain print "err: %f\tfreq: %f\trt %f" % (err, freq, rt) changed = False if err < -1: rt += 0.1 changed = True elif err > 1: rt -= 0.1 changed = True if changed: os.system("echo \"setrot %f\" | nc localhost 3333" % rt) self.afc_channel = 0 self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): print "connect %i" % ch self.connect((self.blocks_deinterleave_0, ch), (self.afc_selector, ch)) self.connect((self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self, fft_length, cp_length, kstime, overrate, logging=True): """ 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 = blocks.add_const_cc(0) # cross-correlate with the known symbol kstime = [k.conjugate() for k in kstime] kstime.reverse() self.crosscorr_filter = filter.fir_filter_ccc(1, kstime) # PN Sync self.corrmag = blocks.complex_to_mag_squared() self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length * overrate / 2) # Correlation from ML Sync self.conjg = blocks.conjugate_cc() self.corr = blocks.multiply_cc() #self.sub = blocks.add_const_ff(-1) self.pk_detect = blocks.peak_detector_fb(0.40, 0.25, fft_length * overrate, 0.00000000000) self.connect(self, self.input) self.connect(self.input, self.crosscorr_filter) self.connect(self.crosscorr_filter, self.corrmag) #self.inputmag = blocks.complex_to_mag_squared() #self.normalize = blocks.divide_ff() #self.inputmovingsum = filter.fir_filter_fff(1, [1.0] * (fft_length//2)) self.square = blocks.multiply_ff() #self.connect(self.input,self.inputmag,self.inputmovingsum) self.connect(self.corrmag, (self.square, 0)) self.connect(self.corrmag, (self.square, 1)) self.dsquare = blocks.multiply_ff() self.connect(self.square, (self.dsquare, 0)) self.connect(self.square, (self.dsquare, 1)) self.connect(self.dsquare, self.pk_detect) # Create a moving sum filter for the corr output self.moving_sum_filter = filter.fir_filter_ccf( 1, [1.0] * (fft_length * overrate // 2)) # Get magnitude (peaks) and angle (phase/freq error) self.angle = blocks.complex_to_arg() self.sample_and_hold = blocks.sample_and_hold_ff() # 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.angle) self.connect(self.angle, (self.sample_and_hold, 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.dsquare, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-dsquare.dat")) self.connect( self.corrmag, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-corrmag.dat")) self.connect( self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat")) self.connect( self.pk_detect, blocks.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat")) self.connect( self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat")) self.connect( self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))
def __init__(self, dab_params, rx_params, debug=False): """ OFDM time and coarse frequency synchronisation for DAB @param mode DAB mode (1-4) @param debug if True: write data streams out to files """ dp = dab_params rp = rx_params gr.hier_block2.__init__( self, "ofdm_sync_dab", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature2(2, 2, gr.sizeof_gr_complex, gr.sizeof_char), ) # output signature # workaround for a problem that prevents connecting more than one block directly (see trac ticket #161) self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.connect(self, self.input) # # null-symbol detection # # (outsourced to detect_zero.py) self.ns_detect = detect_null.detect_null(dp.ns_length, debug) self.connect(self.input, self.ns_detect) # # fine frequency synchronisation # # the code for fine frequency synchronisation is adapted from # ofdm_sync_ml.py; it abuses the cyclic prefix to find the fine # frequency error, as suggested in "ML Estimation of Timing and # Frequency Offset in OFDM Systems", by Jan-Jaap van de Beek, # Magnus Sandell, Per Ola Börjesson, see # http://www.sm.luth.se/csee/sp/research/report/bsb96r.html self.ffs_delay = blocks.delay(gr.sizeof_gr_complex, dp.fft_length) self.ffs_conj = blocks.conjugate_cc() self.ffs_mult = blocks.multiply_cc() self.ffs_moving_sum = dab_swig.moving_sum_cc(dp.cp_length) self.ffs_arg = blocks.complex_to_arg() self.ffs_sample_and_average = dab_swig.ofdm_ffs_sample( dp.symbol_length, dp.fft_length, rp.symbols_for_ffs_estimation, rp.ffs_alpha, dp.sample_rate ) if rp.correct_ffe: self.ffs_delay_input_for_correction = blocks.delay( gr.sizeof_gr_complex, dp.symbol_length * rp.symbols_for_ffs_estimation ) # by delaying the input, we can use the ff offset estimation from the first symbol to correct the first symbol itself self.ffs_delay_frame_start = blocks.delay( gr.sizeof_char, dp.symbol_length * rp.symbols_for_ffs_estimation ) # sample the value at the end of the symbol .. self.ffs_nco = analog.frequency_modulator_fc( 1 ) # ffs_sample_and_hold directly outputs phase error per sample self.ffs_mixer = blocks.multiply_cc() # calculate fine frequency error self.connect(self.input, self.ffs_conj, self.ffs_mult) self.connect(self.input, self.ffs_delay, (self.ffs_mult, 1)) self.connect(self.ffs_mult, self.ffs_moving_sum, self.ffs_arg, (self.ffs_sample_and_average, 0)) self.connect(self.ns_detect, (self.ffs_sample_and_average, 1)) if rp.correct_ffe: # do the correction self.connect(self.ffs_sample_and_average, self.ffs_nco, (self.ffs_mixer, 0)) self.connect(self.input, self.ffs_delay_input_for_correction, (self.ffs_mixer, 1)) # output - corrected signal and start of DAB frames self.connect(self.ffs_mixer, (self, 0)) self.connect(self.ns_detect, self.ffs_delay_frame_start, (self, 1)) else: # just patch the signal through self.connect(self.ffs_sample_and_average, blocks.null_sink(gr.sizeof_float)) self.connect(self.input, (self, 0)) # frame start still needed .. self.connect(self.ns_detect, (self, 1)) if debug: self.connect( self.ffs_sample_and_average, blocks.multiply_const_ff(1.0 / (dp.T * 2 * pi)), gr.file_sink(gr.sizeof_float, "debug/ofdm_sync_dab_fine_freq_err_f.dat"), ) self.connect( self.ffs_mixer, blocks.file_sink(gr.sizeof_gr_complex, "debug/ofdm_sync_dab_fine_freq_corrected_c.dat") )
def __init__(self, mode='VOR', zero_point=59, **kwargs): self.channel_rate = channel_rate = 40000 internal_audio_rate = 20000 # TODO over spec'd self.zero_point = zero_point transition = 5000 SimpleAudioDemodulator.__init__(self, mode=mode, audio_rate=internal_audio_rate, demod_rate=channel_rate, band_filter=fm_subcarrier * 1.25 + fm_deviation + transition / 2, band_filter_transition=transition, **kwargs) self.dir_rate = dir_rate = 10 if internal_audio_rate % dir_rate != 0: raise ValueError( 'Audio rate %s is not a multiple of direction-finding rate %s' % (internal_audio_rate, dir_rate)) self.dir_scale = dir_scale = internal_audio_rate // dir_rate self.audio_scale = audio_scale = channel_rate // internal_audio_rate self.zeroer = blocks.add_const_vff((zero_point * (math.pi / 180), )) self.dir_vector_filter = grfilter.fir_filter_ccf( 1, firdes.low_pass(1, dir_rate, 1, 2, firdes.WIN_HAMMING, 6.76)) self.am_channel_filter_block = grfilter.fir_filter_ccf( 1, firdes.low_pass(1, channel_rate, 5000, 5000, firdes.WIN_HAMMING, 6.76)) self.goertzel_fm = fft.goertzel_fc(channel_rate, dir_scale * audio_scale, 30) self.goertzel_am = fft.goertzel_fc(internal_audio_rate, dir_scale, 30) self.fm_channel_filter_block = grfilter.freq_xlating_fir_filter_ccc( 1, (firdes.low_pass(1.0, channel_rate, fm_subcarrier / 2, fm_subcarrier / 2, firdes.WIN_HAMMING)), fm_subcarrier, channel_rate) self.multiply_conjugate_block = blocks.multiply_conjugate_cc(1) self.complex_to_arg_block = blocks.complex_to_arg(1) self.am_agc_block = analog.feedforward_agc_cc(1024, 1.0) self.am_demod_block = analog.am_demod_cf( channel_rate=channel_rate, audio_decim=audio_scale, audio_pass=5000, audio_stop=5500, ) self.fm_demod_block = analog.quadrature_demod_cf(1) self.phase_agc_fm = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.phase_agc_am = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.probe = blocks.probe_signal_f() self.audio_filter_block = grfilter.fir_filter_fff( 1, design_lofi_audio_filter(internal_audio_rate, False)) ################################################## # Connections ################################################## # Input self.connect(self, self.band_filter_block) # AM chain self.connect(self.band_filter_block, self.am_channel_filter_block, self.am_agc_block, self.am_demod_block) # AM audio self.connect( self.am_demod_block, blocks.multiply_const_ff(1.0 / audio_modulation_index * 0.5), self.audio_filter_block) self.connect_audio_output(self.audio_filter_block) # AM phase self.connect(self.am_demod_block, self.goertzel_am, self.phase_agc_am, (self.multiply_conjugate_block, 0)) # FM phase self.connect(self.band_filter_block, self.fm_channel_filter_block, self.fm_demod_block, self.goertzel_fm, self.phase_agc_fm, (self.multiply_conjugate_block, 1)) # Phase comparison and output self.connect( self.multiply_conjugate_block, self.dir_vector_filter, self.complex_to_arg_block, blocks.multiply_const_ff(-1), # opposite angle conventions self.zeroer, self.probe)
def __init__(self): gr.top_block.__init__(self, "Modes Uf Rx Sigmf V2") Qt.QWidget.__init__(self) self.setWindowTitle("Modes Uf Rx Sigmf V2") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "modes_uf_rx_sigmf_v2") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 2 self.samp_rate = samp_rate = 8000000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine( 1, 1, 0.5, 0.4, 32) self.rms_alpha = rms_alpha = 1e-6 self.rf_gain = rf_gain = 45 self.qt_thresh = qt_thresh = 110 self.es_thresh = es_thresh = 110 self.det_mult = det_mult = 2 self.det_avg_len = det_avg_len = 20 self.cons_offset = cons_offset = 5 self.burst_length = burst_length = 600 self.bit_thresh = bit_thresh = 5 self.avg_len = avg_len = 20 ################################################## # Blocks ################################################## self._rms_alpha_tool_bar = Qt.QToolBar(self) self._rms_alpha_tool_bar.addWidget(Qt.QLabel("rms_alpha" + ": ")) self._rms_alpha_line_edit = Qt.QLineEdit(str(self.rms_alpha)) self._rms_alpha_tool_bar.addWidget(self._rms_alpha_line_edit) self._rms_alpha_line_edit.returnPressed.connect( lambda: self.set_rms_alpha( eng_notation.str_to_num( str(self._rms_alpha_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._rms_alpha_tool_bar, 6, 3, 1, 1) for r in range(6, 7): self.top_grid_layout.setRowStretch(r, 1) for c in range(3, 4): self.top_grid_layout.setColumnStretch(c, 1) self._qt_thresh_tool_bar = Qt.QToolBar(self) self._qt_thresh_tool_bar.addWidget(Qt.QLabel("qt_thresh" + ": ")) self._qt_thresh_line_edit = Qt.QLineEdit(str(self.qt_thresh)) self._qt_thresh_tool_bar.addWidget(self._qt_thresh_line_edit) self._qt_thresh_line_edit.returnPressed.connect( lambda: self.set_qt_thresh( eng_notation.str_to_num( str(self._qt_thresh_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._qt_thresh_tool_bar, 0, 2, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 4): self.top_grid_layout.setColumnStretch(c, 1) self._es_thresh_tool_bar = Qt.QToolBar(self) self._es_thresh_tool_bar.addWidget(Qt.QLabel('ES Thresh' + ": ")) self._es_thresh_line_edit = Qt.QLineEdit(str(self.es_thresh)) self._es_thresh_tool_bar.addWidget(self._es_thresh_line_edit) self._es_thresh_line_edit.returnPressed.connect( lambda: self.set_es_thresh( eng_notation.str_to_num( str(self._es_thresh_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._es_thresh_tool_bar, 0, 5, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(5, 6): self.top_grid_layout.setColumnStretch(c, 1) self._det_mult_tool_bar = Qt.QToolBar(self) self._det_mult_tool_bar.addWidget(Qt.QLabel("det_mult" + ": ")) self._det_mult_line_edit = Qt.QLineEdit(str(self.det_mult)) self._det_mult_tool_bar.addWidget(self._det_mult_line_edit) self._det_mult_line_edit.returnPressed.connect( lambda: self.set_det_mult( eng_notation.str_to_num( str(self._det_mult_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._det_mult_tool_bar, 0, 6, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(6, 8): self.top_grid_layout.setColumnStretch(c, 1) self._det_avg_len_tool_bar = Qt.QToolBar(self) self._det_avg_len_tool_bar.addWidget(Qt.QLabel("det_avg_len" + ": ")) self._det_avg_len_line_edit = Qt.QLineEdit(str(self.det_avg_len)) self._det_avg_len_tool_bar.addWidget(self._det_avg_len_line_edit) self._det_avg_len_line_edit.returnPressed.connect( lambda: self.set_det_avg_len( int(str(self._det_avg_len_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._det_avg_len_tool_bar, 0, 9, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(9, 10): self.top_grid_layout.setColumnStretch(c, 1) self._cons_offset_tool_bar = Qt.QToolBar(self) self._cons_offset_tool_bar.addWidget(Qt.QLabel("cons_offset" + ": ")) self._cons_offset_line_edit = Qt.QLineEdit(str(self.cons_offset)) self._cons_offset_tool_bar.addWidget(self._cons_offset_line_edit) self._cons_offset_line_edit.returnPressed.connect( lambda: self.set_cons_offset( eng_notation.str_to_num( str(self._cons_offset_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._cons_offset_tool_bar, 0, 8, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(8, 9): self.top_grid_layout.setColumnStretch(c, 1) self._avg_len_tool_bar = Qt.QToolBar(self) self._avg_len_tool_bar.addWidget(Qt.QLabel("avg_len" + ": ")) self._avg_len_line_edit = Qt.QLineEdit(str(self.avg_len)) self._avg_len_tool_bar.addWidget(self._avg_len_line_edit) self._avg_len_line_edit.returnPressed.connect(lambda: self.set_avg_len( eng_notation.str_to_num( str(self._avg_len_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._avg_len_tool_bar, 0, 4, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self.vcc_es_tag_to_utc_0 = vcc.es_tag_to_utc(samp_rate) self.vcc_burst_snr_0 = vcc.burst_snr(25, 2) self.sigmf_source_0 = gr_sigmf.source( '/captures/adsb/20210127/MODE-S_2021-01-27T23:43:24.sigmf-data', "ci16" + ("_le" if sys.byteorder == "little" else "_be"), False) self._rf_gain_tool_bar = Qt.QToolBar(self) self._rf_gain_tool_bar.addWidget(Qt.QLabel("rf_gain" + ": ")) self._rf_gain_line_edit = Qt.QLineEdit(str(self.rf_gain)) self._rf_gain_tool_bar.addWidget(self._rf_gain_line_edit) self._rf_gain_line_edit.returnPressed.connect(lambda: self.set_rf_gain( eng_notation.str_to_num( str(self._rf_gain_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._rf_gain_tool_bar, 0, 0, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_1 = qtgui.time_sink_f( burst_length / 2, #size samp_rate, #samp_rate "", #name 3 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.010) self.qtgui_time_sink_x_1.set_y_axis(-5, 20) self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1.enable_tags(-1, True) self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_AUTO, qtgui.TRIG_SLOPE_POS, qt_thresh, 1.0 / samp_rate * 100, 0, "") self.qtgui_time_sink_x_1.enable_autoscale(True) self.qtgui_time_sink_x_1.enable_grid(True) self.qtgui_time_sink_x_1.enable_axis_labels(True) self.qtgui_time_sink_x_1.enable_control_panel(False) self.qtgui_time_sink_x_1.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_1.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(3): if len(labels[i]) == 0: self.qtgui_time_sink_x_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_win = sip.wrapinstance( self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_1_win, 1, 0, 2, 4) for r in range(1, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0_1 = qtgui.time_sink_f( burst_length / 2, #size samp_rate / 2, #samp_rate "soft chips", #name 3 #number of inputs ) self.qtgui_time_sink_x_0_1.set_update_time(0.10) self.qtgui_time_sink_x_0_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_1.enable_tags(-1, True) self.qtgui_time_sink_x_0_1.set_trigger_mode(qtgui.TRIG_MODE_TAG, qtgui.TRIG_SLOPE_POS, 0, 0, 0, "es::event_type") self.qtgui_time_sink_x_0_1.enable_autoscale(True) self.qtgui_time_sink_x_0_1.enable_grid(False) self.qtgui_time_sink_x_0_1.enable_axis_labels(True) self.qtgui_time_sink_x_0_1.enable_control_panel(False) self.qtgui_time_sink_x_0_1.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0_1.disable_legend() labels = ['re', 'abs', 'mag', 'ph', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 2, 1, 1, 1, 1, 1, 1, 1, 1] markers = [0, -1, 0, -1, -1, -1, -1, -1, -1, -1] alphas = [1, 0.25, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(3): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_1_win = sip.wrapinstance( self.qtgui_time_sink_x_0_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_1_win, 3, 0, 3, 5) for r in range(3, 6): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 5): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_raster_sink_x_0 = qtgui.time_raster_sink_b( samp_rate / 2, 20, 56, ([]), ([]), "", 1, ) self.qtgui_time_raster_sink_x_0.set_update_time(0.10) self.qtgui_time_raster_sink_x_0.set_intensity_range(-1, 1) self.qtgui_time_raster_sink_x_0.enable_grid(False) self.qtgui_time_raster_sink_x_0.enable_axis_labels(True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_raster_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_raster_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_raster_sink_x_0.set_color_map(i, colors[i]) self.qtgui_time_raster_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_raster_sink_x_0_win = sip.wrapinstance( self.qtgui_time_raster_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_raster_sink_x_0_win, 3, 5, 3, 5) for r in range(3, 6): self.top_grid_layout.setRowStretch(r, 1) for c in range(5, 10): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( burst_length / 2, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.010) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0.enable_autoscale(True) self.qtgui_const_sink_x_0.enable_grid(True) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win, 1, 8, 2, 2) for r in range(1, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(8, 10): self.top_grid_layout.setColumnStretch(c, 1) self.pyqt_ctime_plot_0 = pyqt.ctime_plot('') self._pyqt_ctime_plot_0_win = self.pyqt_ctime_plot_0 self.top_grid_layout.addWidget(self._pyqt_ctime_plot_0_win, 1, 4, 2, 2) for r in range(1, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 6): self.top_grid_layout.setColumnStretch(c, 1) self.pyqt_const_plot_0 = pyqt.const_plot(label='') self._pyqt_const_plot_0_win = self.pyqt_const_plot_0 self.top_grid_layout.addWidget(self._pyqt_const_plot_0_win, 1, 6, 2, 2) for r in range(1, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(6, 8): self.top_grid_layout.setColumnStretch(c, 1) self.low_pass_filter_0_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 4e6, 250e3, firdes.WIN_BLACKMAN, 6.76)) self.fosphor_glfw_sink_c_0 = fosphor.glfw_sink_c() self.fosphor_glfw_sink_c_0.set_fft_window(window.WIN_BLACKMAN_hARRIS) self.fosphor_glfw_sink_c_0.set_frequency_range(0, samp_rate) self.es_trigger_edge_f_0 = es.trigger_edge_f(es_thresh, burst_length, burst_length / 3, gr.sizeof_gr_complex, 300) self.es_sink_0 = es.sink(1 * [gr.sizeof_gr_complex], 4, 64, 0, 2, 0) self.es_handler_pdu_0 = es.es_make_handler_pdu( es.es_handler_print.TYPE_C32) self.epy_block_1 = epy_block_1.uf_frame_sync(tag_name='sync', msg_len=112, samp_rate=samp_rate, sps=2) self.epy_block_0_0 = epy_block_0_0.uf_decode(msg_filter='All Messages', verbose=True) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf( 2, math.pi / 200, (rrc_taps), 32, 16, 1.1, 1) self.digital_diff_phasor_cc_0 = digital.diff_phasor_cc() self.digital_costas_loop_cc_0 = digital.costas_loop_cc( math.pi / 50, 2, False) self.digital_correlate_access_code_tag_xx_0_0_1_2_2_0_0_0 = digital.correlate_access_code_tag_bb( '00011111000111000001', 3, 'sync') self.digital_binary_slicer_fb_0_0 = digital.binary_slicer_fb() self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate * 2, True) self.blocks_sub_xx_2_0 = blocks.sub_ff(1) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_float * 1, 1) self.blocks_rms_xx_1 = blocks.rms_cf(rms_alpha) self.blocks_pdu_to_tagged_stream_1 = blocks.pdu_to_tagged_stream( blocks.byte_t, 'packet_len') self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream( blocks.complex_t, 'est_len') (self.blocks_pdu_to_tagged_stream_0).set_min_output_buffer(600) self.blocks_pdu_remove_0 = blocks.pdu_remove( pmt.intern("es::event_buffer")) self.blocks_multiply_const_xx_0 = blocks.multiply_const_cc(1.0 / 65536.0) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (-1 * det_mult, )) self.blocks_moving_average_xx_0_0 = blocks.moving_average_ff( int(det_avg_len), 1.0 / det_avg_len, 4000, 1) self.blocks_moving_average_xx_0 = blocks.moving_average_ff( int(avg_len), 1.0 / avg_len, 4000, 1) self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex( True, False) self.blocks_complex_to_real_1_0_0 = blocks.complex_to_real(1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.blocks_char_to_float_0_1 = blocks.char_to_float(1, 1 / 10.0) self.blocks_add_const_vxx_0 = blocks.add_const_vff((cons_offset, )) self.blocks_abs_xx_0 = blocks.abs_ff(1) self._bit_thresh_tool_bar = Qt.QToolBar(self) self._bit_thresh_tool_bar.addWidget(Qt.QLabel("bit_thresh" + ": ")) self._bit_thresh_line_edit = Qt.QLineEdit(str(self.bit_thresh)) self._bit_thresh_tool_bar.addWidget(self._bit_thresh_line_edit) self._bit_thresh_line_edit.returnPressed.connect( lambda: self.set_bit_thresh( eng_notation.str_to_num( str(self._bit_thresh_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._bit_thresh_tool_bar, 6, 4, 1, 1) for r in range(6, 7): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) self.ais_invert_0 = ais.invert() ################################################## # Connections ################################################## self.msg_connect((self.blocks_pdu_remove_0, 'pdus'), (self.vcc_burst_snr_0, 'in')) self.msg_connect((self.epy_block_0_0, 'out'), (self.blocks_pdu_to_tagged_stream_1, 'pdus')) self.msg_connect((self.epy_block_1, 'out'), (self.epy_block_0_0, 'in')) self.msg_connect((self.es_handler_pdu_0, 'pdus_out'), (self.blocks_pdu_remove_0, 'pdus')) self.msg_connect((self.es_trigger_edge_f_0, 'edge_event'), (self.es_handler_pdu_0, 'handle_event')) self.msg_connect((self.es_trigger_edge_f_0, 'which_stream'), (self.es_sink_0, 'schedule_event')) self.msg_connect((self.vcc_burst_snr_0, 'out'), (self.vcc_es_tag_to_utc_0, 'in')) self.msg_connect((self.vcc_es_tag_to_utc_0, 'out'), (self.blocks_pdu_to_tagged_stream_0, 'pdus')) self.msg_connect((self.vcc_es_tag_to_utc_0, 'out'), (self.pyqt_const_plot_0, 'cpdus')) self.msg_connect((self.vcc_es_tag_to_utc_0, 'out'), (self.pyqt_ctime_plot_0, 'cpdus')) self.connect( (self.ais_invert_0, 0), (self.digital_correlate_access_code_tag_xx_0_0_1_2_2_0_0_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.es_trigger_edge_f_0, 1)) self.connect((self.analog_agc2_xx_0, 0), (self.fosphor_glfw_sink_c_0, 0)) self.connect((self.blocks_abs_xx_0, 0), (self.blocks_moving_average_xx_0_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.qtgui_time_sink_x_1, 2)) self.connect((self.blocks_char_to_float_0_1, 0), (self.qtgui_time_sink_x_0_1, 2)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_skiphead_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.qtgui_time_sink_x_1, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.blocks_complex_to_real_1_0_0, 0), (self.blocks_sub_xx_2_0, 0)) self.connect((self.blocks_complex_to_real_1_0_0, 0), (self.qtgui_time_sink_x_0_1, 0)) self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.blocks_multiply_const_xx_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.es_trigger_edge_f_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.blocks_moving_average_xx_0_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_1, 0), (self.qtgui_time_raster_sink_x_0, 0)) self.connect((self.blocks_rms_xx_1, 0), (self.blocks_sub_xx_2_0, 1)) self.connect((self.blocks_rms_xx_1, 0), (self.qtgui_time_sink_x_0_1, 1)) self.connect((self.blocks_skiphead_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_sub_xx_0, 0), (self.blocks_abs_xx_0, 0)) self.connect((self.blocks_sub_xx_2_0, 0), (self.digital_binary_slicer_fb_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.digital_binary_slicer_fb_0_0, 0), (self.ais_invert_0, 0)) self.connect( (self.digital_correlate_access_code_tag_xx_0_0_1_2_2_0_0_0, 0), (self.blocks_char_to_float_0_1, 0)) self.connect( (self.digital_correlate_access_code_tag_xx_0_0_1_2_2_0_0_0, 0), (self.epy_block_1, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_diff_phasor_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.digital_diff_phasor_cc_0, 0), (self.blocks_complex_to_real_1_0_0, 0)) self.connect((self.digital_diff_phasor_cc_0, 0), (self.blocks_rms_xx_1, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.es_trigger_edge_f_0, 0), (self.es_sink_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.sigmf_source_0, 0), (self.blocks_interleaved_short_to_complex_0, 0))