def _setup_head(self): """ Sets up the input of the flow graph, i.e. determine which kind of file source is necessary. """ if self.filename[-4:].lower() == '.wav': if self.options.verbose: print 'Reading data from a WAV file.' src = gr.wavfile_source(self.filename, True) f2c = gr.float_to_complex() self.connect((src, 0), (f2c, 0)) if src.channels() == 2: self.connect((src, 1), (f2c, 1)) self.connect(f2c, self.head) else: if self.options.verbose: print 'Reading data from a raw data file.' src = gr.file_source(self.options.sample_size, self.filename, True) if self.options.sample_size == gr.sizeof_float: f2c = gr.float_to_complex() self.connect(src, f2c, self.head) if self.options.verbose: print ' Input data is considered real.' else: self.connect(src, self.head) if self.options.verbose: print ' Input data is considered complex.'
def __init__(self): gr.top_block.__init__(self, "Phase Diff") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 44100 ################################################## # Blocks ################################################## self.gr_file_sink_0 = gr.file_sink(gr.sizeof_float*1, "phase_diffs.dat") self.gr_float_to_complex_0 = gr.float_to_complex() self.gr_float_to_complex_1 = gr.float_to_complex() self.gr_wavfile_source_0 = gr.wavfile_source("8k.wav", False) self.gr_wavfile_source_1 = gr.wavfile_source("14k.wav", False) self.wmu_phase_compute_cf_0 = wmu.phase_compute_cf() ################################################## # Connections ################################################## self.connect((self.gr_wavfile_source_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_wavfile_source_0, 1), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_wavfile_source_1, 0), (self.gr_float_to_complex_1, 0)) self.connect((self.gr_wavfile_source_1, 1), (self.gr_float_to_complex_1, 1)) self.connect((self.gr_float_to_complex_1, 0), (self.wmu_phase_compute_cf_0, 1)) self.connect((self.gr_float_to_complex_0, 0), (self.wmu_phase_compute_cf_0, 0)) self.connect((self.wmu_phase_compute_cf_0, 0), (self.gr_file_sink_0, 0))
def __init__(self, Np=32, P=128, L=2, filename=None, sample_type='complex', verbose=True): gr.top_block.__init__(self) if filename is None: src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) if verbose: print "Using Gaussian noise source." else: if sample_type == 'complex': src = gr.file_source(gr.sizeof_gr_complex, filename, True) else: fsrc = gr.file_source(gr.sizeof_float, filename, True) src = gr.float_to_complex() self.connect(fsrc, src) if verbose: print "Reading data from %s" % filename if verbose: print "FAM configuration:" print "N' = %d" % Np print "P = %d" % P print "L = %d" % L #print "Δf = %f" % asfd sink = gr.null_sink(gr.sizeof_float * 2 * Np) self.cyclo_fam = specest.cyclo_fam(Np, P, L) self.connect(src, self.cyclo_fam, sink)
def __init__(self, app, samp_rate, at, filename, repeat, sine): ''' in: - app = object of type RXApp - samp_rate = sample rate in Hertz - at = attenuation factor - filename = filename - repeat = if True them reads in a loop the file - sine ''' gr.hier_block2.__init__(self, "RXData", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) # instance variables self.app = app if sine: self.fileSrc = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, 1000, 1.0) else: self.fileSrc = gr.file_source(gr.sizeof_float*1, filename, repeat) # self.fileSrc = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, 1000, 1.0) # self.fileSrc = gr.sig_source_f(samp_rate, gr.GR_CONST_WAVE, 1000, 1.0) self.mulitplyCte = gr.multiply_const_vff((at, )) self.f2c = gr.float_to_complex(1) #EO instance variables self.__makeConnections()
def test_001_t(self): self.degree = 5 self.length = 2**self.degree - 1 expected_result = (self.length - 1) * [-1.0 / self.length] + [1] # send a maximum length sequence with period 31 src_real = digital.glfsr_source_f(self.degree, True, 0, 1) src_imag = gr.null_source(gr.sizeof_float * 1) f2c = gr.float_to_complex(1) mls_correlator = channelsounder_swig.mls_correlator(self.degree, mask=0, seed=1) # keep only the samples of the first two autocorrelation periods head = gr.head(gr.sizeof_gr_complex, 2 * self.length) dest = gr.vector_sink_c(1) self.tb.connect(src_real, (f2c, 0)) self.tb.connect(src_imag, (f2c, 1)) self.tb.connect(f2c, mls_correlator) self.tb.connect(mls_correlator, head, dest) # set up fg self.tb.run() # check data result_data = dest.data() # discard the first period, since it is tainted by the zeros inserted # by set_history() result_data = result_data[self.length:] self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
def __init__(self, rx, reader, tx): gr.top_block.__init__(self) samp_freq = (64 / dec_rate) * 1e6 amplitude = 33000 num_taps = int( 64000 / (dec_rate * up_link_freq * 2)) #Matched filter for 1/2 cycle taps = [complex(1, 1)] * num_taps print num_taps filt = gr.fir_filter_ccc(sw_dec, taps) to_mag = gr.complex_to_mag() amp = gr.multiply_const_cc(amplitude) c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR) zc = rfid.clock_recovery_zc_ff(samples_per_pulse, 2) dummy = gr.null_sink(gr.sizeof_float) to_complex = gr.float_to_complex() r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" self.connect(rx, filt, to_mag, c_gate, zc, reader, amp, tx)
def __init__(self): gr.top_block.__init__(self, "am modulator") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 44100 self.freq = freq = 8000 ################################################## # Blocks ################################################## self.gr_complex_to_float_0 = gr.complex_to_float(1) self.gr_float_to_complex_0 = gr.float_to_complex() self.gr_multiply_vxx_0 = gr.multiply_vcc(1) self.gr_sig_source_x_0 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, freq, 1, 0) self.gr_wavfile_sink_0 = gr.wavfile_sink("8k.wav", 2, samp_rate, 16) self.gr_wavfile_source_0 = gr.wavfile_source("orig.wav", False) ################################################## # Connections ################################################## self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_vxx_0, 0)) self.connect((self.gr_wavfile_source_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.gr_multiply_vxx_0, 1)) self.connect((self.gr_wavfile_source_0, 1), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_multiply_vxx_0, 0), (self.gr_complex_to_float_0, 0)) self.connect((self.gr_complex_to_float_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.gr_complex_to_float_0, 1), (self.gr_wavfile_sink_0, 1))
def __init__(self): gr.top_block.__init__(self) length = 101 data_r = range(length) data_i = range(length,2*length) src_r = gr.vector_source_s(data_r, False) src_i = gr.vector_source_s(data_i, False) s2f_r = gr.short_to_float() s2f_i = gr.short_to_float() f2c = gr.float_to_complex() s2v = gr.stream_to_vector(gr.sizeof_gr_complex, length) shift = True ifft = gr.fft_vcc(length, False, [], shift) fft = gr.fft_vcc(length, True, [], shift) v2s = gr.vector_to_stream(gr.sizeof_gr_complex, length) snk_in = gr.file_sink(gr.sizeof_gr_complex, "fftshift.in") snk_out = gr.file_sink(gr.sizeof_gr_complex, "fftshift.out") self.connect(src_r, s2f_r, (f2c,0)) self.connect(src_i, s2f_i, (f2c,1)) self.connect(f2c, snk_in) self.connect(f2c, s2v, ifft, fft, v2s, snk_out)
def test_001_t (self): self.degree = 5 self.length = 2**self.degree - 1 expected_result = (self.length - 1)*[-1.0/self.length]+[1] # send a maximum length sequence with period 31 src_real = digital.glfsr_source_f(self.degree, True, 0, 1) src_imag = gr.null_source(gr.sizeof_float*1) f2c = gr.float_to_complex(1) mls_correlator = channelsounder_swig.mls_correlator(self.degree, mask = 0, seed = 1) # keep only the samples of the first two autocorrelation periods head = gr.head(gr.sizeof_gr_complex, 2*self.length) dest = gr.vector_sink_c(1) self.tb.connect( src_real, (f2c, 0)) self.tb.connect( src_imag, (f2c, 1)) self.tb.connect( f2c, mls_correlator ) self.tb.connect( mls_correlator, head, dest ) # set up fg self.tb.run () # check data result_data = dest.data() # discard the first period, since it is tainted by the zeros inserted # by set_history() result_data = result_data[self.length:] self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
def __init__(self): gr.top_block.__init__(self) self.frequency = 13.56e6 self.gain = 100 # for 4 MS/s, 32 # self.usrp_interpol = 32 # USRP settings self.u_tx = usrp.sink_c() #create the USRP sink for TX #try and set the LF_RX for this self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX)) #set the interpolation rate to match the USRP's 128 MS/s self.u_tx.set_interp_rate(self.usrp_interpol) #Configure the MUX for the daughterboard self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec)) #Tell it to use the LF_TX self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec) #Make sure it worked print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),) #Set gain.. duh self.subdev_tx.set_gain(self.gain) #Tune the center frequency self.u_tx.tune(0, self.subdev_tx, self.frequency) # self.src = gr.wavfile_source("RFID_command_52_4M_1610.wav", True) self.src = gr.wavfile_source("wave52.wav", True) self.conv = gr.float_to_complex() self.amp = gr.multiply_const_cc(10.0 ** (self.gain / 20.0)) self.connect(self.src, self.conv, self.amp, self.u_tx)
def graph(args): print os.getpid() nargs = len(args) if nargs == 1: infile = args[0] else: sys.stderr.write('usage: interp.py input_file\n') sys.exit(1) tb = gr.top_block() srcf = gr.file_source(gr.sizeof_short, infile) s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src0 = gr.float_to_complex() lp_coeffs = gr.firdes.low_pass(3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING) lp = gr.interp_fir_filter_ccf(3, lp_coeffs) file = gr.file_sink(gr.sizeof_gr_complex, "/tmp/atsc_pipe_1") tb.connect(srcf, s2ss) tb.connect((s2ss, 0), s2f1, (src0, 0)) tb.connect((s2ss, 1), s2f2, (src0, 1)) tb.connect(src0, lp, file) tb.start() raw_input('Head End: Press Enter to stop') tb.stop()
def __init__(self): gr.top_block.__init__(self) self.frequency = 13.56e6 self.gain = 100 self.usrp_interpol = 32 # USRP settings self.u_tx = usrp.sink_c() #create the USRP sink for TX #try and set the LF_RX for this self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX)) #set the interpolation rate to match the USRP's 128 MS/s self.u_tx.set_interp_rate(self.usrp_interpol) #Configure the MUX for the daughterboard self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec)) #Tell it to use the LF_TX self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec) #Make sure it worked print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),) #Set gain.. duh self.subdev_tx.set_gain(self.gain) #Tune the center frequency self.u_tx.tune(0, self.subdev_tx, self.frequency) self.src = gr.wavfile_source("RFID_command_52_4M_1610.wav", False) self.conv = gr.float_to_complex() self.amp = gr.multiply_const_cc(10.0 ** (self.gain / 20.0)) self.connect(self.src, self.conv, self.amp, self.u_tx)
def graph (args): print os.getpid() nargs = len (args) if nargs == 1: infile = args[0] else: sys.stderr.write('usage: interp.py input_file\n') sys.exit (1) tb = gr.top_block () srcf = gr.file_source (gr.sizeof_short,infile) s2ss = gr.stream_to_streams(gr.sizeof_short,2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src0 = gr.float_to_complex() lp_coeffs = gr.firdes.low_pass ( 3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING ) lp = gr.interp_fir_filter_ccf ( 3, lp_coeffs ) file = gr.file_sink(gr.sizeof_gr_complex,"/tmp/atsc_pipe_1") tb.connect( srcf, s2ss ) tb.connect( (s2ss, 0), s2f1, (src0,0) ) tb.connect( (s2ss, 1), s2f2, (src0,1) ) tb.connect( src0, lp, file) tb.start() raw_input ('Head End: Press Enter to stop') tb.stop()
def __init__(self,delay_num,delay_denom): gr.hier_block2.__init__(self,"moms_block", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) cmplx_to_real = gr.complex_to_real() cmplx_to_img = gr.complex_to_imag() iirf_real = gr.iir_filter_ffd([1.5],[1, -0.5]) self.moms_real = moms_ff() self.moms_real.set_init_ip_fraction(delay_num,delay_denom) iirf_imag = gr.iir_filter_ffd([1.5],[1, -0.5]) self.moms_imag = moms_ff() self.moms_imag.set_init_ip_fraction(delay_num,delay_denom) float_to_cmplx = gr.float_to_complex() self.connect((self,0), (cmplx_to_real,0)) self.connect((self,0), (cmplx_to_img,0)) self.connect((cmplx_to_real,0), (iirf_real,0)) self.connect((cmplx_to_img,0), (iirf_imag,0)) self.connect((iirf_real,0), (self.moms_real,0)) self.connect((iirf_imag,0), (self.moms_imag,0)) self.connect((self.moms_real,0), (float_to_cmplx,0)) self.connect((self.moms_imag,0), (float_to_cmplx,1)) self.connect((float_to_cmplx,0), (self,0))
def __init__(self): gr.top_block.__init__(self) input_sample_rate = 1e6 symbol_rate = 152.34e3 output_samples_per_symbol = 5 output_sample_rate = output_samples_per_symbol * symbol_rate # least common multiple lcm = gru.lcm(input_sample_rate, output_sample_rate) intrp = int(lcm // input_sample_rate) decim = int(lcm // output_sample_rate) print intrp print decim resampler = blks2.rational_resampler_ccc(intrp, decim, None, None) src = gr.file_source(gr.sizeof_gr_complex, "infile") sink = gr.file_sink(gr.sizeof_float, "outfile") f2c = gr.float_to_complex() c2r = gr.complex_to_real() #ddc_coeffs = \ #gr.firdes.low_pass (1.0, # gain #input_sample_rate, # sampling rate #2e3, # low pass cutoff freq #6e3, # width of trans. band #gr.firdes.WIN_HANN) # just grab the lower sideband: #ddc = gr.freq_xlating_fir_filter_ccf(1,ddc_coeffs,-111.5e3,input_sample_rate) qdemod = gr.quadrature_demod_cf(1.0) lp_coeffs = \ gr.firdes.low_pass (1.0, # gain output_sample_rate, # sampling rate symbol_rate, # low pass cutoff freq symbol_rate, # width of trans. band gr.firdes.WIN_HANN) lp = gr.fir_filter_fff(1, lp_coeffs) self.connect(src, resampler, qdemod, lp, sink)
def __init__(self, rx, reader, tx): gr.top_block.__init__(self) samp_freq = (64 / dec_rate) * 1e6 amplitude = 33000 num_taps = int(64000 / (dec_rate * up_link_freq * 2)) #Matched filter for 1/2 cycle taps = [complex(1,1)] * num_taps print num_taps filt = gr.fir_filter_ccc(sw_dec, taps) to_mag = gr.complex_to_mag() amp = gr.multiply_const_cc(amplitude) c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR) zc = rfid.clock_recovery_zc_ff(samples_per_pulse, 2); dummy = gr.null_sink(gr.sizeof_float) to_complex = gr.float_to_complex() r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" self.connect(rx, filt, to_mag, c_gate, zc, reader, amp, tx);
def __init__(self): gr.top_block.__init__(self) input_sample_rate = 1e6 symbol_rate = 152.34e3 output_samples_per_symbol = 5 output_sample_rate = output_samples_per_symbol * symbol_rate # least common multiple lcm = gru.lcm(input_sample_rate, output_sample_rate) intrp = int(lcm // input_sample_rate) decim = int(lcm // output_sample_rate) print intrp print decim resampler = blks2.rational_resampler_ccc(intrp, decim, None, None) src = gr.file_source(gr.sizeof_gr_complex, "infile") sink = gr.file_sink(gr.sizeof_float, "outfile") f2c = gr.float_to_complex() c2r = gr.complex_to_real() #ddc_coeffs = \ #gr.firdes.low_pass (1.0, # gain #input_sample_rate, # sampling rate #2e3, # low pass cutoff freq #6e3, # width of trans. band #gr.firdes.WIN_HANN) # just grab the lower sideband: #ddc = gr.freq_xlating_fir_filter_ccf(1,ddc_coeffs,-111.5e3,input_sample_rate) qdemod = gr.quadrature_demod_cf(1.0) lp_coeffs = \ gr.firdes.low_pass (1.0, # gain output_sample_rate, # sampling rate symbol_rate, # low pass cutoff freq symbol_rate, # width of trans. band gr.firdes.WIN_HANN) lp = gr.fir_filter_fff (1,lp_coeffs) self.connect(src,resampler,qdemod,lp,sink)
def __init__(self, fg, src_type, file_samp_type, file_to_open, file_rec_samp_rate, uhd_samp_rate, uhd_gain, center_f, uhd_subdev_spec): gr.hier_block2.__init__(self, "head", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) if (src_type == "File"): try: self.head_src = blocks.file_source(file_samp_type, file_to_open, True) fg.set_samp_rate(file_rec_samp_rate) fg.uhd_src_active = False if fg.cpu_watcher is not None: fg.cpu_watcher.quit() if (file_samp_type == gr.sizeof_float): self.head_bottom = gr.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize file-source!" self.head_src = None elif (src_type == "UHD"): try: self.head_src = uhd.single_usrp_source( device_addr='', io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.head_src.set_samp_rate(fg.d_uhd_samp_rate) self.head_src.set_gain(fg.d_uhd_gain, 0) self.head_src.set_center_freq(fg.center_f * 1e6, 0) self.head_src.set_subdev_spec(fg.d_uhd_subdev_spec) fg.set_samp_rate(fg.d_uhd_samp_rate) fg.uhd_src_active = True fg.cpu_watcher.start() if (fg.d_uhd_samp_type == gr.sizeof_float): self.head_bottom = gr.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize UHD source!" self.head_src = None else: print "Unknown type of source!"
def _setup_head(self): """ Sets up the input of the flow graph, i.e. determine which kind of file source is necessary. """ if self.filename[-4:].lower() == '.wav': src = gr.wavfile_source(self.filename, True) f2c = gr.float_to_complex() self.connect((src, 0), (f2c, 0)) if src.channels() == 2: self.connect((src, 1), (f2c, 1)) self.connect(f2c, self.head) else: src = gr.file_source(self.options.sample_size, self.filename, True) if self.options.sample_size == gr.sizeof_float: f2c = gr.float_to_complex() self.connect(src, f2c, self.head) else: self.connect(src, self.head)
def test_002_square2_ff (self): #src_data = (7, -3, 4, -5.5, 2, 3, 5) #src_coeff = (1, 1, 2, 2, 3) src_data0 = (0.01+0.11j, 0.02+0.22j, 0.03+0.33j, 0.04+0.44j, 0.05+0.55j, 0.06+0.66j, 0.07+0.77j, 0.08+0.88j, 0.09+0.99j) #src_data1 = (0.11, 0.22, 0.33, 0.44, 0.55, 0.66, 0.77, 0.88, 0.99) src_coeff = (0.101, 0.102, 0.103, 0.104, 0.105) scale = 1000 #expected_result = (9, 16, 30.25, 4, 9) #expected_result = (49, 9, 16, 30.20000076, 4, 9, 25) expected_result = (245, 320, 395, 470, 445, 400, 334, 246, 135) src0 = gr.vector_source_c (src_data0) #src1 = gr.vector_source_f (src_data1) #sqr = dsp.fir_ccf (src_coeff, scale, 2) ftoc = gr.float_to_complex () ctof = gr.complex_to_float () gccf = gr.interp_fir_filter_ccf (2, src_coeff) dst0 = gr.vector_sink_c () #dst1 = gr.vector_sink_f () mpoints = 4 taps = gr.firdes.low_pass(1, 1, 1.0/mpoints * 0.4, 1.0/mpoints * 0.1, gr.firdes.WIN_HANN) #print "The length of FILTER is" #print len(taps) #print "The length of FILTER is %d." %len(taps) #print taps #howto.set_taps() #self.tb.connect (src0, (sqr, 0)) #self.tb.connect (src1, (sqr, 1)) #self.tb.connect ((sqr, 0), dst0) #self.tb.connect ((sqr, 1), dst1) #self.tb.connect (src0, (ftoc, 0)) #self.tb.connect (src1, (ftoc, 1)) #self.tb.connect (ftoc, gccf) #self.tb.connect (gccf, ctof) #self.tb.connect ((ctof, 0), dst0) #self.tb.connect ((ctof, 1), dst1) self.tb.connect (src0, gccf) self.tb.connect (gccf, dst0) #self.tb.connect (src0, sqr) #self.tb.connect (sqr, dst0) self.tb.run () result_data0 = dst0.data () print result_data0
def __init__(self, fg, src_type, file_samp_type, file_to_open, file_rec_samp_rate, uhd_samp_rate, uhd_gain, center_f, uhd_subdev_spec): gr.hier_block2.__init__(self, "head", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) if(src_type == "File"): try: self.head_src = gr.file_source(file_samp_type, file_to_open, True) fg.set_samp_rate(file_rec_samp_rate) fg.uhd_src_active = False if fg.cpu_watcher is not None: fg.cpu_watcher.quit() if(file_samp_type == gr.sizeof_float): self.head_bottom = gr.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize file-source!" self.head_src = None elif(src_type == "UHD"): try: self.head_src = uhd.single_usrp_source(device_addr='', io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.head_src.set_samp_rate(fg.d_uhd_samp_rate) self.head_src.set_gain(fg.d_uhd_gain, 0) self.head_src.set_center_freq(fg.center_f*1e6 ,0) self.head_src.set_subdev_spec(fg.d_uhd_subdev_spec) fg.set_samp_rate(fg.d_uhd_samp_rate) fg.uhd_src_active = True fg.cpu_watcher.start() if(fg.d_uhd_samp_type == gr.sizeof_float): self.head_bottom = gr.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize UHD source!" self.head_src = None else: print "Unknown type of source!"
def __init__(self, fd, M, sample_rate): gr.hier_block2.__init__(self, "Rayleigh Channel", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.M = M self.sample_rate = sample_rate n = range(1, M + 1) N = 4 * M + 2 f_n = [fd * math.cos(2 * math.pi * x / N) for x in n] beta_n = [math.pi / M * x for x in n] a_n = [2 * math.cos(x) for x in beta_n] a_n.append(math.sqrt(2) * math.cos(math.pi / 4)) a_n = [x * 2 / math.sqrt(N) for x in a_n] b_n = [2 * math.sin(x) for x in beta_n] b_n.append(math.sqrt(2) * math.sin(math.pi / 4)) b_n = [x * 2 / math.sqrt(N) for x in b_n] f_n.append(fd) self.sin_real = [ gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, f_n[i], a_n[i]) for i in range(M + 1) ] self.sin_imag = [ gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, f_n[i], b_n[i]) for i in range(M + 1) ] self.add_real = gr.add_ff(1) self.add_imag = gr.add_ff(1) for i in range(M + 1): self.connect(self.sin_real[i], (self.add_real, i)) for i in range(M + 1): self.connect(self.sin_imag[i], (self.add_imag, i)) self.ftoc = gr.float_to_complex(1) self.connect(self.add_real, (self.ftoc, 0)) self.connect(self.add_imag, (self.ftoc, 1)) self.mulc = gr.multiply_const_cc((0.5)) #self.divide = gr.divide_cc(1) #self.connect(self,(self.divide,0)) #self.connect(self.ftoc,(self.divide,1)) #self.connect(self.divide, self) self.prod = gr.multiply_cc(1) self.connect(self, (self.prod, 0)) self.connect(self.ftoc, self.mulc, (self.prod, 1)) self.connect(self.prod, self)
def test_float_to_complex_1 (self): src_data = (0, 1, -1, 3, -3, -2, -3, 2) expected_result = (0, 1, -1, 3+0j, -3+0j, -2+0j, -3+0j, 2+0j) src = gr.vector_source_f (src_data) op = gr.float_to_complex (numPorts=1) dst = gr.vector_sink_c () self.tb.connect (src, op) self.tb.connect (op, dst) self.tb.run () actual_result = dst.data () self.assertComplexTuplesAlmostEqual (expected_result, actual_result)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel options = get_options() sample_rate = int(options.sample_rate) self.asrc = audio.source(sample_rate, options.audio_device, True) self.f2c = gr.float_to_complex(1) self.connect((self.asrc, 1), (self.f2c, 1)) self.connect((self.asrc, 0), (self.f2c, 0)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = gr.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = gr.fractional_interpolator_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT) self.scope = fftsink2.fft_sink_c(panel, fft_size=512, sample_rate=sample_rate, ref_scale=2.0, ref_level=-30, y_divs=10, fft_rate=10, average=True, avg_alpha=0.2) self.connect(self.f2c, self.scope)
def _get_gauss_rand_proc_c(self): """ Returns the Gaussian random process. """ spec_getter = getattr(self.model, 'get_' + self.spec_type) if self.spec_type in self.model.specs_odd: from winelo.channel import spec2soc soc = spec2soc(spec_getter(), method=self.method, N=self.N) sources = [] adder = gr.add_cc() for idx, (freq, ampl) in enumerate(soc.get_soc()): sources.append(gr.sig_source_c(self.sample_rate, gr.GR_COS_WAVE, freq, ampl)) self.connect(sources[idx], gr.skiphead(gr.sizeof_gr_complex, randint(low=0, high=self.sample_rate)), (adder, idx)) return adder elif self.spec_type in self.model.specs_even: from winelo.channel import spec2sos # real part of the gaussian random process sos_real = spec2sos(spec_getter(), method=self.method, N=self.N) sources_real = [] adder_real = gr.add_ff() for idx, (freq, ampl) in enumerate(sos_real.get_sos()): sources_real.append(gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, freq, ampl)) self.connect(sources_real[idx], gr.skiphead(gr.sizeof_float, randint(low=0, high=self.sample_rate)), (adder_real, idx)) # imaginary part of the gaussian random process sos_imaginary = spec2sos(spec_getter(), method=self.method, N=self.N + 1) sources_imag = [] adder_imag = gr.add_ff() for idx, (freq, ampl) in enumerate(sos_imaginary.get_sos()): sources_imag.append(gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, freq, ampl)) self.connect(sources_imag[idx], gr.skiphead(gr.sizeof_float, randint(low=0, high=self.sample_rate)), (adder_imag, idx)) float2complex = gr.float_to_complex() self.connect(adder_real, (float2complex, 0)) self.connect(adder_imag, (float2complex, 1)) return float2complex else: print 'You picked a non-existant Doppler spectrum' print 'Pick one of the following: ', \ self.model.specs_even + self.model.specs_odd return None
def test_001_correlate(self): degree = 10 length = 2**degree-1 src = gr.glfsr_source_f(degree) head = gr.head(gr.sizeof_float, length*length) f2c = gr.float_to_complex() corr = gr.pn_correlator_cc(degree) dst = gr.vector_sink_c() self.tb.connect(src, head, f2c, corr, dst) self.tb.run() data = dst.data() self.assertEqual(data[-1], (1.0+0j))
def __init__(self): gr.top_block.__init__(self) self._N = 200000 # number of samples to use self._fs = 9000 # initial sampling rate self._M = 9 # Number of channels to channelize # Create a set of taps for the PFB channelizer self._taps = gr.firdes.low_pass_2(1, self._fs, 500, 20, attenuation_dB=10, window=gr.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc repeated = True if (repeated): self.vco_input = gr.sig_source_f(self._fs, gr.GR_SIN_WAVE, 0.25, 110) else: amp = 100 data = scipy.arange(0, amp, amp / float(self._N)) self.vco_input = gr.vector_source_f(data, False) # Build a VCO controlled by either the sinusoid or single chirp tone # Then convert this to a complex signal self.vco = gr.vco_f(self._fs, 225, 1) self.f2c = gr.float_to_complex() self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct the channelizer filter self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.vco_input, self.vco, self.f2c) self.connect(self.f2c, self.head, self.pfb) self.connect(self.f2c, self.snk_i) # Create a vector sink for each of M output channels of the filter and connect it self.snks = list() for i in xrange(self._M): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
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 = 1000 ################################################## # Blocks ################################################## self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) self.gr_descrambler_bb_0 = gr.descrambler_bb(0x8A, 0x7F, 7) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) self.gr_scrambler_bb_0 = gr.scrambler_bb(0x8A, 0x7F, 7) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate) self.gr_throttle_0_0 = gr.throttle(gr.sizeof_char*1, samp_rate) self.gr_throttle_0_0_0 = gr.throttle(gr.sizeof_char*1, samp_rate*8) self.gr_throttle_0_0_0_0 = gr.throttle(gr.sizeof_char*1, samp_rate*8*8) self.gr_uchar_to_float_0 = gr.uchar_to_float() self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) self.gr_vector_source_x_0 = gr.vector_source_b((0, 1, 3,7,255,3,1,0), True, 1) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate*32, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, ) self.Add(self.wxgui_scopesink2_0.win) ################################################## # Connections ################################################## self.connect((self.gr_float_to_complex_0, 0), (self.gr_throttle_0, 0)) self.connect((self.const_source_x_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_throttle_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.gr_vector_source_x_0, 0), (self.gr_throttle_0_0, 0)) self.connect((self.gr_throttle_0_0, 0), (self.gr_packed_to_unpacked_xx_0, 0)) self.connect((self.gr_descrambler_bb_0, 0), (self.gr_unpacked_to_packed_xx_0, 0)) self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.gr_throttle_0_0_0, 0)) self.connect((self.gr_throttle_0_0_0, 0), (self.gr_scrambler_bb_0, 0)) self.connect((self.gr_scrambler_bb_0, 0), (self.gr_throttle_0_0_0_0, 0)) self.connect((self.gr_throttle_0_0_0_0, 0), (self.gr_descrambler_bb_0, 0)) self.connect((self.gr_uchar_to_float_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.gr_uchar_to_float_0, 0))
def __init__(self,fd,M,sample_rate): gr.hier_block2.__init__(self,"Rayleigh Channel", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.M = M self.sample_rate = sample_rate n=range(1,M+1) N = 4*M+2 f_n= [fd*math.cos(2*math.pi*x/N) for x in n] beta_n = [math.pi/M*x for x in n] a_n = [2*math.cos(x) for x in beta_n] a_n.append(math.sqrt(2)*math.cos(math.pi/4)) a_n = [x*2/math.sqrt(N) for x in a_n] b_n= [2*math.sin(x) for x in beta_n] b_n.append(math.sqrt(2)*math.sin(math.pi/4)) b_n = [x*2/math.sqrt(N) for x in b_n] f_n.append(fd) self.sin_real = [gr.sig_source_f(self.sample_rate,gr.GR_COS_WAVE,f_n[i],a_n[i]) for i in range(M+1)] self.sin_imag = [gr.sig_source_f(self.sample_rate,gr.GR_COS_WAVE,f_n[i],b_n[i]) for i in range(M+1)] self.add_real = gr.add_ff(1) self.add_imag = gr.add_ff(1) for i in range (M+1): self.connect(self.sin_real[i],(self.add_real,i)) for i in range (M+1): self.connect(self.sin_imag[i],(self.add_imag,i)) self.ftoc = gr.float_to_complex(1) self.connect(self.add_real,(self.ftoc,0)) self.connect(self.add_imag,(self.ftoc,1)) self.mulc = gr.multiply_const_cc((0.5)) #self.divide = gr.divide_cc(1) #self.connect(self,(self.divide,0)) #self.connect(self.ftoc,(self.divide,1)) #self.connect(self.divide, self) self.prod = gr.multiply_cc(1) self.connect(self,(self.prod,0)) self.connect(self.ftoc,self.mulc,(self.prod,1)) self.connect(self.prod, self)
def __init__(self, filename="usrp.dat", output="frames.dat", decim=16, pll_alpha=0.05, sync_alpha=0.05): gr.top_block.__init__(self, "USRP HRPT Receiver") ################################################## # Parameters ################################################## self.filename = filename self.output = output self.decim = decim self.pll_alpha = pll_alpha self.sync_alpha = sync_alpha ################################################## # Variables ################################################## self.sym_rate = sym_rate = 600*1109 self.sample_rate = sample_rate = 64e6/decim self.sps = sps = sample_rate/sym_rate self.hs = hs = int(sps/2.0) self.mf_taps = mf_taps = [-0.5/hs,]*hs+[0.5/hs,]*hs self.max_sync_offset = max_sync_offset = 0.01 self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate ################################################## # Blocks ################################################## self.decoder = noaa.hrpt_decoder() self.deframer = noaa.hrpt_deframer() self.deinterleave = gr.deinterleave(gr.sizeof_float*1) self.f2c = gr.float_to_complex(1) self.file_sink = gr.file_sink(gr.sizeof_short*1, output) self.file_source = gr.file_source(gr.sizeof_short*1, filename, False) self.gr_fir_filter_xxx_0 = gr.fir_filter_ccc(1, (mf_taps)) self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset) self.s2f = gr.short_to_float() self.sync = noaa.hrpt_sync_fb(sync_alpha, sync_alpha**2/4.0, sps, max_sync_offset) ################################################## # Connections ################################################## self.connect((self.deframer, 0), (self.file_sink, 0)) self.connect((self.sync, 0), (self.deframer, 0)) self.connect((self.pll, 0), (self.sync, 0)) self.connect((self.deinterleave, 1), (self.f2c, 1)) self.connect((self.deinterleave, 0), (self.f2c, 0)) self.connect((self.deframer, 0), (self.decoder, 0)) self.connect((self.gr_fir_filter_xxx_0, 0), (self.pll, 0)) self.connect((self.f2c, 0), (self.gr_fir_filter_xxx_0, 0)) self.connect((self.s2f, 0), (self.deinterleave, 0)) self.connect((self.file_source, 0), (self.s2f, 0))
def __init__(self, inputfile, callback, options): gr.top_block.__init__(self) # settings for the demodulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/gmsk.py # settings for the demodulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/pkt.py if options.dsp: self.src = audio.source(options.dsp_sample_rate, "", True) else: self.src = gr.wavfile_source( inputfile, False ) self.iq_to_c = gr.float_to_complex() if options.dsp and options.wait: samples = options.dsp_sample_rate * options.wait self._head0 = gr.head(gr.sizeof_float, samples) self._head1 = gr.head(gr.sizeof_float, samples) self.connect( (self.src, 0), self._head0, (self.iq_to_c, 0) ) self.connect( (self.src, 1), self._head1, (self.iq_to_c, 1) ) if verbose: print "installed %d second head filter on dsp (%d samples at %d sps)" % (options.wait, samples, options.dsp_sample_rate) else: self.connect( (self.src, 0), (self.iq_to_c, 0) ) self.connect( (self.src, 1), (self.iq_to_c, 1) ) self.demodulator = blks2.gmsk_demod(samples_per_symbol=options.samples_per_symbol) self.pkt_queue = blks2.demod_pkts( demodulator=self.demodulator, callback=callback, threshold=options.threshold ) if options.carrier_frequency == 0: self.mixer = self.iq_to_c else: self.carrier = gr.sig_source_c( options.carrier_sample_rate, gr.GR_SIN_WAVE, - options.carrier_frequency, 1.0 ) self.mixer = gr.multiply_vcc(1) self.connect(self.iq_to_c, (self.mixer, 0) ) self.connect(self.carrier, (self.mixer, 1) ) self.amp = gr.multiply_const_cc(1); self.amp.set_k(options.amp_amplitude) self.connect(self.mixer, self.amp, self.pkt_queue) if options.debug_wavs: from myblks import debugwav self._dpass = debugwav("rx_passband", options) self._dbase = debugwav("rx_baseband", options) self.connect(self.iq_to_c, self._dpass) self.connect(self.mixer, self._dbase) if options.debug_files: self._dpassf = gr.file_sink(gr.sizeof_gr_complex*1, "debug_rx_passband.d_c") self._dbasef = gr.file_sink(gr.sizeof_gr_complex*1, "debug_rx_baseband.d_c") self.connect(self.iq_to_c, self._dpassf) self.connect(self.mixer, self._dbasef)
def __init__(self): gr.top_block.__init__(self) self._N = 200000 # number of samples to use self._fs = 9000 # initial sampling rate self._M = 9 # Number of channels to channelize # Create a set of taps for the PFB channelizer self._taps = filter.firdes.low_pass_2(1, self._fs, 500, 20, attenuation_dB=10, window=filter.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc repeated = True if(repeated): self.vco_input = gr.sig_source_f(self._fs, gr.GR_SIN_WAVE, 0.25, 110) else: amp = 100 data = scipy.arange(0, amp, amp/float(self._N)) self.vco_input = gr.vector_source_f(data, False) # Build a VCO controlled by either the sinusoid or single chirp tone # Then convert this to a complex signal self.vco = gr.vco_f(self._fs, 225, 1) self.f2c = gr.float_to_complex() self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct the channelizer filter self.pfb = filter.pfb.channelizer_ccf(self._M, self._taps) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.vco_input, self.vco, self.f2c) self.connect(self.f2c, self.head, self.pfb) self.connect(self.f2c, self.snk_i) # Create a vector sink for each of M output channels of the filter and connect it self.snks = list() for i in xrange(self._M): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def __init__(self, alpha=0.1, noise_mag=0): """ Parameters: alpha: float noise_mag: float """ gr.hier_block2.__init__( self, "Phase Noise Generator", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex), ) ################################################## # Parameters ################################################## self.alpha = alpha self.noise_mag = noise_mag ################################################## # Blocks ################################################## self.gr_transcendental_0_0 = gr.transcendental("sin", "float") self.gr_transcendental_0 = gr.transcendental("cos", "float") self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff( alpha, 1) self.gr_noise_source_x_0 = gr.noise_source_f(gr.GR_GAUSSIAN, noise_mag, 42) self.gr_multiply_xx_0 = gr.multiply_vcc(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) ################################################## # Connections ################################################## self.connect((self.gr_float_to_complex_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_single_pole_iir_filter_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self, 0)) self.connect((self, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_transcendental_0, 0)) self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_transcendental_0_0, 0)) self.connect((self.gr_transcendental_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_transcendental_0_0, 0), (self.gr_float_to_complex_0, 1))
def __init__(self,subcarriers,operational_block): gr.hier_block2.__init__(self, "common_power_allocator", gr.io_signature2(2,2,gr.sizeof_gr_complex*subcarriers, gr.sizeof_float*subcarriers), gr.io_signature (1,1,gr.sizeof_gr_complex*subcarriers)) data = (self,0) power = (self,1) to_ampl = sqrt_vff(subcarriers) f2c = gr.float_to_complex(subcarriers) adjust = operational_block self.connect(data,(adjust,0)) self.connect(power,to_ampl,f2c,(adjust,1)) self.connect(adjust, self)
def test_001(self): fft_length = 260 carriers = 100 shift = 20 # select maximum estimation range estim_range = (fft_length - carriers) / 2 l = estim_range + shift r = estim_range - shift # create preambles pn1 = pn_preamble(carriers) pn2 = pn_preamble(carriers) diff_pn = concatenate( [[conjugate(math.sqrt(2) * pn2[2 * i] / pn1[2 * i]), 0.0j] for i in range(carriers / 2)]) pn1_sym = extend_symbol(pn1, l, r) pn2_sym = extend_symbol(pn2, l, r) # block under tests cfo_estimator = ofdm.schmidl_cfo_estimator(fft_length, carriers, estim_range, diff_pn) # source, conversion, sink src_1 = gr.vector_source_c(pn1_sym) src_2 = gr.vector_source_c(pn2_sym) s2v_1 = gr.stream_to_vector(gr.sizeof_gr_complex, fft_length) s2v_2 = gr.stream_to_vector(gr.sizeof_gr_complex, fft_length) v2s = gr.vector_to_stream(gr.sizeof_float, 2 * estim_range + 1) dst = gr.vector_sink_f() self.fg.connect(src_1, s2v_1, (cfo_estimator, 0)) self.fg.connect(src_2, s2v_2, (cfo_estimator, 1)) self.fg.connect(cfo_estimator, v2s, dst) # file output filesink = gr.file_sink(gr.sizeof_float, "test_cfo.float") vec_equ = vector_equalizer(2 * estim_range + 1) self.fg.connect( v2s, gr.float_to_complex(), gr.stream_to_vector(gr.sizeof_gr_complex, 2 * estim_range + 1), vec_equ, gr.vector_to_stream(gr.sizeof_gr_complex, 2 * estim_range + 1), gr.complex_to_float(), filesink) runtime = self.fg runtime.run()
def __init__(self, subcarriers, operational_block): gr.hier_block2.__init__( self, "common_power_allocator", gr.io_signature2(2, 2, gr.sizeof_gr_complex * subcarriers, gr.sizeof_float * subcarriers), gr.io_signature(1, 1, gr.sizeof_gr_complex * subcarriers)) data = (self, 0) power = (self, 1) to_ampl = sqrt_vff(subcarriers) f2c = gr.float_to_complex(subcarriers) adjust = operational_block self.connect(data, (adjust, 0)) self.connect(power, to_ampl, f2c, (adjust, 1)) self.connect(adjust, self)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option("", "--fft-size", type="int", default=512, help="[default=%default]"); parser.add_option("", "--fft-rate", type="int", default=30, help="[default=%default]"); parser.add_option("", "--ref-scale", type="eng_float", default=1.0, help="[default=%default]"); parser.add_option("", "--ref-level", type="int", default=20, help="[default=%default]"); parser.add_option("", "--y-divs", type="int", default=12, help="[default=%default]"); parser.add_option("", "--y-per-div", type="int", default=10, help="[default=%default]"); parser.add_option("", "--baseband-freq", type="eng_float", default=0, help="[default=%default]") parser.add_option("", "--input-file", type="string", default=None, help="[default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 using_wav=False if options.input_file and os.path.exists(options.input_file): self.wav = gr.wavfile_source( options.input_file, True ) using_wav=True else: self.wav = audio.source(sample_rate, "", True) self.f2c = gr.float_to_complex() self.scope = fftsink2.fft_sink_c(panel, fft_size=options.fft_size, sample_rate=sample_rate, fft_rate=options.fft_rate, ref_scale=options.ref_scale, ref_level=options.ref_level, y_divs=options.y_divs, average=True, baseband_freq=options.baseband_freq, y_per_div=options.y_per_div) self.connect((self.wav, 0), (self.f2c, 0)) self.connect((self.wav, 1), (self.f2c, 1)) if using_wav: self.throttle = gr.throttle(gr.sizeof_gr_complex, sample_rate) self.connect(self.f2c, self.throttle, self.scope) else: self.connect((self.f2c, 0), (self.scope, 0)) vbox.Add(self.scope.win, 10, wx.EXPAND)
def __init__(self, fg, lo_freq, usrp_rate): cl = dcf77.clock(07, # hour 35-2, # min 6, # day in month 7, # day of week 2, # month 8, # year 0) # loop tx = dcf77.mod(usrp_rate) f2c = gr.float_to_complex() mixer = gr.multiply_ff() fg.connect (cl, tx, f2c) gr.hier_block.__init__(self, fg, cl, f2c)
def __init__(self, rate, threshold, queue): gr.hier_block2.__init__(self, "adsb_modes_tx_path", gr.io_signature(0,0,0), gr.io_signature(1, 1, gr.sizeof_gr_complex) ) self._rate = int(rate) self._threshold = threshold self._queue = queue # Convert outgoing amplitudes to I/Q baseband (raw modulation) self._mod_raw = gr.float_to_complex() # Modulate ADSB ModeS packet bits and send down the flowgraphs self._mod_adsb = adsb.modulate_adsb(self._rate, self._queue, self._threshold) # Wire up the flowgraph self.connect(self, self._mod_adsb) self.connect(self._mod_adsb, self._mod_raw)
def __init__(self, rate, threshold, queue): gr.hier_block2.__init__(self, "adsb_modes_tx_path", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self._rate = int(rate) self._threshold = threshold self._queue = queue # Convert outgoing amplitudes to I/Q baseband (raw modulation) self._mod_raw = gr.float_to_complex() # Modulate ADSB ModeS packet bits and send down the flowgraphs self._mod_adsb = adsb.modulate_adsb(self._rate, self._queue, self._threshold) # Wire up the flowgraph self.connect(self, self._mod_adsb) self.connect(self._mod_adsb, self._mod_raw)
def test_001(self): fft_length = 260 carriers = 100 shift = 20 # select maximum estimation range estim_range = (fft_length-carriers)/2 l = estim_range+shift r = estim_range-shift # create preambles pn1 = pn_preamble(carriers) pn2 = pn_preamble(carriers) diff_pn = concatenate([[conjugate(math.sqrt(2)*pn2[2*i]/pn1[2*i]),0.0j] for i in range(carriers/2)]) pn1_sym = extend_symbol(pn1,l,r) pn2_sym = extend_symbol(pn2,l,r) # block under tests cfo_estimator = ofdm.schmidl_cfo_estimator(fft_length,carriers,estim_range,diff_pn) # source, conversion, sink src_1 = gr.vector_source_c(pn1_sym) src_2 = gr.vector_source_c(pn2_sym) s2v_1 = gr.stream_to_vector(gr.sizeof_gr_complex,fft_length) s2v_2 = gr.stream_to_vector(gr.sizeof_gr_complex,fft_length) v2s = gr.vector_to_stream(gr.sizeof_float,2*estim_range+1) dst = gr.vector_sink_f() self.fg.connect(src_1, s2v_1, (cfo_estimator,0)) self.fg.connect(src_2, s2v_2, (cfo_estimator,1)) self.fg.connect(cfo_estimator,v2s,dst) # file output filesink = gr.file_sink(gr.sizeof_float,"test_cfo.float") vec_equ = vector_equalizer(2*estim_range+1) self.fg.connect(v2s,gr.float_to_complex(), gr.stream_to_vector(gr.sizeof_gr_complex,2*estim_range+1), vec_equ,gr.vector_to_stream(gr.sizeof_gr_complex,2*estim_range+1), gr.complex_to_float(),filesink) runtime=self.fg runtime.run()
def __init__(self, options): gr.top_block.__init__(self) sample_rate = int(options.sample_rate) self.asrc = audio.source(sample_rate, options.audio_device, True) self.f2c = gr.float_to_complex(1) self.connect((self.asrc, 1), (self.f2c, 1)) self.connect((self.asrc, 0), (self.f2c, 0)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = gr.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = gr.fractional_interpolator_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self, vlen): gr.hier_block2.__init__( self, "vector_equalizer", gr.io_signature(1, 1, gr.sizeof_gr_complex * vlen), gr.io_signature(1, 1, gr.sizeof_gr_complex * vlen)) self.input = gr.add_const_vcc([0.0] * vlen) self.connect(self, self.input) c2mag = gr.complex_to_mag(vlen) max_v = gr.max_ff(vlen) interpolator = gr.interp_fir_filter_fff(vlen, [1.0] * vlen) f2c = gr.float_to_complex() v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen) normalizer = gr.divide_cc() s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen) self.connect(self.input, v2s, (normalizer, 0)) self.connect(self.input, c2mag, max_v, interpolator, f2c, (normalizer, 1)) self.connect(normalizer, s2v) self.connect(s2v, self)
def __init__(self): gr.hier_block2.__init__(self, "tx_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) self.frequency = 13.56e6 self.normal_gain = 100 self.k = 0 self.usrp_interpol = int(128 / (SAMPLERATE / 1e6)) print "[+] Using interpolation rate of", self.usrp_interpol # USRP settings self.u_tx = usrp.sink_c() #create the USRP sink for TX #try and set the LF_RX for this self.tx_subdev_spec = usrp.pick_subdev( self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX)) #set the interpolation rate to match the USRP's 128 MS/s self.u_tx.set_interp_rate(self.usrp_interpol) #Configure the MUX for the daughterboard self.u_tx.set_mux( usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec)) #Tell it to use the LF_TX self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec) #Make sure it worked print "Using TX dboard %s" % (self.subdev_tx.side_and_name(), ) #Set gain.. duh self.subdev_tx.set_gain(self.normal_gain) #Tune the center frequency self.u_tx.tune(0, self.subdev_tx, self.frequency) self.src = gr.wavfile_source("wave52.wav", True) self.conv = gr.float_to_complex() self.amp = gr.multiply_const_cc(10.0**(self.normal_gain / 20.0)) self.connect(self.src, self.conv, self.amp, self.u_tx)
def __init__(self): gr.top_block.__init__(self) amplitude = 30000 filt_out = gr.file_sink(gr.sizeof_gr_complex, "./filt.out") filt2_out = gr.file_sink(gr.sizeof_gr_complex, "./filt2.out") ffilt_out = gr.file_sink(gr.sizeof_float, "./ffilt.out") ffilt2_out = gr.file_sink(gr.sizeof_float, "./ffilt2.out") interp_rate = 128 dec_rate = 8 sw_dec = 4 num_taps = int(64000 / ( (dec_rate * 4) * 256 )) #Filter matched to 1/4 of the 256 kHz tag cycle taps = [complex(1,1)] * num_taps matched_filt = gr.fir_filter_ccc(sw_dec, taps); agc = gr.agc2_cc(0.3, 1e-3, 1, 1, 100) to_mag = gr.complex_to_mag() center = rfid.center_ff(4) omega = 2 mu = 0.25 gain_mu = 0.25 gain_omega = .25 * gain_mu * gain_mu omega_relative_limit = .05 mm = gr.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_relative_limit) self.reader = rfid.reader_f(int(128e6/interp_rate)); tag_decoder = rfid.tag_decoder_f() command_gate = rfid.command_gate_cc(12, 60, 64000000 / dec_rate / sw_dec) to_complex = gr.float_to_complex() amp = gr.multiply_const_ff(amplitude) f_sink = gr.file_sink(gr.sizeof_gr_complex, 'f_sink.out'); f_sink2 = gr.file_sink(gr.sizeof_gr_complex, 'f_sink2.out'); #TX freq = 915e6 rx_gain = 20 tx = usrp.sink_c(fusb_block_size = 1024, fusb_nblocks=8) tx.set_interp_rate(interp_rate) tx_subdev = (0,0) tx.set_mux(usrp.determine_tx_mux_value(tx, tx_subdev)) subdev = usrp.selected_subdev(tx, tx_subdev) subdev.set_enable(True) subdev.set_gain(subdev.gain_range()[2]) t = tx.tune(subdev.which(), subdev, freq) if not t: print "Couldn't set tx freq" #End TX #RX rx = usrp.source_c(0, dec_rate, fusb_block_size = 512 * 4, fusb_nblocks = 16) rx_subdev_spec = (1,0) rx.set_mux(usrp.determine_rx_mux_value(rx, rx_subdev_spec)) rx_subdev = usrp.selected_subdev(rx, rx_subdev_spec) rx_subdev.set_gain(rx_gain) rx_subdev.set_auto_tr(False) rx_subdev.set_enable(True) r = usrp.tune(rx, 0, rx_subdev, freq) self.rx = rx if not r: print "Couldn't set rx freq" #End RX command_gate.set_ctrl_out(self.reader.ctrl_q()) tag_decoder.set_ctrl_out(self.reader.ctrl_q()) agc2 = gr.agc2_ff(0.3, 1e-3, 1, 1, 100) #########Build Graph self.connect(rx, matched_filt) self.connect(matched_filt, command_gate) self.connect(command_gate, agc) self.connect(agc, to_mag) self.connect(to_mag, center, agc2, mm, tag_decoder) self.connect(tag_decoder, self.reader, amp, to_complex, tx); ################# self.connect(matched_filt, filt_out)
def __init__(self, pll_alpha=0.005, satellite='NOAA18', decim=50, gain=25, clock_alpha=0.005, freq=1707e6, deframer_sync_check=True, deframer_insync_frames=2, deframer_outsync_frames=5, symb_rate=600 * 1109, baseband_file=os.environ['HOME'] + '/noaa_hrpt_baseband.dat', frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf'): grc_wxgui.top_block_gui.__init__(self, title="USRP2 NOAA HRPT Receiver") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.pll_alpha = pll_alpha self.satellite = satellite self.decim = decim self.gain = gain self.clock_alpha = clock_alpha self.freq = freq self.deframer_sync_check = deframer_sync_check self.deframer_insync_frames = deframer_insync_frames self.deframer_outsync_frames = deframer_outsync_frames self.symb_rate = symb_rate self.baseband_file = baseband_file self.frames_file = frames_file ################################################## # Variables ################################################## self.decim_tb = decim_tb = decim self.symb_rate_tb = symb_rate_tb = symb_rate self.samp_rate = samp_rate = 100e6 / decim_tb self.sps = sps = samp_rate / symb_rate_tb self.satellite_text = satellite_text = satellite self.samp_rate_st = samp_rate_st = samp_rate self.pll_alpha_sl = pll_alpha_sl = pll_alpha self.max_clock_offset = max_clock_offset = 0.1 self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / samp_rate self.hs = hs = int(sps / 2.0) self.gain_tb = gain_tb = gain self.freq_tb = freq_tb = freq self.frames_file_text_inf = frames_file_text_inf = frames_file self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime()) self.clock_alpha_sl = clock_alpha_sl = clock_alpha self.baseband_file_text_inf = baseband_file_text_inf = baseband_file ################################################## # Notebooks ################################################## self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output") self.Add(self.rx_ntb) ################################################## # Controls ################################################## self._decim_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.decim_tb, callback=self.set_decim_tb, label="Decimation", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1) self._symb_rate_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), value=self.symb_rate_tb, callback=self.set_symb_rate_tb, label="Symbol rate", converter=forms.int_converter(), ) self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1) self._satellite_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.satellite_text, callback=self.set_satellite_text, label="Sat ", converter=forms.str_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1) self._samp_rate_st_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.samp_rate_st, callback=self.set_samp_rate_st, label="Sample rate", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1) _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1) self._gain_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.gain_tb, callback=self.set_gain_tb, label="RX gain [dB]", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1) self._freq_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.freq_tb, callback=self.set_freq_tb, label="Frequency", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1) self._frames_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.frames_file_text_inf, callback=self.set_frames_file_text_inf, label="Frames filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1) self._deframer_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_sync_after_text, callback=self.set_deframer_sync_after_text, label="Deframe sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._deframer_sync_after_text_static_text, 3, 0, 1, 1) self._deframer_nosync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_nosync_after_text, callback=self.set_deframer_nosync_after_text, label="Deframer out of sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._deframer_nosync_after_text_static_text, 4, 0, 1, 1) self._deframer_check_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_check_sync_text, callback=self.set_deframer_check_sync_text, label="Deframer check sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._deframer_check_sync_text_static_text, 2, 0, 1, 1) self._datetime_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.datetime_text, callback=self.set_datetime_text, label="Local time of aquisition start", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1) _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, label="Clock alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1) self._baseband_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.baseband_file_text_inf, callback=self.set_baseband_file_text_inf, label="Baseband filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd( self._baseband_file_text_inf_static_text, 4, 0, 1, 1) ################################################## # Blocks ################################################## self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0) self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb() self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff( sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha, max_clock_offset) self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file) self.gr_file_sink_0_0.set_unbuffered(False) self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_short * 2, baseband_file) self.gr_file_sink_0_1.set_unbuffered(False) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000) self.gr_short_to_float_0 = gr.short_to_float() self.gr_short_to_float_0_0 = gr.short_to_float() self.gr_vector_to_streams_0 = gr.vector_to_streams( gr.sizeof_short * 1, 2) self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True, False) self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0, max_carrier_offset) self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer( deframer_sync_check, 11090, deframer_insync_frames, deframer_outsync_frames) self.usrp2_source_xxxx2_0 = usrp2.source_16sc() self.usrp2_source_xxxx2_0.set_decim(decim_tb) self.usrp2_source_xxxx2_0.set_center_freq(freq_tb) self.usrp2_source_xxxx2_0.set_gain(gain_tb) self.wxgui_fftsink1 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=5, y_divs=10, ref_level=65, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="Not filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win) ################################################## # Connections ################################################## self.connect((self.gr_float_to_complex_0, 0), (self.wxgui_fftsink1, 0)) self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.noaa_hrpt_decoder_0, 0)) self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_univ_hrpt_deframer_0, 0)) self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0)) self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0)) self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0)) self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0)) self.connect((self.gr_agc_xx_0, 0), (self.pll, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.gr_agc_xx_0, 0)) self.connect((self.gr_vector_to_streams_0, 0), (self.gr_short_to_float_0, 0)) self.connect((self.gr_vector_to_streams_0, 1), (self.gr_short_to_float_0_0, 0)) self.connect((self.usrp2_source_xxxx2_0, 0), (self.gr_vector_to_streams_0, 0)) self.connect((self.usrp2_source_xxxx2_0, 0), (self.gr_file_sink_0_1, 0)) self.connect((self.gr_short_to_float_0_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_short_to_float_0, 0), (self.gr_float_to_complex_0, 0))
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 = gr.file_source(gr.sizeof_gr_complex, options.input_file) if options.one_channel: C2F = gr.complex_to_float() F2C = gr.float_to_complex() # osc./mixer for mixing signal down to approx. zero IF LO = gr.sig_source_c(sample_rate, gr.GR_COS_WAVE, options.calibration, 1.0, 0) MIXER = gr.multiply_cc() # get signal into normalized range (-1.0 - +1.0) if options.agc: AMP = gr.feedforward_agc_cc(16, 1.0) else: AMP = gr.multiply_const_cc(options.gain) lpf_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.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 = 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 = repeater.gardner_costas_cc(samples_per_symbol, timing_error_gain, gain_omega, alpha, beta, fmax, fmin) DECIM = gr.fir_filter_ccf(decim_amt, lpf_taps) # probably too much phase noise etc to attempt coherent demodulation # so we use differential DIFF = gr.diff_phasor_cc() # take angle of the phase difference (in radians) TOFLOAT = gr.complex_to_arg() # convert from radians such that signal is in [-3, -1, +1, +3] RESCALE = gr.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 = gr.multiply_const_ff(p) # hard decision at specified points levels = [-2.0, 0.0, 2.0, 4.0] SLICER = 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 = repeater.p25_frame_assembler(hostname, port, debug, do_imbe, do_output, do_msgq, msgq) OUT = gr.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 = gr.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, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.frame_1_menubar = wx.MenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wx.Menu() self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.frame_1_menubar.Append(wxglade_tmp_menu, "File") # Menu Bar end self.panel_1 = wx.Panel(self, -1) self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB") self.button_2 = wx.Button(self, ID_BUTTON_2, "USB") self.button_3 = wx.Button(self, ID_BUTTON_3, "AM") self.button_4 = wx.Button(self, ID_BUTTON_4, "CW") self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper") self.slider_fcutoff_hi = wx.Slider(self, ID_SLIDER_1, 0, -15798, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower") self.slider_fcutoff_lo = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15798, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_5 = wx.Panel(self, -1) self.label_1 = wx.StaticText(self, -1, " Band\nCenter") self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "") self.panel_6 = wx.Panel(self, -1) self.panel_7 = wx.Panel(self, -1) self.panel_2 = wx.Panel(self, -1) self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq") self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000) self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100) self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol") self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500) self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20) self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time") self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew") self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd") self.panel_3 = wx.Panel(self, -1) self.label_2 = wx.StaticText(self, -1, "PGA ") self.panel_4 = wx.Panel(self, -1) self.panel_8 = wx.Panel(self, -1) self.panel_9 = wx.Panel(self, -1) self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier") self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.label_4 = wx.StaticText(self, -1, "Antenna Tune") self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_10 = wx.Panel(self, -1) self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune") self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate") self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset") self.panel_11 = wx.Panel(self, -1) self.panel_12 = wx.Panel(self, -1) self.__set_properties() self.__do_layout() # end wxGlade parser = OptionParser(option_class=eng_option) parser.add_option("", "--address", type="string", default="addr=192.168.10.2", help="Address of UHD device, [default=%default]") parser.add_option("-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ") parser.add_option( "-s", "--samp-rate", type="eng_float", default=256e3, help="set sample rate (bandwidth) [default=%default]") parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE") parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option( "-O", "--audio-output", type="string", default="", help="audio output device name. E.g., hw:0,0, /dev/dsp, or pulse") (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq input_rate = options.samp_rate self.slider_range = input_rate * 0.9375 self.f_lo = self.usrp_center - (self.slider_range / 2) self.f_hi = self.usrp_center + (self.slider_range / 2) self.af_sample_rate = 32000 fir_decim = long(input_rate / self.af_sample_rate) # data point arrays for antenna tuner self.xdata = [] self.ydata = [] self.tb = gr.top_block() # radio variables, initial conditions self.frequency = self.usrp_center # these map the frequency slider (0-6000) to the actual range self.f_slider_offset = self.f_lo self.f_slider_scale = 10000 self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi) self.text_ctrl_1.SetValue(str(int(self.usrp_center))) self.slider_5.SetValue(0) self.AM_mode = False self.slider_3.SetValue( (self.frequency - self.f_slider_offset) / self.f_slider_scale) self.spin_ctrl_1.SetValue(int(self.frequency)) POWERMATE = True try: self.pm = powermate.powermate(self) except: sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n") POWERMATE = False if POWERMATE: powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate) powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton) self.active_button = 7 # command line options if options.audio_file == "": SAVE_AUDIO_TO_FILE = False else: SAVE_AUDIO_TO_FILE = True if options.radio_file == "": SAVE_RADIO_TO_FILE = False else: SAVE_RADIO_TO_FILE = True if options.input_file == "": self.PLAY_FROM_USRP = True else: self.PLAY_FROM_USRP = False if self.PLAY_FROM_USRP: self.src = uhd.usrp_source(device_addr=options.address, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) self.src.set_samp_rate(input_rate) input_rate = self.src.get_samp_rate() self.src.set_center_freq(self.usrp_center, 0) self.tune_offset = 0 else: self.src = gr.file_source(gr.sizeof_short, options.input_file) self.tune_offset = 2200 # 2200 works for 3.5-4Mhz band # convert rf data in interleaved short int form to complex s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src_f2c = gr.float_to_complex() self.tb.connect(self.src, s2ss) self.tb.connect((s2ss, 0), s2f1) self.tb.connect((s2ss, 1), s2f2) self.tb.connect(s2f1, (src_f2c, 0)) self.tb.connect(s2f2, (src_f2c, 1)) # save radio data to a file if SAVE_RADIO_TO_FILE: radio_file = gr.file_sink(gr.sizeof_short, options.radio_file) self.tb.connect(self.src, radio_file) # 2nd DDC xlate_taps = gr.firdes.low_pass ( \ 1.0, input_rate, 16e3, 4e3, gr.firdes.WIN_HAMMING ) self.xlate = gr.freq_xlating_fir_filter_ccf ( \ fir_decim, xlate_taps, self.tune_offset, input_rate ) # Complex Audio filter audio_coeffs = gr.firdes.complex_band_pass( 1.0, # gain self.af_sample_rate, # sample rate -3000, # low cutoff 0, # high cutoff 100, # transition gr.firdes.WIN_HAMMING) # window self.slider_fcutoff_hi.SetValue(0) self.slider_fcutoff_lo.SetValue(-3000) self.audio_filter = gr.fir_filter_ccc(1, audio_coeffs) # Main +/- 16Khz spectrum display self.fft = fftsink2.fft_sink_c(self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)) # AM Sync carrier if AM_SYNC_DISPLAY: self.fft2 = fftsink.fft_sink_c(self.tb, self.panel_9, y_per_div=20, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)) c2f = gr.complex_to_float() # AM branch self.sel_am = gr.multiply_const_cc(0) # the following frequencies turn out to be in radians/sample # gr.pll_refout_cc(alpha,beta,min_freq,max_freq) # suggested alpha = X, beta = .25 * X * X pll = gr.pll_refout_cc(.5, .0625, (2. * math.pi * 7.5e3 / self.af_sample_rate), (2. * math.pi * 6.5e3 / self.af_sample_rate)) self.pll_carrier_scale = gr.multiply_const_cc(complex(10, 0)) am_det = gr.multiply_cc() # these are for converting +7.5kHz to -7.5kHz # for some reason gr.conjugate_cc() adds noise ?? c2f2 = gr.complex_to_float() c2f3 = gr.complex_to_float() f2c = gr.float_to_complex() phaser1 = gr.multiply_const_ff(1) phaser2 = gr.multiply_const_ff(-1) # filter for pll generated carrier pll_carrier_coeffs = gr.firdes.complex_band_pass( 2.0, # gain self.af_sample_rate, # sample rate 7400, # low cutoff 7600, # high cutoff 100, # transition gr.firdes.WIN_HAMMING) # window self.pll_carrier_filter = gr.fir_filter_ccc(1, pll_carrier_coeffs) self.sel_sb = gr.multiply_const_ff(1) combine = gr.add_ff() #AGC sqr1 = gr.multiply_ff() intr = gr.iir_filter_ffd([.004, 0], [0, .999]) offset = gr.add_const_ff(1) agc = gr.divide_ff() self.scale = gr.multiply_const_ff(0.00001) dst = audio.sink(long(self.af_sample_rate), options.audio_output) if self.PLAY_FROM_USRP: self.tb.connect(self.src, self.xlate, self.fft) else: self.tb.connect(src_f2c, self.xlate, self.fft) self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0)) self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3) self.tb.connect((c2f3, 0), phaser1, (f2c, 0)) self.tb.connect((c2f3, 1), phaser2, (f2c, 1)) self.tb.connect(f2c, (am_det, 1)) self.tb.connect(am_det, c2f2, (combine, 0)) self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1)) if AM_SYNC_DISPLAY: self.tb.connect(self.pll_carrier_filter, self.fft2) self.tb.connect(combine, self.scale) self.tb.connect(self.scale, (sqr1, 0)) self.tb.connect(self.scale, (sqr1, 1)) self.tb.connect(sqr1, intr, offset, (agc, 1)) self.tb.connect(self.scale, (agc, 0)) self.tb.connect(agc, dst) if SAVE_AUDIO_TO_FILE: f_out = gr.file_sink(gr.sizeof_short, options.audio_file) sc1 = gr.multiply_const_ff(64000) f2s1 = gr.float_to_short() self.tb.connect(agc, sc1, f2s1, f_out) self.tb.start() # for mouse position reporting on fft display self.fft.win.Bind(wx.EVT_LEFT_UP, self.Mouse) # and left click to re-tune self.fft.win.Bind(wx.EVT_LEFT_DOWN, self.Click) # start a timer to check for web commands if WEB_CONTROL: self.timer = UpdateTimer(self, 1000) # every 1000 mSec, 1 Sec wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb) wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb) wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am) wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw) wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd) wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew) wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate) wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button) wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune) wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume) wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga) wx.EVT_SLIDER(self, ID_SLIDER_6, self.am_carrier) wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune) wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune) wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Rx side A or B (default=A)") parser.add_option( "-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-Q", "--observing", type="eng_float", default=0.0, help="set observing frequency to FREQ") parser.add_option("-a", "--avg", type="eng_float", default=1.0, help="set spectral averaging alpha") parser.add_option("-V", "--favg", type="eng_float", default=2.0, help="set folder averaging alpha") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-l", "--reflevel", type="eng_float", default=30.0, help="Set pulse display reference level") parser.add_option("-L", "--lowest", type="eng_float", default=1.5, help="Lowest valid frequency bin") parser.add_option("-e", "--longitude", type="eng_float", default=-76.02, help="Set Observer Longitude") parser.add_option("-c", "--latitude", type="eng_float", default=44.85, help="Set Observer Latitude") parser.add_option("-F", "--fft_size", type="eng_float", default=1024, help="Size of FFT") parser.add_option("-t", "--threshold", type="eng_float", default=2.5, help="pulsar threshold") parser.add_option("-p", "--lowpass", type="eng_float", default=100, help="Pulse spectra cutoff freq") parser.add_option("-P", "--prefix", default="./", help="File prefix") parser.add_option("-u", "--pulsefreq", type="eng_float", default=0.748, help="Observation pulse rate") parser.add_option("-D", "--dm", type="eng_float", default=1.0e-5, help="Dispersion Measure") parser.add_option("-O", "--doppler", type="eng_float", default=1.0, help="Doppler ratio") parser.add_option("-B", "--divbase", type="eng_float", default=20, help="Y/Div menu base") parser.add_option("-I", "--division", type="eng_float", default=100, help="Y/Div") parser.add_option("-A", "--audio_source", default="plughw:0,0", help="Audio input device spec") parser.add_option("-N", "--num_pulses", default=1, type="eng_float", help="Number of display pulses") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.show_debug_info = True self.reflevel = options.reflevel self.divbase = options.divbase self.division = options.division self.audiodev = options.audio_source self.mult = int(options.num_pulses) # Low-pass cutoff for post-detector filter # Set to 100Hz usually, since lots of pulsars fit in this # range self.lowpass = options.lowpass # What is lowest valid frequency bin in post-detector FFT? # There's some pollution very close to DC self.lowest_freq = options.lowest # What (dB) threshold to use in determining spectral candidates self.threshold = options.threshold # Filename prefix for recording file self.prefix = options.prefix # Dispersion Measure (DM) self.dm = options.dm # Doppler shift, as a ratio # 1.0 == no doppler shift # 1.005 == a little negative shift # 0.995 == a little positive shift self.doppler = options.doppler # # Input frequency and observing frequency--not necessarily the # same thing, if we're looking at the IF of some downconverter # that's ahead of the USRP and daughtercard. This distinction # is important in computing the correct de-dispersion filter. # self.frequency = options.freq if options.observing <= 0: self.observing_freq = options.freq else: self.observing_freq = options.observing # build the graph self.u = usrp.source_c(decim_rate=options.decim) self.u.set_mux( usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) # # Recording file, in case we ever need to record baseband data # self.recording = gr.file_sink(gr.sizeof_char, "/dev/null") self.recording_state = False self.pulse_recording = gr.file_sink(gr.sizeof_short, "/dev/null") self.pulse_recording_state = False # # We come up with recording turned off, but the user may # request recording later on self.recording.close() self.pulse_recording.close() # # Need these two for converting 12-bit baseband signals to 8-bit # self.tofloat = gr.complex_to_float() self.tochar = gr.float_to_char() # Need this for recording pulses (post-detector) self.toshort = gr.float_to_short() # # The spectral measurer sets this when it has a valid # average spectral peak-to-peak distance # We can then use this to program the parameters for the epoch folder # # We set a sentimental value here self.pulse_freq = options.pulsefreq # Folder runs at this raw sample rate self.folder_input_rate = 20000 # Each pulse in the epoch folder is sampled at 128 times the nominal # pulse rate self.folding = 128 # # Try to find candidate parameters for rational resampler # save_i = 0 candidates = [] for i in range(20, 300): input_rate = self.folder_input_rate output_rate = int(self.pulse_freq * i) interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate if (interp < 500 and decim < 250000): candidates.append(i) # We didn't find anything, bail! if (len(candidates) < 1): print "Couldn't converge on resampler parameters" sys.exit(1) # # Now try to find candidate with the least sampling error # mindiff = 999.999 for i in candidates: diff = self.pulse_freq * i diff = diff - int(diff) if (diff < mindiff): mindiff = diff save_i = i # Recompute rates input_rate = self.folder_input_rate output_rate = int(self.pulse_freq * save_i) # Compute new interp and decim, based on best candidate interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate # Save optimized folding parameters, used later self.folding = save_i self.interp = int(interp) self.decim = int(decim) # So that we can view N pulses in the pulse viewer window FOLD_MULT = self.mult # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) self.cardtype = self.u.daughterboard_id(0) # Compute raw input rate input_rate = self.u.adc_freq() / self.u.decim_rate() # BW==input_rate for complex data self.bw = input_rate # # Set baseband filter bandwidth if DBS_RX: # if self.cardtype == usrp_dbid.DBS_RX: lbw = input_rate / 2 if lbw < 1.0e6: lbw = 1.0e6 self.subdev.set_bw(lbw) # # We use this as a crude volume control for the audio output # #self.volume = gr.multiply_const_ff(10**(-1)) # # Create location data for ephem package # self.locality = ephem.Observer() self.locality.long = str(options.longitude) self.locality.lat = str(options.latitude) # # What is the post-detector LPF cutoff for the FFT? # PULSAR_MAX_FREQ = int(options.lowpass) # First low-pass filters down to input_rate/FIRST_FACTOR # and decimates appropriately FIRST_FACTOR = int(input_rate / (self.folder_input_rate / 2)) first_filter = gr.firdes.low_pass(1.0, input_rate, input_rate / FIRST_FACTOR, input_rate / (FIRST_FACTOR * 20), gr.firdes.WIN_HAMMING) # Second filter runs at the output rate of the first filter, # And low-pass filters down to PULSAR_MAX_FREQ*10 # second_input_rate = int(input_rate / (FIRST_FACTOR / 2)) second_filter = gr.firdes.band_pass(1.0, second_input_rate, 0.10, PULSAR_MAX_FREQ * 10, PULSAR_MAX_FREQ * 1.5, gr.firdes.WIN_HAMMING) # Third filter runs at PULSAR_MAX_FREQ*20 # and filters down to PULSAR_MAX_FREQ # third_input_rate = PULSAR_MAX_FREQ * 20 third_filter = gr.firdes_band_pass(1.0, third_input_rate, 0.10, PULSAR_MAX_FREQ, PULSAR_MAX_FREQ / 10.0, gr.firdes.WIN_HAMMING) # # Create the appropriate FFT scope # self.scope = ra_fftsink.ra_fft_sink_f(panel, fft_size=int(options.fft_size), sample_rate=PULSAR_MAX_FREQ * 2, title="Post-detector spectrum", ofunc=self.pulsarfunc, xydfunc=self.xydfunc, fft_rate=200) # # Tell scope we're looking from DC to PULSAR_MAX_FREQ # self.scope.set_baseband_freq(0.0) # # Setup stripchart for showing pulse profiles # hz = "%5.3fHz " % self.pulse_freq per = "(%5.3f sec)" % (1.0 / self.pulse_freq) sr = "%d sps" % (int(self.pulse_freq * self.folding)) times = " %d Pulse Intervals" % self.mult self.chart = ra_stripchartsink.stripchart_sink_f( panel, sample_rate=1, stripsize=self.folding * FOLD_MULT, parallel=True, title="Pulse Profiles: " + hz + per + times, xlabel="Seconds @ " + sr, ylabel="Level", autoscale=True, divbase=self.divbase, scaling=1.0 / (self.folding * self.pulse_freq)) self.chart.set_ref_level(self.reflevel) self.chart.set_y_per_div(self.division) # De-dispersion filter setup # # Do this here, just before creating the filter # that will use the taps. # ntaps = self.compute_disp_ntaps(self.dm, self.bw, self.observing_freq) # Taps for the de-dispersion filter self.disp_taps = Numeric.zeros(ntaps, Numeric.Complex64) # Compute the de-dispersion filter now self.compute_dispfilter(self.dm, self.doppler, self.bw, self.observing_freq) # # Call constructors for receive chains # # # Now create the FFT filter using the computed taps self.dispfilt = gr.fft_filter_ccc(1, self.disp_taps) # # Audio sink # #print "input_rate ", second_input_rate, "audiodev ", self.audiodev #self.audio = audio.sink(second_input_rate, self.audiodev) # # The three post-detector filters # Done this way to allow an audio path (up to 10Khz) # ...and also because going from xMhz down to ~100Hz # In a single filter doesn't seem to work. # self.first = gr.fir_filter_fff(FIRST_FACTOR / 2, first_filter) p = second_input_rate / (PULSAR_MAX_FREQ * 20) self.second = gr.fir_filter_fff(int(p), second_filter) self.third = gr.fir_filter_fff(10, third_filter) # Detector self.detector = gr.complex_to_mag_squared() self.enable_comb_filter = False # Epoch folder comb filter if self.enable_comb_filter == True: bogtaps = Numeric.zeros(512, Numeric.Float64) self.folder_comb = gr.fft_filter_ccc(1, bogtaps) # Rational resampler self.folder_rr = blks2.rational_resampler_fff(self.interp, self.decim) # Epoch folder bandpass bogtaps = Numeric.zeros(1, Numeric.Float64) self.folder_bandpass = gr.fir_filter_fff(1, bogtaps) # Epoch folder F2C/C2F self.folder_f2c = gr.float_to_complex() self.folder_c2f = gr.complex_to_float() # Epoch folder S2P self.folder_s2p = gr.serial_to_parallel(gr.sizeof_float, self.folding * FOLD_MULT) # Epoch folder IIR Filter (produces average pulse profiles) self.folder_iir = gr.single_pole_iir_filter_ff( 1.0 / options.favg, self.folding * FOLD_MULT) # # Set all the epoch-folder goop up # self.set_folding_params() # # Start connecting configured modules in the receive chain # # Connect raw USRP to de-dispersion filter, detector self.connect(self.u, self.dispfilt, self.detector) # Connect detector output to FIR LPF # in two stages, followed by the FFT scope self.connect(self.detector, self.first, self.second, self.third, self.scope) # Connect audio output #self.connect(self.first, self.volume) #self.connect(self.volume, (self.audio, 0)) #self.connect(self.volume, (self.audio, 1)) # Connect epoch folder if self.enable_comb_filter == True: self.connect(self.first, self.folder_bandpass, self.folder_rr, self.folder_f2c, self.folder_comb, self.folder_c2f, self.folder_s2p, self.folder_iir, self.chart) else: self.connect(self.first, self.folder_bandpass, self.folder_rr, self.folder_s2p, self.folder_iir, self.chart) # Connect baseband recording file (initially /dev/null) self.connect(self.u, self.tofloat, self.tochar, self.recording) # Connect pulse recording file (initially /dev/null) self.connect(self.first, self.toshort, self.pulse_recording) # # Build the GUI elements # self._build_gui(vbox) # Make GUI agree with command-line self.myform['average'].set_value(int(options.avg)) self.myform['foldavg'].set_value(int(options.favg)) # Make spectral averager agree with command line if options.avg != 1.0: self.scope.set_avg_alpha(float(1.0 / options.avg)) self.scope.set_average(True) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.freq is None: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0] + r[1]) / 2 self.set_gain(options.gain) #self.set_volume(-10.0) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency") self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name()) self.myform['DM'].set_value(self.dm) self.myform['Doppler'].set_value(self.doppler) # # Start the timer that shows current LMST on the GUI # self.lmst_timer.Start(1000)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option( "-w", "--which", type="int", default=0, help="select which USRP (0, 1, ...) default is %default", metavar="NUM") parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help= "select USRP Rx side A or B (default=first one with a daughterboard)" ) parser.add_option("-A", "--antenna", default=None, help="select Rx Antenna (only on RFX-series boards)") parser.add_option( "-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB [default is midpoint]") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option("--no-hb", action="store_true", default=False, help="don't use halfband filter in usrp") parser.add_option("-S", "--oscilloscope", action="store_true", default=False, help="Enable oscilloscope display") parser.add_option( "", "--avg-alpha", type="eng_float", default=1e-1, help="Set fftsink averaging factor, [default=%default]") parser.add_option("", "--ref-scale", type="eng_float", default=13490.0, help="Set dBFS=0dB input value, [default=%default]") parser.add_option("", "--fft-size", type="int", default=512, help="Set FFT frame size, [default=%default]") parser.add_option("-e", "--order", type="int", default=4, help="order of the AR filter for burg estimator") parser.add_option("", "--shift-fft", action="store_true", default=True, help="shift the DC carrier to the middle.") parser.add_option("-W", "--waterfall", action="store_true", default=False, help="Enable waterfall display") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.options = options self.show_debug_info = True # build the graph if options.no_hb or (options.decim < 8): #Min decimation of this firmware is 4. #contains 4 Rx paths without halfbands and 0 tx paths. self.fpga_filename = "std_4rx_0tx.rbf" self.u = usrp.source_c(which=options.which, decim_rate=options.decim, fpga_filename=self.fpga_filename) else: #Min decimation of standard firmware is 8. #standard fpga firmware "std_2rxhb_2tx.rbf" #contains 2 Rx paths with halfband filters and 2 tx paths (the default) self.u = usrp.source_c(which=options.which, decim_rate=options.decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux( usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) if options.width_8: width = 8 shift = 8 format = self.u.make_format(width, shift) print "format =", hex(format) r = self.u.set_format(format) print "set_format =", r # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) input_rate = self.u.adc_freq() / self.u.decim_rate() self.scope = fftsink2.fft_sink_c(panel, fft_size=options.fft_size, sample_rate=input_rate, ref_scale=options.ref_scale, ref_level=80, y_divs=20, avg_alpha=options.avg_alpha) toskip = 1 self.head = gr.head(gr.sizeof_gr_complex, (toskip + 1) * options.fft_size) self.skip = gr.skiphead(gr.sizeof_gr_complex, toskip * options.fft_size) mywindow1 = window.hamming(options.fft_size) ma_len = 200 overlap = 100 self.welch = specest.welch(options.fft_size, overlap, ma_len, True, mywindow1) self.f2c = gr.float_to_complex(options.fft_size) mywindow2 = window.rectangular(options.fft_size) self.ifft = gr.fft_vcc(options.fft_size, False, mywindow2, True) self.v2s = gr.vector_to_stream(gr.sizeof_gr_complex, options.fft_size) self.connect(self.u, self.welch, self.f2c, self.ifft, self.v2s, self.scope) self._build_gui(vbox) self._setup_events() # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.freq is None: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0] + r[1]) / 2 self.set_gain(options.gain) if options.antenna is not None: print "Selecting antenna %s" % (options.antenna, ) self.subdev.select_rx_antenna(options.antenna) if self.show_debug_info: self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name()) self.myform['baseband'].set_value(0) self.myform['ddc'].set_value(0) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self, fft_length, cp_length, snr, kstime, logging): ''' Maximum Likelihood OFDM synchronizer: J. van de Beek, M. Sandell, and P. O. Borjesson, "ML Estimation of Time and Frequency Offset in OFDM Systems," IEEE Trans. Signal Processing, vol. 45, no. 7, pp. 1800-1805, 1997. ''' gr.hier_block2.__init__(self, "ofdm_sync_ml", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature self.input = gr.add_const_cc(0) SNR = 10.0**(snr/10.0) rho = SNR / (SNR + 1.0) symbol_length = fft_length + cp_length # ML Sync # Energy Detection from ML Sync self.connect(self, self.input) # Create a delay line self.delay = gr.delay(gr.sizeof_gr_complex, fft_length) self.connect(self.input, self.delay) # magnitude squared blocks self.magsqrd1 = gr.complex_to_mag_squared() self.magsqrd2 = gr.complex_to_mag_squared() self.adder = gr.add_ff() moving_sum_taps = [rho/2 for i in range(cp_length)] self.moving_sum_filter = gr.fir_filter_fff(1,moving_sum_taps) self.connect(self.input,self.magsqrd1) self.connect(self.delay,self.magsqrd2) self.connect(self.magsqrd1,(self.adder,0)) self.connect(self.magsqrd2,(self.adder,1)) self.connect(self.adder,self.moving_sum_filter) # Correlation from ML Sync self.conjg = gr.conjugate_cc(); self.mixer = gr.multiply_cc(); movingsum2_taps = [1.0 for i in range(cp_length)] self.movingsum2 = gr.fir_filter_ccf(1,movingsum2_taps) # Correlator data handler self.c2mag = gr.complex_to_mag() self.angle = gr.complex_to_arg() self.connect(self.input,(self.mixer,1)) self.connect(self.delay,self.conjg,(self.mixer,0)) self.connect(self.mixer,self.movingsum2,self.c2mag) self.connect(self.movingsum2,self.angle) # ML Sync output arg, need to find maximum point of this self.diff = gr.sub_ff() self.connect(self.c2mag,(self.diff,0)) self.connect(self.moving_sum_filter,(self.diff,1)) #ML measurements input to sampler block and detect self.f2c = gr.float_to_complex() self.pk_detect = gr.peak_detector_fb(0.2, 0.25, 30, 0.0005) self.sample_and_hold = gr.sample_and_hold_ff() # use the sync loop values to set the sampler and the NCO # self.diff = theta # self.angle = epsilon self.connect(self.diff, self.pk_detect) # The DPLL corrects for timing differences between CP correlations use_dpll = 0 if use_dpll: self.dpll = gr.dpll_bb(float(symbol_length),0.01) self.connect(self.pk_detect, self.dpll) self.connect(self.dpll, (self.sample_and_hold,1)) else: self.connect(self.pk_detect, (self.sample_and_hold,1)) self.connect(self.angle, (self.sample_and_hold,0)) ################################ # correlate against known symbol # This gives us the same timing signal as the PN sync block only on the preamble # we don't use the signal generated from the CP correlation because we don't want # to readjust the timing in the middle of the packet or we ruin the equalizer settings. kstime = [k.conjugate() for k in kstime] kstime.reverse() self.kscorr = gr.fir_filter_ccc(1, kstime) self.corrmag = gr.complex_to_mag_squared() self.div = gr.divide_ff() # The output signature of the correlation has a few spikes because the rest of the # system uses the repeated preamble symbol. It needs to work that generically if # anyone wants to use this against a WiMAX-like signal since it, too, repeats. # The output theta of the correlator above is multiplied with this correlation to # identify the proper peak and remove other products in this cross-correlation self.threshold_factor = 0.1 self.slice = gr.threshold_ff(self.threshold_factor, self.threshold_factor, 0) self.f2b = gr.float_to_char() self.b2f = gr.char_to_float() self.mul = gr.multiply_ff() # Normalize the power of the corr output by the energy. This is not really needed # and could be removed for performance, but it makes for a cleaner signal. # if this is removed, the threshold value needs adjustment. self.connect(self.input, self.kscorr, self.corrmag, (self.div,0)) self.connect(self.moving_sum_filter, (self.div,1)) self.connect(self.div, (self.mul,0)) self.connect(self.pk_detect, self.b2f, (self.mul,1)) self.connect(self.mul, self.slice) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) self.connect(self.slice, self.f2b, (self,1)) if logging: self.connect(self.moving_sum_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat")) self.connect(self.diff, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat")) self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat")) self.connect(self.corrmag, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat")) self.connect(self.kscorr, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat")) self.connect(self.div, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat")) self.connect(self.mul, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat")) self.connect(self.slice, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat")) self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat")) if use_dpll: self.connect(self.dpll, gr.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat")) self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat")) self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat"))
def __init__(self, gain=25, clock_alpha=0.005, freq=1707e6, decim=25, satellite='MetOp', symb_rate=(3500e3 / 3 + 3500e3) / 2, pll_alpha=0.005, deframer_sync_check=True, deframer_insync_frames=2, deframer_outsync_frames=5, frames_file=os.environ['HOME'] + '/metop_ahrpt_frames.cadu', baseband_file=os.environ['HOME'] + '/metop_ahrpt_baseband.dat', viterbi_sync_threshold=0.1, viterbi_sync_check=True, viterbi_insync_frames=5, viterbi_outsync_frames=20): grc_wxgui.top_block_gui.__init__(self, title="USRP2 MetOp AHRPT Receiver") ################################################## # Parameters ################################################## self.gain = gain self.clock_alpha = clock_alpha self.freq = freq self.decim = decim self.satellite = satellite self.symb_rate = symb_rate self.pll_alpha = pll_alpha self.deframer_sync_check = deframer_sync_check self.deframer_insync_frames = deframer_insync_frames self.deframer_outsync_frames = deframer_outsync_frames self.frames_file = frames_file self.baseband_file = baseband_file self.viterbi_sync_threshold = viterbi_sync_threshold self.viterbi_sync_check = viterbi_sync_check self.viterbi_insync_frames = viterbi_insync_frames self.viterbi_outsync_frames = viterbi_outsync_frames ################################################## # Variables ################################################## self.decim_tb = decim_tb = decim self.symb_rate_tb = symb_rate_tb = symb_rate self.samp_rate = samp_rate = 100e6 / decim_tb self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check self.sps = sps = samp_rate / symb_rate_tb self.satellite_text = satellite_text = satellite self.samp_rate_st = samp_rate_st = samp_rate self.pll_alpha_sl = pll_alpha_sl = pll_alpha self.max_clock_offset = max_clock_offset = 0.1 self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / samp_rate self.gain_tb = gain_tb = gain self.freq_tb = freq_tb = freq self.frames_file_text_inf = frames_file_text_inf = frames_file self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime()) self.clock_alpha_sl = clock_alpha_sl = clock_alpha self.baseband_file_text_inf = baseband_file_text_inf = baseband_file ################################################## # Notebooks ################################################## self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output") self.Add(self.rx_ntb) ################################################## # Controls ################################################## self._decim_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.decim_tb, callback=self.set_decim_tb, label="Decimation", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1) self._symb_rate_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), value=self.symb_rate_tb, callback=self.set_symb_rate_tb, label="Symbol rate", converter=forms.int_converter(), ) self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1) self._viterbi_sync_threshold_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_sync_threshold_text, callback=self.set_viterbi_sync_threshold_text, label="Viterbi node sync threshold [BER]", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1) self._viterbi_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_sync_after_text, callback=self.set_viterbi_sync_after_text, label="Valid frames for Viterbi decoder sync", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._viterbi_sync_after_text_static_text, 4, 0, 1, 1) self._viterbi_outofsync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_outofsync_after_text, callback=self.set_viterbi_outofsync_after_text, label="Invalid frames for Viterbi decoder out of sync", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1) self._viterbi_node_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_node_sync_text, callback=self.set_viterbi_node_sync_text, label="Viterbi node sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._viterbi_node_sync_text_static_text, 2, 0, 1, 1) self._satellite_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.satellite_text, callback=self.set_satellite_text, label="Sat ", converter=forms.str_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1) self._samp_rate_st_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.samp_rate_st, callback=self.set_samp_rate_st, label="Sample rate", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1) _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1) self._gain_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.gain_tb, callback=self.set_gain_tb, label="RX gain [dB]", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1) self._freq_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.freq_tb, callback=self.set_freq_tb, label="Frequency", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1) self._frames_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.frames_file_text_inf, callback=self.set_frames_file_text_inf, label="Frames filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1) self._deframer_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_sync_after_text, callback=self.set_deframer_sync_after_text, label="Deframe sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(3).GridAdd( self._deframer_sync_after_text_static_text, 3, 0, 1, 1) self._deframer_nosync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_nosync_after_text, callback=self.set_deframer_nosync_after_text, label="Deframer out of sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(3).GridAdd( self._deframer_nosync_after_text_static_text, 4, 0, 1, 1) self._deframer_check_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_check_sync_text, callback=self.set_deframer_check_sync_text, label="Deframer check sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd( self._deframer_check_sync_text_static_text, 2, 0, 1, 1) self._datetime_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.datetime_text, callback=self.set_datetime_text, label="Local time of aquisition start", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1) _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, label="Clock alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1) self._baseband_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.baseband_file_text_inf, callback=self.set_baseband_file_text_inf, label="Baseband filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).Add(self._baseband_file_text_inf_static_text) ################################################## # Blocks ################################################## self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc( sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl, 0.05) self.gr_costas_loop_cc_0 = gr.costas_loop_cc( pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 4) self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_short * 2, baseband_file) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, )) self.gr_short_to_float_0 = gr.short_to_float() self.gr_short_to_float_0_0 = gr.short_to_float() self.gr_vector_to_streams_0 = gr.vector_to_streams( gr.sizeof_short * 1, 2) self.usrp2_source_xxxx2_0 = usrp2.source_16sc() self.usrp2_source_xxxx2_0.set_decim(decim_tb) self.usrp2_source_xxxx2_0.set_center_freq(freq_tb) self.usrp2_source_xxxx2_0.set_gain(gain_tb) self.wxgui_fftsink1 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=5, y_divs=10, ref_level=50, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="Not filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win) self.wxgui_fftsink2 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=0, y_per_div=5, y_divs=10, ref_level=50, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="RRC filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win) self.wxgui_scopesink2_1 = scopesink2.scope_sink_c( self.rx_ntb.GetPage(1).GetWin(), title="QPSK constellation diagram", sample_rate=symb_rate, v_scale=0.4, v_offset=0, t_scale=1 / samp_rate, ac_couple=False, xy_mode=True, num_inputs=1, ) self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win) ################################################## # Connections ################################################## self.connect((self.gr_float_to_complex_0, 0), (self.wxgui_fftsink1, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.wxgui_fftsink2, 0)) self.connect((self.gr_short_to_float_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_short_to_float_0_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.usrp2_source_xxxx2_0, 0), (self.gr_file_sink_0_1, 0)) self.connect((self.usrp2_source_xxxx2_0, 0), (self.gr_vector_to_streams_0, 0)) self.connect((self.gr_vector_to_streams_0, 1), (self.gr_short_to_float_0_0, 0)) self.connect((self.gr_vector_to_streams_0, 0), (self.gr_short_to_float_0, 0)) self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.gr_costas_loop_cc_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))