def __init__(self): gr.top_block.__init__(self, "Top Block") options = get_options() self.input_file = options.input_file self.gr_file_source_0 = blocks.file_source(gr.sizeof_gr_complex * 1, self.input_file, True) symbol_rate = 18000 sps = 2 # output rate will be 36,000 out_sample_rate = symbol_rate * sps options.low_pass = options.low_pass / 2.0 self.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) self.output = gr.file_sink(gr.sizeof_float, options.output_file) self.connect(self.gr_file_source_0, self.demod, self.output)
def demod(): return cqpsk.cqpsk_demod(samples_per_symbol = 2, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05)
def demod(): return cqpsk.cqpsk_demod(samples_per_symbol=2, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05)
def __init__(self): gr.top_block.__init__(self, "Top Block") options = get_options() self.input_file=options.input_file self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, self.input_file, True) symbol_rate = 18000 sps = 2 # output rate will be 36,000 out_sample_rate = symbol_rate * sps options.low_pass = options.low_pass / 2.0 self.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) self.output = gr.file_sink(gr.sizeof_float, options.output_file) self.connect(self.gr_file_source_0, self.demod, self.output)
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, 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_interpolator_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT) self.scope = fftsink2.fft_sink_c(panel, fft_size=512, sample_rate=sample_rate, ref_scale=2.0, ref_level=-30, y_divs=10, fft_rate=10, average=True, avg_alpha=0.2) self.connect(self.f2c, self.scope)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel options = get_options() sample_rate = int(options.sample_rate) self.asrc = audio.source(sample_rate, options.audio_device, True) self.f2c = gr.float_to_complex(1) self.connect((self.asrc, 1), (self.f2c, 1)) self.connect((self.asrc, 0), (self.f2c, 0)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = gr.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = gr.fractional_interpolator_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT) self.scope = fftsink2.fft_sink_c(panel, fft_size=512, sample_rate=sample_rate, ref_scale=2.0, ref_level=-30, y_divs=10, fft_rate=10, average=True, avg_alpha=0.2) self.connect(self.f2c, self.scope)
def __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 = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = gr.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = gr.fractional_interpolator_cc(0, r) self.connect(self._u, FILTER, INTERPOLATOR, DEMOD, OUT)
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): 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) 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 = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) IN = gr.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 = gr.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = gr.fractional_interpolator_cc(0, r) self.connect(IN, FILTER, INTERPOLATOR, DEMOD, OUT)
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): grc_wxgui.top_block_gui.__init__(self, title="Top Block") options = get_options() self.ifreq = options.frequency self.rfgain = options.gain self.offset = options.frequency_offset self.src = osmosdr.source_c(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)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 out_sample_rate = symbol_rate * sps options.low_pass = options.low_pass / 2.0 if sample_rate == 96000: # FunCube Dongle first_decim = 2 else: first_decim = 10 self.offset = 0 taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.2, gr.firdes.WIN_HANN) self.tuner = gr.freq_xlating_fir_filter_ccf(first_decim, taps, self.offset, sample_rate) self.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) self.output = gr.file_sink(gr.sizeof_float, options.output_file) rerate = float(sample_rate / float(first_decim)) / float(out_sample_rate) sys.stderr.write("resampling factor: %f\n" % rerate) if rerate.is_integer(): sys.stderr.write("using pfb decimator\n") self.resamp = blks2.pfb_decimator_ccf(int(rerate)) else: sys.stderr.write("using pfb resampler\n") self.resamp = blks2.pfb_arb_resampler_ccf(1 / rerate) self.connect(self.src, self.tuner, self.resamp, self.demod, self.output) self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.Main.AddPage(grc_wxgui.Panel(self.Main), "Wideband Spectrum") self.Main.AddPage(grc_wxgui.Panel(self.Main), "Channel Spectrum") self.Main.AddPage(grc_wxgui.Panel(self.Main), "Soft Bits") 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) self.Add(self.Main) def fftsink2_callback(x, y): if abs(x / (sample_rate / 2)) > 0.9: set_ifreq(self.ifreq + x / 2) else: self.offset = -x sys.stderr.write("coarse tuned to: %d Hz => %d Hz\n" % (self.offset, (self.ifreq + self.offset))) self.tuner.set_center_freq(self.offset) self.scope = fftsink2.fft_sink_c(self.Main.GetPage(0).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.6) self.Main.GetPage(0).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 => %d Hz\n" % (self.offset, (self.ifreq + self.offset))) self.tuner.set_center_freq(self.offset) self.scope2 = fftsink2.fft_sink_c(self.Main.GetPage(1).GetWin(), title="Channel Spectrum (click to fine tune)", fft_size=1024, sample_rate=out_sample_rate, ref_scale=2.0, ref_level=-20, y_divs=10, fft_rate=10, average=False, avg_alpha=0.6) self.Main.GetPage(1).Add(self.scope2.win) self.scope2.set_callback(fftsink2_callback2) self.connect(self.resamp, self.scope2) self.scope3 = scopesink2.scope_sink_f( self.Main.GetPage(2).GetWin(), title="Soft Bits", sample_rate=out_sample_rate, v_scale=0, v_offset=0, t_scale=0.001, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Main.GetPage(2).Add(self.scope3.win) self.connect(self.demod, self.scope3)
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, 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 = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = gr.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = gr.fractional_interpolator_cc(0, r) self.connect(self._u, FILTER, INTERPOLATOR, DEMOD, OUT)
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.ifreq = options.frequency self.rfgain = options.gain self.offset = options.frequency_offset 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)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 out_sample_rate = symbol_rate * sps options.low_pass = options.low_pass / 2.0 if sample_rate == 96000: # FunCube Dongle first_decim = 2 else: first_decim = 10 self.offset = 0 taps = firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.2, firdes.WIN_HANN) self.tuner = filter.freq_xlating_fir_filter_ccf( first_decim, taps, self.offset, sample_rate) self.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) self.output = blocks.file_sink(gr.sizeof_float, options.output_file) rerate = float(sample_rate) / float(first_decim) / float( out_sample_rate) sys.stderr.write("resampling factor: %f\n" % rerate) if rerate.is_integer(): sys.stderr.write("using pfb decimator\n") #self.resamp = filter.pfb_decimator_ccf(int(rerate), firdes.low_pass(1,int(sample_rate), 50000,5000), 1) self.resamp = filter.fir_filter_ccf( int(rerate), firdes.low_pass(1, int(sample_rate / first_decim), 50000, 5000)) else: sys.stderr.write("using pfb resampler\n") t = filter.firdes.low_pass_2( 32, 32.0 * sample_rate / first_decim, 60000, 5000, attenuation_dB=3, window=filter.firdes.WIN_BLACKMAN_hARRIS) self.resamp = filter.pfb_arb_resampler_ccf(1.0 / rerate, t, 32) self.connect(self.src, self.tuner, self.resamp, self.demod, self.output) self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.Main.AddPage(grc_wxgui.Panel(self.Main), "Wideband Spectrum") self.Main.AddPage(grc_wxgui.Panel(self.Main), "Channel Spectrum") self.Main.AddPage(grc_wxgui.Panel(self.Main), "Soft Bits") 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) self.Add(self.Main) def fftsink2_callback(x, y): if abs(x / (sample_rate / 2)) > 0.9: set_ifreq(self.ifreq + x / 2) else: self.offset = -x sys.stderr.write("coarse tuned to: %d Hz => %d Hz\n" % (self.offset, (self.ifreq + self.offset))) self.tuner.set_center_freq(self.offset) self.scope = fftsink2.fft_sink_c( self.Main.GetPage(0).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.6) self.Main.GetPage(0).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 => %d Hz\n" % (self.offset, (self.ifreq + self.offset))) self.tuner.set_center_freq(self.offset) self.scope2 = fftsink2.fft_sink_c( self.Main.GetPage(1).GetWin(), title="Channel Spectrum (click to fine tune)", fft_size=1024, sample_rate=out_sample_rate, ref_scale=2.0, ref_level=-20, y_divs=10, fft_rate=10, average=False, avg_alpha=0.6) self.Main.GetPage(1).Add(self.scope2.win) self.scope2.set_callback(fftsink2_callback2) self.connect(self.resamp, self.scope2) self.scope3 = scopesink2.scope_sink_f( self.Main.GetPage(2).GetWin(), title="Soft Bits", sample_rate=out_sample_rate, v_scale=0, v_offset=0, t_scale=0.001, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Main.GetPage(2).Add(self.scope3.win) self.connect(self.demod, self.scope3)
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)