def __init__(self, options): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) #Set up usrp block self.u = usrp.source_c() adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 16 gain = 65 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s print usrp_rate #subdev_spec = usrp.pick_subdev(self.u) subdev_spec = (0, 0) mux_value = usrp.determine_rx_mux_value(self.u, subdev_spec) self.u.set_mux(mux_value) self.subdev = usrp.selected_subdev(self.u, subdev_spec) self.subdev.set_gain(gain) self.subdev.set_auto_tr(False) self.subdev.set_enable(True) if not (self.set_freq(915e6)): print "Failed to set initial frequency" #set up the rest of the path deci = 1 self.agc = gr.agc_cc(rate=1e-7, reference=1.0, gain=0.001, max_gain=0.5) matchtaps = [complex(-1, -1)] * 8 + [complex( 1, 1)] * 8 + [complex(-1, -1)] * 8 + [complex(1, 1)] * 8 #matchtaps = [complex(-1,-1)] * 8 + [complex(1,1)] * 8 self.matchfilter = gr.fir_filter_ccc(1, matchtaps) reverse = [complex(1, 1)] * (8 / deci) + [complex( -1, -1)] * (8 / deci) + [complex( 1, 1)] * (8 / deci) + [complex(-1, -1)] * (8 / deci) #pretaps = matchtaps * 3 + reverse * 4 + matchtaps * 4 + reverse * 8 + matchtaps * 6 + matchtaps * 62 pretaps = matchtaps * 2 + reverse * 2 + matchtaps * 2 + reverse * 4 + matchtaps * 3 + matchtaps * 31 #pretaps = matchtaps * 3 + reverse * 8 + matchtaps * 6 + matchtaps * 64 self.preamble_filter = gr.fir_filter_ccc(1, pretaps) self.c_f = gr.complex_to_real() self.c_f2 = gr.complex_to_real() self.lock = howto.lock_time(32, 5, 32) self.pd = howto.find_pre_ff(55, 200) self.dec = symbols_decoder() self.vect = gr.vector_sink_f() #self.connect(self.u, self.agc, self.matchfilter, self.c_f, (self.lock, 0), self.dec, self.vect) #self.connect(self.agc, self.preamble_filter, self.c_f2, self.pd, (self.lock, 1)) self.connect(self.u, self.agc, self.matchfilter, self.c_f, self.vect)
def __init__(self, options): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) #Set up usrp block self.u = usrp.source_c() adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 16 gain = 65 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s print usrp_rate #subdev_spec = usrp.pick_subdev(self.u) subdev_spec = (0,0) mux_value = usrp.determine_rx_mux_value(self.u, subdev_spec) self.u.set_mux(mux_value) self.subdev = usrp.selected_subdev(self.u, subdev_spec) self.subdev.set_gain(gain) self.subdev.set_auto_tr(False) self.subdev.set_enable(True) if not(self.set_freq(915e6)): print "Failed to set initial frequency" #set up the rest of the path deci = 1 self.agc = gr.agc_cc( rate = 1e-7, reference = 1.0, gain = 0.001, max_gain = 0.5) matchtaps = [complex(-1,-1)] * 8 + [complex(1,1)] * 8 + [complex(-1,-1)]* 8 + [complex(1,1)]* 8 #matchtaps = [complex(-1,-1)] * 8 + [complex(1,1)] * 8 self.matchfilter = gr.fir_filter_ccc(1, matchtaps) reverse = [complex(1,1)] * (8 / deci) + [complex(-1,-1)] * (8 / deci) + [complex(1,1)]* (8 / deci) + [complex(-1,-1)]* (8 / deci) #pretaps = matchtaps * 3 + reverse * 4 + matchtaps * 4 + reverse * 8 + matchtaps * 6 + matchtaps * 62 pretaps = matchtaps * 2 + reverse * 2 + matchtaps * 2 + reverse * 4 + matchtaps * 3 + matchtaps * 31 #pretaps = matchtaps * 3 + reverse * 8 + matchtaps * 6 + matchtaps * 64 self.preamble_filter = gr.fir_filter_ccc(1, pretaps) self.c_f = gr.complex_to_real() self.c_f2 = gr.complex_to_real() self.lock = howto.lock_time(32, 5, 32) self.pd = howto.find_pre_ff(55, 200) self.dec = symbols_decoder() self.vect = gr.vector_sink_f() #self.connect(self.u, self.agc, self.matchfilter, self.c_f, (self.lock, 0), self.dec, self.vect) #self.connect(self.agc, self.preamble_filter, self.c_f2, self.pd, (self.lock, 1)) self.connect(self.u, self.agc, self.matchfilter, self.c_f, self.vect)
def __init__(self): gr.top_block.__init__(self) input_sample_rate = 1e6 symbol_rate = 152.34e3 output_samples_per_symbol = 5 output_sample_rate = output_samples_per_symbol * symbol_rate # least common multiple lcm = gru.lcm(input_sample_rate, output_sample_rate) intrp = int(lcm // input_sample_rate) decim = int(lcm // output_sample_rate) print intrp print decim resampler = blks2.rational_resampler_ccc(intrp, decim, None, None) src = gr.file_source(gr.sizeof_gr_complex, "infile") sink = gr.file_sink(gr.sizeof_float, "outfile") f2c = gr.float_to_complex() c2r = gr.complex_to_real() #ddc_coeffs = \ #gr.firdes.low_pass (1.0, # gain #input_sample_rate, # sampling rate #2e3, # low pass cutoff freq #6e3, # width of trans. band #gr.firdes.WIN_HANN) # just grab the lower sideband: #ddc = gr.freq_xlating_fir_filter_ccf(1,ddc_coeffs,-111.5e3,input_sample_rate) qdemod = gr.quadrature_demod_cf(1.0) lp_coeffs = \ gr.firdes.low_pass (1.0, # gain output_sample_rate, # sampling rate symbol_rate, # low pass cutoff freq symbol_rate, # width of trans. band gr.firdes.WIN_HANN) lp = gr.fir_filter_fff(1, lp_coeffs) self.connect(src, resampler, qdemod, lp, sink)
def __init__(self,delay_num,delay_denom): gr.hier_block2.__init__(self,"moms_block", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) cmplx_to_real = gr.complex_to_real() cmplx_to_img = gr.complex_to_imag() iirf_real = gr.iir_filter_ffd([1.5],[1, -0.5]) self.moms_real = moms_ff() self.moms_real.set_init_ip_fraction(delay_num,delay_denom) iirf_imag = gr.iir_filter_ffd([1.5],[1, -0.5]) self.moms_imag = moms_ff() self.moms_imag.set_init_ip_fraction(delay_num,delay_denom) float_to_cmplx = gr.float_to_complex() self.connect((self,0), (cmplx_to_real,0)) self.connect((self,0), (cmplx_to_img,0)) self.connect((cmplx_to_real,0), (iirf_real,0)) self.connect((cmplx_to_img,0), (iirf_imag,0)) self.connect((iirf_real,0), (self.moms_real,0)) self.connect((iirf_imag,0), (self.moms_imag,0)) self.connect((self.moms_real,0), (float_to_cmplx,0)) self.connect((self.moms_imag,0), (float_to_cmplx,1)) self.connect((float_to_cmplx,0), (self,0))
def __init__(self): gr.top_block.__init__(self) input_sample_rate = 1e6 symbol_rate = 152.34e3 output_samples_per_symbol = 5 output_sample_rate = output_samples_per_symbol * symbol_rate # least common multiple lcm = gru.lcm(input_sample_rate, output_sample_rate) intrp = int(lcm // input_sample_rate) decim = int(lcm // output_sample_rate) print intrp print decim resampler = blks2.rational_resampler_ccc(intrp, decim, None, None) src = gr.file_source(gr.sizeof_gr_complex, "infile") sink = gr.file_sink(gr.sizeof_float, "outfile") f2c = gr.float_to_complex() c2r = gr.complex_to_real() #ddc_coeffs = \ #gr.firdes.low_pass (1.0, # gain #input_sample_rate, # sampling rate #2e3, # low pass cutoff freq #6e3, # width of trans. band #gr.firdes.WIN_HANN) # just grab the lower sideband: #ddc = gr.freq_xlating_fir_filter_ccf(1,ddc_coeffs,-111.5e3,input_sample_rate) qdemod = gr.quadrature_demod_cf(1.0) lp_coeffs = \ gr.firdes.low_pass (1.0, # gain output_sample_rate, # sampling rate symbol_rate, # low pass cutoff freq symbol_rate, # width of trans. band gr.firdes.WIN_HANN) lp = gr.fir_filter_fff (1,lp_coeffs) self.connect(src,resampler,qdemod,lp,sink)
def __init__(self, *args, **kwargs): """ Hierarchical block for BPSK demodulation. The input is the complex modulated signal at baseband. Demodulated packets are sent to the handler. @param callback: function of two args: ok, payload @type callback: ok: bool; payload: string @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default) @type threshold: int See ieee802_15_4_demod for remaining parameters. """ try: self.callback = kwargs.pop('callback') self.threshold = kwargs.pop('threshold') #Return the demodulator self.demodulator = kwargs.pop('demodulator') self.gui = kwargs.pop('gui') self._samples_per_symbol = kwargs.pop('sps') except KeyError: pass gr.hier_block2.__init__(self, "ieee_pkt_receiver", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input gr.io_signature(0, 0, 0)) # Output self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY #Create the sink of packets self._packet_sink = ieee.ieee802_15_4_packet_sink(self._rcvd_pktq, self.threshold) #self.complex_to_float = gr.complex_to_float(1) self.complex_to_real = gr.complex_to_real() #self.null_sink = gr.null_sink(gr.sizeof_float*1) #self.connect((self.gr_complex_to_float_0, 0), (self.gr_vector_sink_x_0, 0)) #self.connect(self.complex_to_float, self.null_sink) # self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c( # self.gui.GetWin(), # title="Constellation Plot", # sample_rate=self._samples_per_symbol, # frame_rate=5, # const_size=2048, # M=2, # theta=0, # alpha=0.005, # fmax=0.06, # mu=0.5, # gain_mu=0.005, # symbol_rate=self._samples_per_symbol/2, # omega_limit=0.005, # ) # self.gui.Add(self.wxgui_constellationsink2_0.win) self.connect(self, self.demodulator, self.complex_to_real, self._packet_sink) #self.connect(self, self.demodulator, self.wxgui_constellationsink2_0) self._watcher = _queue_watcher_thread(self._rcvd_pktq, self.callback)
def __init__(self, usrp_rate, usrp_interp): gr.hier_block2.__init__(self, "downlink_test_file_sink", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) self.c_to_f = gr.complex_to_real() self.chop = gr.head(gr.sizeof_float, 350) self.f = gr.file_sink(gr.sizeof_float, 'output.dat') self.connect(self, self.c_to_f, self.chop, self.f)
def __init__(self,usrp_rate,usrp_interp): gr.hier_block2.__init__(self,"downlink_test_file_sink", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(0,0,0)) self.c_to_f = gr.complex_to_real() self.chop = gr.head(gr.sizeof_float, 350) self.f = gr.file_sink(gr.sizeof_float,'output.dat') self.connect(self,self.c_to_f, self.chop,self.f)
def test_complex_to_real(self): src_data = (0, 1, -1, 3 + 4j, -3 - 4j, -3 + 4j) expected_result = (0, 1, -1, 3, -3, -3) src = gr.vector_source_c(src_data) op = gr.complex_to_real() dst = gr.vector_sink_f() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() actual_result = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
def test_complex_to_real (self): src_data = (0, 1, -1, 3+4j, -3-4j, -3+4j) expected_result = (0, 1, -1, 3, -3, -3) src = gr.vector_source_c (src_data) op = gr.complex_to_real () dst = gr.vector_sink_f () self.tb.connect (src, op) self.tb.connect (op, dst) self.tb.run () actual_result = dst.data () self.assertFloatTuplesAlmostEqual (expected_result, actual_result)
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, 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, "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 ################################################## # 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) ################################################## # 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))
def __init__(self): gr.hier_block2.__init__(self, 'gsm_decode_harddecision', gr.io_signature(1, 1, gr.sizeof_gr_complex * 148 ), gr.io_signature(1,1,58*2)) conf = mlse.make_packet_config_gsm() slice1 = conf.make_slicer(conf.PAYLOAD_FRONT) slice2 = conf.make_slicer(conf.PAYLOAD_REAR) cat = mlse.vector_concat_vv(58*gr.sizeof_gr_complex, 58*gr.sizeof_gr_complex) tostream = gr.vector_to_stream(gr.sizeof_gr_complex, 58*2) real = gr.complex_to_real() sign = gr.binary_slicer_fb() demap = gr.map_bb([1,0]) # invert 0 and 1 because in gsm 0 is mapped to +1 and 1 to -1 tovect = gr.stream_to_vector(1, 58*2) self.connect(self, slice1) self.connect(self, slice2) self.connect(slice1, (cat,0)) self.connect(slice2, (cat,1)) self.connect(cat, tostream, real, sign, demap, tovect, self)
def __init__(self, *args, **kwargs): """ Hierarchical block for BPSK demodulation. The input is the complex modulated signal at baseband. Demodulated packets are sent to the handler. @param callback: function of two args: ok, payload @type callback: ok: bool; payload: string @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default) @type threshold: int See ieee802_15_4_demod for remaining parameters. """ try: self.callback = kwargs.pop('callback') self.threshold = kwargs.pop('threshold') #Return the demodulator self.demodulator = kwargs.pop('demodulator') self.gui = kwargs.pop('gui') self._samples_per_symbol = kwargs.pop('sps') except KeyError: pass gr.hier_block2.__init__(self, "ieee_pkt_receiver", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input gr.io_signature(0, 0, 0)) # Output self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY #Create the sink of packets self._packet_sink = ieee.ieee802_15_4_packet_sink(self._rcvd_pktq, self.threshold) #self.complex_to_float = gr.complex_to_float(1) self.complex_to_real = gr.complex_to_real() self.connect(self, self.demodulator, self.complex_to_real, self._packet_sink) self._watcher = _queue_watcher_thread(self._rcvd_pktq, self.callback)
def __init__(self): gr.hier_block2.__init__( self, 'gsm_decode_harddecision', gr.io_signature(1, 1, gr.sizeof_gr_complex * 148), gr.io_signature(1, 1, 58 * 2)) conf = mlse.make_packet_config_gsm() slice1 = conf.make_slicer(conf.PAYLOAD_FRONT) slice2 = conf.make_slicer(conf.PAYLOAD_REAR) cat = mlse.vector_concat_vv(58 * gr.sizeof_gr_complex, 58 * gr.sizeof_gr_complex) tostream = gr.vector_to_stream(gr.sizeof_gr_complex, 58 * 2) real = gr.complex_to_real() sign = gr.binary_slicer_fb() demap = gr.map_bb( [1, 0]) # invert 0 and 1 because in gsm 0 is mapped to +1 and 1 to -1 tovect = gr.stream_to_vector(1, 58 * 2) self.connect(self, slice1) self.connect(self, slice2) self.connect(slice1, (cat, 0)) self.connect(slice2, (cat, 1)) self.connect(cat, tostream, real, sign, demap, tovect, self)
def __init__(self, demod_rate, audio_decimation): """ Hierarchical block for demodulating a broadcast FM signal. The input is the downconverted complex baseband signal (gr_complex). The output is two streams of the demodulated audio (float) 0=Left, 1=Right. @param demod_rate: input sample rate of complex baseband input. @type demod_rate: float @param audio_decimation: how much to decimate demod_rate to get to audio. @type audio_decimation: integer """ gr.hier_block2.__init__( self, "wfm_rcv_fmdet", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(2, 2, gr.sizeof_float)) # Output signature lowfreq = -125e3 / demod_rate highfreq = 125e3 / demod_rate audio_rate = demod_rate / audio_decimation # We assign to self so that outsiders can grab the demodulator # if they need to. E.g., to plot its output. # # input: complex; output: float self.fm_demod = gr.fmdet_cf(demod_rate, lowfreq, highfreq, 0.05) # input: float; output: float self.deemph_Left = fm_deemph(audio_rate) self.deemph_Right = fm_deemph(audio_rate) # compute FIR filter taps for audio filter width_of_transition_band = audio_rate / 32 audio_coeffs = gr.firdes.low_pass( 1.0, # gain demod_rate, # sampling rate 15000, width_of_transition_band, gr.firdes.WIN_HAMMING) # input: float; output: float self.audio_filter = gr.fir_filter_fff(audio_decimation, audio_coeffs) if 1: # Pick off the stereo carrier/2 with this filter. It # attenuated 10 dB so apply 10 dB gain We pick off the # negative frequency half because we want to base band by # it! ## NOTE THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO ## DEEMPHASIS stereo_carrier_filter_coeffs = gr.firdes.complex_band_pass( 10.0, demod_rate, -19020, -18980, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs) #print "stereo carrier filter ", stereo_carrier_filter_coeffs #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate # Pick off the double side band suppressed carrier # Left-Right audio. It is attenuated 10 dB so apply 10 dB # gain stereo_dsbsc_filter_coeffs = gr.firdes.complex_band_pass( 20.0, demod_rate, 38000 - 15000 / 2, 38000 + 15000 / 2, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs # construct overlap add filter system from coefficients # for stereo carrier self.stereo_carrier_filter = gr.fir_filter_fcc( audio_decimation, stereo_carrier_filter_coeffs) # carrier is twice the picked off carrier so arrange to do # a commplex multiply self.stereo_carrier_generator = gr.multiply_cc() # Pick off the rds signal stereo_rds_filter_coeffs = gr.firdes.complex_band_pass( 30.0, demod_rate, 57000 - 1500, 57000 + 1500, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs # construct overlap add filter system from coefficients for stereo carrier self.rds_signal_filter = gr.fir_filter_fcc( audio_decimation, stereo_rds_filter_coeffs) self.rds_carrier_generator = gr.multiply_cc() self.rds_signal_generator = gr.multiply_cc() self_rds_signal_processor = gr.null_sink(gr.sizeof_gr_complex) loop_bw = 2 * math.pi / 100.0 max_freq = -2.0 * math.pi * 18990 / audio_rate min_freq = -2.0 * math.pi * 19010 / audio_rate self.stereo_carrier_pll_recovery = gr.pll_refout_cc( loop_bw, max_freq, min_freq) #self.stereo_carrier_pll_recovery.squelch_enable(False) ##pll_refout does not have squelch yet, so disabled for #now # set up mixer (multiplier) to get the L-R signal at # baseband self.stereo_basebander = gr.multiply_cc() # pick off the real component of the basebanded L-R # signal. The imaginary SHOULD be zero self.LmR_real = gr.complex_to_real() self.Make_Left = gr.add_ff() self.Make_Right = gr.sub_ff() self.stereo_dsbsc_filter = gr.fir_filter_fcc( audio_decimation, stereo_dsbsc_filter_coeffs) if 1: # send the real signal to complex filter to pick off the # carrier and then to one side of a multiplier self.connect(self, self.fm_demod, self.stereo_carrier_filter, self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator, 0)) # send the already filtered carrier to the otherside of the carrier # the resulting signal from this multiplier is the carrier # with correct phase but at -38000 Hz. self.connect(self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator, 1)) # send the new carrier to one side of the mixer (multiplier) self.connect(self.stereo_carrier_generator, (self.stereo_basebander, 0)) # send the demphasized audio to the DSBSC pick off filter, the complex # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier # the result is BASEBANDED DSBSC with phase zero! self.connect(self.fm_demod, self.stereo_dsbsc_filter, (self.stereo_basebander, 1)) # Pick off the real part since the imaginary is # theoretically zero and then to one side of a summer self.connect(self.stereo_basebander, self.LmR_real, (self.Make_Left, 0)) #take the same real part of the DSBSC baseband signal and #send it to negative side of a subtracter self.connect(self.LmR_real, (self.Make_Right, 1)) # Make rds carrier by taking the squared pilot tone and # multiplying by pilot tone self.connect(self.stereo_basebander, (self.rds_carrier_generator, 0)) self.connect(self.stereo_carrier_pll_recovery, (self.rds_carrier_generator, 1)) # take signal, filter off rds, send into mixer 0 channel self.connect(self.fm_demod, self.rds_signal_filter, (self.rds_signal_generator, 0)) # take rds_carrier_generator output and send into mixer 1 # channel self.connect(self.rds_carrier_generator, (self.rds_signal_generator, 1)) # send basebanded rds signal and send into "processor" # which for now is a null sink self.connect(self.rds_signal_generator, self_rds_signal_processor) if 1: # pick off the audio, L+R that is what we used to have and # send it to the summer self.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1)) # take the picked off L+R audio and send it to the PLUS # side of the subtractor self.connect(self.audio_filter, (self.Make_Right, 0)) # The result of Make_Left gets (L+R) + (L-R) and results in 2*L # The result of Make_Right gets (L+R) - (L-R) and results in 2*R self.connect(self.Make_Left, self.deemph_Left, (self, 0)) self.connect(self.Make_Right, self.deemph_Right, (self, 1))
def __init__ (self, fg, demod_rate, audio_decimation): """ Hierarchical block for demodulating a broadcast FM signal. The input is the downconverted complex baseband signal (gr_complex). The output is two streams of the demodulated audio (float) 0=Left, 1=Right. @param fg: flow graph. @type fg: flow graph @param demod_rate: input sample rate of complex baseband input. @type demod_rate: float @param audio_decimation: how much to decimate demod_rate to get to audio. @type audio_decimation: integer """ bandwidth = 200e3 audio_rate = demod_rate / audio_decimation # We assign to self so that outsiders can grab the demodulator # if they need to. E.g., to plot its output. # # input: complex; output: float alpha = 0.25*bandwidth * math.pi / demod_rate beta = alpha * alpha / 4.0 max_freq = 2.0*math.pi*100e3/demod_rate self.fm_demod = gr.pll_freqdet_cf (alpha,beta,max_freq,-max_freq) # input: float; output: float self.deemph_Left = fm_deemph (fg, audio_rate) self.deemph_Right = fm_deemph (fg, audio_rate) # compute FIR filter taps for audio filter width_of_transition_band = audio_rate / 32 audio_coeffs = gr.firdes.low_pass (1.0 , # gain demod_rate, # sampling rate 15000 , width_of_transition_band, gr.firdes.WIN_HAMMING) # input: float; output: float self.audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) if 1: # Pick off the stereo carrier/2 with this filter. It attenuated 10 dB so apply 10 dB gain # We pick off the negative frequency half because we want to base band by it! ## NOTE THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO DEEMPHASIS stereo_carrier_filter_coeffs = gr.firdes.complex_band_pass(10.0, demod_rate, -19020, -18980, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs) #print "stereo carrier filter ", stereo_carrier_filter_coeffs #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate # Pick off the double side band suppressed carrier Left-Right audio. It is attenuated 10 dB so apply 10 dB gain stereo_dsbsc_filter_coeffs = gr.firdes.complex_band_pass(20.0, demod_rate, 38000-15000/2, 38000+15000/2, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs # construct overlap add filter system from coefficients for stereo carrier self.stereo_carrier_filter = gr.fir_filter_fcc(audio_decimation, stereo_carrier_filter_coeffs) # carrier is twice the picked off carrier so arrange to do a commplex multiply self.stereo_carrier_generator = gr.multiply_cc(); # Pick off the rds signal stereo_rds_filter_coeffs = gr.firdes.complex_band_pass(30.0, demod_rate, 57000 - 1500, 57000 + 1500, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs # construct overlap add filter system from coefficients for stereo carrier self.stereo_carrier_filter = gr.fir_filter_fcc(audio_decimation, stereo_carrier_filter_coeffs) self.rds_signal_filter = gr.fir_filter_fcc(audio_decimation, stereo_rds_filter_coeffs) self.rds_carrier_generator = gr.multiply_cc(); self.rds_signal_generator = gr.multiply_cc(); self_rds_signal_processor = gr.null_sink(gr.sizeof_gr_complex); alpha = 5 * 0.25 * math.pi / (audio_rate) beta = alpha * alpha / 4.0 max_freq = -2.0*math.pi*18990/audio_rate; min_freq = -2.0*math.pi*19010/audio_rate; self.stereo_carrier_pll_recovery = gr.pll_refout_cc(alpha,beta,max_freq,min_freq); #self.stereo_carrier_pll_recovery.squelch_enable(False) #pll_refout does not have squelch yet, so disabled for now # set up mixer (multiplier) to get the L-R signal at baseband self.stereo_basebander = gr.multiply_cc(); # pick off the real component of the basebanded L-R signal. The imaginary SHOULD be zero self.LmR_real = gr.complex_to_real(); self.Make_Left = gr.add_ff(); self.Make_Right = gr.sub_ff(); self.stereo_dsbsc_filter = gr.fir_filter_fcc(audio_decimation, stereo_dsbsc_filter_coeffs) if 1: # send the real signal to complex filter to pick off the carrier and then to one side of a multiplier fg.connect (self.fm_demod,self.stereo_carrier_filter,self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,0)) # send the already filtered carrier to the otherside of the carrier fg.connect (self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,1)) # the resulting signal from this multiplier is the carrier with correct phase but at -38000 Hz. # send the new carrier to one side of the mixer (multiplier) fg.connect (self.stereo_carrier_generator, (self.stereo_basebander,0)) # send the demphasized audio to the DSBSC pick off filter, the complex # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier fg.connect (self.fm_demod,self.stereo_dsbsc_filter, (self.stereo_basebander,1)) # the result is BASEBANDED DSBSC with phase zero! # Pick off the real part since the imaginary is theoretically zero and then to one side of a summer fg.connect (self.stereo_basebander, self.LmR_real, (self.Make_Left,0)) #take the same real part of the DSBSC baseband signal and send it to negative side of a subtracter fg.connect (self.LmR_real,(self.Make_Right,1)) # Make rds carrier by taking the squared pilot tone and multiplying by pilot tone fg.connect (self.stereo_basebander,(self.rds_carrier_generator,0)) fg.connect (self.stereo_carrier_pll_recovery,(self.rds_carrier_generator,1)) # take signal, filter off rds, send into mixer 0 channel fg.connect (self.fm_demod,self.rds_signal_filter,(self.rds_signal_generator,0)) # take rds_carrier_generator output and send into mixer 1 channel fg.connect (self.rds_carrier_generator,(self.rds_signal_generator,1)) # send basebanded rds signal and send into "processor" which for now is a null sink fg.connect (self.rds_signal_generator,self_rds_signal_processor) if 1: # pick off the audio, L+R that is what we used to have and send it to the summer fg.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1)) # take the picked off L+R audio and send it to the PLUS side of the subtractor fg.connect(self.audio_filter,(self.Make_Right, 0)) # The result of Make_Left gets (L+R) + (L-R) and results in 2*L # The result of Make_Right gets (L+R) - (L-R) and results in 2*R # kludge the signals into a stereo channel kludge = gr.kludge_copy(gr.sizeof_float) fg.connect(self.Make_Left , self.deemph_Left, (kludge, 0)) fg.connect(self.Make_Right, self.deemph_Right, (kludge, 1)) #send it to the audio system gr.hier_block.__init__(self, fg, self.fm_demod, # head of the pipeline kludge) # tail of the pipeline else: fg.connect (self.fm_demod, self.audio_filter) gr.hier_block.__init__(self, fg, self.fm_demod, # head of the pipeline self.audio_filter) # tail of the pipeline
def complex_to_real(N): op = gr.complex_to_real() tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_float, 1, 1) return tb
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="USRP LRIT Receiver") ################################################## # Variables ################################################## self.config_filename = config_filename = "usrp_rx_lrit.cfg" self._saved_decim_config = ConfigParser.ConfigParser() self._saved_decim_config.read(config_filename) try: saved_decim = self._saved_decim_config.getint("main", "decim") except: saved_decim = 160 self.saved_decim = saved_decim self.decim = decim = saved_decim self.symbol_rate = symbol_rate = 293e3 self._saved_gain_mu_config = ConfigParser.ConfigParser() self._saved_gain_mu_config.read(config_filename) try: saved_gain_mu = self._saved_gain_mu_config.getfloat("main", "gain_mu") except: saved_gain_mu = 0.005 self.saved_gain_mu = saved_gain_mu self._saved_gain_config = ConfigParser.ConfigParser() self._saved_gain_config.read(config_filename) try: saved_gain = self._saved_gain_config.getfloat("main", "gain") except: saved_gain = 33 self.saved_gain = saved_gain self._saved_freq_config = ConfigParser.ConfigParser() self._saved_freq_config.read(config_filename) try: saved_freq = self._saved_freq_config.getfloat("main", "freq") except: saved_freq = 137e6 self.saved_freq = saved_freq self._saved_costas_alpha_config = ConfigParser.ConfigParser() self._saved_costas_alpha_config.read(config_filename) try: saved_costas_alpha = self._saved_costas_alpha_config.getfloat("main", "costas_alpha") except: saved_costas_alpha = 0.005 self.saved_costas_alpha = saved_costas_alpha self.samp_rate = samp_rate = 64e6/decim self.sps = sps = samp_rate/symbol_rate self.gain_mu = gain_mu = saved_gain_mu self.gain = gain = saved_gain self.freq = freq = saved_freq self.costas_alpha = costas_alpha = saved_costas_alpha ################################################## # Notebooks ################################################## self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.displays.AddPage(grc_wxgui.Panel(self.displays), "USRP RX") self.displays.AddPage(grc_wxgui.Panel(self.displays), "Costas Output") self.GridAdd(self.displays, 2, 0, 1, 3) ################################################## # Controls ################################################## self._decim_text_box = forms.text_box( parent=self.GetWin(), value=self.decim, callback=self.set_decim, label="Decim", converter=forms.int_converter(), ) self.GridAdd(self._decim_text_box, 0, 0, 1, 1) _gain_mu_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_mu_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_mu_sizer, value=self.gain_mu, callback=self.set_gain_mu, label="Gain Mu", converter=forms.float_converter(), proportion=0, ) self._gain_mu_slider = forms.slider( parent=self.GetWin(), sizer=_gain_mu_sizer, value=self.gain_mu, callback=self.set_gain_mu, minimum=0, maximum=0.5, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_mu_sizer, 1, 1, 1, 1) _gain_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, label="Gain", converter=forms.float_converter(), proportion=0, ) self._gain_slider = forms.slider( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, minimum=0, maximum=115, num_steps=115, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 0, 1, 1, 1) _freq_sizer = wx.BoxSizer(wx.VERTICAL) self._freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, label="Frequency", converter=forms.float_converter(), proportion=0, ) self._freq_slider = forms.slider( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, minimum=135e6, maximum=139e6, num_steps=400, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_freq_sizer, 0, 2, 1, 1) _costas_alpha_sizer = wx.BoxSizer(wx.VERTICAL) self._costas_alpha_text_box = forms.text_box( parent=self.GetWin(), sizer=_costas_alpha_sizer, value=self.costas_alpha, callback=self.set_costas_alpha, label="Costas Alpha", converter=forms.float_converter(), proportion=0, ) self._costas_alpha_slider = forms.slider( parent=self.GetWin(), sizer=_costas_alpha_sizer, value=self.costas_alpha, callback=self.set_costas_alpha, minimum=0, maximum=0.5, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_costas_alpha_sizer, 1, 0, 1, 1) ################################################## # Blocks ################################################## self.gr_add_const_vxx_0 = gr.add_const_vff((48.0, )) self.gr_agc_xx_0 = gr.agc_cc(1e-6, 1.0, 1.0/32767.0, 1.0) self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb() self.gr_char_to_float_0 = gr.char_to_float() self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "bits.dat") self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "lrit.dat", False) self.gr_float_to_char_0 = gr.float_to_char() self.gr_mpsk_receiver_cc_0 = gr.mpsk_receiver_cc(2, 0, costas_alpha, costas_alpha*costas_alpha/4.0, -0.05, 0.05, 0.5, gain_mu, sps, gain_mu*gain_mu/4.0, 0.05) self.gr_probe_mpsk_snr_c_0 = grc_blks2.probe_mpsk_snr_c( type='snr', alpha=0.0001, probe_rate=10, ) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.displays.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=50, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=False, avg_alpha=None, title="Spectrum", peak_hold=False, ) self.displays.GetPage(0).GridAdd(self.wxgui_fftsink2_0.win, 0, 0, 1, 1) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.displays.GetPage(1).GetWin(), unit="dB", minval=0, maxval=30, factor=1.0, decimal_places=1, ref_level=0, sample_rate=10, number_rate=10, average=False, avg_alpha=None, label="SNR", peak_hold=False, show_gauge=True, ) self.displays.GetPage(1).GridAdd(self.wxgui_numbersink2_0.win, 2, 0, 1, 1) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.displays.GetPage(0).GetWin(), title="Waveform", sample_rate=samp_rate, v_scale=0.5, t_scale=20.0/samp_rate, ac_couple=False, xy_mode=True, num_inputs=1, ) self.displays.GetPage(0).GridAdd(self.wxgui_scopesink2_0.win, 1, 0, 1, 1) self.wxgui_scopesink2_1 = scopesink2.scope_sink_c( self.displays.GetPage(1).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0.4, t_scale=20.0/samp_rate, ac_couple=False, xy_mode=True, num_inputs=1, ) self.displays.GetPage(1).GridAdd(self.wxgui_scopesink2_1.win, 0, 0, 1, 1) ################################################## # Connections ################################################## self.connect((self.gr_agc_xx_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0)) self.connect((self.gr_probe_mpsk_snr_c_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.gr_mpsk_receiver_cc_0, 0), (self.gr_probe_mpsk_snr_c_0, 0)) self.connect((self.gr_agc_xx_0, 0), (self.gr_mpsk_receiver_cc_0, 0)) self.connect((self.gr_mpsk_receiver_cc_0, 0), (self.wxgui_scopesink2_1, 0)) self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.gr_mpsk_receiver_cc_0, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_binary_slicer_fb_0, 0)) self.connect((self.gr_binary_slicer_fb_0, 0), (self.gr_char_to_float_0, 0)) self.connect((self.gr_char_to_float_0, 0), (self.gr_add_const_vxx_0, 0)) self.connect((self.gr_add_const_vxx_0, 0), (self.gr_float_to_char_0, 0)) self.connect((self.gr_float_to_char_0, 0), (self.gr_file_sink_0, 0))
def __init__(self, if_rate, # Incoming sample rate symbol_rate, # Original symbol rate excess_bw, # RRC excess bandwidth, typically 0.35-0.5 costas_alpha, # Costas loop 1st order gain, typically 0.01-0.2 costas_beta, # Costas loop 2nd order gain, typically alpha^2/4.0 costas_max, # Costas loop max frequency offset in radians/sample mm_gain_mu, # M&M loop 1st order gain, typically 0.001-0.2 mm_gain_omega, # M&M loop 2nd order gain, typically alpha^2/4.0 mm_omega_limit, # M&M loop max timing error ): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature grc_wxgui.top_block_gui.__init__(self, title="Top Block") self._if_rate = if_rate self._sps = int(self._if_rate/symbol_rate) print "IF sample rate:", n2s(self._if_rate) print "Symbol rate:", n2s(symbol_rate) print "Samples/symbol:", self._sps print "RRC bandwidth:", excess_bw # Create AGC to scale input to unity self._agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0) # Create RRC with specified excess bandwidth taps = gr.firdes.root_raised_cosine(1.0, # Gain self._sps, # Sampling rate 1.0, # Symbol rate excess_bw, # Roll-off factor 11*self._sps) # Number of taps self._rrc = gr.fir_filter_ccf(1, taps) # Create a Costas loop frequency/phase recovery block print "Costas alpha:", costas_alpha print "Costas beta:", costas_beta print "Costas max:", costas_max self._costas = gr.costas_loop_cc(costas_alpha, # PLL first order gain costas_beta, # PLL second order gain costas_max, # Max frequency offset rad/sample -costas_max, # Min frequency offset rad/sample 2) # BPSK # Create a M&M bit synchronization retiming block mm_mu = 0.5 mm_omega = self._sps print "MM gain mu:", mm_gain_mu print "MM gain omega:", mm_gain_omega print "MM omega limit:", mm_omega_limit self._mm = gr.clock_recovery_mm_cc(mm_omega, # Initial samples/symbol mm_gain_omega, # Second order gain mm_mu, # Initial symbol phase mm_gain_mu, # First order gain mm_omega_limit) # Maximum timing offset # Add an SNR probe on the demodulated constellation self._snr_probe = gr.probe_mpsk_snr_c(10.0/symbol_rate) # #Null for recuperate the out of snr # self.gr_null_sink_0 = gr.null_sink(gr.sizeof_double) # # self.connect(self._snr_probe, (self.gr_null_sink_0,0)) self.connect(self._mm, self._snr_probe) # Slice the resulting constellation into bits. # Get inphase channel and make decision about 0 self._c2r = gr.complex_to_real() self._slicer = gr.binary_slicer_fb() # Descramble BERT sequence. A channel error will create 3 incorrect bits self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit descrambler # Measure BER by the density of 0s in the stream self._ber = gr.probe_density_b(1.0/symbol_rate) # #Null for recuperate the out of ber # self.gr_null_sink_1 = gr.null_sink(gr.sizeof_double) # # self.connect(self._ber, self.gr_null_sink_1) self.create_number_sink(self._sps) self.connect((self._snr_probe, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self._ber, 0), (self.wxgui_numbersink2_1, 0)) self.connect(self, self._agc, self._rrc, self._costas, self._mm, self._c2r, self._slicer, self._descrambler, self._ber)
def __init__(self,frame,panel,vbox,argv): stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv) usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \ "Make sure your input capture file containes interleaved shorts not complex floats" parser=OptionParser(option_class=eng_option, usage=usage) 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("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-f", "--freq", type="eng_float", default=519.25e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option("-o", "--out-filename", type="string", default="sdl", help="For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)") parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat file in a loop") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if not ((len(args) == 1) or (len(args) == 0)): parser.print_help() sys.exit(1) if len(args) == 1: filename = args[0] else: filename = None self.frame = frame self.panel = panel self.contrast = options.contrast self.brightness = options.brightness self.state = "FREQ" self.freq = 0 self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max # build graph self.u=None if not (options.out_filename=="sdl"): options.repeat=False usrp_rate = options.samp_rate if not ((filename is None) or (filename=="usrp")): # file is data source self.filesource = gr.file_source(gr.sizeof_short,filename,options.repeat) self.istoc = gr.interleaved_short_to_complex() self.connect(self.filesource,self.istoc) self.src=self.istoc options.gain=0.0 self.gain=0.0 else: # use a UHD device self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.src=self.u self.gain = options.gain f2uc=gr.float_to_uchar() # sdl window as final sink if not (options.pal or options.ntsc): options.pal=True #set default to PAL if options.pal: lines_per_frame=625.0 frames_per_sec=25.0 show_width=768 elif options.ntsc: lines_per_frame=525.0 frames_per_sec=29.97002997 show_width=640 width=int(usrp_rate/(lines_per_frame*frames_per_sec)) height=int(lines_per_frame) if (options.out_filename=="sdl"): #Here comes the tv screen, you have to build and install #gr-video-sdl for this (subproject of gnuradio, only in cvs #for now) try: video_sink = video_sdl.sink_uc ( frames_per_sec, width, height, 0, show_width, height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst=video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " +str(width)+ "x" + str(height) \ + " gray:" + options.out_filename print "(Use the spacebar to advance to next frames)" options.repeat=False file_sink=gr.file_sink(gr.sizeof_char, options.out_filename) self.dst =file_sink self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7 self.am_demod = gr.complex_to_mag () self.set_blacklevel=gr.add_const_ff(0.0) self.invert_and_scale = gr.multiply_const_ff (0.0) #-self.contrast *128.0*255.0/(200.0) # now wire it all together #sample_rate=options.width*options.height*options.framerate process_type='do_no_sync' if process_type=='do_no_sync': self.connect (self.src, self.agc,self.am_demod, self.invert_and_scale, self.set_blacklevel, f2uc,self.dst) elif process_type=='do_tv_sync_adv': #defaults: gr.tv_sync_adv (double sampling_freq, unsigned #int tv_format,bool output_active_video_only=false, bool #do_invert=false, double wanted_black_level=0.0, double #wanted_white_level=255.0, double avg_alpha=0.1, double #initial_gain=1.0, double initial_offset=0.0,bool #debug=false) #note, this block is not yet in cvs self.tv_sync_adv=gr.tv_sync_adv(usrp_rate, 0, False, False, 0.0, 255.0, 0.01, 1.0, 0.0, False) self.connect (self.src, self.am_demod, self.invert_and_scale, self.tv_sync_adv, s2f, f2uc, self.dst) elif process_type=='do_nullsink': #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink) c2r=gr.complex_to_real() nullsink=gr.null_sink(gr.sizeof_float) self.connect (self.src, c2r,nullsink) #video_sink) elif process_type=='do_tv_sync_corr': frame_size=width*height #int(usrp_rate/25.0) nframes=10# 32 search_window=20*nframes debug=False video_alpha=0.3 #0.1 corr_alpha=0.3 #Note: this block is not yet in cvs tv_corr=gr.tv_correlator_ff(frame_size,nframes, search_window, video_alpha, corr_alpha,debug) shift=gr.add_const_ff(-0.7) self.connect (self.src, self.agc, self.am_demod, tv_corr, self.invert_and_scale, self.set_blacklevel, f2uc, self.dst) else: # process_type=='do_test_image': src_vertical_bars = gr.sig_source_f (usrp_rate, gr.GR_SIN_WAVE, 10.0 *usrp_rate/320, 255,128) self.connect(src_vertical_bars, f2uc, self.dst) self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate) frange = self.u.get_freq_range() if(frange.start() > self.tv_freq_max or frange.stop() < self.tv_freq_min): sys.stderr.write("Radio does not support required frequency range.\n") sys.exit(1) if(options.freq < self.tv_freq_min or options.freq > self.tv_freq_max): sys.stderr.write("Requested frequency is outside of required frequency range.\n") sys.exit(1) # set initial values self.set_gain(options.gain) self.set_contrast(self.contrast) self.set_brightness(options.brightness) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self, options): gr.hier_block2.__init__(self, "bpsk_demodulator", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature grc_wxgui.top_block_gui.__init__(self, title="Top Block") self._samples_per_symbol = options.samples_per_symbol # Number of bits per symbol self._bits_per_symbol = 1 # Create AGC to scale input to unity self._agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0) # Create RRC with specified excess bandwidth taps = gr.firdes.root_raised_cosine(1.0, # Gain self._samples_per_symbol, # Sampling rate 1.0, # Symbol rate 0.35, # Roll-off factor 11*self._samples_per_symbol) # Number of taps self._rrc = gr.fir_filter_ccf(1, taps) # Create a Costas loop frequency/phase recovery block self._costas = digital.costas_loop_cc(6.28/100.0, 2) self.gr_null_sink_f1 = gr.null_sink(gr.sizeof_float*1) # Create a M&M bit synchronization retiming block self._mm = digital.clock_recovery_mm_cc(self._samples_per_symbol, # Initial samples/symbol 1e-06, # Second order gain 0.5, # Initial symbol phase 0.001, # First order gain 0.0001) # Maximum timing offset # Add an SNR probe on the demodulated constellation #self._snr_probe = gr.probe_mpsk_snr_c(10.0/symbol_rate) self._symbol_rate = options.data_rate / self._bits_per_symbol #self._snr_probe = digital.mpsk_snr_est_cc(0, 10000, 0.001) # 0 at the first mean Simple self._snr_probe = digital.probe_mpsk_snr_est_c(digital.SNR_EST_M2M4, alpha=10.0/self._symbol_rate) #self._snr_probe = digital.mpsk_snr_est_cc(digital.SNR_EST_SIMPLE, alpha=10.0/self._symbol_rate) # Slice the resulting constellation into bits. # Get inphase channel and make decision about 0 self._c2r = gr.complex_to_real() self._slicer = digital.binary_slicer_fb() # Descramble BERT sequence. A channel error will create 3 incorrect bits self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 31) # CCSDS 7-bit descrambler # Measure BER by the density of 0s in the stream # self._ber = gr.probe_density_b(1.0/symbol_rate) self._ber = grc_blks2.error_rate(type='BER', win_size=1000, bits_per_symbol=1) #self.create_number_sink(self._samples_per_symbol) self.gr_null_sink_f2 = gr.null_sink(gr.sizeof_float*1) #Create a vector source reference to calculate BER self._vector_source_ref = gr.vector_source_b(([1,]), True, 1) #create a comparator self.comparator = howto.compare_vector_cci((1, 1, 1, 1 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1), (0,0, 1, 1, 0,0), 5, 0, True) #Connection of blocks #"""""""""""""""""""""""""""""""""-->_snr_probe-->gr_null_sink_cc # agc --> _rrc --> costas --> _mm --> _c2r --> _slicer --> _descrambler --> _ber --> gr_null_sink_f2 #"""""""""""""""""""""""""--> gr_null_sink_f1 "" _vector_source_ref--> # # self.connect(self, self._agc, self._rrc, self._costas, self._mm, # self._c2r, self._slicer, self._descrambler, self.comparator, (self._ber, 1)) # self.connect(self, self._agc, self._rrc, self._costas, self._mm, self._c2r, self._slicer, self._descrambler, (self._ber, 1)) self.connect((self._costas, 1), (self.gr_null_sink_f1, 0)) self.connect(self._mm, self._snr_probe) self.connect(self._vector_source_ref, (self._ber,0)) self.connect(self._ber, self.gr_null_sink_f2)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 192000 self.Noise = Noise = 0.01 self.Loudness = Loudness = 0.7 self.Frequency = Frequency = 5000 ################################################## # Blocks ################################################## _Noise_sizer = wx.BoxSizer(wx.VERTICAL) self._Noise_text_box = forms.text_box( parent=self.GetWin(), sizer=_Noise_sizer, value=self.Noise, callback=self.set_Noise, label="Noise", converter=forms.float_converter(), proportion=0, ) self._Noise_slider = forms.slider( parent=self.GetWin(), sizer=_Noise_sizer, value=self.Noise, callback=self.set_Noise, minimum=0.0, maximum=1, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_Noise_sizer) _Loudness_sizer = wx.BoxSizer(wx.VERTICAL) self._Loudness_text_box = forms.text_box( parent=self.GetWin(), sizer=_Loudness_sizer, value=self.Loudness, callback=self.set_Loudness, label="Loudness", converter=forms.float_converter(), proportion=0, ) self._Loudness_slider = forms.slider( parent=self.GetWin(), sizer=_Loudness_sizer, value=self.Loudness, callback=self.set_Loudness, minimum=0.0, maximum=1.0, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_Loudness_sizer) _Frequency_sizer = wx.BoxSizer(wx.VERTICAL) self._Frequency_text_box = forms.text_box( parent=self.GetWin(), sizer=_Frequency_sizer, value=self.Frequency, callback=self.set_Frequency, label="Frequency", converter=forms.int_converter(), proportion=0, ) self._Frequency_slider = forms.slider( parent=self.GetWin(), sizer=_Frequency_sizer, value=self.Frequency, callback=self.set_Frequency, minimum=10, maximum=20000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.Add(_Frequency_sizer) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=4.0, sample_rate=samp_rate, fft_size=2048, fft_rate=15, average=False, avg_alpha=0.1, title="Waterfall Plot", size=(900,200), ) self.Add(self.wxgui_waterfallsink2_0.win) def wxgui_waterfallsink2_0_callback(x, y): self.set_Frequency(x) self.wxgui_waterfallsink2_0.set_callback(wxgui_waterfallsink2_0_callback) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=4.0, sample_rate=samp_rate, fft_size=2048, fft_rate=15, average=True, avg_alpha=0.1, title="FFT Plot", peak_hold=True, ) self.Add(self.wxgui_fftsink2_0.win) self.gr_sig_source_x_2 = gr.sig_source_c(samp_rate, gr.GR_SIN_WAVE, Frequency, Loudness, 0) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, Noise, 0) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_add_xx_1 = gr.add_vcc(1) self.audio_sink_0 = audio.sink(samp_rate, "", True) ################################################## # Connections ################################################## self.connect((self.gr_complex_to_real_0, 0), (self.audio_sink_0, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_1, 0)) self.connect((self.gr_sig_source_x_2, 0), (self.gr_add_xx_1, 1)) self.connect((self.gr_add_xx_1, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_add_xx_1, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.gr_add_xx_1, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self, satellite='NOAAxx', decim=50, baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_NOAA19_2010-09-10_12-35-34_UTC_U2_d50.sam", frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf', deframer_outsync_frames=5, deframer_insync_frames=2, clock_alpha=0.005, gain_mu=0.005, pll_alpha=0.005, pll_beta=0.00001, deframer_sync_check=True, symb_rate=600*1109): grc_wxgui.top_block_gui.__init__(self, title="NOAA HRPT Receiver from baseband file") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.satellite = satellite self.decim = decim self.baseband_file = baseband_file self.frames_file = frames_file self.deframer_outsync_frames = deframer_outsync_frames self.deframer_insync_frames = deframer_insync_frames self.clock_alpha = clock_alpha self.gain_mu = gain_mu self.pll_alpha = pll_alpha self.pll_beta = pll_beta self.deframer_sync_check = deframer_sync_check self.symb_rate = symb_rate ################################################## # Variables ################################################## self.decim_tb = decim_tb = decim self.symb_rate_tb = symb_rate_tb = symb_rate self.samp_rate = samp_rate = 100e6/decim_tb self.sps = sps = samp_rate/symb_rate_tb self.satellite_text = satellite_text = satellite self.samp_rate_st = samp_rate_st = samp_rate self.pll_beta_sl = pll_beta_sl = pll_beta self.pll_alpha_sl = pll_alpha_sl = pll_alpha self.max_clock_offset = max_clock_offset = 0.1 self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/samp_rate self.hs = hs = int(sps/2.0) self.gain_mu_sl = gain_mu_sl = gain_mu self.frames_file_text_inf = frames_file_text_inf = frames_file self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime()) self.clock_alpha_sl = clock_alpha_sl = clock_alpha self.baseband_file_text_inf = baseband_file_text_inf = baseband_file ################################################## # Notebooks ################################################## self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output") self.Add(self.rx_ntb) ################################################## # Controls ################################################## self._decim_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.decim_tb, callback=self.set_decim_tb, label="Decimation", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1) self._symb_rate_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), value=self.symb_rate_tb, callback=self.set_symb_rate_tb, label="Symbol rate", converter=forms.int_converter(), ) self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1) self._satellite_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.satellite_text, callback=self.set_satellite_text, label="Sat ", converter=forms.str_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1) self._samp_rate_st_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.samp_rate_st, callback=self.set_samp_rate_st, label="Sample rate", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1) _pll_beta_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_beta_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_beta_sl_sizer, value=self.pll_beta_sl, callback=self.set_pll_beta_sl, label="PLL Beta", converter=forms.float_converter(), proportion=0, ) self._pll_beta_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_beta_sl_sizer, value=self.pll_beta_sl, callback=self.set_pll_beta_sl, minimum=0.000001, maximum=0.001, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_pll_beta_sl_sizer, 2, 0, 1, 1) _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1) _gain_mu_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_mu_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_gain_mu_sl_sizer, value=self.gain_mu_sl, callback=self.set_gain_mu_sl, label="Gain MU", converter=forms.float_converter(), proportion=0, ) self._gain_mu_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_gain_mu_sl_sizer, value=self.gain_mu_sl, callback=self.set_gain_mu_sl, minimum=0.0001, maximum=0.01, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_gain_mu_sl_sizer, 1, 2, 1, 1) self._frames_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.frames_file_text_inf, callback=self.set_frames_file_text_inf, label="Frames filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1) self._deframer_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_sync_after_text, callback=self.set_deframer_sync_after_text, label="Deframe sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1) self._deframer_nosync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_nosync_after_text, callback=self.set_deframer_nosync_after_text, label="Deframer out of sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1) self._deframer_check_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_check_sync_text, callback=self.set_deframer_check_sync_text, label="Deframer check sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(2).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1) self._datetime_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.datetime_text, callback=self.set_datetime_text, label="Local time of aquisition start", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1) _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, label="Clock alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1) self._baseband_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.baseband_file_text_inf, callback=self.set_baseband_file_text_inf, label="Baseband filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1) ################################################## # Blocks ################################################## self.cs2cf = gr.interleaved_short_to_complex() self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0) self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb() self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps/2.0, clock_alpha**2/4.0, 0.5, gain_mu_sl, max_clock_offset) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_beta_sl, 0.07, -0.07, 2) self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short*1, frames_file) self.gr_file_sink_0_0.set_unbuffered(False) self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, baseband_file, False) self.gr_moving_average_xx_0 = gr.moving_average_cc(hs, 1.0/hs, 4000) self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*2) self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True,False) self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer(deframer_sync_check, 11090, deframer_insync_frames, deframer_outsync_frames) self.wxgui_fftsink1 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=0, y_per_div=5, y_divs=10, ref_level=50, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="Not filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win) self.wxgui_scopesink2_1 = scopesink2.scope_sink_c( self.rx_ntb.GetPage(1).GetWin(), title="PSK constellation diagram", sample_rate=symb_rate, v_scale=0.4, v_offset=0, t_scale=1/samp_rate, ac_couple=False, xy_mode=True, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, ) self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0)) self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0)) self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_binary_slicer_fb_0, 0)) self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0)) self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_univ_hrpt_deframer_0, 0)) self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.noaa_hrpt_decoder_0, 0)) self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0)) self.connect((self.gr_agc_xx_0_0, 0), (self.gr_costas_loop_cc_0, 0)) self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_moving_average_xx_0, 0)) self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.wxgui_scopesink2_1, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__( self, title="Communication System Graphical Analyzer (LAPS/UFCG)") ################################################## # Default Variables ################################################## self.sps = 2 self.snr = 20 self.symbol_rate = 140000 self.mod_type = "DBPSK" self.view = 1 self.band = 200 self.excess_bw = 0.35 self.fading_flag = False self.fdts = -8 self.fading_state_rx = False ################################################## # Blocks Definition ################################################## #A bit stream of 1's is generated at the source, scrambled, #modulated and sent to the input of an AWGN channel. #random.seed(42) #self.source = gr.vector_source_b([random.randint(0, 2) for i in range(0,10^8)], True) self.source = gr.vector_source_b((1, ), True, 1) self.thottle = gr.throttle(gr.sizeof_char, 10e5) self.scrambler = gr.scrambler_bb(0x40801, 0x92F72, 20) #Taxa de simbolos constante self.pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) self.modulator = utils.mods[self.mod_type](self.sps, excess_bw=self.excess_bw) self.channel = utils.channel(1 / 10.0**(self.snr / 10.0), self.band, self.symbol_rate, self.sps) #The noisy signal is demodulated, descrambled and the BER #is estimated by the ber_estim block using the receiver #density of 0 bits. self.demodulator = utils.demods[self.mod_type]( self.sps, excess_bw=self.excess_bw) self.descrambler = gr.descrambler_bb(0x40801, 0x92F72, 20) self.char2float = gr.char_to_float() self.mov_average = gr.moving_average_ff(524288, 1 / 524288., 10000) self.ber = utils.ber_estim() #self.ber = utils.ber_estim_simple(3) ################################################## # GUI Elements Definition ################################################## #Defines an adds FFT Window to GUI self.fft = fftsink.fft_sink_c(self.GetWin(), sample_rate=self.symbol_rate * self.sps, baseband_freq=5e6) self.GridAdd(self.fft.win, 0, 3, 4, 3) self.ctr = gr.complex_to_real(1) #Defines and adds SNR slider to GUI _snr_sizer = wx.BoxSizer(wx.HORIZONTAL) self._snr_text_box = forms.text_box(parent=self.GetWin(), sizer=_snr_sizer, value=self.snr, callback=self.callback_snr, label=" SNR (dB)", converter=forms.float_converter(), proportion=0) self._snr_slider = forms.slider(parent=self.GetWin(), sizer=_snr_sizer, value=self.snr, callback=self.callback_snr, minimum=0, maximum=20, style=wx.RA_HORIZONTAL, proportion=1) self.GridAdd(_snr_sizer, 4, 3, 1, 3) #Defines and adds bandwidth slider to GUI band_sizer = wx.BoxSizer(wx.HORIZONTAL) self.band_text_box = forms.text_box(parent=self.GetWin(), sizer=band_sizer, value=self.band, callback=self.callback_band, label="Bandwidth (kHz)", converter=forms.float_converter(), proportion=0) self.band_slider = forms.slider(parent=self.GetWin(), sizer=band_sizer, value=self.band, callback=self.callback_band, minimum=30, maximum=200, style=wx.RA_HORIZONTAL, proportion=1) self.GridAdd(band_sizer, 5, 3, 1, 3) #Defines and adds Rayleigh GUI elements fading_sizer = wx.BoxSizer(wx.HORIZONTAL) self.fading_text_box = forms.text_box( parent=self.GetWin(), sizer=fading_sizer, value=self.fdts, callback=self.callback_fading, label='Fading/log(FdTs)', converter=forms.float_converter(), proportion=0) self.fading_slider = forms.slider(parent=self.GetWin(), sizer=fading_sizer, value=self.fdts, callback=self.callback_fading, minimum=-8, maximum=-2, style=wx.RA_HORIZONTAL, proportion=1) self.GridAdd(fading_sizer, 6, 3, 1, 3) #Defines and adds modulation type chooser to GUI self._mod_type_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.mod_type, callback=self.set_mod_type, label="Modulation", choices=["DBPSK", "DQPSK", "D8PSK"], labels=["DBPSK", "DQPSK", "D8PSK"], style=wx.RA_HORIZONTAL) self.GridAdd(self._mod_type_chooser, 7, 4, 1, 2) #Defines and adds signal source chooser self.sig_src_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.view, callback=self.callback_view, label="Signal Source", choices=[0, 1], labels=["Transmitter", "Receiver"], style=wx.RA_VERTICAL) self.GridAdd(self.sig_src_chooser, 7, 3, 1, 1) #Definition of the of constellation window and attachment to the GUI self.constel = constsink.const_sink_c(self.GetWin(), title="RX Constellation Plot", sample_rate=self.symbol_rate, const_size=256, mod=self.mod_type) self.GridAdd(self.constel.win, 0, 0, 8, 3) #Definition of the constellation sink window and attachment to the GUI self.number_sink = bersink.number_sink_f(self.GetWin(), sample_rate=self.symbol_rate) self.GridAdd(self.number_sink.win, 8, 0, 1, 6) ################################################## # Blocks Connections ################################################## #The necessary block connections to the system work as described above. self.connect(self.source, self.scrambler, self.thottle, self.pack) #self.connect(self.source , self.thottle, self.pack) self.connect(self.pack, self.modulator, self.channel, self.demodulator) self.connect(self.channel, self.fft) self.connect(self.demodulator.diffdec, self.constel) self.connect(self.demodulator, self.descrambler, self.char2float, self.mov_average) self.connect(self.mov_average, self.ber, self.number_sink)
def __init__ (self, demod_rate, audio_decimation): """ Hierarchical block for demodulating a broadcast FM signal. The input is the downconverted complex baseband signal (gr_complex). The output is two streams of the demodulated audio (float) 0=Left, 1=Right. Args: demod_rate: input sample rate of complex baseband input. (float) audio_decimation: how much to decimate demod_rate to get to audio. (integer) """ gr.hier_block2.__init__(self, "wfm_rcv_fmdet", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(2, 2, gr.sizeof_float)) # Output signature lowfreq = -125e3/demod_rate highfreq = 125e3/demod_rate audio_rate = demod_rate / audio_decimation # We assign to self so that outsiders can grab the demodulator # if they need to. E.g., to plot its output. # # input: complex; output: float self.fm_demod = gr.fmdet_cf (demod_rate, lowfreq, highfreq, 0.05) # input: float; output: float self.deemph_Left = fm_deemph (audio_rate) self.deemph_Right = fm_deemph (audio_rate) # compute FIR filter taps for audio filter width_of_transition_band = audio_rate / 32 audio_coeffs = gr.firdes.low_pass (1.0 , # gain demod_rate, # sampling rate 15000 , width_of_transition_band, gr.firdes.WIN_HAMMING) # input: float; output: float self.audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) if 1: # Pick off the stereo carrier/2 with this filter. It # attenuated 10 dB so apply 10 dB gain We pick off the # negative frequency half because we want to base band by # it! ## NOTE THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO ## DEEMPHASIS stereo_carrier_filter_coeffs = gr.firdes.complex_band_pass(10.0, demod_rate, -19020, -18980, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs) #print "stereo carrier filter ", stereo_carrier_filter_coeffs #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate # Pick off the double side band suppressed carrier # Left-Right audio. It is attenuated 10 dB so apply 10 dB # gain stereo_dsbsc_filter_coeffs = gr.firdes.complex_band_pass(20.0, demod_rate, 38000-15000/2, 38000+15000/2, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs # construct overlap add filter system from coefficients # for stereo carrier self.stereo_carrier_filter = gr.fir_filter_fcc(audio_decimation, stereo_carrier_filter_coeffs) # carrier is twice the picked off carrier so arrange to do # a commplex multiply self.stereo_carrier_generator = gr.multiply_cc(); # Pick off the rds signal stereo_rds_filter_coeffs = gr.firdes.complex_band_pass(30.0, demod_rate, 57000 - 1500, 57000 + 1500, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs # construct overlap add filter system from coefficients for stereo carrier self.rds_signal_filter = gr.fir_filter_fcc(audio_decimation, stereo_rds_filter_coeffs) self.rds_carrier_generator = gr.multiply_cc(); self.rds_signal_generator = gr.multiply_cc(); self_rds_signal_processor = gr.null_sink(gr.sizeof_gr_complex); loop_bw = 2*math.pi/100.0 max_freq = -2.0*math.pi*18990/audio_rate; min_freq = -2.0*math.pi*19010/audio_rate; self.stereo_carrier_pll_recovery = gr.pll_refout_cc(loop_bw, max_freq, min_freq); #self.stereo_carrier_pll_recovery.squelch_enable(False) ##pll_refout does not have squelch yet, so disabled for #now # set up mixer (multiplier) to get the L-R signal at # baseband self.stereo_basebander = gr.multiply_cc(); # pick off the real component of the basebanded L-R # signal. The imaginary SHOULD be zero self.LmR_real = gr.complex_to_real(); self.Make_Left = gr.add_ff(); self.Make_Right = gr.sub_ff(); self.stereo_dsbsc_filter = gr.fir_filter_fcc(audio_decimation, stereo_dsbsc_filter_coeffs) if 1: # send the real signal to complex filter to pick off the # carrier and then to one side of a multiplier self.connect (self, self.fm_demod, self.stereo_carrier_filter, self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,0)) # send the already filtered carrier to the otherside of the carrier # the resulting signal from this multiplier is the carrier # with correct phase but at -38000 Hz. self.connect (self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,1)) # send the new carrier to one side of the mixer (multiplier) self.connect (self.stereo_carrier_generator, (self.stereo_basebander,0)) # send the demphasized audio to the DSBSC pick off filter, the complex # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier # the result is BASEBANDED DSBSC with phase zero! self.connect (self.fm_demod,self.stereo_dsbsc_filter, (self.stereo_basebander,1)) # Pick off the real part since the imaginary is # theoretically zero and then to one side of a summer self.connect (self.stereo_basebander, self.LmR_real, (self.Make_Left,0)) #take the same real part of the DSBSC baseband signal and #send it to negative side of a subtracter self.connect (self.LmR_real,(self.Make_Right,1)) # Make rds carrier by taking the squared pilot tone and # multiplying by pilot tone self.connect (self.stereo_basebander,(self.rds_carrier_generator,0)) self.connect (self.stereo_carrier_pll_recovery,(self.rds_carrier_generator,1)) # take signal, filter off rds, send into mixer 0 channel self.connect (self.fm_demod,self.rds_signal_filter,(self.rds_signal_generator,0)) # take rds_carrier_generator output and send into mixer 1 # channel self.connect (self.rds_carrier_generator,(self.rds_signal_generator,1)) # send basebanded rds signal and send into "processor" # which for now is a null sink self.connect (self.rds_signal_generator,self_rds_signal_processor) if 1: # pick off the audio, L+R that is what we used to have and # send it to the summer self.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1)) # take the picked off L+R audio and send it to the PLUS # side of the subtractor self.connect(self.audio_filter,(self.Make_Right, 0)) # The result of Make_Left gets (L+R) + (L-R) and results in 2*L # The result of Make_Right gets (L+R) - (L-R) and results in 2*R self.connect(self.Make_Left , self.deemph_Left, (self, 0)) self.connect(self.Make_Right, self.deemph_Right, (self, 1))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Communication System Graphical Analyzer (LAPS/UFCG)") ################################################## # Default Variables ################################################## self.sps = 2 self.snr = 20 self.symbol_rate = 140000 self.mod_type = "DBPSK" self.view = 1 self.band= 200 self.excess_bw=0.35 self.fading_flag = False self.fdts = -8 self.fading_state_rx = False ################################################## # Blocks Definition ################################################## #A bit stream of 1's is generated at the source, scrambled, #modulated and sent to the input of an AWGN channel. #random.seed(42) #self.source = gr.vector_source_b([random.randint(0, 2) for i in range(0,10^8)], True) self.source = gr.vector_source_b((1,), True, 1) self.thottle = gr.throttle(gr.sizeof_char,10e5) self.scrambler = gr.scrambler_bb(0x40801, 0x92F72, 20) #Taxa de simbolos constante self.pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) self.modulator = utils.mods[self.mod_type](self.sps,excess_bw=self.excess_bw) self.channel = utils.channel(1/10.0**(self.snr/10.0),self.band,self.symbol_rate,self.sps) #The noisy signal is demodulated, descrambled and the BER #is estimated by the ber_estim block using the receiver #density of 0 bits. self.demodulator = utils.demods[self.mod_type](self.sps,excess_bw=self.excess_bw) self.descrambler = gr.descrambler_bb(0x40801, 0x92F72, 20) self.char2float = gr.char_to_float() self.mov_average = gr.moving_average_ff(524288, 1/524288., 10000) self.ber = utils.ber_estim() #self.ber = utils.ber_estim_simple(3) ################################################## # GUI Elements Definition ################################################## #Defines an adds FFT Window to GUI self.fft = fftsink.fft_sink_c(self.GetWin(), sample_rate=self.symbol_rate*self.sps, baseband_freq=5e6) self.GridAdd(self.fft.win, 0,3,4,3) self.ctr= gr.complex_to_real(1) #Defines and adds SNR slider to GUI _snr_sizer = wx.BoxSizer(wx.HORIZONTAL) self._snr_text_box = forms.text_box(parent=self.GetWin(), sizer=_snr_sizer, value=self.snr, callback=self.callback_snr, label=" SNR (dB)", converter=forms.float_converter(), proportion=0) self._snr_slider = forms.slider(parent=self.GetWin(), sizer=_snr_sizer, value=self.snr, callback=self.callback_snr, minimum=0, maximum=20, style=wx.RA_HORIZONTAL, proportion=1) self.GridAdd(_snr_sizer, 4, 3, 1, 3) #Defines and adds bandwidth slider to GUI band_sizer = wx.BoxSizer(wx.HORIZONTAL) self.band_text_box = forms.text_box(parent=self.GetWin(), sizer=band_sizer, value=self.band, callback=self.callback_band, label="Bandwidth (kHz)", converter=forms.float_converter(), proportion=0) self.band_slider = forms.slider(parent=self.GetWin(), sizer=band_sizer, value=self.band, callback=self.callback_band, minimum=30, maximum=200, style=wx.RA_HORIZONTAL, proportion=1) self.GridAdd(band_sizer, 5, 3, 1, 3) #Defines and adds Rayleigh GUI elements fading_sizer = wx.BoxSizer(wx.HORIZONTAL) self.fading_text_box = forms.text_box(parent=self.GetWin(), sizer=fading_sizer, value=self.fdts, callback=self.callback_fading, label='Fading/log(FdTs)', converter=forms.float_converter(), proportion=0) self.fading_slider = forms.slider(parent=self.GetWin(), sizer=fading_sizer, value=self.fdts, callback=self.callback_fading, minimum=-8, maximum=-2, style=wx.RA_HORIZONTAL, proportion=1) self.GridAdd(fading_sizer, 6, 3, 1, 3) #Defines and adds modulation type chooser to GUI self._mod_type_chooser = forms.radio_buttons(parent=self.GetWin(), value=self.mod_type, callback=self.set_mod_type, label="Modulation", choices=["DBPSK", "DQPSK", "D8PSK"], labels=["DBPSK", "DQPSK", "D8PSK"], style=wx.RA_HORIZONTAL) self.GridAdd(self._mod_type_chooser, 7, 4, 1, 2) #Defines and adds signal source chooser self.sig_src_chooser = forms.radio_buttons(parent=self.GetWin(), value=self.view, callback=self.callback_view, label="Signal Source", choices=[0,1], labels=["Transmitter","Receiver"], style=wx.RA_VERTICAL) self.GridAdd(self.sig_src_chooser, 7,3,1,1) #Definition of the of constellation window and attachment to the GUI self.constel = constsink.const_sink_c(self.GetWin(), title="RX Constellation Plot", sample_rate=self.symbol_rate, const_size=256, mod=self.mod_type) self.GridAdd(self.constel.win,0,0,8,3) #Definition of the constellation sink window and attachment to the GUI self.number_sink = bersink.number_sink_f(self.GetWin(), sample_rate=self.symbol_rate) self.GridAdd(self.number_sink.win,8,0,1,6) ################################################## # Blocks Connections ################################################## #The necessary block connections to the system work as described above. self.connect(self.source, self.scrambler , self.thottle, self.pack) #self.connect(self.source , self.thottle, self.pack) self.connect(self.pack, self.modulator, self.channel, self.demodulator) self.connect(self.channel, self.fft) self.connect(self.demodulator.diffdec, self.constel) self.connect(self.demodulator, self.descrambler, self.char2float, self.mov_average) self.connect(self.mov_average, self.ber, self.number_sink)
def __init__(self, options, payload='', msgq_limit=2, pad_for_usrp=False): """ Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param options: pass modulation options from higher layers (fft length, occupied tones, etc.) @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples """ gr.hier_block2.__init__( self, "ofdm_mod", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._fft_length = 64 self._total_sub_carriers = 53 self._data_subcarriers = 48 self._cp_length = 16 self._regime = options.regime self._symbol_length = self._fft_length + self._cp_length self._role = options.role # assuming we have 100Ms/s going to the USRP2 and 80 samples per symbol # we can calculate the OFDM symboltime (in microseconds) # depending on the interpolation factor self._symbol_time = options.interp * (self._fft_length + self._cp_length) / 100 win = [] if (self._regime == "1" or self._regime == "2"): rotated_const = ofdm_packet_utils.bpsk(self) elif (self._regime == "3" or self._regime == "4"): rotated_const = ofdm_packet_utils.qpsk(self) elif (self._regime == "5" or self._regime == "6"): rotated_const = ofdm_packet_utils.qam16(self) elif (self._regime == "7" or self._regime == "8"): rotated_const = ofdm_packet_utils.qam64(self) # map groups of bits to complex symbols self._pkt_input = ftw.ofdm_mapper(rotated_const, msgq_limit, self._data_subcarriers, self._fft_length) # insert pilot symbols (use pnc block * by lzyou) if self._role == 'A': print " >>> [FPNC]: *A* Insert Pilot" self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 1) elif self._role == 'B': print " >>> [FPNC]: *B* Insert Pilot" self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 2) else: print " >>> [FTW ]: Insert Pilot" self.pilot = ftw.ofdm_pilot_cc(self._data_subcarriers) # just for test #self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 1) #self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 2) # move subcarriers to their designated place and insert DC self.cmap = ftw.ofdm_cmap_cc(self._fft_length, self._total_sub_carriers) # inverse fast fourier transform self.ifft = gr.fft_vcc(self._fft_length, False, win, False) # add cyclic prefix from gnuradio import digital self.cp_adder = digital.ofdm_cyclic_prefixer(self._fft_length, self._symbol_length) self.connect( gr.null_source(gr.sizeof_char), (self.cp_adder, 1)) # Note: dirty modification to accomdate the API change # scale accordingly self.scale = gr.multiply_const_cc(1.0 / math.sqrt(self._fft_length)) # we need to know the number of OFDM data symbols for preamble and zerogap info = ofdm_packet_utils.get_info(payload, options.regime, self._symbol_time) N_sym = info["N_sym"] # add training sequence (modify by lzyou) if self._role == 'A': print " >>> [FPNC]: *A* Insert Preamble" self.preamble = ofdm_packet_utils.insert_preamble( self._symbol_length, N_sym, 'A') elif self._role == 'B': print " >>> [FPNC]: *B* Insert Preamble" self.preamble = ofdm_packet_utils.insert_preamble( self._symbol_length, N_sym, 'B') else: print " >>> [FTW ]: Insert Preamble" self.preamble = ofdm_packet_utils.insert_preamble( self._symbol_length, N_sym) # append zero samples at the end (receiver needs that to decode) if self._role == None: print " >>> [FTW ]: Insert Zerogap" self.zerogap = ofdm_packet_utils.insert_zerogap( self._symbol_length, N_sym) else: print " >>> [FPNC]: Insert Zerogap" self.zerogap = ofdm_packet_utils.insert_zerogap( self._symbol_length, N_sym, 'FPNC') self.s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._symbol_length) self.v2s = gr.vector_to_stream(gr.sizeof_gr_complex, self._symbol_length) # swap real and immaginary component before sending (GNURadio/USRP2 bug!) if options.swapIQ == True: self.gr_complex_to_imag_0 = gr.complex_to_imag(1) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.connect((self.v2s, 0), (self.gr_complex_to_imag_0, 0)) self.connect((self.v2s, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_complex_to_imag_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self)) elif options.swapIQ == False: self.gr_complex_to_imag_0 = gr.complex_to_imag(1) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.connect((self.v2s, 0), (self.gr_complex_to_imag_0, 0)) self.connect((self.v2s, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_imag_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self)) # connect the blocks self.connect((self._pkt_input, 0), (self.pilot, 0)) self.connect((self._pkt_input, 1), (self.preamble, 1)) self.connect((self.preamble, 1), (self.zerogap, 1)) self.connect(self.pilot, self.cmap, self.ifft, self.cp_adder, self.scale, self.s2v, self.preamble, self.zerogap, self.v2s) if options.log: self.connect( (self._pkt_input), gr.file_sink(gr.sizeof_gr_complex * self._data_subcarriers, "ofdm_mapper.dat")) self.connect( self.pilot, gr.file_sink( gr.sizeof_gr_complex * (5 + self._data_subcarriers), "ofdm_pilot.dat")) self.connect( self.cmap, gr.file_sink(gr.sizeof_gr_complex * self._fft_length, "ofdm_cmap.dat")) self.connect( self.ifft, gr.file_sink(gr.sizeof_gr_complex * self._fft_length, "ofdm_ifft.dat")) self.connect( self.cp_adder, gr.file_sink(gr.sizeof_gr_complex, "ofdm_cp_adder.dat")) self.connect(self.scale, gr.file_sink(gr.sizeof_gr_complex, "ofdm_scale.dat")) self.connect( self.preamble, gr.file_sink(gr.sizeof_gr_complex * self._symbol_length, "ofdm_preamble.dat")) self.connect( self.zerogap, gr.file_sink(gr.sizeof_gr_complex * self._symbol_length, "ofdm_zerogap.dat"))
def __init__(self, options, payload='', msgq_limit=2, pad_for_usrp=False): """ Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param options: pass modulation options from higher layers (fft length, occupied tones, etc.) @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples """ gr.hier_block2.__init__(self, "ofdm_mod", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._fft_length = 64 self._total_sub_carriers = 53 self._data_subcarriers = 48 self._cp_length = 16 self._regime = options.regime self._symbol_length = self._fft_length + self._cp_length self._role = options.role # assuming we have 100Ms/s going to the USRP2 and 80 samples per symbol # we can calculate the OFDM symboltime (in microseconds) # depending on the interpolation factor self._symbol_time = options.interp*(self._fft_length+self._cp_length)/100 win = [] if(self._regime == "1" or self._regime == "2"): rotated_const = ofdm_packet_utils.bpsk(self) elif (self._regime == "3" or self._regime == "4"): rotated_const = ofdm_packet_utils.qpsk(self) elif(self._regime == "5" or self._regime == "6"): rotated_const = ofdm_packet_utils.qam16(self) elif(self._regime == "7" or self._regime == "8"): rotated_const = ofdm_packet_utils.qam64(self) # map groups of bits to complex symbols self._pkt_input = ftw.ofdm_mapper(rotated_const, msgq_limit, self._data_subcarriers, self._fft_length) # insert pilot symbols (use pnc block * by lzyou) if self._role == 'A': print " >>> [FPNC]: *A* Insert Pilot" self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 1) elif self._role == 'B': print " >>> [FPNC]: *B* Insert Pilot" self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 2) else: print " >>> [FTW ]: Insert Pilot" self.pilot = ftw.ofdm_pilot_cc(self._data_subcarriers) # just for test #self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 1) #self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 2) # move subcarriers to their designated place and insert DC self.cmap = ftw.ofdm_cmap_cc(self._fft_length, self._total_sub_carriers) # inverse fast fourier transform self.ifft = gr.fft_vcc(self._fft_length, False, win, False) # add cyclic prefix from gnuradio import digital self.cp_adder = digital.ofdm_cyclic_prefixer(self._fft_length, self._symbol_length) self.connect(gr.null_source(gr.sizeof_char), (self.cp_adder, 1)) # Note: dirty modification to accomdate the API change # scale accordingly self.scale = gr.multiply_const_cc(1.0 / math.sqrt(self._fft_length)) # we need to know the number of OFDM data symbols for preamble and zerogap info = ofdm_packet_utils.get_info(payload, options.regime, self._symbol_time) N_sym = info["N_sym"] # add training sequence (modify by lzyou) if self._role == 'A': print " >>> [FPNC]: *A* Insert Preamble" self.preamble= ofdm_packet_utils.insert_preamble(self._symbol_length, N_sym, 'A') elif self._role == 'B': print " >>> [FPNC]: *B* Insert Preamble" self.preamble= ofdm_packet_utils.insert_preamble(self._symbol_length, N_sym, 'B') else: print " >>> [FTW ]: Insert Preamble" self.preamble= ofdm_packet_utils.insert_preamble(self._symbol_length, N_sym) # append zero samples at the end (receiver needs that to decode) if self._role == None: print " >>> [FTW ]: Insert Zerogap" self.zerogap = ofdm_packet_utils.insert_zerogap(self._symbol_length, N_sym) else: print " >>> [FPNC]: Insert Zerogap" self.zerogap = ofdm_packet_utils.insert_zerogap(self._symbol_length, N_sym, 'FPNC') self.s2v = gr.stream_to_vector(gr.sizeof_gr_complex , self._symbol_length) self.v2s = gr.vector_to_stream(gr.sizeof_gr_complex , self._symbol_length) # swap real and immaginary component before sending (GNURadio/USRP2 bug!) if options.swapIQ == True: self.gr_complex_to_imag_0 = gr.complex_to_imag(1) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.connect((self.v2s, 0), (self.gr_complex_to_imag_0, 0)) self.connect((self.v2s, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_complex_to_imag_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self)) elif options.swapIQ == False: self.gr_complex_to_imag_0 = gr.complex_to_imag(1) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.connect((self.v2s, 0), (self.gr_complex_to_imag_0, 0)) self.connect((self.v2s, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_imag_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self)) # connect the blocks self.connect((self._pkt_input, 0), (self.pilot, 0)) self.connect((self._pkt_input,1), (self.preamble, 1)) self.connect((self.preamble,1), (self.zerogap, 1)) self.connect(self.pilot, self.cmap, self.ifft, self.cp_adder, self.scale, self.s2v, self.preamble, self.zerogap, self.v2s) if options.log: self.connect((self._pkt_input), gr.file_sink(gr.sizeof_gr_complex * self._data_subcarriers, "ofdm_mapper.dat")) self.connect(self.pilot, gr.file_sink(gr.sizeof_gr_complex * (5 + self._data_subcarriers), "ofdm_pilot.dat")) self.connect(self.cmap, gr.file_sink(gr.sizeof_gr_complex * self._fft_length, "ofdm_cmap.dat")) self.connect(self.ifft, gr.file_sink(gr.sizeof_gr_complex * self._fft_length, "ofdm_ifft.dat")) self.connect(self.cp_adder, gr.file_sink(gr.sizeof_gr_complex, "ofdm_cp_adder.dat")) self.connect(self.scale, gr.file_sink(gr.sizeof_gr_complex, "ofdm_scale.dat")) self.connect(self.preamble, gr.file_sink(gr.sizeof_gr_complex * self._symbol_length, "ofdm_preamble.dat")) self.connect(self.zerogap, gr.file_sink(gr.sizeof_gr_complex * self._symbol_length, "ofdm_zerogap.dat"))
def __init__( self, satellite='NOAAxx', decim=50, baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_NOAA19_2010-09-10_12-35-34_UTC_U2_d50.sam", frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf', deframer_outsync_frames=5, deframer_insync_frames=2, clock_alpha=0.005, gain_mu=0.005, pll_alpha=0.005, pll_beta=0.00001, deframer_sync_check=True, symb_rate=600 * 1109): grc_wxgui.top_block_gui.__init__( self, title="NOAA HRPT Receiver from baseband file") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.satellite = satellite self.decim = decim self.baseband_file = baseband_file self.frames_file = frames_file self.deframer_outsync_frames = deframer_outsync_frames self.deframer_insync_frames = deframer_insync_frames self.clock_alpha = clock_alpha self.gain_mu = gain_mu self.pll_alpha = pll_alpha self.pll_beta = pll_beta self.deframer_sync_check = deframer_sync_check self.symb_rate = symb_rate ################################################## # Variables ################################################## self.decim_tb = decim_tb = decim self.symb_rate_tb = symb_rate_tb = symb_rate self.samp_rate = samp_rate = 100e6 / decim_tb self.sps = sps = samp_rate / symb_rate_tb self.satellite_text = satellite_text = satellite self.samp_rate_st = samp_rate_st = samp_rate self.pll_beta_sl = pll_beta_sl = pll_beta self.pll_alpha_sl = pll_alpha_sl = pll_alpha self.max_clock_offset = max_clock_offset = 0.1 self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / samp_rate self.hs = hs = int(sps / 2.0) self.gain_mu_sl = gain_mu_sl = gain_mu self.frames_file_text_inf = frames_file_text_inf = frames_file self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime()) self.clock_alpha_sl = clock_alpha_sl = clock_alpha self.baseband_file_text_inf = baseband_file_text_inf = baseband_file ################################################## # Notebooks ################################################## self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output") self.Add(self.rx_ntb) ################################################## # Controls ################################################## self._decim_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.decim_tb, callback=self.set_decim_tb, label="Decimation", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1) self._symb_rate_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), value=self.symb_rate_tb, callback=self.set_symb_rate_tb, label="Symbol rate", converter=forms.int_converter(), ) self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1) self._satellite_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.satellite_text, callback=self.set_satellite_text, label="Sat ", converter=forms.str_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1) self._samp_rate_st_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.samp_rate_st, callback=self.set_samp_rate_st, label="Sample rate", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1) _pll_beta_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_beta_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_beta_sl_sizer, value=self.pll_beta_sl, callback=self.set_pll_beta_sl, label="PLL Beta", converter=forms.float_converter(), proportion=0, ) self._pll_beta_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_beta_sl_sizer, value=self.pll_beta_sl, callback=self.set_pll_beta_sl, minimum=0.000001, maximum=0.001, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_pll_beta_sl_sizer, 2, 0, 1, 1) _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1) _gain_mu_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_mu_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_gain_mu_sl_sizer, value=self.gain_mu_sl, callback=self.set_gain_mu_sl, label="Gain MU", converter=forms.float_converter(), proportion=0, ) self._gain_mu_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_gain_mu_sl_sizer, value=self.gain_mu_sl, callback=self.set_gain_mu_sl, minimum=0.0001, maximum=0.01, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_gain_mu_sl_sizer, 1, 2, 1, 1) self._frames_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.frames_file_text_inf, callback=self.set_frames_file_text_inf, label="Frames filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1) self._deframer_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_sync_after_text, callback=self.set_deframer_sync_after_text, label="Deframe sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._deframer_sync_after_text_static_text, 3, 0, 1, 1) self._deframer_nosync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_nosync_after_text, callback=self.set_deframer_nosync_after_text, label="Deframer out of sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._deframer_nosync_after_text_static_text, 4, 0, 1, 1) self._deframer_check_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.deframer_check_sync_text, callback=self.set_deframer_check_sync_text, label="Deframer check sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._deframer_check_sync_text_static_text, 2, 0, 1, 1) self._datetime_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.datetime_text, callback=self.set_datetime_text, label="Local time of aquisition start", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1) _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, label="Clock alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1) self._baseband_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.baseband_file_text_inf, callback=self.set_baseband_file_text_inf, label="Baseband filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd( self._baseband_file_text_inf_static_text, 4, 0, 1, 1) ################################################## # Blocks ################################################## self.cs2cf = gr.interleaved_short_to_complex() self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0) self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb() self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc( sps / 2.0, clock_alpha**2 / 4.0, 0.5, gain_mu_sl, max_clock_offset) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_beta_sl, 0.07, -0.07, 2) self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file) self.gr_file_sink_0_0.set_unbuffered(False) self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1, baseband_file, False) self.gr_moving_average_xx_0 = gr.moving_average_cc(hs, 1.0 / hs, 4000) self.gr_throttle_0 = gr.throttle(gr.sizeof_short * 1, samp_rate * 2) self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True, False) self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer( deframer_sync_check, 11090, deframer_insync_frames, deframer_outsync_frames) self.wxgui_fftsink1 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=0, y_per_div=5, y_divs=10, ref_level=50, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="Not filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win) self.wxgui_scopesink2_1 = scopesink2.scope_sink_c( self.rx_ntb.GetPage(1).GetWin(), title="PSK constellation diagram", sample_rate=symb_rate, v_scale=0.4, v_offset=0, t_scale=1 / samp_rate, ac_couple=False, xy_mode=True, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, ) self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0)) self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0)) self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_binary_slicer_fb_0, 0)) self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0)) self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_univ_hrpt_deframer_0, 0)) self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.noaa_hrpt_decoder_0, 0)) self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0)) self.connect((self.gr_agc_xx_0_0, 0), (self.gr_costas_loop_cc_0, 0)) self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_moving_average_xx_0, 0)) self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.wxgui_scopesink2_1, 0))
def __init__(self, options): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(2, 2, gr.sizeof_gr_complex)) common_options.defaults(options) config = self.config = station_configuration() config.data_subcarriers = options.subcarriers config.cp_length = options.cp_length config.frame_data_blocks = options.data_blocks config._verbose = options.verbose config.fft_length = options.fft_length config.training_data = default_block_header(config.data_subcarriers, config.fft_length, options) config.tx_station_id = options.station_id config.coding = options.coding if config.tx_station_id is None: raise SystemError, "Station ID not set" config.frame_id_blocks = 1 # FIXME # digital rms amplitude sent to USRP rms_amp = options.rms_amplitude self._options = copy.copy(options) self.servants = [] # FIXME config.block_length = config.fft_length + config.cp_length config.frame_data_part = config.frame_data_blocks + config.frame_id_blocks config.frame_length = config.frame_data_part + \ config.training_data.no_pilotsyms config.subcarriers = config.data_subcarriers + \ config.training_data.pilot_subcarriers config.virtual_subcarriers = config.fft_length - config.subcarriers # default values if parameters not set if rms_amp is None: rms_amp = math.sqrt(config.subcarriers) config.rms_amplitude = rms_amp # check some bounds if config.fft_length < config.subcarriers: raise SystemError, "Subcarrier number must be less than FFT length" if config.fft_length < config.cp_length: raise SystemError, "Cyclic prefix length must be less than FFT length" ## shortcuts blen = config.block_length flen = config.frame_length dsubc = config.data_subcarriers vsubc = config.virtual_subcarriers # ------------------------------------------------------------------------ # # Adaptive Transmitter Concept used_id_bits = config.used_id_bits = 8 #TODO: no constant in source code rep_id_bits = config.rep_id_bits = config.data_subcarriers / used_id_bits #BPSK if config.data_subcarriers % used_id_bits <> 0: raise SystemError, "Data subcarriers need to be multiple of %d" % ( used_id_bits) ## Control Part if options.debug: self._control = ctrl = static_tx_control(options) print "Statix TX Control used" else: self._control = ctrl = corba_tx_control(options) print "CORBA TX Control used" id_src = (ctrl, 0) mux_src = (ctrl, 1) map_src = self._map_src = (ctrl, 2) pa_src = (ctrl, 3) if options.log: id_src_f = gr.short_to_float() self.connect(id_src, id_src_f) log_to_file(self, id_src_f, "data/id_src_out.float") mux_src_f = gr.short_to_float() self.connect(mux_src, mux_src_f) log_to_file(self, mux_src_f, "data/mux_src_out.float") map_src_s = blocks.vector_to_stream(gr.sizeof_char, config.data_subcarriers) map_src_f = gr.char_to_float() self.connect(map_src, map_src_s, map_src_f) ##log_to_file(self, map_src_f, "data/map_src.float") ##log_to_file(self, pa_src, "data/pa_src_out.float") ## Workaround to avoid periodic structure seed(1) whitener_pn = [ randint(0, 1) for i in range(used_id_bits * rep_id_bits) ] ## ID Encoder id_enc = self._id_encoder = repetition_encoder_sb( used_id_bits, rep_id_bits, whitener_pn) self.connect(id_src, id_enc) if options.log: id_enc_f = gr.char_to_float() self.connect(id_enc, id_enc_f) log_to_file(self, id_enc_f, "data/id_enc_out.float") ## Bitmap Update Trigger # TODO #bmaptrig_stream = concatenate([[1, 2],[0]*(config.frame_data_part-7)]) bmaptrig_stream = concatenate([[1, 1], [0] * (config.frame_data_part - 2)]) print "bmaptrig_stream = ", bmaptrig_stream btrig = self._bitmap_trigger = blocks.vector_source_b( bmaptrig_stream.tolist(), True) if options.log: log_to_file(self, btrig, "data/bitmap_trig.char") ## Bitmap Update Trigger for puncturing # TODO if not options.nopunct: #bmaptrig_stream_puncturing = concatenate([[1],[0]*(config.frame_data_part-2)]) bmaptrig_stream_puncturing = concatenate( [[1], [0] * (config.frame_data_blocks / 2 - 1)]) btrig_puncturing = self._bitmap_trigger_puncturing = blocks.vector_source_b( bmaptrig_stream_puncturing.tolist(), True) bmapsrc_stream_puncturing = concatenate([[1] * dsubc, [2] * dsubc]) bsrc_puncturing = self._bitmap_src_puncturing = blocks.vector_source_b( bmapsrc_stream_puncturing.tolist(), True, dsubc) if options.log and options.coding and not options.nopunct: log_to_file(self, btrig_puncturing, "data/bitmap_trig_puncturing.char") ## Frame Trigger # TODO ftrig_stream = concatenate([[1], [0] * (config.frame_data_part - 1)]) ftrig = self._frame_trigger = blocks.vector_source_b( ftrig_stream.tolist(), True) ## Data Multiplexer # Input 0: control stream # Input 1: encoded ID stream # Inputs 2..n: data streams dmux = self._data_multiplexer = stream_controlled_mux_b() self.connect(mux_src, (dmux, 0)) self.connect(id_enc, (dmux, 1)) self._data_multiplexer_nextport = 2 if options.log: dmux_f = gr.char_to_float() self.connect(dmux, dmux_f) log_to_file(self, dmux_f, "data/dmux_out.float") ## Modulator mod = self._modulator = generic_mapper_bcv(config.data_subcarriers, options.coding) self.connect(dmux, (mod, 0)) self.connect(map_src, (mod, 1)) self.connect(btrig, (mod, 2)) if options.log: log_to_file(self, mod, "data/mod_out.compl") modi = gr.complex_to_imag(config.data_subcarriers) modr = gr.complex_to_real(config.data_subcarriers) self.connect(mod, modi) self.connect(mod, modr) log_to_file(self, modi, "data/mod_imag_out.float") log_to_file(self, modr, "data/mod_real_out.float") ## Power allocator if options.debug: ## static pa = self._power_allocator = power_allocator( config.data_subcarriers) self.connect(mod, (pa, 0)) self.connect(pa_src, (pa, 1)) else: ## with CORBA control event channel ns_ip = ctrl.ns_ip ns_port = ctrl.ns_port evchan = ctrl.evchan pa = self._power_allocator = corba_power_allocator(dsubc, \ evchan, ns_ip, ns_port, True) self.connect(mod, (pa, 0)) self.connect(id_src, (pa, 1)) self.connect(ftrig, (pa, 2)) if options.log: log_to_file(self, pa, "data/pa_out.compl") ## Pilot subcarriers psubc = self._pilot_subcarrier_inserter = pilot_subcarrier_inserter() self.connect(pa, psubc) pilot_subc = config.training_data.shifted_pilot_tones print "pilot_subc", pilot_subc stc = stc_encoder(config.subcarriers, config.frame_data_blocks, pilot_subc) self.connect(psubc, stc) if options.log: log_to_file(self, psubc, "data/psubc_out.compl") log_to_file(self, psubc_2, "data/psubc2_out.compl") log_to_file(self, pa, "data/pa.compl") log_to_file(self, (stc, 0), "data/stc_0.compl") log_to_file(self, (stc, 1), "data/stc_1.compl") ## Add virtual subcarriers if config.fft_length > config.subcarriers: vsubc = self._virtual_subcarrier_extender = \ vector_padding(config.subcarriers, config.fft_length) self.connect(stc, vsubc) vsubc_2 = self._virtual_subcarrier_extender_2 = \ vector_padding(config.subcarriers, config.fft_length) self.connect((stc, 1), vsubc_2) else: vsubc = self._virtual_subcarrier_extender = psubc vsubc_2 = self._virtual_subcarrier_extender_2 = psubc_2 log_to_file(self, psubc, "data/psubc.compl") log_to_file(self, stc, "data/stc1.compl") log_to_file(self, (stc, 1), "data/stc2.compl") if options.log: log_to_file(self, vsubc, "data/vsubc_out.compl") log_to_file(self, vsubc_2, "data/vsubc2_out.compl") ## IFFT, no window, block shift ifft = self._ifft = fft_blocks.fft_vcc(config.fft_length, False, [], True) self.connect(vsubc, ifft) ifft_2 = self._ifft_2 = fft_blocks.fft_vcc(config.fft_length, False, [], True) self.connect(vsubc_2, ifft_2) if options.log: log_to_file(self, ifft, "data/ifft_out.compl") log_to_file(self, ifft_2, "data/ifft2_out.compl") ## Pilot blocks (preambles) pblocks = self._pilot_block_inserter = pilot_block_inserter(1, False) self.connect(ifft, pblocks) pblocks_2 = self._pilot_block_inserter_2 = pilot_block_inserter( 2, False) self.connect(ifft_2, pblocks_2) if options.log: log_to_file(self, pblocks, "data/pilot_block_ins_out.compl") log_to_file(self, pblocks_2, "data/pilot_block_ins2_out.compl") ## Cyclic Prefix cp = self._cyclic_prefixer = cyclic_prefixer(config.fft_length, config.block_length) self.connect(pblocks, cp) cp_2 = self._cyclic_prefixer_2 = cyclic_prefixer( config.fft_length, config.block_length) self.connect(pblocks_2, cp_2) lastblock = cp lastblock_2 = cp_2 if options.log: log_to_file(self, cp, "data/cp_out.compl") log_to_file(self, cp_2, "data/cp2_out.compl") if options.cheat: ## Artificial Channel # kept to compare with previous system achan_ir = concatenate([[1.0], [0.0] * (config.cp_length - 1)]) achan = self._artificial_channel = gr.fir_filter_ccc(1, achan_ir) self.connect(lastblock, achan) lastblock = achan achan_2 = self._artificial_channel_2 = gr.fir_filter_ccc( 1, achan_ir) self.connect(lastblock_2, achan_2) lastblock_2 = achan_2 ## Digital Amplifier amp = self._amplifier = ofdm.multiply_const_ccf(1.0 / math.sqrt(2)) self.connect(lastblock, amp) amp_2 = self._amplifier_2 = ofdm.multiply_const_ccf(1.0 / math.sqrt(2)) self.connect(lastblock_2, amp_2) self.set_rms_amplitude(rms_amp) if options.log: log_to_file(self, amp, "data/amp_tx_out.compl") log_to_file(self, amp_2, "data/amp_tx2_out.compl") ## Setup Output self.connect(amp, (self, 0)) self.connect(amp_2, (self, 1)) # ------------------------------------------------------------------------ # # Display some information about the setup if config._verbose: self._print_verbage()
def __init__(self, deframer_insync_frames=2, deframer_sync_check=True, viterbi_insync_frames=5, deframer_outsync_frames=5, viterbi_outsync_frames=20, viterbi_sync_check=True, viterbi_sync_threshold=0.1, satellite='GOES-LRIT', freq=1691.02e6, gain=23, decim=108, side="A", pll_alpha=0.005, symb_rate=293883, clock_alpha=0.005): grc_wxgui.top_block_gui.__init__(self, title="USRP LRIT Receiver - check signal quality") ################################################## # Parameters ################################################## self.deframer_insync_frames = deframer_insync_frames self.deframer_sync_check = deframer_sync_check self.viterbi_insync_frames = viterbi_insync_frames self.deframer_outsync_frames = deframer_outsync_frames self.viterbi_outsync_frames = viterbi_outsync_frames self.viterbi_sync_check = viterbi_sync_check self.viterbi_sync_threshold = viterbi_sync_threshold self.satellite = satellite self.freq = freq self.gain = gain self.decim = decim self.side = side self.pll_alpha = pll_alpha self.symb_rate = symb_rate self.clock_alpha = clock_alpha ################################################## # Variables ################################################## self.decim_tb = decim_tb = decim self.symb_rate_tb = symb_rate_tb = symb_rate self.samp_rate = samp_rate = 64e6/decim_tb self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check self.sps = sps = samp_rate/symb_rate_tb self.satellite_text = satellite_text = satellite self.samp_rate_st = samp_rate_st = samp_rate self.pll_alpha_sl = pll_alpha_sl = pll_alpha self.gain_tb = gain_tb = gain self.freq_tb = freq_tb = freq self.frames_file_text_inf = frames_file_text_inf = 'no output file' self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime()) self.clock_alpha_sl = clock_alpha_sl = clock_alpha self.baseband_file_text_inf = baseband_file_text_inf = 'no output file' ################################################## # Notebooks ################################################## self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output") self.Add(self.rx_ntb) ################################################## # Controls ################################################## self._decim_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.decim_tb, callback=self.set_decim_tb, label="Decimation", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1) self._symb_rate_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), value=self.symb_rate_tb, callback=self.set_symb_rate_tb, label="Symbol rate", converter=forms.int_converter(), ) self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1) self._viterbi_sync_threshold_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_sync_threshold_text, callback=self.set_viterbi_sync_threshold_text, label="Viterbi node sync threshold [BER]", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1) self._viterbi_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_sync_after_text, callback=self.set_viterbi_sync_after_text, label="Valid frames for Viterbi decoder sync", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_after_text_static_text, 4, 0, 1, 1) self._viterbi_outofsync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_outofsync_after_text, callback=self.set_viterbi_outofsync_after_text, label="Invalid frames for Viterbi decoder out of sync", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd(self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1) self._viterbi_node_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_node_sync_text, callback=self.set_viterbi_node_sync_text, label="Viterbi node sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(2).GridAdd(self._viterbi_node_sync_text_static_text, 2, 0, 1, 1) self._satellite_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.satellite_text, callback=self.set_satellite_text, label="Sat ", converter=forms.str_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1) self._samp_rate_st_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.samp_rate_st, callback=self.set_samp_rate_st, label="Sample rate", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1) _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1) self._gain_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.gain_tb, callback=self.set_gain_tb, label="RX gain [dB]", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1) self._freq_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.freq_tb, callback=self.set_freq_tb, label="Frequency", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1) self._frames_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.frames_file_text_inf, callback=self.set_frames_file_text_inf, label="Frames filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1) self._deframer_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_sync_after_text, callback=self.set_deframer_sync_after_text, label="Deframe sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1) self._deframer_nosync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_nosync_after_text, callback=self.set_deframer_nosync_after_text, label="Deframer out of sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1) self._deframer_check_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_check_sync_text, callback=self.set_deframer_check_sync_text, label="Deframer check sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1) self._datetime_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.datetime_text, callback=self.set_datetime_text, label="Local time of aquisition start", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1) _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, label="Clock alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1) self._baseband_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.baseband_file_text_inf, callback=self.set_baseband_file_text_inf, label="Baseband filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1) ################################################## # Blocks ################################################## self.fec_decode_viterbi_bpsk_fb_0 = fec.decode_viterbi_bpsk_fb(viterbi_sync_check, viterbi_sync_threshold, viterbi_insync_frames, viterbi_outsync_frames, viterbi_outsync_frames*3) self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0) self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, clock_alpha_sl*clock_alpha_sl/4.0, 0.5, clock_alpha_sl, 0.05) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_alpha_sl*pll_alpha_sl/4.0, 0.07, -0.07, 2) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, )) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char*1) self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(True, 1024, deframer_insync_frames, deframer_outsync_frames) self.root_raised_cosine_filter_0 = gr.fir_filter_ccf(1, firdes.root_raised_cosine( 1, samp_rate, symb_rate, 0.25, int(11*samp_rate/symb_rate))) self.usrp_simple_source = grc_usrp.simple_source_c(which=0, side=side, rx_ant="RXA") self.usrp_simple_source.set_decim_rate(decim_tb) self.usrp_simple_source.set_frequency(freq_tb, verbose=True) self.usrp_simple_source.set_gain(gain_tb) self.wxgui_fftsink1 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=2, y_divs=10, ref_level=12, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="Not filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win) self.wxgui_fftsink2 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=0, y_per_div=2, y_divs=10, ref_level=12, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="RRC filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win) self.wxgui_scopesink2_1 = scopesink2.scope_sink_c( self.rx_ntb.GetPage(1).GetWin(), title="BPSK constellation diagram", sample_rate=symb_rate, v_scale=0.4, v_offset=0, t_scale=1/samp_rate, ac_couple=False, xy_mode=True, num_inputs=1, ) self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win) ################################################## # Connections ################################################## self.connect((self.usrp_simple_source, 0), (self.gr_agc_xx_0, 0)) self.connect((self.gr_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0)) self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.fec_decode_viterbi_bpsk_fb_0, 0)) self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.gr_costas_loop_cc_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.wxgui_fftsink2, 0)) self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0)) self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_null_sink_0, 0))
def __init__(self,frame,panel,vbox,argv): stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv) usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \ "Make sure your input capture file containes interleaved shorts not complex floats" parser=OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("-d", "--decim", type="int", default=64, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=519.25e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option("-o", "--out-filename", type="string", default="sdl", help="For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)") parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat file in a loop") parser.add_option("-N", "--no-hb", action="store_true", default=False, help="don't use halfband filter in usrp") (options, args) = parser.parse_args() if not ((len(args) == 1) or (len(args) == 0)): parser.print_help() sys.exit(1) if len(args) == 1: filename = args[0] else: filename = None self.frame = frame self.panel = panel self.contrast = options.contrast self.brightness = options.brightness self.state = "FREQ" self.freq = 0 # build graph self.u=None usrp_decim = options.decim # 32 if not (options.out_filename=="sdl"): options.repeat=False if not ((filename is None) or (filename=="usrp")): self.filesource = gr.file_source(gr.sizeof_short,filename,options.repeat) # file is data source self.istoc = gr.interleaved_short_to_complex() self.connect(self.filesource,self.istoc) adc_rate=64e6 self.src=self.istoc options.gain=0.0 self.gain=0.0 else: if options.no_hb or (options.decim<8): self.fpga_filename="std_4rx_0tx.rbf" #contains 4 Rx paths without halfbands and 0 tx paths else: self.fpga_filename="std_2rxhb_2tx.rbf" # contains 2 Rx paths with halfband filters and 2 tx paths (the default) self.u = usrp.source_c(0,fpga_filename=self.fpga_filename) # usrp is data source if options.width_8: sample_width = 8 sample_shift = 8 format = self.u.make_format(sample_width, sample_shift) r = self.u.set_format(format) adc_rate = self.u.adc_rate() # 64 MS/s self.u.set_decim_rate(usrp_decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(),) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0]+g[1])/2 self.src=self.u usrp_rate = adc_rate / usrp_decim # 320 kS/s f2uc=gr.float_to_uchar() # sdl window as final sink if not (options.pal or options.ntsc): options.pal=True #set default to PAL if options.pal: lines_per_frame=625.0 frames_per_sec=25.0 show_width=768 elif options.ntsc: lines_per_frame=525.0 frames_per_sec=29.97002997 show_width=640 width=int(usrp_rate/(lines_per_frame*frames_per_sec)) height=int(lines_per_frame) if (options.out_filename=="sdl"): #Here comes the tv screen, you have to build and install gr-video-sdl for this (subproject of gnuradio, only in cvs for now) try: video_sink = video_sdl.sink_uc ( frames_per_sec, width, height,0,show_width,height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst=video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" + options.out_filename print "(Use the spacebar to advance to next frames)" options.repeat=False file_sink=gr.file_sink(gr.sizeof_char, options.out_filename) self.dst =file_sink self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7 self.am_demod = gr.complex_to_mag () self.set_blacklevel=gr.add_const_ff(0.0) self.invert_and_scale = gr.multiply_const_ff (0.0) #-self.contrast *128.0*255.0/(200.0) # now wire it all together #sample_rate=options.width*options.height*options.framerate process_type='do_no_sync' if process_type=='do_no_sync': self.connect (self.src, self.agc,self.am_demod,self.invert_and_scale, self.set_blacklevel,f2uc,self.dst) elif process_type=='do_tv_sync_adv': #defaults: gr.tv_sync_adv (double sampling_freq, unsigned int tv_format,bool output_active_video_only=false, bool do_invert=false, double wanted_black_level=0.0, double wanted_white_level=255.0, double avg_alpha=0.1, double initial_gain=1.0, double initial_offset=0.0,bool debug=false) self.tv_sync_adv=gr.tv_sync_adv(usrp_rate,0,False,False,0.0,255.0,0.01,1.0,0.0,False) #note, this block is not yet in cvs self.connect (self.src, self.am_demod,self.invert_and_scale,self.tv_sync_adv,s2f,f2uc,self.dst) elif process_type=='do_nullsink': #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink) c2r=gr.complex_to_real() nullsink=gr.null_sink(gr.sizeof_float) self.connect (self.src, c2r,nullsink) #video_sink) elif process_type=='do_tv_sync_corr': frame_size=width*height #int(usrp_rate/25.0) nframes=10# 32 search_window=20*nframes debug=False video_alpha=0.3 #0.1 corr_alpha=0.3 tv_corr=gr.tv_correlator_ff(frame_size,nframes, search_window, video_alpha, corr_alpha,debug) #Note: this block is not yet in cvs shift=gr.add_const_ff(-0.7) self.connect (self.src, self.agc,self.am_demod,tv_corr,self.invert_and_scale, self.set_blacklevel,f2uc,self.dst) #self.agc, else: # process_type=='do_test_image': src_vertical_bars = gr.sig_source_f (usrp_rate, gr.GR_SIN_WAVE, 10.0 *usrp_rate/320, 255,128) self.connect(src_vertical_bars,f2uc,self.dst) self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate) if abs(options.freq) < 1e6: options.freq *= 1e6 # set initial values self.set_gain(options.gain) self.set_contrast(self.contrast) self.set_brightness(options.brightness) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self, if_rate, # Incoming sample rate symbol_rate, # Original symbol rate excess_bw, # RRC excess bandwidth, typically 0.35-0.5 costas_alpha, # Costas loop 1st order gain, typically 0.01-0.2 costas_beta, # Costas loop 2nd order gain, typically alpha^2/4.0 costas_max, # Costas loop max frequency offset in radians/sample mm_gain_mu, # M&M loop 1st order gain, typically 0.001-0.2 mm_gain_omega, # M&M loop 2nd order gain, typically alpha^2/4.0 mm_omega_limit, # M&M loop max timing error ): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature self._if_rate = if_rate self._sps = int(self._if_rate/symbol_rate) print "IF sample rate:", n2s(self._if_rate) print "Symbol rate:", n2s(symbol_rate) print "Samples/symbol:", self._sps print "RRC bandwidth:", excess_bw # Create AGC to scale input to unity self._agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0) # Create RRC with specified excess bandwidth taps = gr.firdes.root_raised_cosine(1.0, # Gain self._sps, # Sampling rate 1.0, # Symbol rate excess_bw, # Roll-off factor 11*self._sps) # Number of taps self._rrc = gr.fir_filter_ccf(1, taps) # Create a Costas loop frequency/phase recovery block print "Costas alpha:", costas_alpha print "Costas beta:", costas_beta print "Costas max:", costas_max self._costas = gr.costas_loop_cc(costas_alpha, # PLL first order gain costas_beta, # PLL second order gain costas_max, # Max frequency offset rad/sample -costas_max, # Min frequency offset rad/sample 2) # BPSK # Create a M&M bit synchronization retiming block mm_mu = 0.5 mm_omega = self._sps print "MM gain mu:", mm_gain_mu print "MM gain omega:", mm_gain_omega print "MM omega limit:", mm_omega_limit self._mm = gr.clock_recovery_mm_cc(mm_omega, # Initial samples/symbol mm_gain_omega, # Second order gain mm_mu, # Initial symbol phase mm_gain_mu, # First order gain mm_omega_limit) # Maximum timing offset # Add an SNR probe on the demodulated constellation self._snr_probe = gr.probe_mpsk_snr_c(10.0/symbol_rate) self.connect(self._mm, self._snr_probe) # Slice the resulting constellation into bits. # Get inphase channel and make decision about 0 self._c2r = gr.complex_to_real() self._slicer = gr.binary_slicer_fb() # Descramble BERT sequence. A channel error will create 3 incorrect bits self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit descrambler # Measure BER by the density of 0s in the stream self._ber = gr.probe_density_b(1.0/symbol_rate) self.connect(self, self._agc, self._rrc, self._costas, self._mm, self._c2r, self._slicer, self._descrambler, self._ber)
def __init__(self, deframer_insync_frames=2, viterbi_insync_frames=5, deframer_outsync_frames=5, viterbi_outsync_frames=20, viterbi_sync_check=True, viterbi_sync_threshold=0.1, deframer_sync_check=True, clock_alpha=0.005, symb_rate=293883, pll_alpha=0.005, satellite='GOES-LRIT', freq=1691.02e6, gain=23, decim=108, side="A", frames_file=os.environ['HOME'] + '/GOES-LRIT_cadu_frames.cadu', baseband_file=os.environ['HOME'] + '/GOES-LRIT_baseband.dat'): grc_wxgui.top_block_gui.__init__( self, title="LRIT Receiver from baseband file") ################################################## # Parameters ################################################## self.deframer_insync_frames = deframer_insync_frames self.viterbi_insync_frames = viterbi_insync_frames self.deframer_outsync_frames = deframer_outsync_frames self.viterbi_outsync_frames = viterbi_outsync_frames self.viterbi_sync_check = viterbi_sync_check self.viterbi_sync_threshold = viterbi_sync_threshold self.deframer_sync_check = deframer_sync_check self.clock_alpha = clock_alpha self.symb_rate = symb_rate self.pll_alpha = pll_alpha self.satellite = satellite self.freq = freq self.gain = gain self.decim = decim self.side = side self.frames_file = frames_file self.baseband_file = baseband_file ################################################## # Variables ################################################## self.decim_tb = decim_tb = decim self.symb_rate_tb = symb_rate_tb = symb_rate self.samp_rate = samp_rate = 64e6 / decim_tb self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check self.sps = sps = samp_rate / symb_rate_tb self.satellite_text = satellite_text = satellite self.samp_rate_st = samp_rate_st = samp_rate self.pll_alpha_sl = pll_alpha_sl = pll_alpha self.gain_tb = gain_tb = gain self.freq_tb = freq_tb = freq self.frames_file_text_inf = frames_file_text_inf = frames_file self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime()) self.clock_alpha_sl = clock_alpha_sl = clock_alpha self.baseband_file_text_inf = baseband_file_text_inf = 'no output file' ################################################## # Notebooks ################################################## self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer") self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output") self.Add(self.rx_ntb) ################################################## # Controls ################################################## self._decim_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.decim_tb, callback=self.set_decim_tb, label="Decimation", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1) self._symb_rate_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), value=self.symb_rate_tb, callback=self.set_symb_rate_tb, label="Symbol rate", converter=forms.int_converter(), ) self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1) self._viterbi_sync_threshold_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_sync_threshold_text, callback=self.set_viterbi_sync_threshold_text, label="Viterbi node sync threshold [BER]", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1) self._viterbi_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_sync_after_text, callback=self.set_viterbi_sync_after_text, label="Valid frames for Viterbi decoder sync", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._viterbi_sync_after_text_static_text, 4, 0, 1, 1) self._viterbi_outofsync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_outofsync_after_text, callback=self.set_viterbi_outofsync_after_text, label="Invalid frames for Viterbi decoder out of sync", converter=forms.float_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1) self._viterbi_node_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(2).GetWin(), value=self.viterbi_node_sync_text, callback=self.set_viterbi_node_sync_text, label="Viterbi node sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(2).GridAdd( self._viterbi_node_sync_text_static_text, 2, 0, 1, 1) self._satellite_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.satellite_text, callback=self.set_satellite_text, label="Sat ", converter=forms.str_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1) self._samp_rate_st_static_text = forms.static_text( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.samp_rate_st, callback=self.set_samp_rate_st, label="Sample rate", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1) _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_pll_alpha_sl_sizer, value=self.pll_alpha_sl, callback=self.set_pll_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1) self._gain_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.gain_tb, callback=self.set_gain_tb, label="RX gain [dB]", converter=forms.int_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1) self._freq_tb_text_box = forms.text_box( parent=self.rx_ntb.GetPage(0).GetWin(), value=self.freq_tb, callback=self.set_freq_tb, label="Frequency", converter=forms.float_converter(), ) self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1) self._frames_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.frames_file_text_inf, callback=self.set_frames_file_text_inf, label="Frames filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1) self._deframer_sync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_sync_after_text, callback=self.set_deframer_sync_after_text, label="Deframe sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(3).GridAdd( self._deframer_sync_after_text_static_text, 3, 0, 1, 1) self._deframer_nosync_after_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_nosync_after_text, callback=self.set_deframer_nosync_after_text, label="Deframer out of sync after", converter=forms.float_converter(), ) self.rx_ntb.GetPage(3).GridAdd( self._deframer_nosync_after_text_static_text, 4, 0, 1, 1) self._deframer_check_sync_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(3).GetWin(), value=self.deframer_check_sync_text, callback=self.set_deframer_check_sync_text, label="Deframer check sync enable", converter=forms.str_converter(), ) self.rx_ntb.GetPage(3).GridAdd( self._deframer_check_sync_text_static_text, 2, 0, 1, 1) self._datetime_text_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.datetime_text, callback=self.set_datetime_text, label="Local time of aquisition start", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1) _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_sl_text_box = forms.text_box( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, label="Clock alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_sl_slider = forms.slider( parent=self.rx_ntb.GetPage(1).GetWin(), sizer=_clock_alpha_sl_sizer, value=self.clock_alpha_sl, callback=self.set_clock_alpha_sl, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1) self._baseband_file_text_inf_static_text = forms.static_text( parent=self.rx_ntb.GetPage(4).GetWin(), value=self.baseband_file_text_inf, callback=self.set_baseband_file_text_inf, label="Baseband filename", converter=forms.str_converter(), ) self.rx_ntb.GetPage(4).GridAdd( self._baseband_file_text_inf_static_text, 4, 0, 1, 1) ################################################## # Blocks ################################################## self.fec_decode_viterbi_bpsk_fb_0 = fec.decode_viterbi_bpsk_fb( viterbi_sync_check, viterbi_sync_threshold, viterbi_insync_frames, viterbi_outsync_frames, viterbi_outsync_frames * 3) self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0) self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc( sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl, 0.05) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_costas_loop_cc_0 = gr.costas_loop_cc( pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 2) self.gr_file_source_0 = gr.file_source( gr.sizeof_gr_complex * 1, "/home/martin/GNURadioData/lrit/goes_lrit_D108AD64MHz.sam", True) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, )) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char * 1) self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb( 1, gr.GR_MSB_FIRST) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate) self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer( True, 1024, deframer_insync_frames, deframer_outsync_frames) self.root_raised_cosine_filter_0 = gr.fir_filter_ccf( 1, firdes.root_raised_cosine(1, samp_rate, symb_rate, 0.25, int(11 * samp_rate / symb_rate))) self.wxgui_fftsink1 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=2, y_divs=10, ref_level=12, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="Not filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win) self.wxgui_fftsink2 = fftsink2.fft_sink_c( self.rx_ntb.GetPage(0).GetWin(), baseband_freq=0, y_per_div=2, y_divs=10, ref_level=12, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=30, average=True, avg_alpha=0.1, title="RRC filtered spectrum", peak_hold=False, ) self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win) self.wxgui_scopesink2_1 = scopesink2.scope_sink_c( self.rx_ntb.GetPage(1).GetWin(), title="BPSK constellation diagram", sample_rate=symb_rate, v_scale=0.4, v_offset=0, t_scale=1 / samp_rate, ac_couple=False, xy_mode=True, num_inputs=1, ) self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win) ################################################## # Connections ################################################## self.connect((self.gr_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0)) self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.fec_decode_viterbi_bpsk_fb_0, 0)) self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.gr_costas_loop_cc_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.wxgui_fftsink2, 0)) self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0)) self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_null_sink_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0)) self.connect((self.gr_file_source_0, 0), (self.gr_throttle_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, options): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0,0,0), gr.io_signature(2,2,gr.sizeof_gr_complex)) common_options.defaults(options) config = self.config = station_configuration() config.data_subcarriers = options.subcarriers config.cp_length = options.cp_length config.frame_data_blocks = options.data_blocks config._verbose = options.verbose config.fft_length = options.fft_length config.training_data = default_block_header(config.data_subcarriers, config.fft_length,options) config.tx_station_id = options.station_id config.coding = options.coding if config.tx_station_id is None: raise SystemError, "Station ID not set" config.frame_id_blocks = 1 # FIXME # digital rms amplitude sent to USRP rms_amp = options.rms_amplitude self._options = copy.copy(options) self.servants = [] # FIXME config.block_length = config.fft_length + config.cp_length config.frame_data_part = config.frame_data_blocks + config.frame_id_blocks config.frame_length = config.frame_data_part + \ config.training_data.no_pilotsyms config.subcarriers = config.data_subcarriers + \ config.training_data.pilot_subcarriers config.virtual_subcarriers = config.fft_length - config.subcarriers # default values if parameters not set if rms_amp is None: rms_amp = math.sqrt(config.subcarriers) config.rms_amplitude = rms_amp # check some bounds if config.fft_length < config.subcarriers: raise SystemError, "Subcarrier number must be less than FFT length" if config.fft_length < config.cp_length: raise SystemError, "Cyclic prefix length must be less than FFT length" ## shortcuts blen = config.block_length flen = config.frame_length dsubc = config.data_subcarriers vsubc = config.virtual_subcarriers # ------------------------------------------------------------------------ # # Adaptive Transmitter Concept used_id_bits = config.used_id_bits = 8 #TODO: no constant in source code rep_id_bits = config.rep_id_bits = config.data_subcarriers/used_id_bits #BPSK if config.data_subcarriers % used_id_bits <> 0: raise SystemError,"Data subcarriers need to be multiple of %d" % (used_id_bits) ## Control Part if options.debug: self._control = ctrl = static_tx_control(options) print "Statix TX Control used" else: self._control = ctrl = corba_tx_control(options) print "CORBA TX Control used" id_src = (ctrl,0) mux_src = (ctrl,1) map_src = self._map_src = (ctrl,2) pa_src = (ctrl,3) if options.log: id_src_f = gr.short_to_float() self.connect(id_src,id_src_f) log_to_file(self, id_src_f, "data/id_src_out.float") mux_src_f = gr.short_to_float() self.connect(mux_src,mux_src_f) log_to_file(self, mux_src_f, "data/mux_src_out.float") map_src_s = blocks.vector_to_stream(gr.sizeof_char,config.data_subcarriers) map_src_f = gr.char_to_float() self.connect(map_src,map_src_s,map_src_f) ##log_to_file(self, map_src_f, "data/map_src.float") ##log_to_file(self, pa_src, "data/pa_src_out.float") ## Workaround to avoid periodic structure seed(1) whitener_pn = [randint(0,1) for i in range(used_id_bits*rep_id_bits)] ## ID Encoder id_enc = self._id_encoder = repetition_encoder_sb(used_id_bits,rep_id_bits,whitener_pn) self.connect(id_src,id_enc) if options.log: id_enc_f = gr.char_to_float() self.connect(id_enc,id_enc_f) log_to_file(self, id_enc_f, "data/id_enc_out.float") ## Bitmap Update Trigger # TODO #bmaptrig_stream = concatenate([[1, 2],[0]*(config.frame_data_part-7)]) bmaptrig_stream = concatenate([[1, 1],[0]*(config.frame_data_part-2)]) print"bmaptrig_stream = ",bmaptrig_stream btrig = self._bitmap_trigger = blocks.vector_source_b(bmaptrig_stream.tolist(), True) if options.log: log_to_file(self, btrig, "data/bitmap_trig.char") ## Bitmap Update Trigger for puncturing # TODO if not options.nopunct: #bmaptrig_stream_puncturing = concatenate([[1],[0]*(config.frame_data_part-2)]) bmaptrig_stream_puncturing = concatenate([[1],[0]*(config.frame_data_blocks/2-1)]) btrig_puncturing = self._bitmap_trigger_puncturing = blocks.vector_source_b(bmaptrig_stream_puncturing.tolist(), True) bmapsrc_stream_puncturing = concatenate([[1]*dsubc,[2]*dsubc]) bsrc_puncturing = self._bitmap_src_puncturing = blocks.vector_source_b(bmapsrc_stream_puncturing.tolist(), True, dsubc) if options.log and options.coding and not options.nopunct: log_to_file(self, btrig_puncturing, "data/bitmap_trig_puncturing.char") ## Frame Trigger # TODO ftrig_stream = concatenate([[1],[0]*(config.frame_data_part-1)]) ftrig = self._frame_trigger = blocks.vector_source_b(ftrig_stream.tolist(),True) ## Data Multiplexer # Input 0: control stream # Input 1: encoded ID stream # Inputs 2..n: data streams dmux = self._data_multiplexer = stream_controlled_mux_b() self.connect(mux_src,(dmux,0)) self.connect(id_enc,(dmux,1)) self._data_multiplexer_nextport = 2 if options.log: dmux_f = gr.char_to_float() self.connect(dmux,dmux_f) log_to_file(self, dmux_f, "data/dmux_out.float") ## Modulator mod = self._modulator = generic_mapper_bcv(config.data_subcarriers,options.coding) self.connect(dmux,(mod,0)) self.connect(map_src,(mod,1)) self.connect(btrig,(mod,2)) if options.log: log_to_file(self, mod, "data/mod_out.compl") modi = gr.complex_to_imag(config.data_subcarriers) modr = gr.complex_to_real(config.data_subcarriers) self.connect(mod,modi) self.connect(mod,modr) log_to_file(self, modi, "data/mod_imag_out.float") log_to_file(self, modr, "data/mod_real_out.float") ## Power allocator if options.debug: ## static pa = self._power_allocator = power_allocator(config.data_subcarriers) self.connect(mod,(pa,0)) self.connect(pa_src,(pa,1)) else: ## with CORBA control event channel ns_ip = ctrl.ns_ip ns_port = ctrl.ns_port evchan = ctrl.evchan pa = self._power_allocator = corba_power_allocator(dsubc, \ evchan, ns_ip, ns_port, True) self.connect(mod,(pa,0)) self.connect(id_src,(pa,1)) self.connect(ftrig,(pa,2)) if options.log: log_to_file(self, pa, "data/pa_out.compl") ## Pilot subcarriers psubc = self._pilot_subcarrier_inserter = pilot_subcarrier_inserter() self.connect( pa ,psubc ) pilot_subc = config.training_data.shifted_pilot_tones; print "pilot_subc", pilot_subc stc = stc_encoder( config.subcarriers, config.frame_data_blocks, pilot_subc ) self.connect(psubc, stc) if options.log: log_to_file(self, psubc, "data/psubc_out.compl") log_to_file(self, psubc_2, "data/psubc2_out.compl") log_to_file(self, pa, "data/pa.compl") log_to_file(self, ( stc, 0 ), "data/stc_0.compl") log_to_file(self, ( stc, 1 ), "data/stc_1.compl") ## Add virtual subcarriers if config.fft_length > config.subcarriers: vsubc = self._virtual_subcarrier_extender = \ vector_padding(config.subcarriers, config.fft_length) self.connect(stc,vsubc) vsubc_2 = self._virtual_subcarrier_extender_2 = \ vector_padding(config.subcarriers, config.fft_length) self.connect((stc,1),vsubc_2) else: vsubc = self._virtual_subcarrier_extender = psubc vsubc_2 = self._virtual_subcarrier_extender_2 = psubc_2 log_to_file(self, psubc, "data/psubc.compl") log_to_file(self, stc, "data/stc1.compl") log_to_file(self, (stc,1), "data/stc2.compl") if options.log: log_to_file(self, vsubc, "data/vsubc_out.compl") log_to_file(self, vsubc_2, "data/vsubc2_out.compl") ## IFFT, no window, block shift ifft = self._ifft = fft_blocks.fft_vcc(config.fft_length,False,[],True) self.connect(vsubc,ifft) ifft_2 = self._ifft_2 = fft_blocks.fft_vcc(config.fft_length,False,[],True) self.connect(vsubc_2,ifft_2) if options.log: log_to_file(self, ifft, "data/ifft_out.compl") log_to_file(self, ifft_2, "data/ifft2_out.compl") ## Pilot blocks (preambles) pblocks = self._pilot_block_inserter = pilot_block_inserter(1, False) self.connect( ifft, pblocks ) pblocks_2 = self._pilot_block_inserter_2 = pilot_block_inserter( 2, False) self.connect( ifft_2, pblocks_2 ) if options.log: log_to_file(self, pblocks, "data/pilot_block_ins_out.compl") log_to_file(self, pblocks_2, "data/pilot_block_ins2_out.compl") ## Cyclic Prefix cp = self._cyclic_prefixer = cyclic_prefixer(config.fft_length, config.block_length) self.connect( pblocks, cp ) cp_2 = self._cyclic_prefixer_2 = cyclic_prefixer(config.fft_length, config.block_length) self.connect( pblocks_2, cp_2 ) lastblock = cp lastblock_2 = cp_2 if options.log: log_to_file(self, cp, "data/cp_out.compl") log_to_file(self, cp_2, "data/cp2_out.compl") if options.cheat: ## Artificial Channel # kept to compare with previous system achan_ir = concatenate([[1.0],[0.0]*(config.cp_length-1)]) achan = self._artificial_channel = gr.fir_filter_ccc(1,achan_ir) self.connect( lastblock, achan ) lastblock = achan achan_2 = self._artificial_channel_2 = gr.fir_filter_ccc(1,achan_ir) self.connect( lastblock_2, achan_2 ) lastblock_2 = achan_2 ## Digital Amplifier amp = self._amplifier = ofdm.multiply_const_ccf( 1.0/math.sqrt(2) ) self.connect( lastblock, amp ) amp_2 = self._amplifier_2 = ofdm.multiply_const_ccf( 1.0/math.sqrt(2) ) self.connect( lastblock_2, amp_2 ) self.set_rms_amplitude(rms_amp) if options.log: log_to_file(self, amp, "data/amp_tx_out.compl") log_to_file(self, amp_2, "data/amp_tx2_out.compl") ## Setup Output self.connect(amp,(self,0)) self.connect(amp_2,(self,1)) # ------------------------------------------------------------------------ # # Display some information about the setup if config._verbose: self._print_verbage()
def __init__(self, options, msgq_limit=2, pad_for_usrp=False): """ Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param options: pass modulation options from higher layers (fft length, occupied tones, etc.) @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples """ gr.hier_block2.__init__(self, "ofdm_mod", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._fft_length = 64 self._total_sub_carriers = 53 self._data_subcarriers = 48 self._cp_length = 16 self._regime = options.regime self._symbol_length = self._fft_length + self._cp_length # assuming we have 100Ms/s going to the USRP2 and 80 samples per symbol # we can calculate the OFDM symboltime (in microseconds) # depending on the interpolation factor self._symbol_time = 100000000*(self._symbol_length )/(100*options.bandwidth) self._n_sym = options.nsym win = [] self._modulation = options.modulation if self._modulation == "bpsk": rotated_const = ofdm_packet_utils.bpsk(self) elif self._modulation == "qpsk": rotated_const = ofdm_packet_utils.qpsk(self) elif self._modulation == "qam16": rotated_const = ofdm_packet_utils.qam16(self) elif self._modulation == "qam64": rotated_const = ofdm_packet_utils.qam64(self) # if(self._regime == "1" or self._regime == "2"): # rotated_const = ofdm_packet_utils.bpsk(self) # # elif (self._regime == "3" or self._regime == "4"): # rotated_const = ofdm_packet_utils.qpsk(self) # # elif(self._regime == "5" or self._regime == "6"): # rotated_const = ofdm_packet_utils.qam16(self) # # elif(self._regime == "7" or self._regime == "8"): # rotated_const = ofdm_packet_utils.qam64(self) # map groups of bits to complex symbols self._pkt_input = gr_ieee802_11.ofdm_symbol_mapper(rotated_const, msgq_limit, self._data_subcarriers, self._fft_length) # insert pilot symbols self.pilot = gr_ieee802_11.ofdm_pilot_insert(self._data_subcarriers) # move subcarriers to their designated place and insert DC self.cmap = gr_ieee802_11.ofdm_carrier_mapper(self._fft_length, self._total_sub_carriers) # inverse fast fourier transform self.ifft = gr.fft_vcc(self._fft_length, False, win, False) # add cyclic prefix self.cp_adder = digital_swig.ofdm_cyclic_prefixer(self._fft_length, self._symbol_length) # scale accordingly self.scale = gr.multiply_const_cc(1.0 / math.sqrt(self._fft_length)) # we need to know the number of OFDM data symbols for preamble and zerogap # MODIFIED FROM ORIGINAL # Instead of having the OFDM data symbols recorded in a python dictionary, the value of N_sym is updated when the class ofdm_mod invoked. N_sym = self._n_sym # add training sequence self.preamble= ofdm_packet_utils.insert_preamble(self._symbol_length, N_sym) # append zero samples at the end (receiver needs that to decode) self.zerogap = ofdm_packet_utils.insert_zerogap(self._symbol_length, N_sym) # repeat the frame a number of times self.repeat = gr_ieee802_11.ofdm_symbol_repeater(self._symbol_length, options.repetition, N_sym) self.s2v = gr.stream_to_vector(gr.sizeof_gr_complex , self._symbol_length) self.v2s = gr.vector_to_stream(gr.sizeof_gr_complex , self._symbol_length) # swap real and immaginary component before sending (GNURadio/USRP2 bug!) self.gr_complex_to_imag_0 = gr.complex_to_imag(1) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.connect((self.v2s, 0), (self.gr_complex_to_imag_0, 0)) self.connect((self.v2s, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_imag_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self)) # connect the blocks self.connect((self._pkt_input, 0), (self.pilot, 0)) self.connect((self._pkt_input,1), (self.preamble, 1)) self.connect((self.preamble,1), (self.zerogap, 1)) #if options.repetition == 1: self.connect(self.pilot, self.cmap, self.ifft, self.cp_adder, self.scale, self.s2v, \ self.preamble, self.zerogap, self.v2s) #elif options.repetition > 1: #self.connect(self.pilot, self.cmap, self.ifft, self.cp_adder, self.scale, self.s2v, self.preamble, self.zerogap, self.repeat, self.v2s) #else: # print"Error: repetiton must be a integer number >= 1 \n" # sys.exit(1) if options.log: self.connect((self._pkt_input), gr.file_sink(gr.sizeof_gr_complex * self._data_subcarriers, "ofdm_mapper.dat")) self.connect(self.pilot, gr.file_sink(gr.sizeof_gr_complex * (5 + self._data_subcarriers), "ofdm_pilot.dat")) self.connect(self.cmap, gr.file_sink(gr.sizeof_gr_complex * self._fft_length, "ofdm_cmap.dat")) self.connect(self.ifft, gr.file_sink(gr.sizeof_gr_complex * self._fft_length, "ofdm_ifft.dat")) self.connect(self.cp_adder, gr.file_sink(gr.sizeof_gr_complex, "ofdm_cp_adder.dat")) self.connect(self.scale, gr.file_sink(gr.sizeof_gr_complex, "ofdm_scale.dat")) self.connect(self.preamble, gr.file_sink(gr.sizeof_gr_complex * self._symbol_length, "ofdm_preamble.dat")) self.connect(self.zerogap, gr.file_sink(gr.sizeof_gr_complex * self._symbol_length, "ofdm_zerogap.dat"))