def __init__(self, infile="data", samp_rate=1000000, outfile="data.wav", amp=70): gr.top_block.__init__(self, "Analyze") ################################################## # Parameters ################################################## self.infile = infile self.samp_rate = samp_rate self.outfile = outfile self.amp = amp ################################################## # Blocks ################################################## self.gr_wavfile_sink_0 = gr.wavfile_sink(outfile, 3, samp_rate, 16) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((amp, )) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, infile, False) self.gr_complex_to_mag_0 = gr.complex_to_mag(1) self.gr_complex_to_float_0 = gr.complex_to_float(1) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_float_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_mag_0, 0)) self.connect((self.gr_complex_to_mag_0, 0), (self.gr_wavfile_sink_0, 2)) self.connect((self.gr_complex_to_float_0, 1), (self.gr_wavfile_sink_0, 1)) self.connect((self.gr_complex_to_float_0, 0), (self.gr_wavfile_sink_0, 0))
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, input_path, sample_rate, output_path): gr.top_block.__init__(self) # We don't use the existing NBFM demodulator block because it # contains a lowpass output filter which is unsuitable for 9600 # GMSK (it's designed for voice). self.source = gr.file_source(gr.sizeof_gr_complex * 1, input_path, False) self.low_pass_filter = gr.fir_filter_ccf( 4, firdes.low_pass(1, sample_rate, 15000, 100, firdes.WIN_HAMMING, 6.76)) # High pass filter to remove the DC component. This is important # when the signal is near the SDR's local oscillator. # NOTE(tstranex): Disabled since we are now shifting the FCD # center frequency instead. #self.high_pass_filter = gr.fir_filter_ccf(1, firdes.high_pass( # 1, sample_rate/4, 100, 100, firdes.WIN_HAMMING, 6.76)) self.quadrature_demod = gr.quadrature_demod_cf(sample_rate / 4 / (2 * 3.14 * 3000)) self.fm_deemph = blks2.fm_deemph(fs=sample_rate / 4, tau=75e-6) self.boost_volume = gr.multiply_const_vff((1.52, )) self.sink = gr.wavfile_sink(output_path, 1, sample_rate / 4, 16) self.connect((self.source, 0), (self.low_pass_filter, 0)) #self.connect((self.low_pass_filter, 0), (self.high_pass_filter, 0)) #self.connect((self.high_pass_filter, 0), (self.quadrature_demod, 0)) self.connect((self.low_pass_filter, 0), (self.quadrature_demod, 0)) self.connect((self.quadrature_demod, 0), (self.fm_deemph, 0)) self.connect((self.fm_deemph, 0), (self.boost_volume, 0)) self.connect((self.boost_volume, 0), (self.sink, 0))
def __init__(self): gr.top_block.__init__(self) usage = "%prog: [options] filename" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, help="set sample rate to RATE (48000)") parser.add_option("-N", "--samples", type="eng_float", default=None, help="number of samples to record") (options, args) = parser.parse_args () if len(args) != 1 or options.samples is None: parser.print_help() raise SystemExit, 1 sample_rate = int(options.sample_rate) ampl = 0.1 src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl) src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl) head0 = gr.head(gr.sizeof_float, int(options.samples)) head1 = gr.head(gr.sizeof_float, int(options.samples)) dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16) self.connect(src0, head0, (dst, 0)) self.connect(src1, head1, (dst, 1))
def __init__(self, input_path, sample_rate, output_path): gr.top_block.__init__(self) # We don't use the existing NBFM demodulator block because it # contains a lowpass output filter which is unsuitable for 9600 # GMSK (it's designed for voice). self.source = gr.file_source(gr.sizeof_gr_complex * 1, input_path, False) self.low_pass_filter = gr.fir_filter_ccf( 4, firdes.low_pass(1, sample_rate, 15000, 100, firdes.WIN_HAMMING, 6.76) ) # High pass filter to remove the DC component. This is important # when the signal is near the SDR's local oscillator. # NOTE(tstranex): Disabled since we are now shifting the FCD # center frequency instead. # self.high_pass_filter = gr.fir_filter_ccf(1, firdes.high_pass( # 1, sample_rate/4, 100, 100, firdes.WIN_HAMMING, 6.76)) self.quadrature_demod = gr.quadrature_demod_cf(sample_rate / 4 / (2 * 3.14 * 3000)) self.fm_deemph = blks2.fm_deemph(fs=sample_rate / 4, tau=75e-6) self.boost_volume = gr.multiply_const_vff((1.52,)) self.sink = gr.wavfile_sink(output_path, 1, sample_rate / 4, 16) self.connect((self.source, 0), (self.low_pass_filter, 0)) # self.connect((self.low_pass_filter, 0), (self.high_pass_filter, 0)) # self.connect((self.high_pass_filter, 0), (self.quadrature_demod, 0)) self.connect((self.low_pass_filter, 0), (self.quadrature_demod, 0)) self.connect((self.quadrature_demod, 0), (self.fm_deemph, 0)) self.connect((self.fm_deemph, 0), (self.boost_volume, 0)) self.connect((self.boost_volume, 0), (self.sink, 0))
def __init__(self): gr.top_block.__init__(self) usage = "%prog: [options] filename" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, help="set sample rate to RATE (48000)") parser.add_option("-N", "--samples", type="eng_float", default=None, help="number of samples to record") (options, args) = parser.parse_args() if len(args) != 1 or options.samples is None: parser.print_help() raise SystemExit, 1 sample_rate = int(options.sample_rate) ampl = 0.1 src0 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 350, ampl) src1 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 440, ampl) head0 = gr.head(gr.sizeof_float, int(options.samples)) head1 = gr.head(gr.sizeof_float, int(options.samples)) dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16) self.connect(src0, head0, (dst, 0)) self.connect(src1, head1, (dst, 1))
def __init__(self): gr.top_block.__init__(self, "FM Receiver") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 96000 self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass(1, samp_rate, 48000, 5000, firdes.WIN_HAMMING, 6.76) self.sql_lev = sql_lev = -100 self.rf_gain = rf_gain = 20 self.freq = freq = 144800000 self.af_gain = af_gain = 2 self.sat_file_name = sat_file_name = "Undefined" ################################################## # Blocks ################################################## self.xlating_fir_filter = gr.freq_xlating_fir_filter_ccc(1, (xlate_filter_taps), 0, samp_rate) self.nbfm_normal = blks2.nbfm_rx( audio_rate=48000, quad_rate=96000, tau=75e-6, max_dev=5e3, ) self.low_pass_filter = gr.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 12500, 1500, firdes.WIN_HAMMING, 6.76)) self.gr_simple_squelch_cc_0 = gr.simple_squelch_cc(sql_lev, 1) self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((af_gain, )) self.fcd_source_c_1 = fcd.source_c("hw:1") self.fcd_source_c_1.set_freq(freq) self.fcd_source_c_1.set_freq_corr(-32) self.audio_sink = audio.sink(48000, "", True) self.wavfile_sink = gr.wavfile_sink(self.sat_file_name, 1, 11025, 16) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=11025, decimation=48000, taps=None, fractional_bw=None, ) ################################################## # Connections ################################################## self.connect((self.xlating_fir_filter, 0), (self.low_pass_filter, 0)) self.connect((self.low_pass_filter, 0), (self.gr_simple_squelch_cc_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink, 1)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink, 0)) self.connect((self.gr_simple_squelch_cc_0, 0), (self.nbfm_normal, 0)) self.connect((self.nbfm_normal, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.fcd_source_c_1, 0), (self.xlating_fir_filter, 0)) self.connect((self.nbfm_normal, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.wavfile_sink, 0))
def __init__(self): gr.top_block.__init__(self, "CW/SSB Receiver") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 96000 self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass(1, samp_rate, 48000, 5000, firdes.WIN_HAMMING, 6.76) self.sql_lev = sql_lev = -100 self.rf_gain = rf_gain = 20 self.pass_trans = pass_trans = 600 self.pass_low = pass_low = 300 self.pass_high = pass_high = 1200 self.freq = freq = 144800000 self.af_gain = af_gain = 5 self.sat_file_name = sat_file_name = "Undefined" ################################################## # Blocks ################################################## self.xlating_fir_filter = gr.freq_xlating_fir_filter_ccc(1, (xlate_filter_taps), 0, samp_rate) self.gr_simple_squelch_cc_0 = gr.simple_squelch_cc(sql_lev, 1) self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((af_gain, )) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_agc2_xx_0 = gr.agc2_cc(1e-1, 20.8e-6, 0.3, 1.0, 0.0) self.fcd_source_c_1 = fcd.source_c("hw:1") self.fcd_source_c_1.set_freq(freq) self.fcd_source_c_1.set_freq_corr(-10) self.band_pass_filter_0 = gr.fir_filter_ccf(2, firdes.band_pass( 1, samp_rate, pass_low, pass_high, pass_trans, firdes.WIN_HAMMING, 6.76)) self.audio_sink = audio.sink(48000, "", True) self.wavfile_sink = gr.wavfile_sink(self.sat_file_name, 1, 11025, 16) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=11025, decimation=48000, taps=None, fractional_bw=None, ) ################################################## # Connections ################################################## self.connect((self.fcd_source_c_1, 0), (self.xlating_fir_filter, 0)) self.connect((self.xlating_fir_filter, 0), (self.gr_simple_squelch_cc_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.gr_agc2_xx_0, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_agc2_xx_0, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_simple_squelch_cc_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink, 1)) self.connect((self.gr_complex_to_real_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.wavfile_sink, 0))
def __init__(self): gr.top_block.__init__(self) self.rcvd_pktq = gr.msg_queue() audio_rate = 48000 src = audio.source (audio_rate,"plughw:0,0") mult = gr.multiply_const_ff(10) # multiply raw_wave = gr.wavfile_sink(filename, 1, audio_rate,16) raw_wave1 = gr.wavfile_sink(filename2, 1, audio_rate,16) fsk_c = gr.hilbert_fc((audio_rate/300)+1) bp_coeff = gr.firdes.band_pass(1,audio_rate,BandPass,BandStop,100) bpf = gr.fir_filter_fff(1,bp_coeff) quad_demod = gr.quadrature_demod_cf(1)#originally 1 hpf_coeff = gr.firdes.high_pass(10, audio_rate, 10, 5) dc_block = gr.add_const_ff(-2.225) mm = gr.clock_recovery_mm_ff(RepeatTime,0.000625,0.5,0.01,0.1) slicer = gr.binary_slicer_fb() sync_corr = gr.correlate_access_code_bb("0100011101111000",0) file_sink = gr.file_sink(1, "decoded-bits.dat") sink = goodney.sink2(self.rcvd_pktq) self.connect(bpf,raw_wave1) self.connect(src,raw_wave) self.connect(src,bpf,fsk_c,quad_demod,dc_block,mm,slicer,sync_corr,sink) self.watcher = _queue_watcher_thread(self.rcvd_pktq, message_callback)
def xSetEnable(self, sender, state): # ------------------------------------------------------------------------ if sender == "Audio Out": self.audiomute.set_mute(not state) if sender == "UDP Out": host = self.udpconfig["host"] port = self.udpconfig["port"] self.Stop() if state == False or not host or not port: self.udp = gr.null_sink(gr.sizeof_float) wx.GetApp().PostStatus( "SignalGenerator Info: Stopped UDP output to \"%s:%s\"" % ( host, port)) else: self.udp = gr.udp_sink(gr.sizeof_float, host, port, 1472, True) wx.GetApp().PostStatus( "SignalGenerator Info: Started UDP output to \"%s:%s\"" % ( host, port)) self.Start() if sender == "File Out": filename = self.fileconfig["filename"] self.Stop() if state == False or not filename: self.rawfile = gr.null_sink(gr.sizeof_float) wx.GetApp().PostStatus( "SignalGenerator Info: Stopped rawfile device \"%s\"" % ( filename,)) else: self.rawfile = gr.file_sink(gr.sizeof_float, filename) wx.GetApp().PostStatus( "SignalGenerator Info: Started rawfile device \"%s\"" % ( filename,)) self.Start() if sender == "Wave Out": filename = self.waveconfig["filename"] self.Stop() if state == False or not filename: self.wavefile = gr.null_sink(gr.sizeof_float) wx.GetApp().PostStatus( "SignalGenerator Info: Stopped wave device \"%s\"" % ( filename,)) else: self.wavefile = gr.wavfile_sink(filename, 1, self.samprate, 16) wx.GetApp().PostStatus( "SignalGenerator Info: Started wave device \"%s\"" % ( filename,)) self.Start()
def __init__(self): gr.top_block.__init__(self) frequency = 57000 sample_rate = 500000 ampl = 0.8 src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, frequency, ampl) # use 'head' to stop block running after 10 seconds head = gr.head(gr.sizeof_float, sample_rate*10) dst = gr.wavfile_sink ("sample_57k_sin.wav", 1, sample_rate) self.connect (src0, head, dst)
def __init__(self, name, options): gr.hier_block2.__init__( self, "debugger: " + name, gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(0, 0, 0*0), # output signature ) fname = "debug_" + name + ".wav" self.c_to_iq = gr.complex_to_float() self.wavdump = gr.wavfile_sink(fname, 2, options.wav_sample_rate, 16) if options.verbose: print "writing a complex stream to file: %s" % fname self.connect( self, self.c_to_iq ) self.connect( (self.c_to_iq, 0), (self.wavdump, 0)) self.connect( (self.c_to_iq, 1), (self.wavdump, 1))
def __init__(self, outputfile, options): gr.top_block.__init__(self) if options.dsp: self.dst = audio.sink( options.dsp_sample_rate ) else: self.dst = gr.wavfile_sink(outputfile, 2, options.wav_sample_rate, 16) self.c_to_iq = gr.complex_to_float() self.connect( (self.c_to_iq, 0), (self.dst, 0)) self.connect( (self.c_to_iq, 1), (self.dst, 1)) # settings for the modulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/gmsk.py self.modulator = blks2.gmsk_mod(samples_per_symbol=options.samples_per_symbol) self.pkt_queue = blks2.mod_pkts( modulator=self.modulator ) if options.carrier_frequency == 0: self.mixer = self.pkt_queue else: self.mixer = gr.multiply_vcc(1) self.carrier = gr.sig_source_c( options.carrier_sample_rate, gr.GR_SIN_WAVE, options.carrier_frequency, 1.0 ) self.lowpass = gr.fir_filter_ccf(1, firdes.low_pass(1, 48000, 48000/(2*options.samples_per_symbol)+500, 500, firdes.WIN_HAMMING, 6.76)) self.connect(self.pkt_queue, self.lowpass, (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.c_to_iq) if options.debug_wavs: from myblks import debugwav self._dpassw = debugwav("tx_passband", options) self._dprefw = debugwav("tx_prefband", options) self._dbasew = debugwav("tx_baseband", options) self.connect(self.amp, self._dpassw) self.connect(self.lowpass, self._dbasew) self.connect(self.pkt_queue, self._dprefw) if options.debug_files: self._dpassf = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_passband.d_c") self._dpreff = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_prefband.d_c") self._dbasef = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_baseband.d_c") self.connect(self.amp, self._dpassf) self.connect(self.pkt_queue, self._dpreff) self.connect(self.lowpass, self._dbasef)
def __init__(self, input_path, sample_rate, output_path): gr.top_block.__init__(self) self.source = gr.file_source( gr.sizeof_gr_complex, input_path, False) self.lowpass_and_decimate = gr.fir_filter_ccf( 8, firdes.low_pass(1, sample_rate, FREQ_SPACE, 100)) self.lsb_tune = gr.freq_xlating_fir_filter_ccc( 1, (1,), -FREQ_SPACE, sample_rate/8) self.boost_volume = gr.multiply_const_vcc((10, )) self.complex_to_real = gr.complex_to_real(1) self.sink = gr.wavfile_sink(output_path, 1, sample_rate/8, 16) self.connect((self.source, 0), (self.lowpass_and_decimate, 0)) self.connect((self.lowpass_and_decimate, 0), (self.lsb_tune, 0)) self.connect((self.lsb_tune, 0), (self.boost_volume, 0)) self.connect((self.boost_volume, 0), (self.complex_to_real, 0)) self.connect((self.complex_to_real, 0), (self.sink, 0))
def __init__(self): gr.top_block.__init__(self) self.rcvd_pktq = gr.msg_queue() self.rcvd_pktq_tone = gr.msg_queue() mult = gr.multiply_const_ff(0.2) # attenuating signal for tone triggering src = audio.source (AUDIO_RATE,"plughw:0,0") raw_wave = gr.wavfile_sink("recieve.wav", 1, AUDIO_RATE,16) hierblock1= HierBlock_data() hierblock2= HierBlock_tone() sink = goodney.sink2(self.rcvd_pktq) sink2 = tone.sink(self.rcvd_pktq_tone,1) self.connect(src,hierblock1,sink) self.connect(src,mult,hierblock2,sink2) self.watcher = _queue_watcher_thread(self.rcvd_pktq, message_callback) self.watcher = _queue_watcher_thread_tone(self.rcvd_pktq_tone, message_callback_tone)
def __init__(self, infile="data", samp_rate=1000000, outfile="data.wav", amp=70): gr.top_block.__init__(self, "Analyze") ################################################## # Parameters ################################################## self.infile = infile self.samp_rate = samp_rate self.outfile = outfile self.amp = amp ################################################## # Blocks ################################################## self.gr_wavfile_sink_0 = gr.wavfile_sink(outfile, 3, samp_rate, 16) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((amp, )) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex * 1, infile, False) self.gr_complex_to_mag_0 = gr.complex_to_mag(1) self.gr_complex_to_float_0 = gr.complex_to_float(1) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_float_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_mag_0, 0)) self.connect((self.gr_complex_to_mag_0, 0), (self.gr_wavfile_sink_0, 2)) self.connect((self.gr_complex_to_float_0, 1), (self.gr_wavfile_sink_0, 1)) self.connect((self.gr_complex_to_float_0, 0), (self.gr_wavfile_sink_0, 0))
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-I", "--filename", type="string", help="read input from wav FILE") parser.add_option("-s", "--input-rate", type="eng_float", default="500k", help="set sample rate to RATE (500k)") parser.add_option("-O", "--outname", type="string", help="output to wav file FILE") parser.add_option("-r", "--output-rate", type="eng_float", default="192k", help="set output sample rate to RATE (192k)") parser.add_option("-F", "--filter", action="store_true", default=False, help="filter out audible sounds, retain ultrasonic") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 src = gr.wavfile_source (options.filename) input_rate = int(options.input_rate) output_rate = int(options.output_rate) interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate dst = gr.wavfile_sink (options.outname, 1, output_rate) rr = blks2.rational_resampler_fff(int(interp), int(decim)) if options.filter: highpass = gr.firdes.high_pass (1, # gain output_rate, # sampling rate 15000, # cutoff freq 2000, # width of trans. band gr.firdes.WIN_HANN) # filter type filt = gr.fir_filter_fff(1,highpass) self.connect (src, rr, filt, dst) else: self.connect (src, rr, dst)
def test_002_checkwavcopy(self): infile = g_in_file outfile = "test_out.wav" wf_in = gr.wavfile_source(infile) wf_out = gr.wavfile_sink(outfile, wf_in.channels(), wf_in.sample_rate(), wf_in.bits_per_sample()) self.tb.connect(wf_in, wf_out) self.tb.run() wf_out.close() self.assertEqual(getsize(infile), getsize(outfile)) in_f = file(infile, 'rb') out_f = file(outfile, 'rb') in_data = in_f.read() out_data = out_f.read() out_f.close() os.remove(outfile) self.assertEqual(in_data, out_data)
def __init__(self): gr.top_block.__init__(self) audio_rate =48000 # audio rate changed self.src = gr.message_source(gr.sizeof_char, msgq_limit) src = self.src b_to_syms = gr.bytes_to_syms() mult = gr.multiply_const_ff(1000) add = gr.add_const_ff(CentreFreq) repeater = gr.repeat(gr.sizeof_float,RepeatTime) fsk_f = gr.vco_f(audio_rate, 2*pi,0.5) # Sensitivity is rad/sec/volt ( e.g 2*pi*f/sec = 1Khz) and here f = volts (input amplitude of VCO) attenuator = gr.multiply_const_ff(0.05) # multiply speaker = audio.sink(audio_rate, "plughw:0,0"); dst = gr.wavfile_sink("tx-signal.wav",1, audio_rate, 16) self.connect(src,b_to_syms,mult,add,repeater,fsk_f,attenuator,speaker) self.connect(fsk_f,dst)
def test_002_checkwavcopy (self): infile = g_in_file outfile = "test_out.wav" wf_in = gr.wavfile_source(infile) wf_out = gr.wavfile_sink(outfile, wf_in.channels(), wf_in.sample_rate(), wf_in.bits_per_sample()) self.tb.connect(wf_in, wf_out) self.tb.run() wf_out.close() self.assertEqual(getsize(infile), getsize(outfile)) in_f = file(infile, 'rb') out_f = file(outfile, 'rb') in_data = in_f.read() out_data = out_f.read() out_f.close() os.remove(outfile) self.assertEqual(in_data, out_data)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Am Aviation") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.sql_threshold = sql_threshold = -30 self.samp_rate = samp_rate = 1000000 self.frq_offset = frq_offset = 0 self.base_frq = base_frq = 134.5e6 ################################################## # Blocks ################################################## _sql_threshold_sizer = wx.BoxSizer(wx.VERTICAL) self._sql_threshold_text_box = forms.text_box( parent=self.GetWin(), sizer=_sql_threshold_sizer, value=self.sql_threshold, callback=self.set_sql_threshold, label="Squelch Threshold", converter=forms.float_converter(), proportion=0, ) self._sql_threshold_slider = forms.slider( parent=self.GetWin(), sizer=_sql_threshold_sizer, value=self.sql_threshold, callback=self.set_sql_threshold, minimum=-100, maximum=0, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_sql_threshold_sizer) _frq_offset_sizer = wx.BoxSizer(wx.VERTICAL) self._frq_offset_text_box = forms.text_box( parent=self.GetWin(), sizer=_frq_offset_sizer, value=self.frq_offset, callback=self.set_frq_offset, label="Frequency Offset", converter=forms.float_converter(), proportion=0, ) self._frq_offset_slider = forms.slider( parent=self.GetWin(), sizer=_frq_offset_sizer, value=self.frq_offset, callback=self.set_frq_offset, minimum=-30e6, maximum=10e6, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_frq_offset_sizer) self._base_frq_text_box = forms.text_box( parent=self.GetWin(), value=self.base_frq, callback=self.set_base_frq, label="Base frequency", converter=forms.float_converter(), ) self.Add(self._base_frq_text_box) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.Add(self.wxgui_waterfallsink2_0.win) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) if self.rtl2832_source_0.create() == False: raise Exception( "Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_bandwidth(500000) self.rtl2832_source_0.set_sample_rate(samp_rate) self.rtl2832_source_0.set_frequency(base_frq + frq_offset) self.rtl2832_source_0.set_auto_gain_mode(True) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(30) self.gr_wavfile_sink_0 = gr.wavfile_sink( "/home/louis/Dropbox/sdr/AM/134.5MHZ.am.wav", 1, 48000, 16) self.gr_simple_squelch_cc_0 = gr.simple_squelch_cc( sql_threshold, 0.0001) self.gr_agc2_xx_0 = gr.agc2_cc(100e-3, 200e-3, 1.0, 1.0, 2.0) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc( interpolation=48, decimation=1000, taps=None, fractional_bw=None, ) self.blks2_am_demod_cf_0 = blks2.am_demod_cf( channel_rate=48000, audio_decim=1, audio_pass=5000, audio_stop=5500, ) self.audio_sink_0 = audio.sink(48000, "pulse", True) ################################################## # Connections ################################################## self.connect((self.blks2_am_demod_cf_0, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_simple_squelch_cc_0, 0)) self.connect((self.gr_simple_squelch_cc_0, 0), (self.gr_agc2_xx_0, 0)) self.connect((self.gr_agc2_xx_0, 0), (self.blks2_am_demod_cf_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.blks2_am_demod_cf_0, 0), (self.gr_wavfile_sink_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Example bitcpf - FM Rx") _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 = 8e6 self.rx_gain = rx_gain = 15 self.lpf_decim = lpf_decim = 20 self.freq = freq = 106.7e6 self.audio_samp_rate = audio_samp_rate = 96e3 ################################################## # Blocks ################################################## _rx_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, label='rx_gain', converter=forms.float_converter(), proportion=0, ) self._rx_gain_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, minimum=0, maximum=30, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rx_gain_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio") self.Add(self.notebook_0) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label='freq', converter=forms.float_converter(), ) self.Add(self._freq_text_box) self.wxgui_fftsink2_1 = fftsink2.fft_sink_f( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate/lpf_decim, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.low_pass_filter_0 = gr.fir_filter_ccf(lpf_decim, firdes.low_pass( 1, samp_rate, 100e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.gr_wavfile_sink_0 = gr.wavfile_sink("fm_record.wav", 1, int(audio_samp_rate), 8) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate/lpf_decim, audio_decimation=1, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=96, decimation=int(samp_rate/lpf_decim/1000), taps=None, fractional_bw=None, ) self.audio_sink_0 = audio.sink(int(audio_samp_rate), "", True) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-f", "--freq", type="string", default="131725000", help="Frequency in Hz") parser.add_option("-o", "--output", type="string", default="output.txt", help="ACARS log output") parser.add_option( "-s", "--samp-rate", type="eng_float", default="250e3", help="set sample rate (bandwidth) [default=%default]") parser.add_option( "-d", "--device", type="string", default="", help="PCM device name, e.g. hw:0,0 /dev/dsp pulse etc.") parser.add_option("-w", "--wav-file", type="string", default="", help="WAV file output.") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.freq = float(options.freq) usrp_rate = options.samp_rate audio_rate = 48e3 # init USRP source block self.usrp = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) if (options.spec): self.usrp.set_subdev_spec(options.spec, 0) if (options.antenna): self.usrp.set_antenna(options.antenna, 0) self.usrp.set_samp_rate(usrp_rate) self.usrp.set_center_freq(self.freq, 0) # FIR block (5KHz low pass filter) chan_filt_coeffs = gr.firdes.low_pass_2( 8, # gain usrp_rate, # sampling rate 5e3, # passband_cutoff 1e2, # transition bw 60) # stopband attenuation self.chan_filt = gr.freq_xlating_fir_filter_ccf( 1, # decimation chan_filt_coeffs, # taps 0, # center freq usrp_rate) # samp rate # AM demodulator block self.am_demod = gr.complex_to_mag() # resampler block self.resamp = blks2.rational_resampler_fff( interpolation=int(audio_rate), decimation=int(usrp_rate), taps=None, fractional_bw=None) # acars2 demod/decode blocks self.acars2_demod = acars2.demod(int(audio_rate)) self.acars2_decode = acars2.decode() # file sink self.file_sink = gr.file_sink(gr.sizeof_char, options.output) # build flow graph self.connect(self.usrp, self.chan_filt, self.am_demod, self.resamp, self.acars2_demod, self.acars2_decode, self.file_sink) # add audio sink (optional) if (options.device): print "using audio device %s" % options.device self.audio_sink = audio.sink(int(audio_rate), options.device, True) self.connect(self.resamp, self.audio_sink) # add WAV file sink (optional) if (options.wav_file): print "writing to WAV file %s" % options.wav_file self.wavsink = gr.wavfile_sink(options.wav_file, 1, int(audio_rate), 16) self.connect(self.resamp, self.wavsink) self._build_gui(vbox, usrp_rate, audio_rate) print "built flow graph..."
def __init__(self, options, queue): gr.top_block.__init__(self) if options.filename is not None: self.fs = gr.file_source(gr.sizeof_gr_complex, options.filename) self.rate = 64000000 / options.decim # allow setting of recorded decimation in options else: self.u = usrp.source_c() self.u.set_mux( usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % self.subdev.side_and_name() self.u.set_decim_rate(options.decim) self.centerfreq = options.centerfreq print "Tuning to: %fMHz" % (self.centerfreq - options.error) if not (self.tune(options.centerfreq - options.error)): print "Failed to set initial frequency" if options.gain is None: #set to halfway g = self.subdev.gain_range() options.gain = (g[0] + g[1]) / 2.0 print "Setting gain to %i" % options.gain self.subdev.set_gain(options.gain) if self.subdev.name() == "DBS Rx": self.subdev.set_bw(options.bandwidth) #only for DBSRX print "Setting DBS RX bandwidth to %fMHz" % float( options.bandwidth / 1e6) self.rate = self.u.adc_rate() / options.decim print "Samples per second is %i" % self.rate self._syms_per_sec = 3600 options.samples_per_second = self.rate options.syms_per_sec = self._syms_per_sec options.gain_mu = 0.01 options.mu = 0.5 options.omega_relative_limit = 0.3 options.syms_per_sec = self._syms_per_sec options.offset = options.centerfreq - options.freq print "Control channel offset: %f" % options.offset self.demod = fsk_demod(options) self.start_correlator = gr.correlate_access_code_bb( "10101100", 0) #should mark start of packet self.smartnet_sync = smartnet.sync() self.smartnet_deinterleave = smartnet.deinterleave() self.smartnet_parity = smartnet.parity() self.smartnet_crc = smartnet.crc() self.smartnet_packetize = smartnet.packetize() self.parse = smartnet.parse( queue ) #packet-based. this simply posts lightly-formatted messages to the queue. # self.filesink = gr.file_sink(gr.sizeof_char*16, "smartnet_decoded.dat") #set a friggin filename in the options # self.paritysink = gr.file_sink(gr.sizeof_char, "smartnet_parity.dat") if options.filename is None: self.connect(self.u, self.demod) else: self.connect(self.fs, self.demod) self.connect(self.demod, self.start_correlator, self.smartnet_sync, self.smartnet_deinterleave, self.smartnet_parity, self.smartnet_crc, self.smartnet_packetize, self.parse) #hook up the audio patch if options.audio: self.audiorate = 48000 # self.audiodemoddecim = 4 self.audiotaps = gr.firdes.low_pass(1, self.rate, 8000, 2000, firdes.WIN_HANN) self.prefilter_decim = ( self.rate / self.audiorate ) #might have to use a rational resampler for audio print "Prefilter decimation: %i" % self.prefilter_decim self.audio_prefilter = gr.freq_xlating_fir_filter_ccc( self.prefilter_decim, #decimation self.audiotaps, #taps 0, #freq offset self.rate) #sampling rate #on a trunked network where you know you will have good signal, a carrier power squelch works well. real FM receviers use a noise squelch, where #the received audio is high-passed above the cutoff and then fed to a reverse squelch. If the power is then BELOW a threshold, open the squelch. self.squelch = gr.pwr_squelch_cc( options.squelch, #squelch point alpha=0.1, #wat ramp=10, #wat gate=False) self.audiodemod = blks2.fm_demod_cf( self.rate / self.prefilter_decim, #rate 1, #audio decimation 4000, #deviation 3000, #audio passband 4000, #audio stopband 1, #gain 75e-6) #deemphasis constant #the point of the resampler is to bring data to the soundcard at a rate it supports, but it seems to sound fine without it, and it saves some CPU cycles not to have it #the audio rate is 48kHz because seemingly it's all my *&$# integrated sound card will support, otherwise it'd be like 8k or something reasonable #running a 48kHz audio rate isn't the end of the world -- with decim 18 and prefilter decim 74, the native rate is 48.048kHz. that's close enough to avoid the resampler. # self.gcd = self.euclid(self.audiorate, self.rate/self.prefilter_decim) # print "Resampling: decim %i, interp %i" % (self.rate/self.prefilter_decim/self.gcd, self.audiorate/self.gcd) # self.audioresamp = blks2.rational_resampler_fff(self.audiorate/self.gcd, self.rate/self.prefilter_decim/self.gcd)#, self.audiofilttaps) #the filtering removes FSK data woobling from the subaudible channel self.audiofilttaps = gr.firdes.high_pass(1, self.audiorate, 300, 50, firdes.WIN_HANN) self.audiofilt = gr.fir_filter_fff(1, self.audiofilttaps) self.audiogain = gr.multiply_const_ff(options.volume) # self.audiosink = audio.sink (self.audiorate, "") self.audiosink = gr.wavfile_sink("test.wav", 1, self.audiorate, 8) self.mute() if options.filename is None: self.connect(self.u, self.audio_prefilter) else: self.connect(self.fs, self.audio_prefilter) # self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audioresamp, self.audiosink) self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audiosink)
def __init__( self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__( self, frame, panel, vbox, argv) self.frame = frame self.panel = panel self.offset = 0.0 # Channel frequency offset parser = OptionParser(option_class=eng_option) parser.add_option("-p", "--protocol", type="int", default=1, help="set protocol: 0 = RDLAP 19.2kbps; 1 = APCO25 (default)") parser.add_option("-g", "--gain", type="eng_float", default=1.0, help="set linear input gain (default: %default)") parser.add_option("-x", "--freq-translation", type="eng_float", default=0.0, help="initial channel frequency translation") parser.add_option("-n", "--frame-decim", type="int", default=1, help="set oscope frame decimation factor to n [default=1]") parser.add_option("-v", "--v-scale", type="eng_float", default=5000, help="set oscope initial V/div to SCALE [default=%default]") parser.add_option("-t", "--t-scale", type="eng_float", default=49e-6, help="set oscope initial s/div to SCALE [default=50us]") parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, help="set sample rate to RATE (default: %default)") parser.add_option("-d", "--channel-decim", type="int", default=None, help="set channel decimation factor to n [default depends on protocol]") parser.add_option("-w", "--wav-file", type="string", default=None, help="WAV input path") parser.add_option("-f", "--data-file", type="string", default=None, help="Data input path") parser.add_option("-B", "--base-band", action="store_true", default=False) parser.add_option("-R", "--repeat", action="store_true", default=False) parser.add_option("-o", "--wav-out", type="string", default=None, help="WAV output path") parser.add_option("-G", "--wav-out-gain", type="eng_float", default=0.05, help="set WAV output gain (default: %default)") parser.add_option("-F", "--data-out", type="string", default=None, help="Data output path") parser.add_option("-C", "--carrier-freq", type="eng_float", default=None, help="set data output carrier frequency to FREQ", metavar="FREQ") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.options = options if options.wav_file is not None: #try: self.input_file = gr.wavfile_source(options.wav_file, options.repeat) #except: # print "WAV file not found or not a WAV file" # sys.exit(1) print "WAV input: %i Hz, %i bits, %i channels" % (self.input_file.sample_rate(), self.input_file.bits_per_sample(), self.input_file.channels()) self.sample_rate = self.input_file.sample_rate() self.input_stream = gr.throttle(gr.sizeof_float, self.sample_rate) self.connect(self.input_file, self.input_stream) self.src = gr.multiply_const_ff(options.gain) elif options.data_file is not None: if options.base_band: sample_size = gr.sizeof_float print "Data file is baseband (float)" self.src = gr.multiply_const_ff(options.gain) else: sample_size = gr.sizeof_gr_complex print "Data file is IF (complex)" self.src = gr.multiply_const_cc(options.gain) self.input_file = gr.file_source(sample_size, options.data_file, options.repeat) self.sample_rate = options.sample_rate # E.g. 250000 print "Data file sampling rate = " + str(self.sample_rate) self.input_stream = gr.throttle(sample_size, self.sample_rate) self.connect(self.input_file, self.input_stream) else: self.sample_rate = options.sample_rate print "Soundcard sampling rate = " + str(self.sample_rate) self.input_stream = audio.source(self.sample_rate, options.audio_input) # float samples self.src = gr.multiply_const_ff(options.gain) print "Fixed input gain = " + str(options.gain) self.connect(self.input_stream, self.src) if options.wav_out is not None: output_rate = int(self.sample_rate) if options.channel_decim is not None: output_rate /= options.channel_decim self.wav_out = gr.wavfile_sink(options.wav_out, 1, output_rate, 16) print "Opened WAV output file: " + options.wav_out + " at rate: " + str(output_rate) else: self.wav_out = None if options.data_out is not None: if options.carrier_freq is None: self.data_out = gr.file_sink(gr.sizeof_float, options.data_out) print "Opened float data output file: " + options.data_out else: self.data_out = gr.file_sink(gr.sizeof_gr_complex, options.data_out) print "Opened complex data output file: " + options.data_out else: self.data_out = None self.num_inputs = 1 input_rate = self.sample_rate #title='IF', #size=(1024,800), if (options.data_file is not None) and (options.base_band == False): self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale, num_inputs=self.num_inputs) else: self.scope = scopesink2.scope_sink_f(panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale, num_inputs=self.num_inputs) #self.di = gr.deinterleave(gr.sizeof_float) #self.di = gr.complex_to_float(1) #self.di = gr.complex_to_imag() #self.dr = gr.complex_to_real() #self.connect(self.src,self.dr) #self.connect(self.src,self.di) #self.null = gr.null_sink(gr.sizeof_double) #self.connect(self.src,self.di) #self.connect((self.di,0),(self.scope,0)) #self.connect((self.di,1),(self.scope,1)) #self.connect(self.dr,(self.scope,0)) #self.connect(self.di,(self.scope,1)) self.msgq = gr.msg_queue(2) # queue that holds a maximum of 2 messages self.queue_watcher = queue_watcher(self.msgq, self.adjust_freq_norm) #------------------------------------------------------------------------------- if options.protocol == 0: # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel, print "RD-LAP selected" self.symbol_rate = 9600 # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps if options.channel_decim is None: self.channel_decimation = 10 # decimation (final rate should be at least several symbol rate) else: self.channel_decimation = options.channel_decim self.max_frequency_offset = 12000.0 # coarse carrier tracker leash, ~ half a channel either way self.symbol_deviation = 1200.0 # this is frequency offset from center of channel to +1 / -1 symbols self.input_sample_rate = self.sample_rate self.protocol_processing = fsk4.rdlap_f(self.msgq, 0) # desired protocol processing block selected here self.channel_rate = self.input_sample_rate / self.channel_decimation # channel selection filter characteristics channel_taps = optfir.low_pass(1.0, # Filter gain self.input_sample_rate, # Sample rate 10000, # One-sided modulation bandwidth 12000, # One-sided channel bandwidth 0.1, # Passband ripple 60) # Stopband attenuation # symbol shaping filter characteristics symbol_coeffs = gr.firdes.root_raised_cosine (1.0, # gain self.channel_rate , # sampling rate self.symbol_rate, # symbol rate 0.2, # alpha 500) # taps if options.protocol == 1: # ---------- APCO-25 C4FM Test Data print "APCO selected" self.symbol_rate = 4800 # symbol rate if options.channel_decim is None: self.channel_decimation = 20 # decimation else: self.channel_decimation = options.channel_decim self.max_frequency_offset = 6000.0 # coarse carrier tracker leash self.symbol_deviation = 600.0 # this is frequency offset from center of channel to +1 / -1 symbols self.input_sample_rate = self.sample_rate self.protocol_processing = fsk4.apco25_f(self.msgq, 0) self.channel_rate = self.input_sample_rate / self.channel_decimation # channel selection filter if (options.data_file is not None) and (options.base_band == False): channel_taps = optfir.low_pass(1.0, # Filter gain self.input_sample_rate, # Sample rate 5000, # One-sided modulation bandwidth 6500, # One-sided channel bandwidth 0.2, # Passband ripple (was 0.1) 60) # Stopband attenuation else: channel_taps = None # symbol shaping filter symbol_coeffs = gr.firdes.root_raised_cosine (1.0, # gain self.channel_rate, # sampling rate self.symbol_rate, # symbol rate 0.2, # alpha 500) # taps # ----------------- End of setup block print "Input rate = " + str(self.input_sample_rate) print "Channel decimation = " + str(self.channel_decimation) print "Channel rate = " + str(self.channel_rate) if channel_taps is not None: self.chan = gr.freq_xlating_fir_filter_ccf(self.channel_decimation, # Decimation rate channel_taps, # Filter taps 0.0, # Offset frequency self.input_sample_rate) # Sample rate if (options.freq_translation != 0): print "Channel center frequency = " + str(options.freq_translation) self.chan.set_center_freq(options.freq_translation) else: self.chan = None if options.carrier_freq is not None: print "Carrier frequency = " + str(options.carrier_freq) self.sig_carrier = gr.sig_source_c(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, 0) self.carrier_mul = gr.multiply_vcc(1) # cc(gr.sizeof_gr_complex) self.connect(self.sig_carrier, (self.carrier_mul, 0)) self.connect(self.chan, (self.carrier_mul, 1)) self.sig_i_carrier = gr.sig_source_f(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, 0) self.sig_q_carrier = gr.sig_source_f(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, (pi / 2.0)) self.carrier_i_mul = gr.multiply_ff(1) self.carrier_q_mul = gr.multiply_ff(1) self.iq_to_float = gr.complex_to_float(1) self.carrier_iq_add = gr.add_ff(1) self.connect(self.carrier_mul, self.iq_to_float) self.connect((self.iq_to_float, 0), (self.carrier_i_mul, 0)) self.connect((self.iq_to_float, 1), (self.carrier_q_mul, 0)) self.connect(self.sig_i_carrier, (self.carrier_i_mul, 1)) self.connect(self.sig_q_carrier, (self.carrier_q_mul, 1)) self.connect(self.carrier_i_mul, (self.carrier_iq_add, 0)) self.connect(self.carrier_q_mul, (self.carrier_iq_add, 1)) else: self.sig_carrier = None self.carrier_mul = None #lf_channel_taps = optfir.low_pass(1.0, # Filter gain # self.input_sample_rate, # Sample rate # 2500, # One-sided modulation bandwidth # 3250, # One-sided channel bandwidth # 0.1, # Passband ripple (0.1) # 60, # Stopband attenuation # 9) # Extra taps (default 2, which doesn't work at 48kHz) #self.lf = gr.fir_filter_fff(self.channel_decimation, lf_channel_taps) self.scope2 = scopesink2.scope_sink_f(panel, sample_rate=self.symbol_rate, frame_decim=1, v_scale=2, t_scale=0.025, num_inputs=self.num_inputs) # also note: this specifies the nominal frequency deviation for the 4-level fsk signal self.fm_demod_gain = self.channel_rate / (2.0 * pi * self.symbol_deviation) self.fm_demod = gr.quadrature_demod_cf(self.fm_demod_gain) symbol_decim = 1 self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs) # eventually specify: sample rate, symbol rate self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate, self.symbol_rate) if (self.chan is not None): self.connect(self.src, self.chan, self.fm_demod, self.symbol_filter, self.demod_fsk4, self.protocol_processing) if options.wav_out is not None: print "WAV output gain = " + str(options.wav_out_gain) self.scaled_wav_data = gr.multiply_const_ff(float(options.wav_out_gain)) self.connect(self.scaled_wav_data, self.wav_out) if self.carrier_mul is None: self.connect(self.fm_demod, self.scaled_wav_data) else: self.connect(self.carrier_iq_add, self.scaled_wav_data) if self.data_out is not None: if self.carrier_mul is None: self.connect(self.fm_demod, self.data_out) else: self.connect(self.carrier_mul, self.data_out) # During signal, -4..4 #self.connect(self.fm_demod, self.scope2) else: self.connect(self.src, self.symbol_filter, self.demod_fsk4, self.protocol_processing) self.connect(self.src, self.scope) #self.connect(self.lf, self.scope) self.connect(self.demod_fsk4, self.scope2) #self.connect(self.symbol_filter, self.scope2) # --------------- End of most of the 4L-FSK hack & slash self._build_gui(vbox) # set initial values if options.gain is None: options.gain = 0 self.set_gain(options.gain)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Example bitcpf - FM Rx") _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 = 8e6 self.rx_gain = rx_gain = 15 self.lpf_decim = lpf_decim = 20 self.freq = freq = 106.7e6 self.audio_samp_rate = audio_samp_rate = 96e3 ################################################## # Blocks ################################################## _rx_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, label='rx_gain', converter=forms.float_converter(), proportion=0, ) self._rx_gain_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, minimum=0, maximum=30, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rx_gain_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio") self.Add(self.notebook_0) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label='freq', converter=forms.float_converter(), ) self.Add(self._freq_text_box) self.wxgui_fftsink2_1 = fftsink2.fft_sink_f( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate / lpf_decim, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.low_pass_filter_0 = gr.fir_filter_ccf( lpf_decim, firdes.low_pass(1, samp_rate, 100e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.gr_wavfile_sink_0 = gr.wavfile_sink("fm_record.wav", 1, int(audio_samp_rate), 8) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate / lpf_decim, audio_decimation=1, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=96, decimation=int(samp_rate / lpf_decim / 1000), taps=None, fractional_bw=None, ) self.audio_sink_0 = audio.sink(int(audio_samp_rate), "", True) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] input-samples-320kS.dat output.wav" parser=OptionParser(option_class=eng_option, usage=usage) parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) input_filename = args[0] output_filename = args[1] self.vol = 0 # build graph self.src = gr.file_source(gr.sizeof_gr_complex, input_filename, False) adc_rate = 64e6 # 64 MS/s usrp_decim = 200 usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz chan_filt_coeffs = optfir.low_pass (1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs) #self.guts = blks2.wfm_rcv (demod_rate, audio_decimation) self.guts = blks2.wfm_rcv_pll (demod_rate, audio_decimation) # FIXME rework {add,multiply}_const_* to handle multiple streams self.volume_control_l = gr.multiply_const_ff(self.vol) self.volume_control_r = gr.multiply_const_ff(self.vol) # wave file as final sink if 1: sink = gr.wavfile_sink(output_filename, 2, int(audio_rate), 16) else: sink = audio.sink (int (audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect (self.src, chan_filt, self.guts) self.connect ((self.guts, 0), self.volume_control_l, (sink, 0)) self.connect ((self.guts, 1), self.volume_control_r, (sink, 1)) try: self.guts.stereo_carrier_pll_recovery.squelch_enable(True) except: pass #print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet" if options.volume is None: g = self.volume_range() options.volume = float(g[0]+g[1])/2 # set initial values self.set_vol(options.volume) try: self.guts.stereo_carrier_pll_recovery.set_lock_threshold(options.squelch) except: pass
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel self.offset = 0.0 # Channel frequency offset parser = OptionParser(option_class=eng_option) parser.add_option( "-p", "--protocol", type="int", default=1, help="set protocol: 0 = RDLAP 19.2kbps; 1 = APCO25 (default)") parser.add_option("-g", "--gain", type="eng_float", default=1.0, help="set linear input gain (default: %default)") parser.add_option("-x", "--freq-translation", type="eng_float", default=0.0, help="initial channel frequency translation") parser.add_option( "-n", "--frame-decim", type="int", default=1, help="set oscope frame decimation factor to n [default=1]") parser.add_option( "-v", "--v-scale", type="eng_float", default=5000, help="set oscope initial V/div to SCALE [default=%default]") parser.add_option( "-t", "--t-scale", type="eng_float", default=49e-6, help="set oscope initial s/div to SCALE [default=50us]") parser.add_option( "-I", "--audio-input", type="string", default="", help="pcm input device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, help="set sample rate to RATE (default: %default)") parser.add_option( "-d", "--channel-decim", type="int", default=None, help= "set channel decimation factor to n [default depends on protocol]") parser.add_option("-w", "--wav-file", type="string", default=None, help="WAV input path") parser.add_option("-f", "--data-file", type="string", default=None, help="Data input path") parser.add_option("-B", "--base-band", action="store_true", default=False) parser.add_option("-R", "--repeat", action="store_true", default=False) parser.add_option("-o", "--wav-out", type="string", default=None, help="WAV output path") parser.add_option("-G", "--wav-out-gain", type="eng_float", default=0.05, help="set WAV output gain (default: %default)") parser.add_option("-F", "--data-out", type="string", default=None, help="Data output path") parser.add_option("-C", "--carrier-freq", type="eng_float", default=None, help="set data output carrier frequency to FREQ", metavar="FREQ") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.options = options if options.wav_file is not None: #try: self.input_file = gr.wavfile_source(options.wav_file, options.repeat) #except: # print "WAV file not found or not a WAV file" # sys.exit(1) print "WAV input: %i Hz, %i bits, %i channels" % ( self.input_file.sample_rate(), self.input_file.bits_per_sample(), self.input_file.channels()) self.sample_rate = self.input_file.sample_rate() self.input_stream = gr.throttle(gr.sizeof_float, self.sample_rate) self.connect(self.input_file, self.input_stream) self.src = gr.multiply_const_ff(options.gain) elif options.data_file is not None: if options.base_band: sample_size = gr.sizeof_float print "Data file is baseband (float)" self.src = gr.multiply_const_ff(options.gain) else: sample_size = gr.sizeof_gr_complex print "Data file is IF (complex)" self.src = gr.multiply_const_cc(options.gain) self.input_file = gr.file_source(sample_size, options.data_file, options.repeat) self.sample_rate = options.sample_rate # E.g. 250000 print "Data file sampling rate = " + str(self.sample_rate) self.input_stream = gr.throttle(sample_size, self.sample_rate) self.connect(self.input_file, self.input_stream) else: self.sample_rate = options.sample_rate print "Soundcard sampling rate = " + str(self.sample_rate) self.input_stream = audio.source( self.sample_rate, options.audio_input) # float samples self.src = gr.multiply_const_ff(options.gain) print "Fixed input gain = " + str(options.gain) self.connect(self.input_stream, self.src) if options.wav_out is not None: output_rate = int(self.sample_rate) if options.channel_decim is not None: output_rate /= options.channel_decim self.wav_out = gr.wavfile_sink(options.wav_out, 1, output_rate, 16) print "Opened WAV output file: " + options.wav_out + " at rate: " + str( output_rate) else: self.wav_out = None if options.data_out is not None: if options.carrier_freq is None: self.data_out = gr.file_sink(gr.sizeof_float, options.data_out) print "Opened float data output file: " + options.data_out else: self.data_out = gr.file_sink(gr.sizeof_gr_complex, options.data_out) print "Opened complex data output file: " + options.data_out else: self.data_out = None self.num_inputs = 1 input_rate = self.sample_rate #title='IF', #size=(1024,800), if (options.data_file is not None) and (options.base_band == False): self.scope = scopesink2.scope_sink_c( panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale, num_inputs=self.num_inputs) else: self.scope = scopesink2.scope_sink_f( panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale, num_inputs=self.num_inputs) #self.di = gr.deinterleave(gr.sizeof_float) #self.di = gr.complex_to_float(1) #self.di = gr.complex_to_imag() #self.dr = gr.complex_to_real() #self.connect(self.src,self.dr) #self.connect(self.src,self.di) #self.null = gr.null_sink(gr.sizeof_double) #self.connect(self.src,self.di) #self.connect((self.di,0),(self.scope,0)) #self.connect((self.di,1),(self.scope,1)) #self.connect(self.dr,(self.scope,0)) #self.connect(self.di,(self.scope,1)) self.msgq = gr.msg_queue(2) # queue that holds a maximum of 2 messages self.queue_watcher = queue_watcher(self.msgq, self.adjust_freq_norm) #------------------------------------------------------------------------------- if options.protocol == 0: # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel, print "RD-LAP selected" self.symbol_rate = 9600 # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps if options.channel_decim is None: self.channel_decimation = 10 # decimation (final rate should be at least several symbol rate) else: self.channel_decimation = options.channel_decim self.max_frequency_offset = 12000.0 # coarse carrier tracker leash, ~ half a channel either way self.symbol_deviation = 1200.0 # this is frequency offset from center of channel to +1 / -1 symbols self.input_sample_rate = self.sample_rate self.protocol_processing = fsk4.rdlap_f( self.msgq, 0) # desired protocol processing block selected here self.channel_rate = self.input_sample_rate / self.channel_decimation # channel selection filter characteristics channel_taps = optfir.low_pass( 1.0, # Filter gain self.input_sample_rate, # Sample rate 10000, # One-sided modulation bandwidth 12000, # One-sided channel bandwidth 0.1, # Passband ripple 60) # Stopband attenuation # symbol shaping filter characteristics symbol_coeffs = gr.firdes.root_raised_cosine( 1.0, # gain self.channel_rate, # sampling rate self.symbol_rate, # symbol rate 0.2, # alpha 500) # taps if options.protocol == 1: # ---------- APCO-25 C4FM Test Data print "APCO selected" self.symbol_rate = 4800 # symbol rate if options.channel_decim is None: self.channel_decimation = 20 # decimation else: self.channel_decimation = options.channel_decim self.max_frequency_offset = 6000.0 # coarse carrier tracker leash self.symbol_deviation = 600.0 # this is frequency offset from center of channel to +1 / -1 symbols self.input_sample_rate = self.sample_rate self.protocol_processing = fsk4.apco25_f(self.msgq, 0) self.channel_rate = self.input_sample_rate / self.channel_decimation # channel selection filter if (options.data_file is not None) and (options.base_band == False): channel_taps = optfir.low_pass( 1.0, # Filter gain self.input_sample_rate, # Sample rate 5000, # One-sided modulation bandwidth 6500, # One-sided channel bandwidth 0.2, # Passband ripple (was 0.1) 60) # Stopband attenuation else: channel_taps = None # symbol shaping filter symbol_coeffs = gr.firdes.root_raised_cosine( 1.0, # gain self.channel_rate, # sampling rate self.symbol_rate, # symbol rate 0.2, # alpha 500) # taps # ----------------- End of setup block print "Input rate = " + str(self.input_sample_rate) print "Channel decimation = " + str(self.channel_decimation) print "Channel rate = " + str(self.channel_rate) if channel_taps is not None: self.chan = gr.freq_xlating_fir_filter_ccf( self.channel_decimation, # Decimation rate channel_taps, # Filter taps 0.0, # Offset frequency self.input_sample_rate) # Sample rate if (options.freq_translation != 0): print "Channel center frequency = " + str( options.freq_translation) self.chan.set_center_freq(options.freq_translation) else: self.chan = None if options.carrier_freq is not None: print "Carrier frequency = " + str(options.carrier_freq) self.sig_carrier = gr.sig_source_c(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, 0) self.carrier_mul = gr.multiply_vcc(1) # cc(gr.sizeof_gr_complex) self.connect(self.sig_carrier, (self.carrier_mul, 0)) self.connect(self.chan, (self.carrier_mul, 1)) self.sig_i_carrier = gr.sig_source_f(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, 0) self.sig_q_carrier = gr.sig_source_f(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, (pi / 2.0)) self.carrier_i_mul = gr.multiply_ff(1) self.carrier_q_mul = gr.multiply_ff(1) self.iq_to_float = gr.complex_to_float(1) self.carrier_iq_add = gr.add_ff(1) self.connect(self.carrier_mul, self.iq_to_float) self.connect((self.iq_to_float, 0), (self.carrier_i_mul, 0)) self.connect((self.iq_to_float, 1), (self.carrier_q_mul, 0)) self.connect(self.sig_i_carrier, (self.carrier_i_mul, 1)) self.connect(self.sig_q_carrier, (self.carrier_q_mul, 1)) self.connect(self.carrier_i_mul, (self.carrier_iq_add, 0)) self.connect(self.carrier_q_mul, (self.carrier_iq_add, 1)) else: self.sig_carrier = None self.carrier_mul = None #lf_channel_taps = optfir.low_pass(1.0, # Filter gain # self.input_sample_rate, # Sample rate # 2500, # One-sided modulation bandwidth # 3250, # One-sided channel bandwidth # 0.1, # Passband ripple (0.1) # 60, # Stopband attenuation # 9) # Extra taps (default 2, which doesn't work at 48kHz) #self.lf = gr.fir_filter_fff(self.channel_decimation, lf_channel_taps) self.scope2 = scopesink2.scope_sink_f(panel, sample_rate=self.symbol_rate, frame_decim=1, v_scale=2, t_scale=0.025, num_inputs=self.num_inputs) # also note: this specifies the nominal frequency deviation for the 4-level fsk signal self.fm_demod_gain = self.channel_rate / (2.0 * pi * self.symbol_deviation) self.fm_demod = gr.quadrature_demod_cf(self.fm_demod_gain) symbol_decim = 1 self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs) # eventually specify: sample rate, symbol rate self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate, self.symbol_rate) if (self.chan is not None): self.connect(self.src, self.chan, self.fm_demod, self.symbol_filter, self.demod_fsk4, self.protocol_processing) if options.wav_out is not None: print "WAV output gain = " + str(options.wav_out_gain) self.scaled_wav_data = gr.multiply_const_ff( float(options.wav_out_gain)) self.connect(self.scaled_wav_data, self.wav_out) if self.carrier_mul is None: self.connect(self.fm_demod, self.scaled_wav_data) else: self.connect(self.carrier_iq_add, self.scaled_wav_data) if self.data_out is not None: if self.carrier_mul is None: self.connect(self.fm_demod, self.data_out) else: self.connect(self.carrier_mul, self.data_out) # During signal, -4..4 #self.connect(self.fm_demod, self.scope2) else: self.connect(self.src, self.symbol_filter, self.demod_fsk4, self.protocol_processing) self.connect(self.src, self.scope) #self.connect(self.lf, self.scope) self.connect(self.demod_fsk4, self.scope2) #self.connect(self.symbol_filter, self.scope2) # --------------- End of most of the 4L-FSK hack & slash self._build_gui(vbox) # set initial values if options.gain is None: options.gain = 0 self.set_gain(options.gain)
def __init__(self, devid="type=b100", rdsfile="rds_fifo", gain=35.0, freq=101.1e6, xmlport=13777, arate=int(48e3), mute=-15.0, ftune=0, ant="J1", subdev="A:0", ahw="pulse", deemph=75.0e-6, prenames='["UWRF","89.3","950","WEVR"]', prefreqs="[88.715e6,89.3e6,950.735e6,106.317e6]", volume=1.0): grc_wxgui.top_block_gui.__init__(self, title="Simple FM (Stereo) Receiver") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.devid = devid self.rdsfile = rdsfile self.gain = gain self.freq = freq self.xmlport = xmlport self.arate = arate self.mute = mute self.ftune = ftune self.ant = ant self.subdev = subdev self.ahw = ahw self.deemph = deemph self.prenames = prenames self.prefreqs = prefreqs self.volume = volume ################################################## # Variables ################################################## self.pthresh = pthresh = 350 self.preselect = preselect = eval(prefreqs)[0] self.pilot_level = pilot_level = 0 self.ifreq = ifreq = freq self.stpilotdet = stpilotdet = True if (pilot_level > pthresh) else False self.stereo = stereo = True self.rf_pwr_lvl = rf_pwr_lvl = 0 self.cur_freq = cur_freq = simple_fm_helper.freq_select(ifreq,preselect) self.vol = vol = volume self.variable_static_text_0 = variable_static_text_0 = 10.0*math.log(rf_pwr_lvl+1.0e-11)/math.log(10) self.tone_med = tone_med = 5 self.tone_low = tone_low = 5 self.tone_high = tone_high = 5 self.stereo_0 = stereo_0 = stpilotdet self.st_enabled = st_enabled = 1 if (stereo == True and pilot_level > pthresh) else 0 self.squelch_probe = squelch_probe = 0 self.sq_thresh = sq_thresh = mute self.samp_rate = samp_rate = 250e3 self.rtext_0 = rtext_0 = cur_freq self.record = record = False self.rdsrate = rdsrate = 25e3 self.osmo_taps = osmo_taps = firdes.low_pass(1.0,1.00e6,95e3,20e3,firdes.WIN_HAMMING,6.76) self.mod_reset = mod_reset = 0 self.igain = igain = gain self.fine = fine = ftune self.farate = farate = arate self.dm = dm = deemph self.discrim_dc = discrim_dc = 0 self.capture_file = capture_file = "capture.wav" self.asrate = asrate = 125e3 ################################################## # Blocks ################################################## _sq_thresh_sizer = wx.BoxSizer(wx.VERTICAL) self._sq_thresh_text_box = forms.text_box( parent=self.GetWin(), sizer=_sq_thresh_sizer, value=self.sq_thresh, callback=self.set_sq_thresh, label="Mute Level", converter=forms.float_converter(), proportion=0, ) self._sq_thresh_slider = forms.slider( parent=self.GetWin(), sizer=_sq_thresh_sizer, value=self.sq_thresh, callback=self.set_sq_thresh, minimum=-30.0, maximum=-5.0, num_steps=40, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_sq_thresh_sizer, 1, 5, 1, 1) self.input_power = gr.probe_avg_mag_sqrd_c(sq_thresh, 1.0/(samp_rate/10)) self.dc_level = gr.probe_signal_f() _vol_sizer = wx.BoxSizer(wx.VERTICAL) self._vol_text_box = forms.text_box( parent=self.GetWin(), sizer=_vol_sizer, value=self.vol, callback=self.set_vol, label="Volume", converter=forms.float_converter(), proportion=0, ) self._vol_slider = forms.slider( parent=self.GetWin(), sizer=_vol_sizer, value=self.vol, callback=self.set_vol, minimum=0, maximum=11, num_steps=110, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_vol_sizer, 0, 3, 1, 1) _tone_med_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_med_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_med_sizer, value=self.tone_med, callback=self.set_tone_med, label="1Khz-4Khz", converter=forms.float_converter(), proportion=0, ) self._tone_med_slider = forms.slider( parent=self.GetWin(), sizer=_tone_med_sizer, value=self.tone_med, callback=self.set_tone_med, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_med_sizer, 1, 3, 1, 1) _tone_low_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_low_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_low_sizer, value=self.tone_low, callback=self.set_tone_low, label="0-1Khz", converter=forms.float_converter(), proportion=0, ) self._tone_low_slider = forms.slider( parent=self.GetWin(), sizer=_tone_low_sizer, value=self.tone_low, callback=self.set_tone_low, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_low_sizer, 1, 2, 1, 1) _tone_high_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_high_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_high_sizer, value=self.tone_high, callback=self.set_tone_high, label="4Khz-15Khz", converter=forms.float_converter(), proportion=0, ) self._tone_high_slider = forms.slider( parent=self.GetWin(), sizer=_tone_high_sizer, value=self.tone_high, callback=self.set_tone_high, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_high_sizer, 1, 4, 1, 1) def _squelch_probe_probe(): while True: val = self.input_power.unmuted() try: self.set_squelch_probe(val) except AttributeError, e: pass time.sleep(1.0/(10)) _squelch_probe_thread = threading.Thread(target=_squelch_probe_probe) _squelch_probe_thread.daemon = True _squelch_probe_thread.start() self._record_check_box = forms.check_box( parent=self.GetWin(), value=self.record, callback=self.set_record, label="Record Audio", true=True, false=False, ) self.GridAdd(self._record_check_box, 2, 2, 1, 1) self.pilot_probe = gr.probe_signal_f() _fine_sizer = wx.BoxSizer(wx.VERTICAL) self._fine_text_box = forms.text_box( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, label="Fine Tuning", converter=forms.float_converter(), proportion=0, ) self._fine_slider = forms.slider( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, minimum=-50.0e3, maximum=50.e03, num_steps=400, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_fine_sizer, 1, 0, 1, 1) def _discrim_dc_probe(): while True: val = self.dc_level.level() try: self.set_discrim_dc(val) except AttributeError, e: pass time.sleep(1.0/(2.5)) _discrim_dc_thread = threading.Thread(target=_discrim_dc_probe) _discrim_dc_thread.daemon = True _discrim_dc_thread.start() self._capture_file_text_box = forms.text_box( parent=self.GetWin(), value=self.capture_file, callback=self.set_capture_file, label="Record Filename", converter=forms.str_converter(), ) self.GridAdd(self._capture_file_text_box, 2, 0, 1, 2) self.Main = self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.Main.AddPage(grc_wxgui.Panel(self.Main), "L/R") self.Main.AddPage(grc_wxgui.Panel(self.Main), "FM Demod Spectrum") self.Add(self.Main) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.Add(self.wxgui_waterfallsink2_0.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.Main.GetPage(0).GetWin(), title="Audio Channels (L and R)", sample_rate=farate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Rel. Audio Level", ) self.Main.GetPage(0).Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.Main.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=asrate, fft_size=1024, fft_rate=6, average=True, avg_alpha=0.1, title="FM Demod Spectrum", peak_hold=False, ) self.Main.GetPage(1).Add(self.wxgui_fftsink2_0.win) self._variable_static_text_0_static_text = forms.static_text( parent=self.GetWin(), value=self.variable_static_text_0, callback=self.set_variable_static_text_0, label="RF Power ", converter=forms.float_converter(formatter=lambda x: "%4.1f" % x), ) self.GridAdd(self._variable_static_text_0_static_text, 0, 2, 1, 1) self._stereo_0_check_box = forms.check_box( parent=self.GetWin(), value=self.stereo_0, callback=self.set_stereo_0, label="Stereo Detect", true=True, false=False, ) self.GridAdd(self._stereo_0_check_box, 2, 5, 1, 1) self._stereo_check_box = forms.check_box( parent=self.GetWin(), value=self.stereo, callback=self.set_stereo, label="Stereo", true=True, false=False, ) self.GridAdd(self._stereo_check_box, 2, 4, 1, 1) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_sample_rate(1.0e6) self.rtl2832_source_0.set_frequency(cur_freq+200e3) self.rtl2832_source_0.set_auto_gain_mode(False) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(gain) self._rtext_0_static_text = forms.static_text( parent=self.GetWin(), value=self.rtext_0, callback=self.set_rtext_0, label="CURRENT FREQUENCY>>", converter=forms.float_converter(), ) self.GridAdd(self._rtext_0_static_text, 0, 1, 1, 1) def _rf_pwr_lvl_probe(): while True: val = self.input_power.level() try: self.set_rf_pwr_lvl(val) except AttributeError, e: pass time.sleep(1.0/(2)) _rf_pwr_lvl_thread = threading.Thread(target=_rf_pwr_lvl_probe) _rf_pwr_lvl_thread.daemon = True _rf_pwr_lvl_thread.start() self._preselect_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.preselect, callback=self.set_preselect, label='preselect', choices=eval(prefreqs), labels=eval(prenames), style=wx.RA_HORIZONTAL, ) self.GridAdd(self._preselect_chooser, 0, 4, 1, 1) def _pilot_level_probe(): while True: val = self.pilot_probe.level() try: self.set_pilot_level(val) except AttributeError, e: pass time.sleep(1.0/(5)) _pilot_level_thread = threading.Thread(target=_pilot_level_probe) _pilot_level_thread.daemon = True _pilot_level_thread.start() self.low_pass_filter_3 = gr.fir_filter_fff(1, firdes.low_pass( 3, asrate/500, 10, 3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2 = gr.fir_filter_fff(10, firdes.low_pass( 3, asrate/50, 100, 30, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1 = gr.fir_filter_fff(10, firdes.low_pass( 3, asrate/5, 1e3, 200, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = gr.fir_filter_fff(5, firdes.low_pass( 3, asrate, 10e3, 2e3, firdes.WIN_HAMMING, 6.76)) _igain_sizer = wx.BoxSizer(wx.VERTICAL) self._igain_text_box = forms.text_box( parent=self.GetWin(), sizer=_igain_sizer, value=self.igain, callback=self.set_igain, label="RF Gain", converter=forms.float_converter(), proportion=0, ) self._igain_slider = forms.slider( parent=self.GetWin(), sizer=_igain_sizer, value=self.igain, callback=self.set_igain, minimum=0, maximum=50, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_igain_sizer, 1, 1, 1, 1) _ifreq_sizer = wx.BoxSizer(wx.VERTICAL) self._ifreq_text_box = forms.text_box( parent=self.GetWin(), sizer=_ifreq_sizer, value=self.ifreq, callback=self.set_ifreq, label="Center Frequency", converter=forms.float_converter(), proportion=0, ) self._ifreq_slider = forms.slider( parent=self.GetWin(), sizer=_ifreq_sizer, value=self.ifreq, callback=self.set_ifreq, minimum=88.1e6, maximum=108.1e6, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_ifreq_sizer, 0, 0, 1, 1) self.gr_wavfile_sink_0 = gr.wavfile_sink("/dev/null" if record == False else capture_file, 2, int(farate), 16) self.gr_sub_xx_0 = gr.sub_ff(1) self.gr_single_pole_iir_filter_xx_1 = gr.single_pole_iir_filter_ff(2.5/(asrate/500), 1) self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff(1.0/(asrate/3), 1) self.gr_multiply_xx_1 = gr.multiply_vff(1) self.gr_multiply_xx_0_0 = gr.multiply_vff(1) self.gr_multiply_xx_0 = gr.multiply_vff(1) self.gr_multiply_const_vxx_3 = gr.multiply_const_vff((3.16e3 if st_enabled else 0, )) self.gr_multiply_const_vxx_2 = gr.multiply_const_vff((1.0 if st_enabled else 1.414, )) self.gr_multiply_const_vxx_1_0 = gr.multiply_const_vff((0 if st_enabled else 1, )) self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((0 if squelch_probe == 0 else 1.0, )) self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vff((vol*1.5*10.0, )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((vol*1.5*10.0 if st_enabled else 0, )) self.gr_keep_one_in_n_0 = gr.keep_one_in_n(gr.sizeof_float*1, int(asrate/3)) self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(4, (osmo_taps), 200e3+fine+(-12e3*discrim_dc), 1.0e6) self.gr_fractional_interpolator_xx_0_0 = gr.fractional_interpolator_ff(0, asrate/farate) self.gr_fractional_interpolator_xx_0 = gr.fractional_interpolator_ff(0, asrate/farate) self.gr_fft_filter_xxx_1_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_high/10.0,asrate,3.5e3,15.0e3,5.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_1_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_med/10.0,asrate,1.0e3,4.0e3,2.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_1 = gr.fft_filter_fff(1, (firdes.low_pass(tone_low/10.0,asrate,1.2e3,500,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_high/10.0,asrate,3.5e3,13.5e3,3.5e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_med/10.0,asrate,1.0e3,4.0e3,2.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0 = gr.fft_filter_fff(1, (firdes.low_pass(tone_low/10.0,asrate,1.2e3,500,firdes.WIN_HAMMING)), 1) self.gr_divide_xx_0 = gr.divide_ff(1) self.gr_agc_xx_1 = gr.agc_cc(1e-2, 0.35, 1.0, 5000) self.gr_add_xx_2_0 = gr.add_vff(1) self.gr_add_xx_2 = gr.add_vff(1) self.gr_add_xx_1 = gr.add_vff(1) self.gr_add_xx_0 = gr.add_vff(1) self.gr_add_const_vxx_0 = gr.add_const_vff((1.0e-7, )) self._dm_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.dm, callback=self.set_dm, label="FM Deemphasis", choices=[75.0e-6, 50.0e-6], labels=["NA", "EU"], style=wx.RA_HORIZONTAL, ) self.GridAdd(self._dm_chooser, 0, 5, 1, 1) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate, audio_decimation=2, ) self.blks2_fm_deemph_0_0 = blks2.fm_deemph(fs=farate, tau=deemph) self.blks2_fm_deemph_0 = blks2.fm_deemph(fs=farate, tau=deemph) self.band_pass_filter_2_0 = gr.fir_filter_fff(1, firdes.band_pass( 20, asrate, 17.5e3, 17.9e3, 250, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_2 = gr.fir_filter_fff(1, firdes.band_pass( 10, asrate, 18.8e3, 19.2e3, 350, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0_0 = gr.fir_filter_fff(1, firdes.band_pass( 1, asrate, 38e3-(15e3), 38e3+(15e3), 4.0e3, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0 = audio.sink(int(farate), "" if ahw == "Default" else ahw, True) ################################################## # Connections ################################################## self.connect((self.gr_add_xx_1, 0), (self.gr_fractional_interpolator_xx_0, 0)) self.connect((self.gr_sub_xx_0, 0), (self.gr_fractional_interpolator_xx_0_0, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.gr_multiply_xx_1, 0)) self.connect((self.gr_multiply_const_vxx_1_0, 0), (self.gr_add_xx_0, 0)) self.connect((self.band_pass_filter_2_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.band_pass_filter_2_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_multiply_xx_0_0, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_divide_xx_0, 0), (self.gr_single_pole_iir_filter_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_add_const_vxx_0, 0)) self.connect((self.gr_add_const_vxx_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_keep_one_in_n_0, 0)) self.connect((self.gr_keep_one_in_n_0, 0), (self.pilot_probe, 0)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_1, 2)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_0_0, 0)) self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_add_xx_1, 0)) self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_sub_xx_0, 0)) self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_sub_xx_0, 1)) self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_add_xx_1, 1)) self.connect((self.gr_fractional_interpolator_xx_0, 0), (self.gr_multiply_const_vxx_0_0, 0)) self.connect((self.gr_fractional_interpolator_xx_0_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0, 0)) self.connect((self.gr_fft_filter_xxx_1, 0), (self.gr_add_xx_2, 0)) self.connect((self.gr_fft_filter_xxx_1_0, 0), (self.gr_add_xx_2, 1)) self.connect((self.gr_fft_filter_xxx_1_0_0, 0), (self.gr_add_xx_2, 2)) self.connect((self.gr_add_xx_2, 0), (self.gr_multiply_const_vxx_2, 0)) self.connect((self.gr_add_xx_2_0, 0), (self.gr_multiply_const_vxx_3, 0)) self.connect((self.gr_fft_filter_xxx_0, 0), (self.gr_add_xx_2_0, 0)) self.connect((self.gr_fft_filter_xxx_0_0, 0), (self.gr_add_xx_2_0, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0_0, 0)) self.connect((self.gr_fft_filter_xxx_0_0_0, 0), (self.gr_add_xx_2_0, 2)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0_0_0, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.gr_multiply_const_vxx_1_0, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1_0_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.blks2_fm_deemph_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.audio_sink_0, 1)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_fm_deemph_0_0, 0)) self.connect((self.blks2_fm_deemph_0_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_0_0, 1)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_2, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.audio_sink_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_2_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_wavfile_sink_0, 1)) self.connect((self.blks2_fm_deemph_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.blks2_wfm_rcv_0, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_agc_xx_1, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.gr_agc_xx_1, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.input_power, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.low_pass_filter_1, 0), (self.low_pass_filter_2, 0)) self.connect((self.low_pass_filter_2, 0), (self.low_pass_filter_3, 0)) self.connect((self.gr_single_pole_iir_filter_xx_1, 0), (self.dc_level, 0)) self.connect((self.low_pass_filter_3, 0), (self.gr_single_pole_iir_filter_xx_1, 0)) self.connect((self.rtl2832_source_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_waterfallsink2_0, 0))
def __init__(self, options, queue): gr.top_block.__init__(self) if options.filename is not None: self.fs = gr.file_source(gr.sizeof_gr_complex, options.filename) self.rate = 64000000 / options.decim # allow setting of recorded decimation in options else: self.u = usrp.source_c() self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % self.subdev.side_and_name() self.u.set_decim_rate(options.decim) self.centerfreq = options.centerfreq print "Tuning to: %fMHz" % (self.centerfreq - options.error) if not(self.tune(options.centerfreq - options.error)): print "Failed to set initial frequency" if options.gain is None: #set to halfway g = self.subdev.gain_range() options.gain = (g[0]+g[1]) / 2.0 print "Setting gain to %i" % options.gain self.subdev.set_gain(options.gain) if self.subdev.name() == "DBS Rx": self.subdev.set_bw(options.bandwidth) #only for DBSRX print "Setting DBS RX bandwidth to %fMHz" % float(options.bandwidth / 1e6) self.rate = self.u.adc_rate() / options.decim print "Samples per second is %i" % self.rate self._syms_per_sec = 3600; options.samples_per_second = self.rate options.syms_per_sec = self._syms_per_sec options.gain_mu = 0.01 options.mu=0.5 options.omega_relative_limit = 0.3 options.syms_per_sec = self._syms_per_sec options.offset = options.centerfreq - options.freq print "Control channel offset: %f" % options.offset self.demod = fsk_demod(options) self.start_correlator = gr.correlate_access_code_bb("10101100",0) #should mark start of packet self.smartnet_sync = smartnet.sync() self.smartnet_deinterleave = smartnet.deinterleave() self.smartnet_parity = smartnet.parity() self.smartnet_crc = smartnet.crc() self.smartnet_packetize = smartnet.packetize() self.parse = smartnet.parse(queue) #packet-based. this simply posts lightly-formatted messages to the queue. # self.filesink = gr.file_sink(gr.sizeof_char*16, "smartnet_decoded.dat") #set a friggin filename in the options # self.paritysink = gr.file_sink(gr.sizeof_char, "smartnet_parity.dat") if options.filename is None: self.connect(self.u, self.demod) else: self.connect(self.fs, self.demod) self.connect(self.demod, self.start_correlator, self.smartnet_sync, self.smartnet_deinterleave, self.smartnet_parity, self.smartnet_crc, self.smartnet_packetize, self.parse) #hook up the audio patch if options.audio: self.audiorate = 48000 # self.audiodemoddecim = 4 self.audiotaps = gr.firdes.low_pass(1, self.rate, 8000, 2000, firdes.WIN_HANN) self.prefilter_decim = (self.rate / self.audiorate) #might have to use a rational resampler for audio print "Prefilter decimation: %i" % self.prefilter_decim self.audio_prefilter = gr.freq_xlating_fir_filter_ccc(self.prefilter_decim, #decimation self.audiotaps, #taps 0, #freq offset self.rate) #sampling rate #on a trunked network where you know you will have good signal, a carrier power squelch works well. real FM receviers use a noise squelch, where #the received audio is high-passed above the cutoff and then fed to a reverse squelch. If the power is then BELOW a threshold, open the squelch. self.squelch = gr.pwr_squelch_cc(options.squelch, #squelch point alpha = 0.1, #wat ramp = 10, #wat gate = False) self.audiodemod = blks2.fm_demod_cf(self.rate/self.prefilter_decim, #rate 1, #audio decimation 4000, #deviation 3000, #audio passband 4000, #audio stopband 1, #gain 75e-6) #deemphasis constant #the point of the resampler is to bring data to the soundcard at a rate it supports, but it seems to sound fine without it, and it saves some CPU cycles not to have it #the audio rate is 48kHz because seemingly it's all my *&$# integrated sound card will support, otherwise it'd be like 8k or something reasonable #running a 48kHz audio rate isn't the end of the world -- with decim 18 and prefilter decim 74, the native rate is 48.048kHz. that's close enough to avoid the resampler. # self.gcd = self.euclid(self.audiorate, self.rate/self.prefilter_decim) # print "Resampling: decim %i, interp %i" % (self.rate/self.prefilter_decim/self.gcd, self.audiorate/self.gcd) # self.audioresamp = blks2.rational_resampler_fff(self.audiorate/self.gcd, self.rate/self.prefilter_decim/self.gcd)#, self.audiofilttaps) #the filtering removes FSK data woobling from the subaudible channel self.audiofilttaps = gr.firdes.high_pass(1, self.audiorate, 300, 50, firdes.WIN_HANN) self.audiofilt = gr.fir_filter_fff(1, self.audiofilttaps) self.audiogain = gr.multiply_const_ff(options.volume) # self.audiosink = audio.sink (self.audiorate, "") self.audiosink = gr.wavfile_sink("test.wav", 1, self.audiorate, 8) self.mute() if options.filename is None: self.connect(self.u, self.audio_prefilter) else: self.connect(self.fs, self.audio_prefilter) # self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audioresamp, self.audiosink) self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audiosink)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Am Aviation") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.sql_threshold = sql_threshold = -30 self.samp_rate = samp_rate = 1000000 self.frq_offset = frq_offset = 0 self.base_frq = base_frq = 134.5e6 ################################################## # Blocks ################################################## _sql_threshold_sizer = wx.BoxSizer(wx.VERTICAL) self._sql_threshold_text_box = forms.text_box( parent=self.GetWin(), sizer=_sql_threshold_sizer, value=self.sql_threshold, callback=self.set_sql_threshold, label="Squelch Threshold", converter=forms.float_converter(), proportion=0, ) self._sql_threshold_slider = forms.slider( parent=self.GetWin(), sizer=_sql_threshold_sizer, value=self.sql_threshold, callback=self.set_sql_threshold, minimum=-100, maximum=0, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_sql_threshold_sizer) _frq_offset_sizer = wx.BoxSizer(wx.VERTICAL) self._frq_offset_text_box = forms.text_box( parent=self.GetWin(), sizer=_frq_offset_sizer, value=self.frq_offset, callback=self.set_frq_offset, label="Frequency Offset", converter=forms.float_converter(), proportion=0, ) self._frq_offset_slider = forms.slider( parent=self.GetWin(), sizer=_frq_offset_sizer, value=self.frq_offset, callback=self.set_frq_offset, minimum=-30e6, maximum=10e6, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_frq_offset_sizer) self._base_frq_text_box = forms.text_box( parent=self.GetWin(), value=self.base_frq, callback=self.set_base_frq, label="Base frequency", converter=forms.float_converter(), ) self.Add(self._base_frq_text_box) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.Add(self.wxgui_waterfallsink2_0.win) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_bandwidth(500000) self.rtl2832_source_0.set_sample_rate(samp_rate) self.rtl2832_source_0.set_frequency(base_frq+frq_offset) self.rtl2832_source_0.set_auto_gain_mode(True) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(30) self.gr_wavfile_sink_0 = gr.wavfile_sink("/home/louis/Dropbox/sdr/AM/134.5MHZ.am.wav", 1, 48000, 16) self.gr_simple_squelch_cc_0 = gr.simple_squelch_cc(sql_threshold, 0.0001) self.gr_agc2_xx_0 = gr.agc2_cc(100e-3, 200e-3, 1.0, 1.0, 2.0) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc( interpolation=48, decimation=1000, taps=None, fractional_bw=None, ) self.blks2_am_demod_cf_0 = blks2.am_demod_cf( channel_rate=48000, audio_decim=1, audio_pass=5000, audio_stop=5500, ) self.audio_sink_0 = audio.sink(48000, "pulse", True) ################################################## # Connections ################################################## self.connect((self.blks2_am_demod_cf_0, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_simple_squelch_cc_0, 0)) self.connect((self.gr_simple_squelch_cc_0, 0), (self.gr_agc2_xx_0, 0)) self.connect((self.gr_agc2_xx_0, 0), (self.blks2_am_demod_cf_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.blks2_am_demod_cf_0, 0), (self.gr_wavfile_sink_0, 0))
def __init__(self, ahw="default", freq=150.0e6, ppm=0.0, vol=1.0, ftune=0.0, xftune=0.0, srate=1.0e6, upclo=0.0, devinfo="rtl=0", agc=0, arate=48.0e3, upce=0, mthresh=-10.0, offs=50.e3, flist="", dfifo="multimode_fifo", mbw=2.0e3, deemph=75.0e-6, dmode="NFM1"): grc_wxgui.top_block_gui.__init__(self, title="Multimode Radio Receiver") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.ahw = ahw self.freq = freq self.ppm = ppm self.vol = vol self.ftune = ftune self.xftune = xftune self.srate = srate self.upclo = upclo self.devinfo = devinfo self.agc = agc self.arate = arate self.upce = upce self.mthresh = mthresh self.offs = offs self.flist = flist self.dfifo = dfifo self.mbw = mbw self.deemph = deemph self.dmode = dmode ################################################## # Variables ################################################## self.sc_list_str = sc_list_str = flist self.zoom = zoom = 1 self.thresh = thresh = mthresh self.scan_rate = scan_rate = 15 self.scan_power = scan_power = 0 self.sc_low = sc_low = 150e6 self.sc_listm = sc_listm = False self.sc_list = sc_list = eval("["+sc_list_str+"]") self.sc_incr = sc_incr = 12.5e3 self.sc_high = sc_high = 300e6 self.sc_ena = sc_ena = False self.samp_rate = samp_rate = int(mh.get_good_rate(devinfo,srate)) self.rf_power = rf_power = 0 self.ifreq = ifreq = freq self.zoomed_lp = zoomed_lp = (samp_rate/2.1)/zoom self.wbfm = wbfm = 200e3 self.rf_d_power = rf_d_power = 0 self.mode = mode = dmode self.logpower = logpower = math.log10(rf_power+1.0e-14)*10.0 self.cur_freq = cur_freq = mh.scan_freq_out(sc_ena,sc_low,sc_high,freq,ifreq,scan_power+1.0e-14,thresh,sc_incr,scan_rate,sc_listm,sc_list) self.bw = bw = mbw self.audio_int_rate = audio_int_rate = 40e3 self.zoom_taps = zoom_taps = firdes.low_pass(1.0,samp_rate,zoomed_lp,zoomed_lp/3,firdes.WIN_HAMMING,6.76) self.xfine = xfine = xftune self.volume = volume = vol self.variable_static_text_1 = variable_static_text_1 = cur_freq self.variable_static_text_0_0 = variable_static_text_0_0 = samp_rate self.variable_static_text_0 = variable_static_text_0 = float(int(math.log10(rf_d_power+1.0e-14)*100.0)/10.0) self.upc_offset = upc_offset = upclo self.upc = upc = upce self.ssbo = ssbo = -bw/2 if mode == "LSB" else 0.0 self.sc_list_len = sc_list_len = len(sc_list) self.rfgain = rfgain = 25 self.record_file = record_file = "recording.wav" self.record = record = False self.offset = offset = offs self.muted = muted = 0.0 if logpower >= thresh else 1 self.main_taps = main_taps = firdes.low_pass(1.0,wbfm,mh.get_mode_deviation(mode,bw)*1.05,mh.get_mode_deviation(mode,bw)/2.0,firdes.WIN_HAMMING,6.76) self.k = k = wbfm/(2*math.pi*mh.get_mode_deviation(mode,bw)) self.iagc = iagc = agc self.freq_update = freq_update = 0 self.fine = fine = ftune self.digi_rate = digi_rate = 50e3 self.aratio = aratio = int(wbfm/audio_int_rate) ################################################## # Blocks ################################################## self.rf_probe = gr.probe_avg_mag_sqrd_c(0, 0.015) self.Main = self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.Main.AddPage(grc_wxgui.Panel(self.Main), "Main Controls") self.Main.AddPage(grc_wxgui.Panel(self.Main), "Scan/Upconv Controls") self.Add(self.Main) self._zoom_chooser = forms.drop_down( parent=self.Main.GetPage(0).GetWin(), value=self.zoom, callback=self.set_zoom, label="Spectral Zoom Ratio", choices=[1, 2, 5, 10, 20, 50, 100], labels=[], ) self.Main.GetPage(0).GridAdd(self._zoom_chooser, 1, 4, 1, 1) _xfine_sizer = wx.BoxSizer(wx.VERTICAL) self._xfine_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), sizer=_xfine_sizer, value=self.xfine, callback=self.set_xfine, label="Extra Fine Tuning", converter=forms.float_converter(), proportion=0, ) self._xfine_slider = forms.slider( parent=self.Main.GetPage(0).GetWin(), sizer=_xfine_sizer, value=self.xfine, callback=self.set_xfine, minimum=-1.0e3, maximum=1.0e3, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Main.GetPage(0).GridAdd(_xfine_sizer, 0, 3, 1, 1) _volume_sizer = wx.BoxSizer(wx.VERTICAL) self._volume_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, label="Volume", converter=forms.float_converter(), proportion=0, ) self._volume_slider = forms.slider( parent=self.Main.GetPage(0).GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, minimum=1.0, maximum=10.0, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Main.GetPage(0).GridAdd(_volume_sizer, 0, 0, 1, 1) self._upc_offset_text_box = forms.text_box( parent=self.Main.GetPage(1).GetWin(), value=self.upc_offset, callback=self.set_upc_offset, label="Upconv. LO Freq", converter=forms.float_converter(), ) self.Main.GetPage(1).GridAdd(self._upc_offset_text_box, 3, 2, 1, 2) self._upc_check_box = forms.check_box( parent=self.Main.GetPage(1).GetWin(), value=self.upc, callback=self.set_upc, label="Ext. Upconv.", true=1, false=0, ) self.Main.GetPage(1).GridAdd(self._upc_check_box, 3, 0, 1, 1) _rfgain_sizer = wx.BoxSizer(wx.VERTICAL) self._rfgain_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), sizer=_rfgain_sizer, value=self.rfgain, callback=self.set_rfgain, label="RF Gain", converter=forms.float_converter(), proportion=0, ) self._rfgain_slider = forms.slider( parent=self.Main.GetPage(0).GetWin(), sizer=_rfgain_sizer, value=self.rfgain, callback=self.set_rfgain, minimum=0, maximum=50, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Main.GetPage(0).GridAdd(_rfgain_sizer, 2, 1, 1, 1) self._record_file_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), value=self.record_file, callback=self.set_record_file, label="Recording Filename", converter=forms.str_converter(), ) self.Main.GetPage(0).GridAdd(self._record_file_text_box, 2, 3, 1, 3) self._record_check_box = forms.check_box( parent=self.Main.GetPage(0).GetWin(), value=self.record, callback=self.set_record, label="Record", true=True, false=False, ) self.Main.GetPage(0).GridAdd(self._record_check_box, 2, 2, 1, 1) _offset_sizer = wx.BoxSizer(wx.VERTICAL) self._offset_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), sizer=_offset_sizer, value=self.offset, callback=self.set_offset, label="LO Offset", converter=forms.float_converter(), proportion=0, ) self._offset_slider = forms.slider( parent=self.Main.GetPage(0).GetWin(), sizer=_offset_sizer, value=self.offset, callback=self.set_offset, minimum=25e3, maximum=500e3, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Main.GetPage(0).GridAdd(_offset_sizer, 1, 3, 1, 1) self._mode_chooser = forms.drop_down( parent=self.Main.GetPage(0).GetWin(), value=self.mode, callback=self.set_mode, label="Mode", choices=mh.get_modes_values(), labels=mh.get_modes_names(), ) self.Main.GetPage(0).GridAdd(self._mode_chooser, 0, 4, 1, 1) self._iagc_check_box = forms.check_box( parent=self.Main.GetPage(0).GetWin(), value=self.iagc, callback=self.set_iagc, label="AGC", true=1, false=0, ) self.Main.GetPage(0).GridAdd(self._iagc_check_box, 2, 0, 1, 1) def _freq_update_probe(): while True: val = self.rf_probe.level() try: self.set_freq_update(val) except AttributeError, e: pass time.sleep(1.0/(1.0/(2.5))) _freq_update_thread = threading.Thread(target=_freq_update_probe) _freq_update_thread.daemon = True _freq_update_thread.start() _fine_sizer = wx.BoxSizer(wx.VERTICAL) self._fine_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, label="Fine Tuning", converter=forms.float_converter(), proportion=0, ) self._fine_slider = forms.slider( parent=self.Main.GetPage(0).GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, minimum=-35e3, maximum=35e3, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Main.GetPage(0).GridAdd(_fine_sizer, 0, 2, 1, 1) self.display_probe = gr.probe_avg_mag_sqrd_c(0, 0.002) _bw_sizer = wx.BoxSizer(wx.VERTICAL) self._bw_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), sizer=_bw_sizer, value=self.bw, callback=self.set_bw, label="AM/SSB Bandwidth", converter=forms.float_converter(), proportion=0, ) self._bw_slider = forms.slider( parent=self.Main.GetPage(0).GetWin(), sizer=_bw_sizer, value=self.bw, callback=self.set_bw, minimum=1.0e3, maximum=audio_int_rate/2, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Main.GetPage(0).GridAdd(_bw_sizer, 1, 2, 1, 1) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.Main.GetPage(0).GetWin(), baseband_freq=mh.get_last_returned(freq_update), dynamic_range=40, ref_level=0, ref_scale=2.0, sample_rate=samp_rate/zoom, fft_size=1024, fft_rate=4, average=True, avg_alpha=None, title="Spectrogram", win=window.hamming, ) self.Main.GetPage(0).Add(self.wxgui_waterfallsink2_0.win) def wxgui_waterfallsink2_0_callback(x, y): self.set_freq(x) self.wxgui_waterfallsink2_0.set_callback(wxgui_waterfallsink2_0_callback) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.Main.GetPage(0).GetWin(), baseband_freq=mh.get_last_returned(freq_update), y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate/zoom, fft_size=1024, fft_rate=4, average=True, avg_alpha=0.1, title="Panorama", peak_hold=False, win=window.hamming, ) self.Main.GetPage(0).Add(self.wxgui_fftsink2_0.win) def wxgui_fftsink2_0_callback(x, y): self.set_freq(x) self.wxgui_fftsink2_0.set_callback(wxgui_fftsink2_0_callback) self._variable_static_text_1_static_text = forms.static_text( parent=self.Main.GetPage(1).GetWin(), value=self.variable_static_text_1, callback=self.set_variable_static_text_1, label="Current Scan Freq", converter=forms.float_converter(), ) self.Main.GetPage(1).GridAdd(self._variable_static_text_1_static_text, 0, 5, 1, 2) self._variable_static_text_0_0_static_text = forms.static_text( parent=self.Main.GetPage(0).GetWin(), value=self.variable_static_text_0_0, callback=self.set_variable_static_text_0_0, label="Actual srate", converter=forms.float_converter(), ) self.Main.GetPage(0).GridAdd(self._variable_static_text_0_0_static_text, 1, 5, 1, 1) self._variable_static_text_0_static_text = forms.static_text( parent=self.Main.GetPage(0).GetWin(), value=self.variable_static_text_0, callback=self.set_variable_static_text_0, label="RF Level", converter=forms.float_converter(), ) self.Main.GetPage(0).GridAdd(self._variable_static_text_0_static_text, 1, 0, 1, 1) _thresh_sizer = wx.BoxSizer(wx.VERTICAL) self._thresh_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), sizer=_thresh_sizer, value=self.thresh, callback=self.set_thresh, label="Mute Threshold", converter=forms.float_converter(), proportion=0, ) self._thresh_slider = forms.slider( parent=self.Main.GetPage(0).GetWin(), sizer=_thresh_sizer, value=self.thresh, callback=self.set_thresh, minimum=-50, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Main.GetPage(0).GridAdd(_thresh_sizer, 1, 1, 1, 1) def _scan_power_probe(): while True: val = self.rf_probe.level() try: self.set_scan_power(val) except AttributeError, e: pass time.sleep(1.0/(scan_rate)) _scan_power_thread = threading.Thread(target=_scan_power_probe) _scan_power_thread.daemon = True _scan_power_thread.start() self._sc_low_text_box = forms.text_box( parent=self.Main.GetPage(1).GetWin(), value=self.sc_low, callback=self.set_sc_low, label="Scan Low", converter=forms.float_converter(), ) self.Main.GetPage(1).GridAdd(self._sc_low_text_box, 0, 1, 1, 1) self._sc_listm_check_box = forms.check_box( parent=self.Main.GetPage(1).GetWin(), value=self.sc_listm, callback=self.set_sc_listm, label="Scan List Mode", true=True, false=False, ) self.Main.GetPage(1).GridAdd(self._sc_listm_check_box, 2, 0, 1, 1) self._sc_list_str_text_box = forms.text_box( parent=self.Main.GetPage(1).GetWin(), value=self.sc_list_str, callback=self.set_sc_list_str, label="Scan List", converter=forms.str_converter(), ) self.Main.GetPage(1).GridAdd(self._sc_list_str_text_box, 2, 1, 1, 5) self._sc_incr_chooser = forms.drop_down( parent=self.Main.GetPage(1).GetWin(), value=self.sc_incr, callback=self.set_sc_incr, label="Scan Increment (Hz)", choices=[5.0e3,6.25e3,10.0e3,12.5e3,15e3,25e3], labels=[], ) self.Main.GetPage(1).GridAdd(self._sc_incr_chooser, 0, 0, 1, 1) self._sc_high_text_box = forms.text_box( parent=self.Main.GetPage(1).GetWin(), value=self.sc_high, callback=self.set_sc_high, label="Scan High", converter=forms.float_converter(), ) self.Main.GetPage(1).GridAdd(self._sc_high_text_box, 0, 2, 1, 1) self._sc_ena_check_box = forms.check_box( parent=self.Main.GetPage(1).GetWin(), value=self.sc_ena, callback=self.set_sc_ena, label="Scan Enable", true=True, false=False, ) self.Main.GetPage(1).GridAdd(self._sc_ena_check_box, 0, 3, 1, 1) def _rf_power_probe(): while True: val = self.rf_probe.level() try: self.set_rf_power(val) except AttributeError, e: pass time.sleep(1.0/(10)) _rf_power_thread = threading.Thread(target=_rf_power_probe) _rf_power_thread.daemon = True _rf_power_thread.start() def _rf_d_power_probe(): while True: val = self.display_probe.level() try: self.set_rf_d_power(val) except AttributeError, e: pass time.sleep(1.0/(5)) _rf_d_power_thread = threading.Thread(target=_rf_d_power_probe) _rf_d_power_thread.daemon = True _rf_d_power_thread.start() self.osmosdr_source_c_0 = osmosdr.source_c( args="nchan=" + str(1) + " " + devinfo ) self.osmosdr_source_c_0.set_sample_rate(samp_rate) self.osmosdr_source_c_0.set_center_freq(cur_freq+offset+(upc_offset*float(upc)), 0) self.osmosdr_source_c_0.set_freq_corr(ppm, 0) self.osmosdr_source_c_0.set_gain_mode(iagc, 0) self.osmosdr_source_c_0.set_gain(25 if iagc == 1 else rfgain, 0) self.osmosdr_source_c_0.set_if_gain(20, 0) self._ifreq_text_box = forms.text_box( parent=self.Main.GetPage(0).GetWin(), value=self.ifreq, callback=self.set_ifreq, label="Frequency", converter=forms.float_converter(), ) self.Main.GetPage(0).GridAdd(self._ifreq_text_box, 0, 1, 1, 1) self.gr_wavfile_sink_0 = gr.wavfile_sink("/dev/null" if record == False else record_file, 1, int(audio_int_rate), 8) self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf(k) self.gr_multiply_const_vxx_2 = gr.multiply_const_vff((1.0 if mh.get_mode_type(mode) == "FM" else 0.0, )) self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((0.0 if muted else volume/4.5, )) self.gr_multiply_const_vxx_0_0_0 = gr.multiply_const_vff((0.85 if mh.get_mode_type(mode) == "AM" else 0.0, )) self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vff((0.85 if mh.get_mode_type(mode) == "SSB" else 0.0, )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc(((1.0/math.sqrt(mh.get_mode_deviation(mode,bw))*250), )) self.gr_keep_one_in_n_1 = gr.keep_one_in_n(gr.sizeof_gr_complex*1, aratio) self.gr_keep_one_in_n_0_0 = gr.keep_one_in_n(gr.sizeof_gr_complex*1, zoom) self.gr_keep_one_in_n_0 = gr.keep_one_in_n(gr.sizeof_gr_complex*1, int(wbfm/digi_rate)) self.gr_freq_xlating_fir_filter_xxx_0_1 = gr.freq_xlating_fir_filter_ccc(1, (1.0, ), (offset+fine+xfine)/(samp_rate/1.0e6), samp_rate) self.gr_fractional_interpolator_xx_0 = gr.fractional_interpolator_ff(0, audio_int_rate/arate) self.gr_file_sink_0 = gr.file_sink(gr.sizeof_gr_complex*1, "/dev/null" if mh.get_mode_type(mode) != "DIG" else dfifo) self.gr_file_sink_0.set_unbuffered(True) self.gr_fft_filter_xxx_3 = gr.fft_filter_ccc(1, (zoom_taps), 1) self.gr_fft_filter_xxx_2_0 = gr.fft_filter_fff(5, (firdes.low_pass(1.0,wbfm,14.5e3,8.5e3,firdes.WIN_HAMMING,6.76)), 1) self.gr_fft_filter_xxx_2 = gr.fft_filter_ccc(1, (main_taps), 1) self.gr_fft_filter_xxx_0 = gr.fft_filter_ccc(int(samp_rate/wbfm), (firdes.low_pass(1.0,samp_rate,98.5e3,66e3,firdes.WIN_HAMMING,6.76)), 1) self.gr_feedforward_agc_cc_0 = gr.feedforward_agc_cc(1024, 0.75) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(1) self.gr_add_xx_0 = gr.add_vff(1) self.blks2_fm_deemph_0 = blks2.fm_deemph(fs=audio_int_rate, tau=deemph) self.audio_sink_0 = audio.sink(int(arate), ahw, True) ################################################## # Connections ################################################## self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_fractional_interpolator_xx_0, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink_0, 1)) self.connect((self.gr_feedforward_agc_cc_0, 0), (self.gr_complex_to_mag_squared_0, 0)) self.connect((self.osmosdr_source_c_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0_1, 0)) self.connect((self.gr_multiply_const_vxx_0_0_0, 0), (self.gr_add_xx_0, 2)) self.connect((self.gr_feedforward_agc_cc_0, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_multiply_const_vxx_0_0, 0)) self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_add_xx_0, 0)) self.connect((self.gr_complex_to_mag_squared_0, 0), (self.gr_multiply_const_vxx_0_0_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.display_probe, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.rf_probe, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_fractional_interpolator_xx_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0_1, 0), (self.gr_fft_filter_xxx_0, 0)) self.connect((self.gr_keep_one_in_n_0, 0), (self.gr_file_sink_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0_1, 0), (self.gr_fft_filter_xxx_3, 0)) self.connect((self.gr_fft_filter_xxx_3, 0), (self.gr_keep_one_in_n_0_0, 0)) self.connect((self.gr_keep_one_in_n_0_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.gr_keep_one_in_n_0_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.gr_multiply_const_vxx_2, 0)) self.connect((self.gr_quadrature_demod_cf_0, 0), (self.gr_fft_filter_xxx_2_0, 0)) self.connect((self.gr_fft_filter_xxx_2, 0), (self.gr_keep_one_in_n_0, 0)) self.connect((self.gr_fft_filter_xxx_2, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_fft_filter_xxx_0, 0), (self.gr_fft_filter_xxx_2, 0)) self.connect((self.gr_keep_one_in_n_1, 0), (self.gr_feedforward_agc_cc_0, 0)) self.connect((self.gr_fft_filter_xxx_2, 0), (self.gr_keep_one_in_n_1, 0)) self.connect((self.gr_fft_filter_xxx_2, 0), (self.gr_quadrature_demod_cf_0, 0)) self.connect((self.gr_fft_filter_xxx_2_0, 0), (self.blks2_fm_deemph_0, 0))
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) parser=OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-f", "--freq", type="string", default="131725000", help="Frequency in Hz") parser.add_option("-o", "--output", type="string", default="output.txt", help="ACARS log output") parser.add_option("-s", "--samp-rate", type="eng_float", default="250e3", help="set sample rate (bandwidth) [default=%default]") parser.add_option("-d", "--device", type="string", default="", help="PCM device name, e.g. hw:0,0 /dev/dsp pulse etc.") parser.add_option("-w", "--wav-file", type="string", default="", help="WAV file output.") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.freq = float(options.freq) usrp_rate = options.samp_rate audio_rate = 48e3 # init USRP source block self.usrp = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) if (options.spec): self.usrp.set_subdev_spec(options.spec, 0) if (options.antenna): self.usrp.set_antenna(options.antenna, 0) self.usrp.set_samp_rate(usrp_rate) self.usrp.set_center_freq(self.freq, 0) # FIR block (5KHz low pass filter) chan_filt_coeffs = gr.firdes.low_pass_2(8, # gain usrp_rate, # sampling rate 5e3, # passband_cutoff 1e2, # transition bw 60) # stopband attenuation self.chan_filt = gr.freq_xlating_fir_filter_ccf(1, # decimation chan_filt_coeffs, # taps 0, # center freq usrp_rate) # samp rate # AM demodulator block self.am_demod = gr.complex_to_mag() # resampler block self.resamp = blks2.rational_resampler_fff(interpolation=int(audio_rate), decimation=int(usrp_rate), taps=None, fractional_bw=None) # acars2 demod/decode blocks self.acars2_demod = acars2.demod(int(audio_rate)) self.acars2_decode = acars2.decode() # file sink self.file_sink = gr.file_sink(gr.sizeof_char, options.output) # build flow graph self.connect(self.usrp, self.chan_filt, self.am_demod, self.resamp, self.acars2_demod, self.acars2_decode, self.file_sink) # add audio sink (optional) if (options.device): print "using audio device %s" % options.device self.audio_sink = audio.sink(int (audio_rate), options.device, True) self.connect(self.resamp, self.audio_sink) # add WAV file sink (optional) if (options.wav_file): print "writing to WAV file %s" % options.wav_file self.wavsink = gr.wavfile_sink(options.wav_file, 1, int(audio_rate), 16) self.connect(self.resamp, self.wavsink) self._build_gui(vbox, usrp_rate, audio_rate) print "built flow graph..."
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] input-samples-320kS.dat output.wav" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) input_filename = args[0] output_filename = args[1] self.vol = 0 # build graph self.src = gr.file_source(gr.sizeof_gr_complex, input_filename, False) adc_rate = 64e6 # 64 MS/s usrp_decim = 200 usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz chan_filt_coeffs = optfir.low_pass( 1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) #self.guts = blks2.wfm_rcv (demod_rate, audio_decimation) self.guts = blks2.wfm_rcv_pll(demod_rate, audio_decimation) # FIXME rework {add,multiply}_const_* to handle multiple streams self.volume_control_l = gr.multiply_const_ff(self.vol) self.volume_control_r = gr.multiply_const_ff(self.vol) # wave file as final sink if 1: sink = gr.wavfile_sink(output_filename, 2, int(audio_rate), 16) else: sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect(self.src, chan_filt, self.guts) self.connect((self.guts, 0), self.volume_control_l, (sink, 0)) self.connect((self.guts, 1), self.volume_control_r, (sink, 1)) try: self.guts.stereo_carrier_pll_recovery.squelch_enable(True) except: pass #print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet" if options.volume is None: g = self.volume_range() options.volume = float(g[0] + g[1]) / 2 # set initial values self.set_vol(options.volume) try: self.guts.stereo_carrier_pll_recovery.set_lock_threshold( options.squelch) except: pass