def test_002_cc(self): N = 10000 # number of samples to use fs = 1000 # baseband sampling rate rrate = 1.123 # resampling rate freq = 10 data = sig_source_c(fs, freq, 1, N) signal = blocks.vector_source_c(data) op = filter.fractional_resampler_cc(0.0, rrate) snk = blocks.vector_sink_c() self.tb.connect(signal, op, snk) self.tb.run() Ntest = 5000 L = len(snk.data()) t = map(lambda x: float(x)/(fs/rrate), xrange(L)) phase = 0.1884 expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \ 1j*math.sin(2.*math.pi*freq*x+phase), t) dst_data = snk.data() self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
def __init__(self, sample_rate, amplitude): gr.hier_block2.__init__(self, "gsm_source_c", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._symb_rate = 13e6 / 48; self._samples_per_symbol = 2 self._data = blocks.vector_source_b(self.gen_gsm_seq(), True, 2) self._split = blocks.vector_to_streams(gr.sizeof_char*1, 2) self._pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) self._mod = digital.gmsk_mod(self._samples_per_symbol, bt=0.35) self._pwr_f = blocks.char_to_float(1, 1) self._pwr_c = blocks.float_to_complex(1) self._pwr_w = blocks.repeat(gr.sizeof_gr_complex*1, self._samples_per_symbol) self._mul = blocks.multiply_vcc(1) self._interpolate = filter.fractional_resampler_cc( 0, (self._symb_rate * self._samples_per_symbol) / sample_rate ) self._scale = blocks.multiply_const_cc(amplitude) self.connect(self._data, self._split) self.connect((self._split, 0), self._pack, self._mod, (self._mul, 0)) self.connect((self._split, 1), self._pwr_f, self._pwr_c, self._pwr_w, (self._mul, 1)) self.connect(self._mul, self._interpolate, self._scale, self)
def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset, mode=0): gr.top_block.__init__(self) rrc_taps = filter.firdes.root_raised_cosine( sps, sps, 1.0, rolloff, ntaps) gain = bw nfilts = 32 rrc_taps_rx = filter.firdes.root_raised_cosine( nfilts, sps*nfilts, 1.0, rolloff, ntaps*nfilts) data = 2.0*scipy.random.randint(0, 2, N) - 1.0 data = scipy.exp(1j*poffset) * data self.src = blocks.vector_source_c(data.tolist(), False) self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps) self.chn = channels.channel_model(noise, foffset, toffset) self.off = filter.fractional_resampler_cc(0.20, 1.0) if mode == 0: self.clk = digital.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx, nfilts, nfilts//2, 1) self.taps = self.clk.taps() self.dtaps = self.clk.diff_taps() self.delay = int(scipy.ceil(((len(rrc_taps)-1)/2 + (len(self.taps[0])-1)/2)/float(sps))) + 1 self.vsnk_err = blocks.vector_sink_f() self.vsnk_rat = blocks.vector_sink_f() self.vsnk_phs = blocks.vector_sink_f() self.connect((self.clk,1), self.vsnk_err) self.connect((self.clk,2), self.vsnk_rat) self.connect((self.clk,3), self.vsnk_phs) else: # mode == 1 mu = 0.5 gain_mu = bw gain_omega = 0.25*gain_mu*gain_mu omega_rel_lim = 0.02 self.clk = digital.clock_recovery_mm_cc(sps, gain_omega, mu, gain_mu, omega_rel_lim) self.vsnk_err = blocks.vector_sink_f() self.connect((self.clk,1), self.vsnk_err) self.vsnk_src = blocks.vector_sink_c() self.vsnk_clk = blocks.vector_sink_c() self.connect(self.src, self.rrc, self.chn, self.off, self.clk, self.vsnk_clk) self.connect(self.src, self.vsnk_src)
def __init__(self): gr.top_block.__init__(self, "SQ5BPF Tetra live receiver 1ch UDP HEADLESS") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2000000 self.first_decim = first_decim = 32 self.xlate_offset_fine1 = xlate_offset_fine1 = 0 self.xlate_offset1 = xlate_offset1 = 500e3 self.udp_packet_size = udp_packet_size = 1472 self.udp_dest_addr = udp_dest_addr = "127.0.0.1" self.telive_receiver_name = telive_receiver_name = 'SQ5BPF 1-channel headless rx for telive' self.telive_receiver_channels = telive_receiver_channels = 1 self.sdr_ifgain = sdr_ifgain = 20 self.sdr_gain = sdr_gain = 38 self.ppm_corr = ppm_corr = 56 self.out_sample_rate = out_sample_rate = 36000 self.options_low_pass = options_low_pass = 12500 self.if_samp_rate = if_samp_rate = samp_rate/first_decim self.freq = freq = 435e6 self.first_port = first_port = 42000 ################################################## # Blocks ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(("0.0.0.0", first_port), allow_none=True) self.xmlrpc_server_0.register_instance(self) threading.Thread(target=self.xmlrpc_server_0.serve_forever).start() self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(freq, 0) self.osmosdr_source_0.set_freq_corr(ppm_corr, 0) self.osmosdr_source_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(False, 0) self.osmosdr_source_0.set_gain(sdr_gain, 0) self.osmosdr_source_0.set_if_gain(sdr_ifgain, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna("", 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(first_decim, (firdes.low_pass(1, samp_rate, options_low_pass, options_low_pass*0.2)), xlate_offset1+xlate_offset_fine1, samp_rate) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, float(float(if_samp_rate)/float(out_sample_rate))) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_gr_complex*1, udp_dest_addr, first_port+1, udp_packet_size, False) self.analog_agc3_xx_0 = analog.agc3_cc(1e-3, 1e-4, 1.0, 1.0, 1) self.analog_agc3_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.analog_agc3_xx_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_agc3_xx_0, 0))
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel options = get_options() sample_rate = int(options.sample_rate) self.asrc = audio.source(sample_rate, options.audio_device, True) self.f2c = blocks.float_to_complex(1) self.connect((self.asrc, 1), (self.f2c, 1)) self.connect((self.asrc, 0), (self.f2c, 0)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT) self.scope = fftsink2.fft_sink_c(panel, fft_size=512, sample_rate=sample_rate, ref_scale=2.0, ref_level=-30, y_divs=10, fft_rate=10, average=True, avg_alpha=0.2) self.connect(self.f2c, self.scope)
def __init__(self, options): gr.top_block.__init__(self) # Create a USRP2 source and set decimation rate self._u = usrp2.source_32fc(options.interface, options.mac_addr) self._u.set_decim(512) # Set receive daughterboard gain if options.gain is None: g = self._u.gain_range() options.gain = float(g[0]+g[1])/2 print "Using mid-point gain of", options.gain, "(", g[0], "-", g[1], ")" self._u.set_gain(options.gain) # Set receive frequency if options.lo_offset is not None: self._u.set_lo_offset(options.lo_offset) tr = self._u.set_center_freq(options.freq) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 sample_rate = 100e6/512 symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self._u, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self, n_samples, n_offset_samples, n_prbs, linear_gain, pad_interval, mcs, frequency_offset): super(GrLTETracesFlowgraph, self).__init__() self.subcarrier_spacing = 15000 # params self.n_samples = n_samples self.n_prbs = n_prbs self.linear_gain = linear_gain self.mcs = mcs # derived params self.fft_size = GrLTETracesFlowgraph.prb_mapping[self.n_prbs] self.samp_rate = float(self.fft_size * self.subcarrier_spacing) n_prbs_str = "%02d" % (self.n_prbs, ) mcs_str = "%02d" % (self.mcs) fname = '{}/lte_dump_prb_{}_mcs_{}.32fc'.format( frames_path, n_prbs_str, mcs_str) self.expected_bw = GrLTETracesFlowgraph.fftsize_mapping[self.fft_size] self.resamp_ratio = 20.0e6 / self.samp_rate self.n_samples_per_frame = int(10.0e-3 * self.samp_rate) self.n_offset_samples = int( lf.random_generator.load_value(n_offset_samples)) randgen = lf.random_generator.load_generator(pad_interval) # scale by sampling rate new_params = tuple( [int(v / self.resamp_ratio) for v in randgen.params]) randgen.params = new_params if isinstance(frequency_offset, tuple): assert frequency_offset[0] == 'uniform' self.frequency_offset = frequency_offset[1] else: # it is just a value self.frequency_offset = [frequency_offset] # blocks self.file_reader = blocks.file_source(gr.sizeof_gr_complex, fname, True) self.tagger = blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, self.n_samples_per_frame, "packet_len") self.burst_shaper = specmonitor.random_burst_shaper_cc( randgen.dynrandom(), 0, self.frequency_offset, "packet_len") # self.resampler = filter.rational_resampler_base_ccc(interp,decim,taps) self.resampler = filter.fractional_resampler_cc( 0, 1 / self.resamp_ratio) self.skiphead = blocks.skiphead(gr.sizeof_gr_complex, self.n_offset_samples) self.head = blocks.head(gr.sizeof_gr_complex, self.n_samples) self.dst = blocks.vector_sink_c() self.setup_flowgraph()
def __init__(self, ppm=0, osr=4, fc=940e6, samp_rate_in=1e6): gr.hier_block2.__init__( self, "GSM input adaptor", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.ppm = ppm self.osr = osr self.fc = fc self.samp_rate_in = samp_rate_in ################################################## # Variables ################################################## self.samp_rate_out = samp_rate_out = 1625000.0/6.0*osr ################################################## # Blocks ################################################## if version(gr.version()) >= version('3.7.9'): self.message_port_register_hier_in("ppm_in") else: self.message_port_register_hier_out("ppm_in") self.low_pass_filter_0_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate_out, 125e3, 5e3, firdes.WIN_HAMMING, 6.76)) self.gsm_clock_offset_corrector_0 = grgsm.clock_offset_corrector( fc=fc, ppm=ppm, samp_rate_in=samp_rate_in, ) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0_0, 0), (self, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.gsm_clock_offset_corrector_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self, 0), (self.gsm_clock_offset_corrector_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self, "ppm_in", self.gsm_clock_offset_corrector_0, "ppm_in")
def __init__(self, fc=936.6e6, ppm=0, samp_rate_in=1625000.0/6.0*4.0): gr.hier_block2.__init__( self, "Clock offset corrector", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) if version(gr.version()) >= version('3.7.9'): self.message_port_register_hier_in("ppm_in") else: self.message_port_register_hier_out("ppm_in") ################################################## # Parameters ################################################## self.fc = fc self.ppm = ppm self.samp_rate_in = samp_rate_in ################################################## # Variables ################################################## self.samp_rate_out = samp_rate_out = samp_rate_in ################################################## # Blocks ################################################## self.gsm_controlled_rotator_cc_0 = grgsm.controlled_rotator_cc(0,samp_rate_out) self.gsm_controlled_const_source_f_0 = grgsm.controlled_const_source_f(ppm) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((1.0e-6*samp_rate_in/samp_rate_out, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((fc/samp_rate_out*(2*math.pi)/1e6, )) self.blocks_add_const_vxx_0 = blocks.add_const_vff((samp_rate_in/samp_rate_out, )) ################################################## # Connections ################################################## self.connect((self, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.gsm_controlled_rotator_cc_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.fractional_resampler_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.gsm_controlled_rotator_cc_0, 1)) self.connect((self.gsm_controlled_rotator_cc_0, 0), (self, 0)) self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self, "ppm_in", self.gsm_controlled_const_source_f_0, "constant_msg")
def __init__(self): gr.top_block.__init__(self) options = get_options() self.tune_corrector_callback = tune_corrector(self) self.synchronizer_callback = synchronizer(self) self.converter = blocks.vector_to_stream(gr.sizeof_float, 142) self.ifreq = options.frequency self.rfgain = options.gain self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(int(options.sample_rate)) if self.rfgain is None: self.src.set_gain_mode(1) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(0) self.src.set_gain(self.rfgain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % (sample_rate)) gsm_symb_rate = 1625000.0 / 6.0 sps = sample_rate / gsm_symb_rate / 4 out_sample_rate = gsm_symb_rate * 4 self.offset = 0 taps = filter.firdes.low_pass(1.0, sample_rate, 145e3, 10e3, filter.firdes.WIN_HANN) self.tuner = filter.freq_xlating_fir_filter_ccf( 1, taps, self.offset, sample_rate) self.interpolator = filter.fractional_resampler_cc(0, sps) self.receiver = gsm.receiver_cf(self.tune_corrector_callback, self.synchronizer_callback, 4, options.key.replace(' ', '').lower(), options.configuration.upper()) self.output = blocks.file_sink(gr.sizeof_float, options.output_file) self.connect(self.src, self.tuner, self.interpolator, self.receiver, self.converter, self.output)
def __init__(self, fc=936.6e6, ppm=0, samp_rate_in=1625000.0/6.0*4.0): grgsm.hier_block.__init__( self, "Clock offset corrector", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) self.message_port_register_hier_in("ppm_in") ################################################## # Parameters ################################################## self.fc = fc self.ppm = ppm self.samp_rate_in = samp_rate_in ################################################## # Variables ################################################## self.samp_rate_out = samp_rate_out = samp_rate_in ################################################## # Blocks ################################################## self.gsm_controlled_rotator_cc_0 = grgsm.controlled_rotator_cc(0,samp_rate_out) self.gsm_controlled_const_source_f_0 = grgsm.controlled_const_source_f(ppm) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((1.0e-6*samp_rate_in/samp_rate_out, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((fc/samp_rate_out*(2*math.pi)/1e6, )) self.blocks_add_const_vxx_0 = blocks.add_const_vff((samp_rate_in/samp_rate_out, )) ################################################## # Connections ################################################## self.connect((self, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.gsm_controlled_rotator_cc_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.fractional_resampler_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.gsm_controlled_rotator_cc_0, 1)) self.connect((self.gsm_controlled_rotator_cc_0, 0), (self, 0)) self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self, "ppm_in", self.gsm_controlled_const_source_f_0, "constant_msg")
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-c", "--calibration", type="eng_float", default=0, help="freq offset") parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file") parser.add_option("-l", "--log", action="store_true", default=False, help="dump debug .dat files") parser.add_option("-L", "--low-pass", type="eng_float", default=25e3, help="low pass cut-off", metavar="Hz") parser.add_option("-o", "--output-file", type="string", default="out.dat", help="specify the output file") parser.add_option("-s", "--sample-rate", type="int", default=100000000/512, help="input sample rate") parser.add_option("-v", "--verbose", action="store_true", default=False, help="dump demodulation data") (options, args) = parser.parse_args() sample_rate = options.sample_rate symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) IN = blocks.file_source(gr.sizeof_gr_complex, options.input_file) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(IN, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self, ppm=0, osr=4, fc=940e6, samp_rate_in=1e6): gr.hier_block2.__init__( self, "GSM input adaptor", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.ppm = ppm self.osr = osr self.fc = fc self.samp_rate_in = samp_rate_in ################################################## # Variables ################################################## self.samp_rate_out = samp_rate_out = 1625000.0/6.0*osr ################################################## # Blocks ################################################## self.ppm_in = None;self.message_port_register_hier_out("ppm_in") self.low_pass_filter_0_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate_out, 125e3, 5e3, firdes.WIN_HAMMING, 6.76)) self.gsm_clock_offset_corrector_0 = grgsm.clock_offset_corrector( fc=936.6e6, ppm=0, samp_rate_in=samp_rate_in, ) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0_0, 0), (self, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.gsm_clock_offset_corrector_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self, 0), (self.gsm_clock_offset_corrector_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self, "ppm_in", self.gsm_clock_offset_corrector_0, "ppm_in")
def __init__(self, options): gr.top_block.__init__(self) sample_rate = int(options.sample_rate) self.asrc = audio.source(sample_rate, options.audio_device, True) self.f2c = blocks.float_to_complex(1) self.connect((self.asrc, 1), (self.f2c, 1)) self.connect((self.asrc, 0), (self.f2c, 0)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" % (sample_rate)) DEMOD = cqpsk.cqpsk_demod(samples_per_symbol=sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self,n_samples, n_offset_samples, n_prbs, linear_gain, pad_interval, frequency_offset): super(GrLTEULTracesFlowgraph, self).__init__() # params self.n_samples = n_samples self.n_offset_samples = int(lf.random_generator.load_value(n_offset_samples)) self.linear_gain = linear_gain trace_number = 0 #derived subcarrier_spacing = 15000 fftsize = GrLTEULTracesFlowgraph.prb_mapping[n_prbs]#50] self.samp_rate = float(fftsize*subcarrier_spacing) self.expected_bw = GrLTEULTracesFlowgraph.fftsize_mapping[fftsize] self.fname = GrLTEULTracesFlowgraph.lte_up_filenames[trace_number] self.fname = os.path.expanduser(os.path.join('~/tmp/lte_frames/ul',self.fname)) self.n_samples_per_frame = int(10.0e-3*self.samp_rate) self.resamp_ratio = 20.0e6/self.samp_rate randgen = lf.random_generator.load_generator(pad_interval) # scale by sampling rate new_params = [int(v/self.resamp_ratio) for v in randgen.params] randgen = lf.random_generator(randgen.dist_name,new_params) if isinstance(frequency_offset,tuple): assert frequency_offset[0]=='uniform' self.frequency_offset = frequency_offset[1] else: # it is just a value self.frequency_offset = [frequency_offset] # blocks self.file_reader = blocks.file_source(gr.sizeof_gr_complex,self.fname,True) self.tagger = blocks.stream_to_tagged_stream(gr.sizeof_gr_complex,1,self.n_samples_per_frame,"packet_len") self.burst_shaper = random_burst_shaper_cc(randgen.dynrandom(), 0, self.frequency_offset,"packet_len") self.resampler = filter.fractional_resampler_cc(0,1/self.resamp_ratio) self.skiphead = blocks.skiphead(gr.sizeof_gr_complex, self.n_offset_samples) self.head = blocks.head(gr.sizeof_gr_complex, self.n_samples) self.dst = blocks.vector_sink_c() self.setup_flowgraph()
def __init__(self, noise_voltage, freq, timing): gr.hier_block2.__init__(self, "channel_model", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) timing_offset = filter.fractional_resampler_cc(0, timing) noise_adder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_voltage, 0) freq_offset = analog.sig_source_c(1, analog.GR_SIN_WAVE, freq, 1.0, 0.0) mixer_offset = blocks.multiply_cc() self.connect(self, timing_offset) self.connect(timing_offset, (mixer_offset, 0)) self.connect(freq_offset, (mixer_offset, 1)) self.connect(mixer_offset, (noise_adder, 1)) self.connect(noise, (noise_adder, 0)) self.connect(noise_adder, self)
def __init__(self, options): gr.top_block.__init__(self) sample_rate = int(options.sample_rate) self.asrc = audio.source(sample_rate, options.audio_device, True) self.f2c = blocks.float_to_complex(1) self.connect((self.asrc, 1), (self.f2c, 1)) self.connect((self.asrc, 0), (self.f2c, 0)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass( 1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN ) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" % (sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol=sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose, ) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self, noise_voltage, freq, timing): gr.hier_block2.__init__(self, "channel_model", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) timing_offset = filter.fractional_resampler_cc(0, timing) noise_adder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_voltage, 0) freq_offset = analog.sig_source_c(1, analog.GR_SIN_WAVE, freq, 1.0, 0.0) mixer_offset = blocks.multiply_cc(); self.connect(self, timing_offset) self.connect(timing_offset, (mixer_offset,0)) self.connect(freq_offset, (mixer_offset,1)) self.connect(mixer_offset, (noise_adder,1)) self.connect(noise, (noise_adder,0)) self.connect(noise_adder, self)
def __init__(self, in_samp_rate, freq, offset, finetune, realtime): gr.hier_block2.__init__(self, "lora_receiver", # Min, Max, gr.sizeof_<type> gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature # Parameters self.finetune = finetune self.offset = offset self.in_samp_rate = in_samp_rate self.realtime = realtime bw = 125000 # Define blocks null1 = null_sink(gr.sizeof_float) null2 = null_sink(gr.sizeof_float) if realtime: self.c_decoder = lora.decoder(finetune) out_samp_rate = 1000000 decimation = 1 else: decoder = lora_decoder() out_samp_rate = 10000000 decimation = 10 lpf = firdes.low_pass(1, out_samp_rate, bw, 10000, firdes.WIN_HAMMING, 6.67) qdemod = quadrature_demod_cf(1.0) channelizer = freq_xlating_fir_filter_ccf(decimation, lpf, offset, out_samp_rate) resampler = fractional_resampler_cc(0, in_samp_rate / float(out_samp_rate)) # Connect blocks self.connect((self, 0), (resampler, 0)) self.connect((resampler, 0), (channelizer, 0)) if realtime: self.connect((channelizer, 0), (self.c_decoder, 0)) else: self.connect((channelizer, 0), (qdemod, 0)) self.connect((channelizer, 0), (decoder, 1)) self.connect((qdemod, 0), (decoder, 0)) self.connect((decoder, 0), (null1, 0)) self.connect((decoder, 1), (null2, 0))
def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 4 self.excess_bw = excess_bw = 0.35 self.samp_rate = samp_rate = 32000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine( 1, sps, 1, excess_bw, 32) self.qpsk_0 = qpsk_0 = digital.constellation_rect( ([1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.qpsk = qpsk = digital.constellation_rect( ([1 + 0j, -1 + 0j, 0 - 1j, 0 + 1j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() ################################################## # Blocks ################################################## self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 2000, #size samp_rate, #samp_rate "", #name 2 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "cyan", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [0, 0, 0, 0, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2 * 2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.fractional_resampler_xx_0_0_0_0 = filter.fractional_resampler_cc( 0, 4) self.fractional_resampler_xx_0_0_0 = filter.fractional_resampler_cc( 0.2, 4) self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(1, (rrc_taps)) self.fir_filter_xxx_0_0.declare_sample_delay(0) self.fir_filter_xxx_0 = filter.fir_filter_ccc(1, (rrc_taps)) self.fir_filter_xxx_0.declare_sample_delay(0) self.digital_constellation_modulator_0_0 = digital.generic_mod( constellation=qpsk, differential=True, samples_per_symbol=sps, pre_diff_code=True, excess_bw=excess_bw, verbose=False, log=False, ) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=qpsk, differential=False, samples_per_symbol=sps, pre_diff_code=True, excess_bw=excess_bw, verbose=False, log=False, ) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, 255, 1000)), True) ################################################## # Connections ################################################## self.connect((self.analog_random_source_x_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.digital_constellation_modulator_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.digital_constellation_modulator_0_0, 0), (self.fir_filter_xxx_0_0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.fractional_resampler_xx_0_0_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.fractional_resampler_xx_0_0_0_0, 0)) self.connect((self.fractional_resampler_xx_0_0_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.fractional_resampler_xx_0_0_0_0, 0), (self.qtgui_time_sink_x_0, 1))
def __init__(self): gr.top_block.__init__(self) # Variables options = self.get_options() self.src = osmosdr.source(options.args) self.src.set_center_freq(options.frequency) self.src.set_freq_corr(options.ppm) self.src.set_sample_rate(int(options.sample_rate)) if options.gain is None: self.src.set_gain_mode(1) else: self.src.set_gain_mode(0) self.src.set_gain(options.gain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % sample_rate) gsm_symb_rate = 1625000.0 / 6.0 sps = sample_rate / gsm_symb_rate / options.osr # configure channel filter filter_cutoff = 145e3 # 135,417Hz is GSM bandwidth filter_t_width = 10e3 offset = 0.0 filter_taps = filter.firdes.low_pass(1.0, sample_rate, filter_cutoff, filter_t_width, filter.firdes.WIN_HAMMING) self.gr_null_sink = blocks.null_sink(568) # gr.sizeof_gr_complex*1 self.filter = filter.freq_xlating_fir_filter_ccf(1, filter_taps, offset, sample_rate) self.interpolator = filter.fractional_resampler_cc(0, sps) self.tuner_callback = tuner(self) self.synchronizer_callback = synchronizer(self) print ">>>>>Input rate: ", sample_rate sdr_config = npgsm.SDRconfiguration() sdr_config.decim = 96 #set fgpa decimation rate to DECIM sdr_config.freq = 891000000 #set input frequency to FREQ sdr_config.osr = 4 #set oversample rate sdr_config.ch0_infile = "/home/nick/my_project/gnuradio/cfile/TD-60-32-20120901-145641_d.cfile" sdr_config.ch1_infile = "/home/nick/my_project/gnuradio/cfile/TD-60-32-20120901-145641_d.cfile" sdr_config.ch0_arfcn = 297 #set ch0_arfcn sdr_config.rxa_gain = 30 sdr_config.rxb_gain = 30 sdr_config.fcch_ch = 0 sdr_config.is_double_downlink = 0 # using two downlink sdr_config.realtime = 1 sdr_config.which_board = 0 # for bts scanner settings sdr_config.sch_timeout_boundary = 10 sdr_config.fcch_timeout_boundary = 50 sdr_config.width8 = 0 sdr_config.ch0_upload =1 sdr_config.ch1_upload =1 sdr_config.server = "127.0.0.1" sdr_config.port = 8000 self.receiver = npgsm.receiver_cf2( self.tuner_callback, self.synchronizer_callback, options.osr, options.key.replace(' ', '').lower(), options.configuration.upper(), sdr_config) self.connect((self.src, 0), (self.filter, 0), (self.interpolator, 0), (self.receiver, 0))
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-c", "--calibration", type="eng_float", default=0, help="freq offset") parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file") parser.add_option("-l", "--log", action="store_true", default=False, help="dump debug .dat files") parser.add_option("-L", "--low-pass", type="eng_float", default=25e3, help="low pass cut-off", metavar="Hz") parser.add_option("-o", "--output-file", type="string", default="out.dat", help="specify the output file") parser.add_option("-s", "--sample-rate", type="int", default=100000000 / 512, help="input sample rate") parser.add_option("-v", "--verbose", action="store_true", default=False, help="dump demodulation data") (options, args) = parser.parse_args() sample_rate = options.sample_rate symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" % (sample_rate)) IN = blocks.file_source(gr.sizeof_gr_complex, options.input_file) DEMOD = cqpsk.cqpsk_demod(samples_per_symbol=sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(IN, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self): gr.top_block.__init__(self, "WBFM Receiver V2- F1ATB - MARCH 2021") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2400e3 self.Largeur_filtre = Largeur_filtre = 150000 self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass( 1, samp_rate, Largeur_filtre / 2, 25000) self.decim_LP = decim_LP = 16 self.Squelch = Squelch = -80 self.Gain_RF = Gain_RF = 0 self.Gain_IF = Gain_IF = 20 self.Gain_BB = Gain_BB = 20 self.FrRX = FrRX = 7000000 self.F_Fine = F_Fine = 0 ################################################## # Blocks ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer( ('localhost', 9003), allow_none=True) self.xmlrpc_server_0.register_instance(self) self.xmlrpc_server_0_thread = threading.Thread( target=self.xmlrpc_server_0.serve_forever) self.xmlrpc_server_0_thread.daemon = True self.xmlrpc_server_0_thread.start() self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(FrRX, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_dc_offset_mode(2, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(False, 0) self.osmosdr_source_0.set_gain(Gain_RF, 0) self.osmosdr_source_0.set_if_gain(Gain_IF, 0) self.osmosdr_source_0.set_bb_gain(Gain_BB, 0) self.osmosdr_source_0.set_antenna('', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, decim_LP * samp_rate / 200, 5200, 1200, firdes.WIN_HAMMING, 6.76)) self.logpwrfft_x_0 = logpwrfft.logpwrfft_c( sample_rate=samp_rate / 200, fft_size=2048, ref_scale=0.00001, frame_rate=samp_rate / 200 / 2048, avg_alpha=1.0, average=False, ) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 15, (xlate_filter_taps), F_Fine, samp_rate) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc( 0, decim_LP) self.dc_blocker_xx_0 = filter.dc_blocker_cc(1024, True) self.blocks_udp_sink_1 = blocks.udp_sink(gr.sizeof_short * 2048, '127.0.0.1', 9002, 4096, True) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_short * 1, '127.0.0.1', 9001, 1000, True) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, int(2048 * decim_LP), 409600, 0) self.blocks_float_to_short_1 = blocks.float_to_short(2048, 100) self.blocks_float_to_short_0 = blocks.float_to_short(1, 16000) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=samp_rate / 15, audio_decimation=16, ) self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(Squelch, 1) ################################################## # Connections ################################################## self.connect((self.analog_simple_squelch_cc_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.blocks_float_to_short_0, 0)) self.connect((self.blocks_float_to_short_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.blocks_float_to_short_1, 0), (self.blocks_udp_sink_1, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.logpwrfft_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_simple_squelch_cc_0, 0)) self.connect((self.logpwrfft_x_0, 0), (self.blocks_float_to_short_1, 0)) self.connect((self.low_pass_filter_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.dc_blocker_xx_0, 0))
def __init__(self, freq, ch_width, num_chan, audio_rate, squelch, out_scale, do_audio, zmqh, loop, filename=None, file_samprate=None, osmo_args=None, osmo_freq_cor=None, osmo_rf_gain=None, osmo_if_gain=None, osmo_bb_gain=None): gr.top_block.__init__(self, "Multipager") sample_rate = num_chan * ch_width ################################################## # Blocks ################################################## if not (filename == None) ^ (osmo_args == None): raise (exceptions.ValueError( 'Must specify either filename or osmo_args')) if filename != None: self.source = blocks.file_source(gr.sizeof_gr_complex * 1, filename, True) if file_samprate != None and file_samprate < sample_rate: raise (exceptions.ValueError( 'File sample %f rate must be >= computed sample rate %f' % (file_samprate, sample_rate))) else: self.source = osmosdr.source(args=osmo_args) if self.source.set_sample_rate(sample_rate) != sample_rate: raise (exceptions.ValueError( 'Wanted %.4f kSPS got %.4f kSPS' % (sample_rate / 1e3, self.source.get_sample_rate() / 1e3))) self.source.set_center_freq(freq, 0) if osmo_freq_cor != None: self.source.set_freq_corr(osmo_freq_cor, 0) self.source.set_dc_offset_mode(0, 0) self.source.set_iq_balance_mode(0, 0) self.source.set_gain_mode(False, 0) if osmo_rf_gain != None: self.source.set_gain(osmo_rf_gain, 0) if osmo_if_gain != None: self.source.set_if_gain(osmo_if_gain, 0) if osmo_bb_gain != None: self.source.set_bb_gain(osmo_bb_gain, 0) self.source.set_antenna("", 0) self.source.set_bandwidth(0, 0) self.pfb_channelizer_ccf_0 = pfb.channelizer_ccf( num_chan, (firdes.low_pass(1.0, sample_rate, 8e3, 1.5e3, firdes.WIN_HAMMING, 6.76)), 1, 60) self.pfb_channelizer_ccf_0.set_channel_map(([])) self.pfb_channelizer_ccf_0.declare_sample_delay(0) ################################################## # Connections ################################################## if file_samprate != None: logger.info('Resampling %f' % (file_samprate / sample_rate)) self.filter = grfilter.fir_filter_ccf( 1, firdes.low_pass(1, file_samprate, sample_rate / 2, 1e4, firdes.WIN_HAMMING, 6.76)) self.resampler = grfilter.fractional_resampler_cc( 0, file_samprate / sample_rate) self.connect((self.source, 0), (self.filter, 0)) self.connect((self.filter, 0), (self.resampler, 0)) self.connect((self.resampler, 0), (self.pfb_channelizer_ccf_0, 0)) else: self.connect((self.source, 0), (self.pfb_channelizer_ccf_0, 0)) # Enable decoding on all channels sel = [True] * num_chan self.fms = {} for i in range(num_chan): if i > num_chan / 2: chfreq = freq + ch_width * (i - num_chan) else: chfreq = freq + ch_width * i if sel[i]: logger.info("Channel %d %.3f MHz" % (i, chfreq / 1e6)) command = cmdpat.format(audio_in=ch_width, audio_out=audio_rate) fm = FMtoCommand(squelch, int(ch_width), 5e3, out_scale, chfreq, command, do_audio=(i == 0) and do_audio) self.connect((self.pfb_channelizer_ccf_0, i), (fm, 0)) self.fms[chfreq] = fm loop.add_reader(fm.p.stdout, parse_multimon, zmqh, fm.p.stdout, chfreq, fm.p) else: n = blocks.null_sink(gr.sizeof_gr_complex * 1) self.connect((self.pfb_channelizer_ccf_0, i), (n, 0))
def __init__(self, ppm=0, osr=4, fc=925.2e6, samp_rate_in=20e6, ca=[], band='P-GSM'): self.num_streams = len(ca) grgsm.hier_block.__init__( self, "GSM wideband input adaptor", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(self.num_streams, self.num_streams, gr.sizeof_gr_complex * 1), ) ################################################## # Parameters ################################################## self.ppm = ppm self.osr = osr self.fc = fc self.samp_rate_in = samp_rate_in self.ca = ca self.blocks_fir_filters = {} self.blocks_resamplers = {} self.blocks_ocs = {} self.band = band ################################################## # Variables ################################################## self.samp_rate_out = samp_rate_out = 1625000.0 / 6.0 * osr ################################################## # Blocks ################################################## self.ppm_in = None self.message_port_register_hier_in("ppm_in") #self.lpf = firdes.low_pass(1, samp_rate_out, 125e3, 5e3, firdes.WIN_HAMMING, 6.76) self.lpf = firdes.low_pass(1, samp_rate_in, 125e3, 75e3, firdes.WIN_HAMMING, 6.76) self.gsm_clock_offset_corrector_0 = grgsm.clock_offset_corrector( fc=fc, ppm=ppm, samp_rate_in=samp_rate_in, ) center_arfcn = arfcn.downlink2arfcn(fc, band) fc_str = eng_notation.num_to_str(fc) print( "Extracting channels %s, given center frequency at %sHz (ARFCN %d)" % (str(ca), fc_str, center_arfcn)) self.connect((self, 0), (self.gsm_clock_offset_corrector_0, 0)) output_port = 0 for channel in ca: channel_freq = arfcn.arfcn2downlink(channel, band) if channel_freq is None: print("Warning: invalid ARFCN %d for band %s" % (channel, band)) continue freq_diff = channel_freq - fc freq_diff_str = "+" if 0 <= freq_diff else "" freq_diff_str += eng_notation.num_to_str(freq_diff) print("ARFCN %d is at %sHz %sHz" % (channel, fc_str, freq_diff_str)) self.blocks_resamplers[channel] = filter.fractional_resampler_cc( 0, samp_rate_in / samp_rate_out) self.blocks_fir_filters[ channel] = filter.freq_xlating_fir_filter_ccc( 1, self.lpf, freq_diff, samp_rate_in) self.connect((self.gsm_clock_offset_corrector_0, 0), (self.blocks_fir_filters[channel], 0)) self.connect((self.blocks_fir_filters[channel], 0), (self.blocks_resamplers[channel], 0)) self.connect((self.blocks_resamplers[channel], 0), (self, output_port)) output_port += 1 ################################################## # Asynch Message Connections ################################################## self.msg_connect(self, "ppm_in", self.gsm_clock_offset_corrector_0, "ppm_in")
def __init__(self, options): gr.top_block.__init__(self) # Create a UHD source self._u = uhd.usrp_source( device_addr=options.args, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) # 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) # Pick the lowest possible value for the input rate supported_rates = self._u.get_samp_rates() self._u.set_samp_rate(supported_rates.start()) sample_rate = self._u.get_samp_rate() symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps # Set receive daughterboard gain if options.gain is None: g = self._u.get_gain_range() options.gain = float(g.stop()+g.start())/2 print "Using mid-point gain of", options.gain, "(", g.start(), "-", g.stop(), ")" self._u.set_gain(options.gain) # Set frequency (tune request takes lo_offset) if(options.lo_offset is not None): treq = uhd.tune_request(options.freq, options.lo_offset) else: treq = uhd.tune_request(options.freq) tr = self._u.set_center_freq(treq) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self._u, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self): gr.top_block.__init__(self) # Variables options = self.get_options() self.src = osmosdr.source(options.args) self.src.set_center_freq(options.frequency) self.src.set_freq_corr(options.ppm) self.src.set_sample_rate(int(options.sample_rate)) if options.gain is None: self.src.set_gain_mode(1) else: self.src.set_gain_mode(0) self.src.set_gain(options.gain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % sample_rate) gsm_symb_rate = 1625000.0 / 6.0 sps = sample_rate / gsm_symb_rate / options.osr # configure channel filter filter_cutoff = 135e3 # 135,417Hz is GSM bandwidth filter_t_width = 10e3 offset = 0.0 filter_taps = filter.firdes.low_pass(1.0, sample_rate, filter_cutoff, filter_t_width, filter.firdes.WIN_HAMMING) self.gr_null_sink = blocks.null_sink(568) self.filter = filter.freq_xlating_fir_filter_ccf(1, filter_taps, offset, sample_rate) self.interpolator = filter.fractional_resampler_cc(0, sps) self.tuner_callback = tuner(self) self.synchronizer_callback = synchronizer(self) self.null_callback = nullcb(self) print ">>>>>Input rate: ", sample_rate self.receiver = npgsm.receiver_cf( self.tuner_callback, self.synchronizer_callback, options.osr, options.c0pos, options.ma.replace(' ', '').lower(), options.maio, options.hsn, options.key.replace(' ', '').lower(), options.configuration.upper(), True) #self.receiver_1 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'1S',False) #self.receiver_2 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'2S',False) #self.receiver_3 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'3S',False) #self.receiver_4 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'4S',False) #self.receiver_5 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'5S',False) #self.receiver_6 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'6S',False) #self.receiver_7 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'7S',False) self.connect((self.src, 0), (self.filter, 0), (self.interpolator, 0), (self.receiver, 0), (self.gr_null_sink, 0))
def __init__(self, dab_params, rx_params, verbose=False, debug=False): """ Hierarchical block for OFDM demodulation @param dab_params DAB parameter object (grdab.parameters.dab_parameters) @param rx_params RX parameter object (grdab.parameters.receiver_parameters) @param debug enables debug output to files @param verbose whether to produce verbose messages """ self.dp = dp = dab_params self.rp = rp = rx_params self.verbose = verbose if self.rp.softbits: gr.hier_block2.__init__(self,"ofdm_demod", gr.io_signature (1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature (1, 1, gr.sizeof_float*self.dp.num_carriers*2)) # output signature else: gr.hier_block2.__init__(self,"ofdm_demod", gr.io_signature (1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature (1, 1, gr.sizeof_char*self.dp.num_carriers/4)) # output signature # workaround for a problem that prevents connecting more than one block directly (see trac ticket #161) #self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.input = blocks.multiply_const_cc(1.0) # FIXME self.connect(self, self.input) # input filtering if self.rp.input_fft_filter: if verbose: print "--> RX filter enabled" lowpass_taps = filter.firdes_low_pass(1.0, # gain dp.sample_rate, # sampling rate rp.filt_bw, # cutoff frequency rp.filt_tb, # width of transition band filter.firdes.WIN_HAMMING) # Hamming window self.fft_filter = filter.fft_filter_ccc(1, lowpass_taps) # correct sample rate offset, if enabled if self.rp.autocorrect_sample_rate: if verbose: print "--> dynamic sample rate correction enabled" self.rate_detect_ns = grdab.detect_null(dp.ns_length, False) self.rate_estimator = grdab.estimate_sample_rate_bf(dp.sample_rate, dp.frame_length) self.rate_prober = blocks.probe_signal_f() self.connect(self.input, self.rate_detect_ns, self.rate_estimator, self.rate_prober) # self.resample = gr.fractional_interpolator_cc(0, 1) self.resample = grdab.fractional_interpolator_triggered_update_cc(0,1) self.connect(self.rate_detect_ns, (self.resample,1)) self.updater = Timer(0.1,self.update_correction) # self.updater = threading.Thread(target=self.update_correction) self.run_interpolater_update_thread = True self.updater.setDaemon(True) self.updater.start() else: self.run_interpolater_update_thread = False if self.rp.sample_rate_correction_factor != 1 or self.rp.always_include_resample: if verbose: print "--> static sample rate correction enabled" self.resample = filter.fractional_resampler_cc(0, self.rp.sample_rate_correction_factor) # timing and fine frequency synchronisation self.sync = grdab.ofdm_sync_dab2(self.dp, self.rp, debug) # ofdm symbol sampler self.sampler = grdab.ofdm_sampler(dp.fft_length, dp.cp_length, dp.symbols_per_frame, rp.cp_gap) # fft for symbol vectors self.fft = fft.fft_vcc(dp.fft_length, True, [], True) # coarse frequency synchronisation self.cfs = grdab.ofdm_coarse_frequency_correct(dp.fft_length, dp.num_carriers, dp.cp_length) # diff phasor self.phase_diff = grdab.diff_phasor_vcc(dp.num_carriers) # remove pilot symbol self.remove_pilot = grdab.ofdm_remove_first_symbol_vcc(dp.num_carriers) # magnitude equalisation if self.rp.equalize_magnitude: if verbose: print "--> magnitude equalization enabled" self.equalizer = grdab.magnitude_equalizer_vcc(dp.num_carriers, rp.symbols_for_magnitude_equalization) # frequency deinterleaving self.deinterleave = grdab.frequency_interleaver_vcc(dp.frequency_deinterleaving_sequence_array) # symbol demapping self.demapper = grdab.qpsk_demapper_vcb(dp.num_carriers) # # connect everything # if self.rp.autocorrect_sample_rate or self.rp.sample_rate_correction_factor != 1 or self.rp.always_include_resample: self.connect(self.input, self.resample) self.input2 = self.resample else: self.input2 = self.input if self.rp.input_fft_filter: self.connect(self.input2, self.fft_filter, self.sync) else: self.connect(self.input2, self.sync) # data stream self.connect(self.sync, self.sampler, self.fft, self.cfs, self.phase_diff, self.remove_pilot) if self.rp.equalize_magnitude: self.connect(self.remove_pilot, self.equalizer, self.deinterleave) else: self.connect(self.remove_pilot, self.deinterleave) if self.rp.softbits: if verbose: print "--> using soft bits" self.softbit_interleaver = grdab.complex_to_interleaved_float_vcf(self.dp.num_carriers) self.connect(self.deinterleave, self.softbit_interleaver, (self,0)) else: self.connect(self.deinterleave, self.demapper, (self,0)) # calculate an estimate of the SNR self.phase_var_decim = blocks.keep_one_in_n(gr.sizeof_gr_complex*self.dp.num_carriers, self.rp.phase_var_estimate_downsample) self.phase_var_arg = blocks.complex_to_arg(dp.num_carriers) self.phase_var_v2s = blocks.vector_to_stream(gr.sizeof_float, dp.num_carriers) self.phase_var_mod = grdab.modulo_ff(pi/2) self.phase_var_avg_mod = filter.iir_filter_ffd([rp.phase_var_estimate_alpha], [0,1-rp.phase_var_estimate_alpha]) self.phase_var_sub_avg = blocks.sub_ff() self.phase_var_sqr = blocks.multiply_ff() self.phase_var_avg = filter.iir_filter_ffd([rp.phase_var_estimate_alpha], [0,1-rp.phase_var_estimate_alpha]) self.probe_phase_var = blocks.probe_signal_f() self.connect((self.remove_pilot,0), self.phase_var_decim, self.phase_var_arg, self.phase_var_v2s, self.phase_var_mod, (self.phase_var_sub_avg,0), (self.phase_var_sqr,0)) self.connect(self.phase_var_mod, self.phase_var_avg_mod, (self.phase_var_sub_avg,1)) self.connect(self.phase_var_sub_avg, (self.phase_var_sqr,1)) self.connect(self.phase_var_sqr, self.phase_var_avg, self.probe_phase_var) # measure processing rate self.measure_rate = grdab.measure_processing_rate(gr.sizeof_gr_complex, 2000000) self.connect(self.input, self.measure_rate) # debugging if debug: self.connect(self.fft, blocks.file_sink(gr.sizeof_gr_complex*dp.fft_length, "debug/ofdm_after_fft.dat")) self.connect((self.cfs,0), blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_after_cfs.dat")) self.connect(self.phase_diff, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_diff_phasor.dat")) self.connect((self.remove_pilot,0), blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_pilot_removed.dat")) self.connect((self.remove_pilot,1), blocks.file_sink(gr.sizeof_char, "debug/ofdm_after_cfs_trigger.dat")) self.connect(self.deinterleave, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_deinterleaved.dat")) if self.rp.equalize_magnitude: self.connect(self.equalizer, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_equalizer.dat")) if self.rp.softbits: self.connect(self.softbit_interleaver, blocks.file_sink(gr.sizeof_float*dp.num_carriers*2, "debug/softbits.dat"))
def __init__(self): gr.top_block.__init__(self, "WBFM Receiver V2- F1ATB - MARCH 2021") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1200000 self.Largeur_filtre = Largeur_filtre = 150000 self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass( 1, samp_rate, Largeur_filtre / 2, 25000) self.decim_LP = decim_LP = 16 self.Squelch = Squelch = -80 self.Gain_RF = Gain_RF = 30 self.Gain_IF = Gain_IF = 20 self.Gain_BB = Gain_BB = 20 self.FrRX = FrRX = 145000000 self.F_Fine = F_Fine = 0 ################################################## # Blocks ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer( ('localhost', 9003), allow_none=True) self.xmlrpc_server_0.register_instance(self) self.xmlrpc_server_0_thread = threading.Thread( target=self.xmlrpc_server_0.serve_forever) self.xmlrpc_server_0_thread.daemon = True self.xmlrpc_server_0_thread.start() self.pluto_source_0 = iio.pluto_source('192.168.2.1', 145000000, int(samp_rate), 1000000, 32768, True, True, True, "manual", 50, '', True) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, decim_LP * samp_rate / 200, 5200, 1200, firdes.WIN_HAMMING, 6.76)) self.logpwrfft_x_0 = logpwrfft.logpwrfft_c( sample_rate=samp_rate / 100, fft_size=2048, ref_scale=0.00001, frame_rate=samp_rate / 100 / 2048, avg_alpha=1.0, average=False, ) self.iio_attr_updater_0_0 = iio.attr_updater('hardwaregain', str(int(Gain_RF * 1.75)), 1000) self.iio_attr_updater_0 = iio.attr_updater('frequency', str(int(FrRX)), 1000) self.iio_attr_sink_0_0 = iio.attr_sink("ip:192.168.2.1", "ad9361-phy", "voltage0", 0, False, False) self.iio_attr_sink_0 = iio.attr_sink("ip:192.168.2.1", "ad9361-phy", "altvoltage0", 0, True, False) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 6, (xlate_filter_taps), F_Fine, samp_rate) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc( 0, decim_LP / 2) self.blocks_udp_sink_1 = blocks.udp_sink(gr.sizeof_short * 2048, '127.0.0.1', 9002, 4096, True) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_short * 1, '127.0.0.1', 9001, 1000, True) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, int(1024 * decim_LP), 204800, 0) self.blocks_float_to_short_1 = blocks.float_to_short(2048, 100) self.blocks_float_to_short_0 = blocks.float_to_short(1, 16000) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=samp_rate / 6, audio_decimation=20, ) self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(Squelch, 1) ################################################## # Connections ################################################## self.msg_connect((self.iio_attr_updater_0, 'out'), (self.iio_attr_sink_0, 'attr')) self.msg_connect((self.iio_attr_updater_0_0, 'out'), (self.iio_attr_sink_0_0, 'attr')) self.connect((self.analog_simple_squelch_cc_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.blocks_float_to_short_0, 0)) self.connect((self.blocks_float_to_short_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.blocks_float_to_short_1, 0), (self.blocks_udp_sink_1, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.logpwrfft_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_simple_squelch_cc_0, 0)) self.connect((self.logpwrfft_x_0, 0), (self.blocks_float_to_short_1, 0)) self.connect((self.low_pass_filter_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.pluto_source_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.pluto_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def __init__(self, options): gr.top_block.__init__(self) # Create a UHD source self._u = uhd.usrp_source(device_addr=options.args, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) # 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) # Pick the lowest possible value for the input rate supported_rates = self._u.get_samp_rates() self._u.set_samp_rate(supported_rates.start()) sample_rate = self._u.get_samp_rate() symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps # Set receive daughterboard gain if options.gain is None: g = self._u.get_gain_range() options.gain = float(g.stop() + g.start()) / 2 print "Using mid-point gain of", options.gain, "(", g.start( ), "-", g.stop(), ")" self._u.set_gain(options.gain) # Set frequency (tune request takes lo_offset) if (options.lo_offset is not None): treq = uhd.tune_request(options.freq, options.lo_offset) else: treq = uhd.tune_request(options.freq) tr = self._u.set_center_freq(treq) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" % (sample_rate)) DEMOD = cqpsk.cqpsk_demod(samples_per_symbol=sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self._u, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self, ppm=0, osr=4, fc=925.2e6, samp_rate_in=20e6, ca=[]): self.num_streams = len(ca) gr.hier_block2.__init__( self, "GSM wideband input adaptor", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(self.num_streams, self.num_streams, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.ppm = ppm self.osr = osr self.fc = fc self.samp_rate_in = samp_rate_in self.ca = ca self.blocks_fir_filters = {} self.blocks_resamplers = {} self.blocks_ocs = {} self.band = band = 'E-GSM' # TODO make selectable ################################################## # Variables ################################################## self.samp_rate_out = samp_rate_out = 1625000.0/6.0*osr ################################################## # Blocks ################################################## self.ppm_in = None self.message_port_register_hier_out("ppm_in") #self.lpf = firdes.low_pass(1, samp_rate_out, 125e3, 5e3, firdes.WIN_HAMMING, 6.76) self.lpf = firdes.low_pass(1, samp_rate_in, 125e3, 75e3, firdes.WIN_HAMMING, 6.76) self.gsm_clock_offset_corrector_0 = grgsm.clock_offset_corrector( fc=fc, ppm=ppm, samp_rate_in=samp_rate_in, ) c0_arfcn = arfcn.downlink2arfcn(fc, band) print("Extracting channels %s, given that the center frequency is at ARFCN %d (%s)" % (str(ca), c0_arfcn, eng_notation.num_to_str(fc))) self.connect((self, 0), (self.gsm_clock_offset_corrector_0, 0)) output_port = 0 for channel in ca: channel_freq = arfcn.arfcn2downlink(channel, band) if channel_freq is None: print("Warning: invalid ARFCN %d for band %s" % (channel, band)) continue freq_diff = channel_freq - fc print("ARFCN %d is at C0 %+d KHz" % (channel, int(freq_diff / 1000.0))) self.blocks_resamplers[channel] = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out) self.blocks_fir_filters[channel] = filter.freq_xlating_fir_filter_ccc(1, self.lpf, freq_diff, samp_rate_in) self.connect((self.gsm_clock_offset_corrector_0, 0), (self.blocks_fir_filters[channel], 0)) self.connect((self.blocks_fir_filters[channel], 0), (self.blocks_resamplers[channel], 0)) self.connect((self.blocks_resamplers[channel], 0), (self, output_port)) output_port += 1 ################################################## # Asynch Message Connections ################################################## self.msg_connect(self, "ppm_in", self.gsm_clock_offset_corrector_0, "ppm_in")
def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.dect_symbol_rate = dect_symbol_rate = 1152000 self.dect_occupied_bandwidth = dect_occupied_bandwidth = 1.2*dect_symbol_rate self.dect_channel_bandwidth = dect_channel_bandwidth = 1.728e6 self.baseband_sampling_rate = baseband_sampling_rate = 100000000/32 self.rx_gain = rx_gain = 0 self.rx_freq = rx_freq = 1897344000 self.resampler_filter_taps = resampler_filter_taps = firdes.low_pass_2(1, 3*baseband_sampling_rate, dect_occupied_bandwidth/2, (dect_channel_bandwidth - dect_occupied_bandwidth)/2, 30) self.part_id = part_id = 0 ################################################## # Blocks ################################################## self._rx_gain_layout = Qt.QVBoxLayout() self._rx_gain_tool_bar = Qt.QToolBar(self) self._rx_gain_layout.addWidget(self._rx_gain_tool_bar) self._rx_gain_tool_bar.addWidget(Qt.QLabel("RX Gain"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._rx_gain_counter = qwt_counter_pyslot() self._rx_gain_counter.setRange(0, 30, 1) self._rx_gain_counter.setNumButtons(2) self._rx_gain_counter.setValue(self.rx_gain) self._rx_gain_tool_bar.addWidget(self._rx_gain_counter) self._rx_gain_counter.valueChanged.connect(self.set_rx_gain) self._rx_gain_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._rx_gain_slider.setRange(0, 30, 1) self._rx_gain_slider.setValue(self.rx_gain) self._rx_gain_slider.setMinimumWidth(200) self._rx_gain_slider.valueChanged.connect(self.set_rx_gain) self._rx_gain_layout.addWidget(self._rx_gain_slider) self.top_layout.addLayout(self._rx_gain_layout) self._rx_freq_options = [1897344000, 1881792000, 1883520000, 1885248000, 1886876000, 1888704000, 1890432000, 1892160000, 1893888000, 1895616000,] self._rx_freq_labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] self._rx_freq_tool_bar = Qt.QToolBar(self) self._rx_freq_tool_bar.addWidget(Qt.QLabel("Carrier Number"+": ")) self._rx_freq_combo_box = Qt.QComboBox() self._rx_freq_tool_bar.addWidget(self._rx_freq_combo_box) for label in self._rx_freq_labels: self._rx_freq_combo_box.addItem(label) self._rx_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._rx_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._rx_freq_options.index(i))) self._rx_freq_callback(self.rx_freq) self._rx_freq_combo_box.currentIndexChanged.connect( lambda i: self.set_rx_freq(self._rx_freq_options[i])) self.top_layout.addWidget(self._rx_freq_tool_bar) self.vocoder_g721_decode_bs_0 = vocoder.g721_decode_bs() self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(3125000) self.uhd_usrp_source_0.set_center_freq(rx_freq, 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.uhd_usrp_source_0.set_antenna("RX2", 0) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=6, decimation=1, taps=None, fractional_bw=None, ) self.rational_resampler = filter.rational_resampler_base_ccc(3, 2, (resampler_filter_taps)) self._part_id_options = [0, 1, 2, 3, 4, 5, 6, 7, 8] self._part_id_labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8"] self._part_id_tool_bar = Qt.QToolBar(self) self._part_id_tool_bar.addWidget(Qt.QLabel("Select Part"+": ")) self._part_id_combo_box = Qt.QComboBox() self._part_id_tool_bar.addWidget(self._part_id_combo_box) for label in self._part_id_labels: self._part_id_combo_box.addItem(label) self._part_id_callback = lambda i: Qt.QMetaObject.invokeMethod(self._part_id_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._part_id_options.index(i))) self._part_id_callback(self.part_id) self._part_id_combo_box.currentIndexChanged.connect( lambda i: self.set_part_id(self._part_id_options[i])) self.top_layout.addWidget(self._part_id_tool_bar) self.fractional_resampler = filter.fractional_resampler_cc(0, (3.0*baseband_sampling_rate/2.0)/dect_symbol_rate/4.0) self.dect2_phase_diff_0 = dect2.phase_diff() self.dect2_packet_receiver_0 = dect2.packet_receiver() self.dect2_packet_decoder_0 = dect2.packet_decoder() self.console_0 = dect2.console() self.top_layout.addWidget(self.console_0) self.blocks_short_to_float_0 = blocks.short_to_float(1, 32768) self.audio_sink_0 = audio.sink(48000, "", True) ################################################## # Connections ################################################## self.connect((self.rational_resampler, 0), (self.fractional_resampler, 0)) self.connect((self.fractional_resampler, 0), (self.dect2_phase_diff_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.vocoder_g721_decode_bs_0, 0), (self.blocks_short_to_float_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.rational_resampler, 0)) self.connect((self.dect2_packet_decoder_0, 0), (self.vocoder_g721_decode_bs_0, 0)) self.connect((self.dect2_phase_diff_0, 0), (self.dect2_packet_receiver_0, 0)) self.connect((self.dect2_packet_receiver_0, 0), (self.dect2_packet_decoder_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.rational_resampler_xxx_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self.dect2_packet_decoder_0, "log_out", self.console_0, "in") self.msg_connect(self.dect2_packet_receiver_0, "rcvr_msg_out", self.dect2_packet_decoder_0, "rcvr_msg_in")
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel options = get_options() sample_rate = int(options.sample_rate) self.asrc = audio.source(sample_rate, options.audio_device, True) self.f2c = blocks.float_to_complex(1) self.connect((self.asrc, 1), (self.f2c, 1)) self.connect((self.asrc, 0), (self.f2c, 0)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" % (sample_rate)) DEMOD = cqpsk.cqpsk_demod(samples_per_symbol=sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT) self.scope = fftsink2.fft_sink_c(panel, fft_size=512, sample_rate=sample_rate, ref_scale=2.0, ref_level=-30, y_divs=10, fft_rate=10, average=True, avg_alpha=0.2) self.connect(self.f2c, self.scope)
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] center_freq band_width" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device 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 [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--meas-interval", type="eng_float", default=0.1, metavar="SECS", help="interval over which to measure statistic (in seconds) [default=%default]") parser.add_option("-c", "--number-channels", type="int", default=100, help="number of uniform channels for which to report power measurements [default=%default]") parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=half the sample rate]") parser.add_option("-F", "--fft-size", type="int", default=1024, help="specify number of FFT bins [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option("-d", "--dest-host", type="string", default="", help="set destination host for sending data") parser.add_option("", "--skip-DC", action="store_true", default=False, help="skip the DC bin when mapping channels") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) self.center_freq = eng_notation.str_to_num(args[0]) self.bandwidth = eng_notation.str_to_num(args[1]) if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph 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(options.samp_rate) usrp_rate = self.u.get_samp_rate() if usrp_rate != options.samp_rate: if usrp_rate < options.samp_rate: # create list of allowable rates samp_rates = self.u.get_samp_rates() rate_list = [0.0]*len(samp_rates) for i in range(len(rate_list)): last_rate = samp_rates.pop() rate_list[len(rate_list) - 1 - i] = last_rate.start() # choose next higher rate rate_ind = rate_list.index(usrp_rate) + 1 if rate_ind < len(rate_list): self.u.set_samp_rate(rate_list[rate_ind]) usrp_rate = self.u.get_samp_rate() print "New actual sample rate =", usrp_rate/1e6, "MHz" resamp = filter.fractional_resampler_cc(0.0, usrp_rate / options.samp_rate) self.samp_rate = options.samp_rate if(options.lo_offset): self.lo_offset = options.lo_offset else: self.lo_offset = usrp_rate / 2.0 print "LO offset set to", self.lo_offset/1e6, "MHz" self.fft_size = options.fft_size self.num_ch = options.number_channels s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) window_power = sum(map(lambda x: x*x, mywindow)) c2mag = blocks.complex_to_mag_squared(self.fft_size) self.bin2ch_map = [0] * self.fft_size hz_per_bin = self.samp_rate / self.fft_size channel_bw = hz_per_bin * round(self.bandwidth / self.num_ch / hz_per_bin) self.bandwidth = channel_bw * self.num_ch print "Actual width of band is", self.bandwidth/1e6, "MHz." start_freq = self.center_freq - self.bandwidth/2.0 stop_freq = start_freq + self.bandwidth for j in range(self.fft_size): fj = self.bin_freq(j, self.center_freq) if (fj >= start_freq) and (fj < stop_freq): channel_num = int(math.floor((fj - start_freq) / channel_bw)) + 1 self.bin2ch_map[j] = channel_num if options.skip_DC: self.bin2ch_map[(self.fft_size + 1) / 2 + 1:] = self.bin2ch_map[(self.fft_size + 1) / 2 : -1] self.bin2ch_map[(self.fft_size + 1) / 2] = 0 if self.bandwidth > self.samp_rate: print "Warning: Width of band (" + str(self.bandwidth/1e6), "MHz) is greater than the sample rate (" + str(self.samp_rate/1e6), "MHz)." self.aggr = myblocks.bin_aggregator_ff(self.fft_size, self.num_ch, self.bin2ch_map) meas_frames = max(1, int(round(options.meas_interval * self.samp_rate / self.fft_size))) # in fft_frames self.meas_duration = meas_frames * self.fft_size / self.samp_rate print "Actual measurement duration =", self.meas_duration, "s" self.stats = myblocks.bin_statistics_ff(self.num_ch, meas_frames) # Divide magnitude-square by a constant to obtain power # in Watts. Assumes unit of USRP source is volts. impedance = 50.0 # ohms Vsq2W_dB = -10.0 * math.log10(self.fft_size * window_power * impedance) # Convert from Watts to dBm. W2dBm = blocks.nlog10_ff(10.0, self.num_ch, 30.0 + Vsq2W_dB) f2c = blocks.float_to_char(self.num_ch, 1.0) self.dest_host = options.dest_host # file descriptor is set in main loop; use dummy value for now self.srvr = myblocks.file_descriptor_sink(self.num_ch * gr.sizeof_char, 0) if usrp_rate > self.samp_rate: # insert resampler self.connect(self.u, resamp, s2v) else: self.connect(self.u, s2v) self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, f2c, self.srvr) #self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, self.srvr) g = self.u.get_gain_range() if options.gain is None: # if no gain was specified, use the mid-point in dB options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain) print "gain =", options.gain, "dB in range (%0.1f dB, %0.1f dB)" % (float(g.start()), float(g.stop())) self.atten = float(g.stop()) - options.gain
def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.tx_gain = tx_gain = 32000 self.samp_rate = samp_rate = 64000 self.rx_gain = rx_gain = 32000 self.center_freq = center_freq = 2.4e9 ################################################## # Blocks ################################################## self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("serial=3112474", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(center_freq, 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.uhd_usrp_source_0.set_antenna('TX/RX', 0) self.uhd_usrp_sink_0 = uhd.usrp_sink( ",".join(("address=30EF55F", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0.set_center_freq(center_freq, 0) self.uhd_usrp_sink_0.set_gain(tx_gain, 0) self.uhd_usrp_sink_0.set_antenna('TX/RX', 0) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 256, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / 64, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, 64) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 0, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.fractional_resampler_xx_0, 0))
def __init__(self): gr.top_block.__init__(self, "SQ5BPF Tetra live receiver 6ch UDP HEADLESS") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2000000 self.first_decim = first_decim = 32 self.xlate_offset_fine6 = xlate_offset_fine6 = 0 self.xlate_offset_fine5 = xlate_offset_fine5 = 0 self.xlate_offset_fine4 = xlate_offset_fine4 = 0 self.xlate_offset_fine3 = xlate_offset_fine3 = 0 self.xlate_offset_fine2 = xlate_offset_fine2 = 0 self.xlate_offset_fine1 = xlate_offset_fine1 = 0 self.xlate_offset6 = xlate_offset6 = 500e3 self.xlate_offset5 = xlate_offset5 = 500e3 self.xlate_offset4 = xlate_offset4 = 500e3 self.xlate_offset3 = xlate_offset3 = 500e3 self.xlate_offset2 = xlate_offset2 = 500e3 self.xlate_offset1 = xlate_offset1 = 500e3 self.udp_packet_size = udp_packet_size = 1472 self.udp_dest_addr = udp_dest_addr = "127.0.0.1" self.telive_receiver_name = telive_receiver_name = 'SQ5BPF 6-channel headless rx for telive' self.telive_receiver_channels = telive_receiver_channels = 6 self.sdr_ifgain = sdr_ifgain = 20 self.sdr_gain = sdr_gain = 38 self.ppm_corr = ppm_corr = 56 self.out_sample_rate = out_sample_rate = 36000 self.options_low_pass = options_low_pass = 12500 self.if_samp_rate = if_samp_rate = samp_rate / first_decim self.freq = freq = 435e6 self.first_port = first_port = 42000 ################################################## # Blocks ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer( ("0.0.0.0", first_port), allow_none=True) self.xmlrpc_server_0.register_instance(self) threading.Thread(target=self.xmlrpc_server_0.serve_forever).start() self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "") self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(freq, 0) self.osmosdr_source_0.set_freq_corr(ppm_corr, 0) self.osmosdr_source_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(False, 0) self.osmosdr_source_0.set_gain(sdr_gain, 0) self.osmosdr_source_0.set_if_gain(sdr_ifgain, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna("", 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.freq_xlating_fir_filter_xxx_0_0_0_0_0_0 = filter.freq_xlating_fir_filter_ccc( first_decim, (firdes.low_pass(1, samp_rate, options_low_pass, options_low_pass * 0.2)), xlate_offset6 + xlate_offset_fine6, samp_rate) self.freq_xlating_fir_filter_xxx_0_0_0_0_0 = filter.freq_xlating_fir_filter_ccc( first_decim, (firdes.low_pass(1, samp_rate, options_low_pass, options_low_pass * 0.2)), xlate_offset5 + xlate_offset_fine5, samp_rate) self.freq_xlating_fir_filter_xxx_0_0_0_0 = filter.freq_xlating_fir_filter_ccc( first_decim, (firdes.low_pass(1, samp_rate, options_low_pass, options_low_pass * 0.2)), xlate_offset4 + xlate_offset_fine4, samp_rate) self.freq_xlating_fir_filter_xxx_0_0_0 = filter.freq_xlating_fir_filter_ccc( first_decim, (firdes.low_pass(1, samp_rate, options_low_pass, options_low_pass * 0.2)), xlate_offset3 + xlate_offset_fine3, samp_rate) self.freq_xlating_fir_filter_xxx_0_0 = filter.freq_xlating_fir_filter_ccc( first_decim, (firdes.low_pass(1, samp_rate, options_low_pass, options_low_pass * 0.2)), xlate_offset2 + xlate_offset_fine2, samp_rate) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( first_decim, (firdes.low_pass(1, samp_rate, options_low_pass, options_low_pass * 0.2)), xlate_offset1 + xlate_offset_fine1, samp_rate) self.fractional_resampler_xx_0_4 = filter.fractional_resampler_cc( 0, float(float(if_samp_rate) / float(out_sample_rate))) self.fractional_resampler_xx_0_3 = filter.fractional_resampler_cc( 0, float(float(if_samp_rate) / float(out_sample_rate))) self.fractional_resampler_xx_0_2 = filter.fractional_resampler_cc( 0, float(float(if_samp_rate) / float(out_sample_rate))) self.fractional_resampler_xx_0_1 = filter.fractional_resampler_cc( 0, float(float(if_samp_rate) / float(out_sample_rate))) self.fractional_resampler_xx_0_0 = filter.fractional_resampler_cc( 0, float(float(if_samp_rate) / float(out_sample_rate))) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc( 0, float(float(if_samp_rate) / float(out_sample_rate))) self.blocks_udp_sink_0_4 = blocks.udp_sink(gr.sizeof_gr_complex * 1, udp_dest_addr, first_port + 5, udp_packet_size, False) self.blocks_udp_sink_0_3 = blocks.udp_sink(gr.sizeof_gr_complex * 1, udp_dest_addr, first_port + 6, udp_packet_size, False) self.blocks_udp_sink_0_2 = blocks.udp_sink(gr.sizeof_gr_complex * 1, udp_dest_addr, first_port + 4, udp_packet_size, False) self.blocks_udp_sink_0_1 = blocks.udp_sink(gr.sizeof_gr_complex * 1, udp_dest_addr, first_port + 3, udp_packet_size, False) self.blocks_udp_sink_0_0 = blocks.udp_sink(gr.sizeof_gr_complex * 1, udp_dest_addr, first_port + 2, udp_packet_size, False) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_gr_complex * 1, udp_dest_addr, first_port + 1, udp_packet_size, False) self.analog_agc3_xx_0_0_0_0_0_0 = analog.agc3_cc( 1e-3, 1e-4, 1.0, 1.0, 1) self.analog_agc3_xx_0_0_0_0_0_0.set_max_gain(65536) self.analog_agc3_xx_0_0_0_0_0 = analog.agc3_cc(1e-3, 1e-4, 1.0, 1.0, 1) self.analog_agc3_xx_0_0_0_0_0.set_max_gain(65536) self.analog_agc3_xx_0_0_0_0 = analog.agc3_cc(1e-3, 1e-4, 1.0, 1.0, 1) self.analog_agc3_xx_0_0_0_0.set_max_gain(65536) self.analog_agc3_xx_0_0_0 = analog.agc3_cc(1e-3, 1e-4, 1.0, 1.0, 1) self.analog_agc3_xx_0_0_0.set_max_gain(65536) self.analog_agc3_xx_0_0 = analog.agc3_cc(1e-3, 1e-4, 1.0, 1.0, 1) self.analog_agc3_xx_0_0.set_max_gain(65536) self.analog_agc3_xx_0 = analog.agc3_cc(1e-3, 1e-4, 1.0, 1.0, 1) self.analog_agc3_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.fractional_resampler_xx_0_0, 0), (self.blocks_udp_sink_0_0, 0)) self.connect((self.analog_agc3_xx_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_agc3_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0, 0), (self.analog_agc3_xx_0_0, 0)) self.connect((self.analog_agc3_xx_0_0, 0), (self.fractional_resampler_xx_0_0, 0)) self.connect((self.analog_agc3_xx_0_0_0, 0), (self.fractional_resampler_xx_0_1, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0_0, 0), (self.analog_agc3_xx_0_0_0, 0)) self.connect((self.fractional_resampler_xx_0_1, 0), (self.blocks_udp_sink_0_1, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0_0_0, 0)) self.connect((self.analog_agc3_xx_0_0_0_0, 0), (self.fractional_resampler_xx_0_2, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0_0_0, 0), (self.analog_agc3_xx_0_0_0_0, 0)) self.connect((self.fractional_resampler_xx_0_2, 0), (self.blocks_udp_sink_0_2, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0_0_0_0, 0)) self.connect((self.analog_agc3_xx_0_0_0_0_0, 0), (self.fractional_resampler_xx_0_3, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0_0_0_0, 0), (self.analog_agc3_xx_0_0_0_0_0, 0)) self.connect((self.fractional_resampler_xx_0_3, 0), (self.blocks_udp_sink_0_4, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0_0_0_0_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0_0_0_0_0_0, 0)) self.connect((self.fractional_resampler_xx_0_4, 0), (self.blocks_udp_sink_0_3, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0_0_0_0_0, 0), (self.analog_agc3_xx_0_0_0_0_0_0, 0)) self.connect((self.analog_agc3_xx_0_0_0_0_0_0, 0), (self.fractional_resampler_xx_0_4, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Decoder 433Mhz") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.target_rate_IM = target_rate_IM = 50000 self.target_rate = target_rate = 1200 self.samp_rate = samp_rate = 1000000 self.xlate_offset = xlate_offset = -100000 self.variable_static_text_0 = variable_static_text_0 = target_rate self.samp_per_sym = samp_per_sym = 5 self.gain = gain = 1 self.firdes_tap = firdes_tap = firdes.low_pass(1, samp_rate, 2000, target_rate_IM / 4, firdes.WIN_HAMMING, 6.76) ################################################## # Blocks ################################################## _xlate_offset_sizer = wx.BoxSizer(wx.VERTICAL) self._xlate_offset_text_box = forms.text_box( parent=self.GetWin(), sizer=_xlate_offset_sizer, value=self.xlate_offset, callback=self.set_xlate_offset, label="xlate_offset", converter=forms.float_converter(), proportion=0, ) self._xlate_offset_slider = forms.slider( parent=self.GetWin(), sizer=_xlate_offset_sizer, value=self.xlate_offset, callback=self.set_xlate_offset, minimum=-samp_rate / 2, maximum=samp_rate / 2, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_xlate_offset_sizer, 2, 2, 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.01, maximum=10, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 3, 2, 1, 1) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="Units", minval=0, maxval=10, factor=1.0, decimal_places=10, ref_level=0, sample_rate=target_rate * samp_per_sym, number_rate=15, average=False, avg_alpha=None, label="Max level", peak_hold=True, show_gauge=True, ) self.GridAdd(self.wxgui_numbersink2_0.win, 4, 2, 1, 1) self.wxgui_fftsink2_1 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=target_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=True, ) self.GridAdd(self.wxgui_fftsink2_1.win, 1, 2, 1, 1) self._variable_static_text_0_static_text = forms.static_text( parent=self.GetWin(), value=self.variable_static_text_0, callback=self.set_variable_static_text_0, label="Sample rate out (target_rate * samp_pre_sym)", converter=forms.float_converter(), ) self.GridAdd(self._variable_static_text_0_static_text, 6, 2, 1, 1) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "") self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(434e6, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(False, 0) self.osmosdr_source_0.set_gain(10, 0) self.osmosdr_source_0.set_if_gain(20, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna("", 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.freq_xlating_fir_filter_xxx_1 = filter.freq_xlating_fir_filter_ccc( int(samp_rate / target_rate_IM), (firdes_tap), xlate_offset, samp_rate) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc( 0, (target_rate_IM) / (target_rate * samp_per_sym)) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((gain, )) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float * 1, "/tmp/gnu_radio_out", False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_1, 0))
def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset, mode=0): gr.top_block.__init__(self) rrc_taps = filter.firdes.root_raised_cosine(sps, sps, 1.0, rolloff, ntaps) gain = bw nfilts = 32 rrc_taps_rx = filter.firdes.root_raised_cosine(nfilts, sps * nfilts, 1.0, rolloff, ntaps * nfilts) data = 2.0 * scipy.random.randint(0, 2, N) - 1.0 data = scipy.exp(1j * poffset) * data self.src = blocks.vector_source_c(data.tolist(), False) self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps) self.chn = channels.channel_model(noise, foffset, toffset) self.off = filter.fractional_resampler_cc(0.20, 1.0) if mode == 0: self.clk = digital.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx, nfilts, nfilts // 2, 1) self.taps = self.clk.taps() self.dtaps = self.clk.diff_taps() self.delay = int( scipy.ceil(((len(rrc_taps) - 1) / 2 + (len(self.taps[0]) - 1) / 2) / float(sps))) + 1 self.vsnk_err = blocks.vector_sink_f() self.vsnk_rat = blocks.vector_sink_f() self.vsnk_phs = blocks.vector_sink_f() self.connect((self.clk, 1), self.vsnk_err) self.connect((self.clk, 2), self.vsnk_rat) self.connect((self.clk, 3), self.vsnk_phs) else: # mode == 1 mu = 0.5 gain_mu = bw gain_omega = 0.25 * gain_mu * gain_mu omega_rel_lim = 0.02 self.clk = digital.clock_recovery_mm_cc(sps, gain_omega, mu, gain_mu, omega_rel_lim) self.vsnk_err = blocks.vector_sink_f() self.connect((self.clk, 1), self.vsnk_err) self.vsnk_src = blocks.vector_sink_c() self.vsnk_clk = blocks.vector_sink_c() self.connect(self.src, self.rrc, self.chn, self.off, self.clk, self.vsnk_clk) self.connect(self.src, self.vsnk_src)
def __init__(self, options): gr.top_block.__init__(self) fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096) fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16) self._u = usrp.source_c(decim_rate=options.decim, fusb_block_size=fusb_block_size, fusb_nblocks=fusb_nblocks) # master clock if options.fpga_freq is not None: self._u.set_fpga_master_clock_freq(long(options.fpga_freq)) # default subdev if use didn't pick one if options.rx_subdev_spec is None: if u.db(0, 0).dbid() >= 0: options.rx_subdev_spec = (0, 0) elif u.db(1, 0).dbid() >= 0: options.rx_subdev_spec = (1, 0) else: options.rx_subdev_spec = (0, 0) # configure usrp mux self._u.set_mux(usrp.determine_rx_mux_value(self._u, options.rx_subdev_spec)) # determine the daughterboard subdevice self.subdev = usrp.selected_subdev(self._u, options.rx_subdev_spec) # select antenna if options.antenna is not None: print "Selecting antenna %s" % (options.antenna,) self.subdev.select_rx_antenna(options.antenna) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0]+g[1])/2 r = self._u.tune(0, self.subdev, options.freq) self.subdev.set_gain(options.gain) #sample_rate = options.fpga_clock/options.decim sample_rate = self._u.adc_freq() / self._u.decim_rate() symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self._u, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") options = get_options() self.tune_corrector_callback = tune_corrector(self) self.synchronizer_callback = synchronizer(self) self.converter = blocks.vector_to_stream(gr.sizeof_float, 142) self.ifreq = options.frequency self.rfgain = options.gain self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(int(options.sample_rate)) if self.rfgain is None: self.src.set_gain_mode(1) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(0) self.src.set_gain(self.rfgain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % (sample_rate)) gsm_symb_rate = 1625000.0 / 6.0 sps = sample_rate / gsm_symb_rate / 4 out_sample_rate = gsm_symb_rate * 4 self.offset = 0 taps = filter.firdes.low_pass(1.0, sample_rate, 145e3, 10e3, filter.firdes.WIN_HANN) self.tuner = filter.freq_xlating_fir_filter_ccf(1, taps, self.offset, sample_rate) self.interpolator = filter.fractional_resampler_cc(0, sps) self.receiver = gsm.receiver_cf( self.tune_corrector_callback, self.synchronizer_callback, 4, options.key.replace(' ', '').lower(), options.configuration.upper()) self.output = blocks.file_sink(gr.sizeof_float, options.output_file) self.connect(self.src, self.tuner, self.interpolator, self.receiver, self.converter, self.output) def set_ifreq(ifreq): self.ifreq = ifreq self._ifreq_text_box.set_value(self.ifreq) self.src.set_center_freq(self.ifreq) self._ifreq_text_box = forms.text_box( parent=self.GetWin(), value=self.ifreq, callback=set_ifreq, label="Center Frequency", converter=forms.float_converter(), ) self.Add(self._ifreq_text_box) def set_iagc(iagc): self.iagc = iagc self._agc_check_box.set_value(self.iagc) self.src.set_gain_mode(self.iagc, 0) self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0) self._agc_check_box = forms.check_box( parent=self.GetWin(), value=self.iagc, callback=set_iagc, label="Automatic Gain", true=1, false=0, ) self.Add(self._agc_check_box) def set_rfgain(rfgain): self.rfgain = rfgain self._rfgain_slider.set_value(self.rfgain) self._rfgain_text_box.set_value(self.rfgain) self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0) _rfgain_sizer = wx.BoxSizer(wx.VERTICAL) self._rfgain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rfgain_sizer, value=self.rfgain, callback=set_rfgain, label="RF Gain", converter=forms.float_converter(), proportion=0, ) self._rfgain_slider = forms.slider( parent=self.GetWin(), sizer=_rfgain_sizer, value=self.rfgain, callback=set_rfgain, minimum=0, maximum=50, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rfgain_sizer) def fftsink2_callback(x, y): if abs(x / (sample_rate / 2)) > 0.9: set_ifreq(self.ifreq + x / 2) else: sys.stderr.write("coarse tuned to: %d Hz\n" % x) self.offset = -x self.tuner.set_center_freq(self.offset) self.scope = fftsink2.fft_sink_c(self.GetWin(), title="Wideband Spectrum (click to coarse tune)", fft_size=1024, sample_rate=sample_rate, ref_scale=2.0, ref_level=0, y_divs=10, fft_rate=10, average=False, avg_alpha=0.3) self.Add(self.scope.win) self.scope.set_callback(fftsink2_callback) self.connect(self.src, self.scope) def fftsink2_callback2(x, y): self.offset = self.offset - (x / 10) sys.stderr.write("fine tuned to: %d Hz\n" % self.offset) self.tuner.set_center_freq(self.offset) self.scope2 = fftsink2.fft_sink_c(self.GetWin(), title="Channel Spectrum (click to fine tune)", fft_size=1024, sample_rate=gsm_symb_rate * 4, ref_scale=2.0, ref_level=-20, y_divs=10, fft_rate=10, average=False, avg_alpha=0.3) self.Add(self.scope2.win) self.scope2.set_callback(fftsink2_callback2) self.connect(self.interpolator, self.scope2)
def __init__(self): gr.top_block.__init__(self) # grc_wxgui.top_block_gui.__init__(self, title="Top Block") options = get_options() self.tune_corrector_callback = tune_corrector(self) self.synchronizer_callback = synchronizer(self) self.converter = blocks.vector_to_stream(gr.sizeof_float, 142) self.ifreq = options.frequency self.rfgain = options.gain self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(int(options.sample_rate)) if self.rfgain is None: self.src.set_gain_mode(1) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(0) self.src.set_gain(self.rfgain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % (sample_rate)) gsm_symb_rate = 1625000.0 / 6.0 sps = sample_rate / gsm_symb_rate / 4 out_sample_rate = gsm_symb_rate * 4 self.offset = 0 taps = filter.firdes.low_pass(1.0, sample_rate, 145e3, 10e3, filter.firdes.WIN_HANN) self.tuner = filter.freq_xlating_fir_filter_ccf(1, taps, self.offset, sample_rate) self.interpolator = filter.fractional_resampler_cc(0, sps) self.receiver = gsm.receiver_cf( self.tune_corrector_callback, self.synchronizer_callback, 4, options.key.replace(' ', '').lower(), options.configuration.upper()) self.output = blocks.file_sink(gr.sizeof_float, options.output_file) self.connect(self.src, self.tuner, self.interpolator, self.receiver, self.converter, self.output) def set_ifreq(ifreq): self.ifreq = ifreq self._ifreq_text_box.set_value(self.ifreq) self.src.set_center_freq(self.ifreq) def set_iagc(iagc): self.iagc = iagc self._agc_check_box.set_value(self.iagc) self.src.set_gain_mode(self.iagc, 0) self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0) def set_rfgain(rfgain): self.rfgain = rfgain self._rfgain_slider.set_value(self.rfgain) self._rfgain_text_box.set_value(self.rfgain) self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0) def fftsink2_callback(x, y): if abs(x / (sample_rate / 2)) > 0.9: set_ifreq(self.ifreq + x / 2) else: sys.stderr.write("coarse tuned to: %d Hz\n" % x) self.offset = -x self.tuner.set_center_freq(self.offset) def fftsink2_callback2(x, y): self.offset = self.offset - (x / 10) sys.stderr.write("fine tuned to: %d Hz\n" % self.offset) self.tuner.set_center_freq(self.offset)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") options = get_options() self.tune_corrector_callback = tune_corrector(self) self.synchronizer_callback = synchronizer(self) self.converter = blocks.vector_to_stream(gr.sizeof_float, 142) self.ifreq = options.frequency self.rfgain = options.gain self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(int(options.sample_rate)) if self.rfgain is None: self.src.set_gain_mode(1) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(0) self.src.set_gain(self.rfgain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % (sample_rate)) gsm_symb_rate = 1625000.0 / 6.0 sps = sample_rate / gsm_symb_rate / 4 out_sample_rate = gsm_symb_rate * 4 self.offset = 0 taps = filter.firdes.low_pass(1.0, sample_rate, 145e3, 10e3, filter.firdes.WIN_HANN) self.tuner = filter.freq_xlating_fir_filter_ccf( 1, taps, self.offset, sample_rate) self.interpolator = filter.fractional_resampler_cc(0, sps) self.receiver = gsm.receiver_cf(self.tune_corrector_callback, self.synchronizer_callback, 4, options.key.replace(' ', '').lower(), options.configuration.upper()) self.output = blocks.file_sink(gr.sizeof_float, options.output_file) self.connect(self.src, self.tuner, self.interpolator, self.receiver, self.converter, self.output) def set_ifreq(ifreq): self.ifreq = ifreq self._ifreq_text_box.set_value(self.ifreq) self.src.set_center_freq(self.ifreq) self._ifreq_text_box = forms.text_box( parent=self.GetWin(), value=self.ifreq, callback=set_ifreq, label="Center Frequency", converter=forms.float_converter(), ) self.Add(self._ifreq_text_box) def set_iagc(iagc): self.iagc = iagc self._agc_check_box.set_value(self.iagc) self.src.set_gain_mode(self.iagc, 0) self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0) self._agc_check_box = forms.check_box( parent=self.GetWin(), value=self.iagc, callback=set_iagc, label="Automatic Gain", true=1, false=0, ) self.Add(self._agc_check_box) def set_rfgain(rfgain): self.rfgain = rfgain self._rfgain_slider.set_value(self.rfgain) self._rfgain_text_box.set_value(self.rfgain) self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0) _rfgain_sizer = wx.BoxSizer(wx.VERTICAL) self._rfgain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rfgain_sizer, value=self.rfgain, callback=set_rfgain, label="RF Gain", converter=forms.float_converter(), proportion=0, ) self._rfgain_slider = forms.slider( parent=self.GetWin(), sizer=_rfgain_sizer, value=self.rfgain, callback=set_rfgain, minimum=0, maximum=50, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rfgain_sizer) def fftsink2_callback(x, y): if abs(x / (sample_rate / 2)) > 0.9: set_ifreq(self.ifreq + x / 2) else: sys.stderr.write("coarse tuned to: %d Hz\n" % x) self.offset = -x self.tuner.set_center_freq(self.offset) self.scope = fftsink2.fft_sink_c( self.GetWin(), title="Wideband Spectrum (click to coarse tune)", fft_size=1024, sample_rate=sample_rate, ref_scale=2.0, ref_level=0, y_divs=10, fft_rate=10, average=False, avg_alpha=0.3) self.Add(self.scope.win) self.scope.set_callback(fftsink2_callback) self.connect(self.src, self.scope) def fftsink2_callback2(x, y): self.offset = self.offset - (x / 10) sys.stderr.write("fine tuned to: %d Hz\n" % self.offset) self.tuner.set_center_freq(self.offset) self.scope2 = fftsink2.fft_sink_c( self.GetWin(), title="Channel Spectrum (click to fine tune)", fft_size=1024, sample_rate=gsm_symb_rate * 4, ref_scale=2.0, ref_level=-20, y_divs=10, fft_rate=10, average=False, avg_alpha=0.3) self.Add(self.scope2.win) self.scope2.set_callback(fftsink2_callback2) self.connect(self.interpolator, self.scope2)
def __init__(self): gr.hier_block2.__init__( self, "PW-Sat2 Demodulator", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(0, 0, 0), ) self.message_port_register_hier_out("frames") Qt.QWidget.__init__(self) self.top_layout = Qt.QVBoxLayout() self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.setLayout(self.top_layout) ################################################## # Variables ################################################## self.symb_rate = symb_rate = 1200 self.samp_per_sym = samp_per_sym = 10 self.samp_rate = samp_rate = symb_rate * samp_per_sym self.frequency_offset = frequency_offset = -20e3 self.decimation = decimation = 16 self.bpsk = bpsk = digital.constellation_calcdist(([-1, 1]), ([0, 1]), 2, 1).base() self.alpha = alpha = 0.5 ################################################## # Blocks ################################################## self._frequency_offset_range = Range(-40e3, 40e3, 10, -20e3, 200) self._frequency_offset_win = RangeWidget(self._frequency_offset_range, self.set_frequency_offset, 'Frequency Offset', "counter_slider", float) self.top_grid_layout.addWidget(self._frequency_offset_win) self._decimation_options = ( 16, 8, 4, 2, ) self._decimation_labels = ( '1200', '2400', '4800', '9600', ) self._decimation_tool_bar = Qt.QToolBar(self) self._decimation_tool_bar.addWidget(Qt.QLabel('Symbol Rate' + ": ")) self._decimation_combo_box = Qt.QComboBox() self._decimation_tool_bar.addWidget(self._decimation_combo_box) for label in self._decimation_labels: self._decimation_combo_box.addItem(label) self._decimation_callback = lambda i: Qt.QMetaObject.invokeMethod( self._decimation_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._decimation_options.index(i))) self._decimation_callback(self.decimation) self._decimation_combo_box.currentIndexChanged.connect( lambda i: self.set_decimation(self._decimation_options[i])) self.top_grid_layout.addWidget(self._decimation_tool_bar) self._alpha_range = Range(0, 1, 1e-3, 0.5, 200) self._alpha_win = RangeWidget(self._alpha_range, self.set_alpha, "alpha", "counter_slider", float) self.top_grid_layout.addWidget(self._alpha_win) self.satellites_nrzi_decode_0 = satellites.nrzi_decode() self.satellites_hdlc_deframer_0 = satellites.hdlc_deframer( check_fcs=True, max_length=10000) self.root_raised_cosine_filter_0_0 = filter.fir_filter_ccf( 1, firdes.root_raised_cosine(1, samp_rate, symb_rate, alpha, 300)) self.qtgui_waterfall_sink_x_1 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc 192000, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_1.set_update_time(0.10) self.qtgui_waterfall_sink_x_1.enable_grid(False) self.qtgui_waterfall_sink_x_1.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_1.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_1.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_1.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_1.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_1.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_1.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_1_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_1_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc 192000, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0_0.set_update_time(0.10) self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0_0.enable_autoscale(False) self.qtgui_freq_sink_x_0_0.enable_grid(False) self.qtgui_freq_sink_x_0_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 128, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0.enable_autoscale(False) self.qtgui_const_sink_x_0.enable_grid(False) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 1, (firdes.low_pass(1, 192000, 40000, 1000)), frequency_offset, 192000) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc( 0, decimation) self.digital_symbol_sync_xx_0 = digital.symbol_sync_cc( digital.TED_ZERO_CROSSING, samp_per_sym, 0.045, 1.0, 1, 0.1, 1, digital.constellation_bpsk().base(), digital.IR_MMSE_8TAP, 128, ([])) self.digital_descrambler_bb_0_1 = digital.descrambler_bb( 0x21, 0x00, 16) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(0.1, 2, False) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( bpsk) self.analog_agc_xx_0 = analog.agc_cc(1e-3, 1, 1.0) self.analog_agc_xx_0.set_max_gain(30) ################################################## # Connections ################################################## self.msg_connect((self.satellites_hdlc_deframer_0, 'out'), (self, 'frames')) self.connect((self.analog_agc_xx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_descrambler_bb_0_1, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.root_raised_cosine_filter_0_0, 0)) self.connect((self.digital_descrambler_bb_0_1, 0), (self.satellites_nrzi_decode_0, 0)) self.connect((self.digital_symbol_sync_xx_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_symbol_sync_xx_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self, 0), (self.qtgui_waterfall_sink_x_1, 0)) self.connect((self.root_raised_cosine_filter_0_0, 0), (self.digital_symbol_sync_xx_0, 0)) self.connect((self.root_raised_cosine_filter_0_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.satellites_nrzi_decode_0, 0), (self.satellites_hdlc_deframer_0, 0))
def __init__(self): gr.top_block.__init__(self, "SSB Receiver V2- F1ATB - MARCH 2021") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2400e3 self.Largeur_filtre = Largeur_filtre = 3800 self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass( 1, samp_rate, Largeur_filtre / 2, 500) self.decim_LP = decim_LP = 16 self.LSB_USB = LSB_USB = 0 self.Gain_RF = Gain_RF = 0 self.Gain_IF = Gain_IF = 20 self.Gain_BB = Gain_BB = 20 self.FrRX = FrRX = 7000000 self.F_Fine = F_Fine = 0 ################################################## # Blocks ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer( ('localhost', 9003), allow_none=True) self.xmlrpc_server_0.register_instance(self) self.xmlrpc_server_0_thread = threading.Thread( target=self.xmlrpc_server_0.serve_forever) self.xmlrpc_server_0_thread.daemon = True self.xmlrpc_server_0_thread.start() self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(FrRX, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_dc_offset_mode(2, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(False, 0) self.osmosdr_source_0.set_gain(Gain_RF, 0) self.osmosdr_source_0.set_if_gain(Gain_IF, 0) self.osmosdr_source_0.set_bb_gain(Gain_BB, 0) self.osmosdr_source_0.set_antenna('', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, decim_LP * samp_rate / 200, 5200, 1200, firdes.WIN_HAMMING, 6.76)) self.logpwrfft_x_0 = logpwrfft.logpwrfft_c( sample_rate=samp_rate / 200, fft_size=2048, ref_scale=0.00001, frame_rate=samp_rate / 200 / 2048, avg_alpha=1.0, average=False, ) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 240, (xlate_filter_taps), F_Fine - Largeur_filtre / 2 + LSB_USB * Largeur_filtre - 100 + LSB_USB * 200, samp_rate) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc( 0, decim_LP) self.dc_blocker_xx_0 = filter.dc_blocker_cc(1024, True) self.blocks_udp_sink_1 = blocks.udp_sink(gr.sizeof_short * 2048, '127.0.0.1', 9002, 4096, True) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_short * 1, '127.0.0.1', 9001, 1000, True) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (1 - 2 * LSB_USB, )) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, int(2048 * decim_LP), 409600, 0) self.blocks_float_to_short_1 = blocks.float_to_short(2048, 100) self.blocks_float_to_short_0 = blocks.float_to_short(1, 16000) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.analog_sig_source_x_0_0 = analog.sig_source_f( samp_rate / 240, analog.GR_SIN_WAVE, Largeur_filtre / 2 + 100, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f( samp_rate / 240, analog.GR_COS_WAVE, Largeur_filtre / 2 + 100, 1, 0) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(100) ################################################## # Connections ################################################## self.connect((self.analog_agc2_xx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_float_to_short_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_float_to_short_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.blocks_float_to_short_1, 0), (self.blocks_udp_sink_1, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.logpwrfft_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.logpwrfft_x_0, 0), (self.blocks_float_to_short_1, 0)) self.connect((self.low_pass_filter_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.dc_blocker_xx_0, 0))
def __init__(self, dab_params, rx_params, verbose=False, debug=False): """ Hierarchical block for OFDM demodulation @param dab_params DAB parameter object (grdab.parameters.dab_parameters) @param rx_params RX parameter object (grdab.parameters.receiver_parameters) @param debug enables debug output to files @param verbose whether to produce verbose messages """ self.dp = dp = dab_params self.rp = rp = rx_params self.verbose = verbose if self.rp.softbits: gr.hier_block2.__init__( self, "ofdm_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_float * self.dp.num_carriers * 2)) # output signature else: gr.hier_block2.__init__( self, "ofdm_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_char * self.dp.num_carriers / 4)) # output signature # workaround for a problem that prevents connecting more than one block directly (see trac ticket #161) #self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.input = blocks.multiply_const_cc(1.0) # FIXME self.connect(self, self.input) # input filtering if self.rp.input_fft_filter: if verbose: print "--> RX filter enabled" lowpass_taps = filter.firdes_low_pass( 1.0, # gain dp.sample_rate, # sampling rate rp.filt_bw, # cutoff frequency rp.filt_tb, # width of transition band filter.firdes.WIN_HAMMING) # Hamming window self.fft_filter = filter.fft_filter_ccc(1, lowpass_taps) # correct sample rate offset, if enabled if self.rp.autocorrect_sample_rate: if verbose: print "--> dynamic sample rate correction enabled" self.rate_detect_ns = grdab.detect_null(dp.ns_length, False) self.rate_estimator = grdab.estimate_sample_rate_bf( dp.sample_rate, dp.frame_length) self.rate_prober = blocks.probe_signal_f() self.connect(self.input, self.rate_detect_ns, self.rate_estimator, self.rate_prober) # self.resample = gr.fractional_interpolator_cc(0, 1) self.resample = grdab.fractional_interpolator_triggered_update_cc( 0, 1) self.connect(self.rate_detect_ns, (self.resample, 1)) self.updater = Timer(0.1, self.update_correction) # self.updater = threading.Thread(target=self.update_correction) self.run_interpolater_update_thread = True self.updater.setDaemon(True) self.updater.start() else: self.run_interpolater_update_thread = False if self.rp.sample_rate_correction_factor != 1 or self.rp.always_include_resample: if verbose: print "--> static sample rate correction enabled" self.resample = filter.fractional_resampler_cc( 0, self.rp.sample_rate_correction_factor) # timing and fine frequency synchronisation self.sync = grdab.ofdm_sync_dab2(self.dp, self.rp, debug) # ofdm symbol sampler self.sampler = grdab.ofdm_sampler(dp.fft_length, dp.cp_length, dp.symbols_per_frame, rp.cp_gap) # fft for symbol vectors self.fft = fft.fft_vcc(dp.fft_length, True, [], True) # coarse frequency synchronisation self.cfs = grdab.ofdm_coarse_frequency_correct(dp.fft_length, dp.num_carriers, dp.cp_length) # diff phasor self.phase_diff = grdab.diff_phasor_vcc(dp.num_carriers) # remove pilot symbol self.remove_pilot = grdab.ofdm_remove_first_symbol_vcc(dp.num_carriers) # magnitude equalisation if self.rp.equalize_magnitude: if verbose: print "--> magnitude equalization enabled" self.equalizer = grdab.magnitude_equalizer_vcc( dp.num_carriers, rp.symbols_for_magnitude_equalization) # frequency deinterleaving self.deinterleave = grdab.frequency_interleaver_vcc( dp.frequency_deinterleaving_sequence_array) # symbol demapping self.demapper = grdab.qpsk_demapper_vcb(dp.num_carriers) # # connect everything # if self.rp.autocorrect_sample_rate or self.rp.sample_rate_correction_factor != 1 or self.rp.always_include_resample: self.connect(self.input, self.resample) self.input2 = self.resample else: self.input2 = self.input if self.rp.input_fft_filter: self.connect(self.input2, self.fft_filter, self.sync) else: self.connect(self.input2, self.sync) # data stream self.connect(self.sync, self.sampler, self.fft, self.cfs, self.phase_diff, self.remove_pilot) if self.rp.equalize_magnitude: self.connect(self.remove_pilot, self.equalizer, self.deinterleave) else: self.connect(self.remove_pilot, self.deinterleave) if self.rp.softbits: if verbose: print "--> using soft bits" self.softbit_interleaver = grdab.complex_to_interleaved_float_vcf( self.dp.num_carriers) self.connect(self.deinterleave, self.softbit_interleaver, (self, 0)) else: self.connect(self.deinterleave, self.demapper, (self, 0)) # calculate an estimate of the SNR self.phase_var_decim = blocks.keep_one_in_n( gr.sizeof_gr_complex * self.dp.num_carriers, self.rp.phase_var_estimate_downsample) self.phase_var_arg = blocks.complex_to_arg(dp.num_carriers) self.phase_var_v2s = blocks.vector_to_stream(gr.sizeof_float, dp.num_carriers) self.phase_var_mod = grdab.modulo_ff(pi / 2) self.phase_var_avg_mod = filter.iir_filter_ffd( [rp.phase_var_estimate_alpha], [0, 1 - rp.phase_var_estimate_alpha]) self.phase_var_sub_avg = blocks.sub_ff() self.phase_var_sqr = blocks.multiply_ff() self.phase_var_avg = filter.iir_filter_ffd( [rp.phase_var_estimate_alpha], [0, 1 - rp.phase_var_estimate_alpha]) self.probe_phase_var = blocks.probe_signal_f() self.connect((self.remove_pilot, 0), self.phase_var_decim, self.phase_var_arg, self.phase_var_v2s, self.phase_var_mod, (self.phase_var_sub_avg, 0), (self.phase_var_sqr, 0)) self.connect(self.phase_var_mod, self.phase_var_avg_mod, (self.phase_var_sub_avg, 1)) self.connect(self.phase_var_sub_avg, (self.phase_var_sqr, 1)) self.connect(self.phase_var_sqr, self.phase_var_avg, self.probe_phase_var) # measure processing rate self.measure_rate = grdab.measure_processing_rate( gr.sizeof_gr_complex, 2000000) self.connect(self.input, self.measure_rate) # debugging if debug: self.connect( self.fft, blocks.file_sink(gr.sizeof_gr_complex * dp.fft_length, "debug/ofdm_after_fft.dat")) self.connect( (self.cfs, 0), blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_after_cfs.dat")) self.connect( self.phase_diff, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_diff_phasor.dat")) self.connect( (self.remove_pilot, 0), blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_pilot_removed.dat")) self.connect((self.remove_pilot, 1), blocks.file_sink(gr.sizeof_char, "debug/ofdm_after_cfs_trigger.dat")) self.connect( self.deinterleave, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_deinterleaved.dat")) if self.rp.equalize_magnitude: self.connect( self.equalizer, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_equalizer.dat")) if self.rp.softbits: self.connect( self.softbit_interleaver, blocks.file_sink(gr.sizeof_float * dp.num_carriers * 2, "debug/softbits.dat"))
def __init__(self): gr.top_block.__init__(self, "SSB Receiver V2- F1ATB - MARCH 2021") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1200000 self.Largeur_filtre = Largeur_filtre = 3800 self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass( 1, samp_rate, Largeur_filtre / 2, 500) self.decim_LP = decim_LP = 16 self.LSB_USB = LSB_USB = 0 self.Gain_RF = Gain_RF = 30 self.Gain_IF = Gain_IF = 20 self.Gain_BB = Gain_BB = 20 self.FrRX = FrRX = 145000000 self.F_Fine = F_Fine = 0 ################################################## # Blocks ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer( ('localhost', 9003), allow_none=True) self.xmlrpc_server_0.register_instance(self) self.xmlrpc_server_0_thread = threading.Thread( target=self.xmlrpc_server_0.serve_forever) self.xmlrpc_server_0_thread.daemon = True self.xmlrpc_server_0_thread.start() self.pluto_source_0 = iio.pluto_source('192.168.2.1', 145000000, int(samp_rate), 1000000, 32768, True, True, True, "manual", 50, '', True) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, decim_LP * samp_rate / 200, 5200, 1200, firdes.WIN_HAMMING, 6.76)) self.logpwrfft_x_0 = logpwrfft.logpwrfft_c( sample_rate=samp_rate / 100, fft_size=2048, ref_scale=0.00001, frame_rate=samp_rate / 100 / 2048, avg_alpha=1.0, average=False, ) self.iio_attr_updater_0_0 = iio.attr_updater('hardwaregain', str(int(Gain_RF * 1.75)), 1000) self.iio_attr_updater_0 = iio.attr_updater('frequency', str(int(FrRX)), 1000) self.iio_attr_sink_0_0 = iio.attr_sink("ip:192.168.2.1", "ad9361-phy", "voltage0", 0, False, False) self.iio_attr_sink_0 = iio.attr_sink("ip:192.168.2.1", "ad9361-phy", "altvoltage0", 0, True, False) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 120, (xlate_filter_taps), F_Fine - Largeur_filtre / 2 + LSB_USB * Largeur_filtre - 100 + LSB_USB * 200, samp_rate) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc( 0, decim_LP / 2) self.blocks_udp_sink_1 = blocks.udp_sink(gr.sizeof_short * 2048, '127.0.0.1', 9002, 4096, True) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_short * 1, '127.0.0.1', 9001, 1000, True) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (1 - 2 * LSB_USB, )) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, int(1024 * decim_LP), 204800, 0) self.blocks_float_to_short_1 = blocks.float_to_short(2048, 100) self.blocks_float_to_short_0 = blocks.float_to_short(1, 16000) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.analog_sig_source_x_0_0 = analog.sig_source_f( samp_rate / 120, analog.GR_SIN_WAVE, Largeur_filtre / 2 + 100, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f( samp_rate / 120, analog.GR_COS_WAVE, Largeur_filtre / 2 + 100, 1, 0) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(100) ################################################## # Connections ################################################## self.msg_connect((self.iio_attr_updater_0, 'out'), (self.iio_attr_sink_0, 'attr')) self.msg_connect((self.iio_attr_updater_0_0, 'out'), (self.iio_attr_sink_0_0, 'attr')) self.connect((self.analog_agc2_xx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_float_to_short_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_float_to_short_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.blocks_float_to_short_1, 0), (self.blocks_udp_sink_1, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.fractional_resampler_xx_0, 0), (self.logpwrfft_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.logpwrfft_x_0, 0), (self.blocks_float_to_short_1, 0)) self.connect((self.low_pass_filter_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.pluto_source_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.pluto_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] center_freq1 band_width1 [center_freq2 band_width2 ...]" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option( "-a", "--args", type="string", default="", help="UHD device 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 [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option( "", "--acquisition-period", type="eng_float", default=3, metavar="SECS", help= "time to delay (in seconds) after changing frequency [default=%default]" ) parser.add_option( "", "--dwell-delay", type="eng_float", default=3, metavar="SECS", help= "time to dwell (in seconds) at a given frequency [default=%default]" ) parser.add_option( "", "--meas-interval", type="eng_float", default=0.1, metavar="SECS", help= "interval over which to measure statistic (in seconds) [default=%default]" ) parser.add_option( "-c", "--number-channels", type="int", default=100, help= "number of uniform channels for which to report power measurements [default=%default]" ) parser.add_option( "-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=half the sample rate]") parser.add_option("-F", "--fft-size", type="int", default=1024, help="specify number of FFT bins [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option("-d", "--dest-url", type="string", default="", help="set destination url for posting data") parser.add_option("", "--skip-DC", action="store_true", default=False, help="skip the DC bin when mapping channels") (options, args) = parser.parse_args() if (len(args) < 2) or (len(args) % 2 == 1): parser.print_help() sys.exit(1) self.center_freq = [] self.bandwidth = [] for i in range(len(args) / 2): self.center_freq.append(eng_notation.str_to_num(args[2 * i])) self.bandwidth.append(eng_notation.str_to_num(args[2 * i + 1])) self.band_ind = len(self.center_freq) - 1 if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph 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(options.samp_rate) usrp_rate = self.u.get_samp_rate() if usrp_rate != options.samp_rate: if usrp_rate < options.samp_rate: # create list of allowable rates samp_rates = self.u.get_samp_rates() rate_list = [0.0] * len(samp_rates) for i in range(len(rate_list)): last_rate = samp_rates.pop() rate_list[len(rate_list) - 1 - i] = last_rate.start() # choose next higher rate rate_ind = rate_list.index(usrp_rate) + 1 if rate_ind < len(rate_list): self.u.set_samp_rate(rate_list[rate_ind]) usrp_rate = self.u.get_samp_rate() print "New actual sample rate =", usrp_rate / 1e6, "MHz" resamp = filter.fractional_resampler_cc( 0.0, usrp_rate / options.samp_rate) self.samp_rate = options.samp_rate if (options.lo_offset): self.lo_offset = options.lo_offset else: self.lo_offset = usrp_rate / 2.0 print "LO offset set to", self.lo_offset / 1e6, "MHz" self.fft_size = options.fft_size self.num_ch = options.number_channels self.acq_period = options.acquisition_period self.dwell_delay = options.dwell_delay self.head = blocks.head(gr.sizeof_gr_complex, int(self.dwell_delay * usrp_rate)) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) window_power = sum(map(lambda x: x * x, mywindow)) c2mag = blocks.complex_to_mag_squared(self.fft_size) self.bin2ch_map = [[0] * self.fft_size for i in range(len(self.center_freq))] hz_per_bin = self.samp_rate / self.fft_size for i in range(len(self.center_freq)): channel_bw = hz_per_bin * round( self.bandwidth[i] / self.num_ch / hz_per_bin) self.bandwidth[i] = channel_bw * self.num_ch print "Actual width of band", i + 1, "is", self.bandwidth[ i] / 1e6, "MHz." start_freq = self.center_freq[i] - self.bandwidth[i] / 2.0 stop_freq = start_freq + self.bandwidth[i] for j in range(self.fft_size): fj = self.bin_freq(j, self.center_freq[i]) if (fj >= start_freq) and (fj < stop_freq): channel_num = int( math.floor((fj - start_freq) / channel_bw)) + 1 self.bin2ch_map[i][j] = channel_num if options.skip_DC: self.bin2ch_map[i][(self.fft_size + 1) / 2 + 1:] = self.bin2ch_map[i][(self.fft_size + 1) / 2:-1] self.bin2ch_map[i][(self.fft_size + 1) / 2] = 0 if self.bandwidth[i] > self.samp_rate: print "Warning: Width of band", i + 1, "(" + str( self.bandwidth[i] / 1e6), "MHz) is greater than the sample rate (" + str( self.samp_rate / 1e6), "MHz)." self.aggr = myblocks.bin_aggregator_ff(self.fft_size, self.num_ch, self.bin2ch_map[0]) meas_frames = max(1, int( round(options.meas_interval * self.samp_rate / self.fft_size))) # in fft_frames self.meas_duration = meas_frames * self.fft_size / self.samp_rate print "Actual measurement duration =", self.meas_duration, "s" self.stats = myblocks.bin_statistics_ff(self.num_ch, meas_frames) # Divide magnitude-square by a constant to obtain power # in Watts. Assumes unit of USRP source is volts. impedance = 50.0 # ohms Vsq2W_dB = -10.0 * math.log10(self.fft_size * window_power * impedance) # Convert from Watts to dBm. W2dBm = blocks.nlog10_ff(10.0, self.num_ch, 30.0 + Vsq2W_dB) f2c = blocks.float_to_char(self.num_ch, 1.0) self.dest_url = options.dest_url # file descriptor is set in main loop; use dummy value for now self.srvr = myblocks.file_descriptor_sink(self.num_ch * gr.sizeof_char, 0) self.connect(self.u, self.head) if usrp_rate > self.samp_rate: # insert resampler self.connect(self.head, resamp, s2v) else: self.connect(self.head, s2v) self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, f2c, self.srvr) #self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, self.srvr) g = self.u.get_gain_range() if options.gain is None: # if no gain was specified, use the mid-point in dB options.gain = float(g.start() + g.stop()) / 2.0 self.set_gain(options.gain) print "gain =", options.gain, "dB in range (%0.1f dB, %0.1f dB)" % ( float(g.start()), float(g.stop())) self.atten = float(g.stop()) - options.gain
def _set_interpolator(self): interpolator = filter.fractional_resampler_cc(0, self.sps) return interpolator
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Rds") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.sound_samp_rate = sound_samp_rate = 44.1e3 self.samp_rate = samp_rate = 2e6 self.samp_post_receive = samp_post_receive = 350e3 self.freq = freq = 90.7e6 ################################################## # Blocks ################################################## _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='freq', 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=87.9e6, maximum=107.9e6, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_freq_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.GetWin(), title="Final Output", sample_rate=17.5e3, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(freq, 0) self.rtlsdr_source_0.set_freq_corr(0, 0) self.rtlsdr_source_0.set_dc_offset_mode(0, 0) self.rtlsdr_source_0.set_iq_balance_mode(0, 0) self.rtlsdr_source_0.set_gain_mode(0, 0) self.rtlsdr_source_0.set_gain(10, 0) self.rtlsdr_source_0.set_if_gain(20, 0) self.rtlsdr_source_0.set_bb_gain(20, 0) self.rtlsdr_source_0.set_antenna("", 0) self.rtlsdr_source_0.set_bandwidth(0, 0) self.low_pass_filter_1 = filter.fir_filter_fff(1, firdes.low_pass( 1, samp_post_receive, 2.2e3, 2e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 75e3, 150e3, firdes.WIN_HAMMING, 6.76)) self.fractional_resampler_xx_2 = filter.fractional_resampler_ff(0, 20) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, 4) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.band_pass_filter_0_0 = filter.fir_filter_fff(1, firdes.band_pass( 1, samp_post_receive, 18.5e3, 19.5e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0 = filter.fir_filter_fff(1, firdes.band_pass( 1, samp_post_receive, 54e3, 60e3, 3e3, firdes.WIN_HAMMING, 6.76)) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=350e3, audio_decimation=2, ) ################################################## # Connections ################################################## self.connect((self.rtlsdr_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.blocks_multiply_xx_0, 2)) self.connect((self.band_pass_filter_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.band_pass_filter_0_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.blocks_multiply_xx_0, 3)) self.connect((self.fractional_resampler_xx_2, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.fractional_resampler_xx_2, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_1, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Decoder 433Mhz") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.variable_function_probe_0 = variable_function_probe_0 = 0 self.target_rate_IM = target_rate_IM = 50000 self.target_rate = target_rate = 1200 self.samp_rate = samp_rate = 2000000 self.xlate_offset = xlate_offset = -47000 self.variable_text_box_0 = variable_text_box_0 = variable_function_probe_0 self.variable_static_text_0 = variable_static_text_0 = target_rate self.samp_per_sym = samp_per_sym = 5 self.gain = gain = 1 self.firdes_tap = firdes_tap = firdes.low_pass(1, samp_rate, 2000, target_rate_IM/4, firdes.WIN_HAMMING, 6.76) ################################################## # Blocks ################################################## _target_rate_sizer = wx.BoxSizer(wx.VERTICAL) self._target_rate_text_box = forms.text_box( parent=self.GetWin(), sizer=_target_rate_sizer, value=self.target_rate, callback=self.set_target_rate, label='target_rate', converter=forms.float_converter(), proportion=0, ) self._target_rate_slider = forms.slider( parent=self.GetWin(), sizer=_target_rate_sizer, value=self.target_rate, callback=self.set_target_rate, minimum=1000, maximum=2000, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_target_rate_sizer) _xlate_offset_sizer = wx.BoxSizer(wx.VERTICAL) self._xlate_offset_text_box = forms.text_box( parent=self.GetWin(), sizer=_xlate_offset_sizer, value=self.xlate_offset, callback=self.set_xlate_offset, label="xlate_offset", converter=forms.float_converter(), proportion=0, ) self._xlate_offset_slider = forms.slider( parent=self.GetWin(), sizer=_xlate_offset_sizer, value=self.xlate_offset, callback=self.set_xlate_offset, minimum=-samp_rate/10, maximum=samp_rate/10, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_xlate_offset_sizer, 2, 2, 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.01, maximum=10, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 3, 2, 1, 1) self.ask_demod_my_ask_clock_detector_0 = ask_demod.my_ask_clock_detector(0.01, target_rate, samp_per_sym) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="Units", minval=0, maxval=10, factor=1.0, decimal_places=10, ref_level=0, sample_rate=target_rate*samp_per_sym, number_rate=15, average=False, avg_alpha=None, label="Max level", peak_hold=True, show_gauge=True, ) self.GridAdd(self.wxgui_numbersink2_0.win, 4, 2, 1, 1) self.wxgui_fftsink2_1 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=target_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=True, ) self.GridAdd(self.wxgui_fftsink2_1.win, 1, 2, 1, 1) self._variable_text_box_0_text_box = forms.text_box( parent=self.GetWin(), value=self.variable_text_box_0, callback=self.set_variable_text_box_0, label="te", converter=forms.int_converter(), ) self.Add(self._variable_text_box_0_text_box) self._variable_static_text_0_static_text = forms.static_text( parent=self.GetWin(), value=self.variable_static_text_0, callback=self.set_variable_static_text_0, label="Sample rate out (target_rate * samp_pre_sym)", converter=forms.float_converter(), ) self.GridAdd(self._variable_static_text_0_static_text, 6, 2, 1, 1) def _variable_function_probe_0_probe(): while True: val = self.ask_demod_my_ask_clock_detector_0.samp_adjust() try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (1)) _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start() self.freq_xlating_fir_filter_xxx_1 = filter.freq_xlating_fir_filter_ccc(int(samp_rate/target_rate_IM), (firdes_tap), xlate_offset, samp_rate) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, (target_rate_IM)/(target_rate*samp_per_sym)) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((gain, )) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, "/home/ubuntu/433/2M_sample_record", True) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float*1, "/tmp/gnu_radio_out", False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.ask_demod_my_ask_clock_detector_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.freq_xlating_fir_filter_xxx_1, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.wxgui_fftsink2_1, 0))
def __init__(self): gr.top_block.__init__(self) # Variables options = self.get_options() self.src = osmosdr.source(options.args) self.src.set_center_freq(options.frequency) self.src.set_freq_corr(options.ppm) self.src.set_sample_rate(int(options.sample_rate)) if options.gain is None: self.src.set_gain_mode(1) else: self.src.set_gain_mode(0) self.src.set_gain(options.gain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % sample_rate) gsm_symb_rate = 1625000.0 / 6.0 sps = sample_rate / gsm_symb_rate / options.osr # configure channel filter filter_cutoff = 135e3 # 135,417Hz is GSM bandwidth filter_t_width = 10e3 offset = 0.0 filter_taps = filter.firdes.low_pass(1.0, sample_rate, filter_cutoff, filter_t_width, filter.firdes.WIN_HAMMING) self.gr_null_sink = blocks.null_sink(568) self.filter = filter.freq_xlating_fir_filter_ccf( 1, filter_taps, offset, sample_rate) self.interpolator = filter.fractional_resampler_cc(0, sps) self.tuner_callback = tuner(self) self.synchronizer_callback = synchronizer(self) self.null_callback = nullcb(self) print ">>>>>Input rate: ", sample_rate self.receiver = npgsm.receiver_cf(self.tuner_callback, self.synchronizer_callback, options.osr, options.c0pos, options.ma.replace(' ', '').lower(), options.maio, options.hsn, options.key.replace(' ', '').lower(), options.configuration.upper(), True) #self.receiver_1 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'1S',False) #self.receiver_2 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'2S',False) #self.receiver_3 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'3S',False) #self.receiver_4 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'4S',False) #self.receiver_5 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'5S',False) #self.receiver_6 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'6S',False) #self.receiver_7 = npgsm.receiver_cf(self.null_callback,self.null_callback,options.osr,options.c0pos,options.ma.replace(' ', '').lower(),options.maio,options.hsn,options.key.replace(' ', '').lower(),'7S',False) self.connect((self.src, 0), (self.filter, 0), (self.interpolator, 0), (self.receiver, 0), (self.gr_null_sink, 0))