def __init__(self): gr.top_block.__init__(self) self.sample_rate = 5000000 self.ampl = 0.1 self.freq = 144000000 self.uhd = uhd.usrp_source( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd.set_samp_rate(self.sample_rate) self.uhd.set_center_freq(self.freq, 0) self.uhd.set_gain(0, 0) self.uhd.set_antenna("RX2", 0) self.fft_vxx_0 = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), True, 1) self.throttle = blocks.throttle(gr.sizeof_gr_complex*1, self.sample_rate,True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, self.sample_rate,True) self.stream = blocks.stream_to_vector_decimator( item_size=gr.sizeof_gr_complex, sample_rate=self.sample_rate, vec_rate=30, vec_len=1024, ) self.probe = blocks.probe_signal_vf(1024) self.fft = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), True, 1) src0 = analog.sig_source_c(self.sample_rate, analog.GR_SIN_WAVE, self.freq, self.ampl) dst = audio.sink(self.sample_rate, "") self.sqrt = blocks.complex_to_mag_squared(1024) def fft_out(): while 1: val = self.probe.level() print max(val) freq = (val.index(max(val)) * (self.sample_rate/1024.0)) + (self.freq - (self.sample_rate/2.0)) print freq time.sleep(1) fft_thread = threading.Thread(target=fft_out) fft_thread.daemon = True fft_thread.start() self.connect((self.uhd,0),(self.throttle, 0)) self.connect((self.throttle,0),(self.stream,0)) self.connect((self.stream, 0),(self.fft, 0)) self.connect((self.fft, 0),(self.sqrt, 0)) self.connect((self.sqrt, 0),(self.probe, 0))
def test_002(self): vector_length = 10 repeats = 10 value = [0.5+i for i in range(0, vector_length)] src_data = value * repeats src = blocks.vector_source_f(src_data) s2v = blocks.stream_to_vector(gr.sizeof_float, vector_length) dst = blocks.probe_signal_vf(vector_length) self.tb.connect(src, s2v, dst) self.tb.run() output = dst.level() self.assertEqual(len(output), vector_length) self.assertAlmostEqual(value[3], output[3], places=6)
def __init__(self): gr.top_block.__init__(self) self.sample_rate = 5000000 self.ampl = 0.1 self.freq = 144000000 self.stream = blocks.stream_to_vector_decimator( item_size=gr.sizeof_gr_complex, sample_rate=self.sample_rate, vec_rate=30, vec_len=1024, ) self.probe = blocks.probe_signal_vf(1024) self.fft = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), True, 1) src0 = analog.sig_source_c(self.sample_rate, analog.GR_SIN_WAVE, self.freq, self.ampl) dst = audio.sink(self.sample_rate, "") self.sqrt = blocks.complex_to_mag_squared(1024) def fft_out(): while 1: val = self.probe.level() print max(val) freq = (val.index(max(val)) - 512) * (self.sample_rate/1024.0) print freq time.sleep(1) fft_thread = threading.Thread(target=fft_out) fft_thread.daemon = True fft_thread.start() self.connect((src0,0),(self.stream, 0)) self.connect((self.stream, 0),(self.fft, 0)) self.connect((self.fft, 0),(self.sqrt, 0)) self.connect((self.sqrt, 0),(self.probe, 0))
def setup_top_block(self): self.tb = gr.top_block() uhd_usrp_source = uhd.usrp_source("", uhd.stream_args(cpu_format="fc32", channels=range(1))) uhd_usrp_source.set_samp_rate(self.samp_rate) uhd_usrp_source.set_center_freq(self.center_freq, 0) uhd_usrp_source.set_gain(self.gain, 0) blocks_stream_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) fft_vxx = fft.fft_vcc(self.fft_size, True, (window.blackmanharris(self.fft_size)), True, 1) blocks_complex_to_mag_squared = blocks.complex_to_mag_squared(self.fft_size) avg_size = int(self.samp_rate / self.fft_size * self.time_window) specest_moving_average_vff = specest.moving_average_vff(avg_size, self.fft_size, 1.0 / avg_size, 4096) self.probe_signal = blocks.probe_signal_vf(self.fft_size) self.tb.connect((uhd_usrp_source, 0), (blocks_stream_to_vector, 0)) self.tb.connect((blocks_stream_to_vector, 0), (fft_vxx, 0)) self.tb.connect((fft_vxx, 0), (blocks_complex_to_mag_squared, 0)) self.tb.connect((blocks_complex_to_mag_squared, 0), (specest_moving_average_vff, 0)) self.tb.connect((specest_moving_average_vff, 0), (self.probe_signal, 0))
def __init__(self, end_f=500e6, start_f=50e6): gr.top_block.__init__(self, "Electosense") Qt.QWidget.__init__(self) self.setWindowTitle("Electosense") 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", "electrosense_hopping") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.end_f = end_f self.start_f = start_f ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2e6 self.prober = prober = 1 self.hop_mode = hop_mode = 2 self.tune_delay = tune_delay = 50e-3 self.sensorid = sensorid = 123456 self.rfgain = rfgain = 40 self.ppm = ppm = 0 self.navg_vectors = navg_vectors = 100 self.fft_size = fft_size = 512 self.cfreq = cfreq = scanning.step(start_f, end_f, samp_rate / 1.5, prober, hop_mode, 0.8, 0.8) self.alpha = alpha = 0.75 ################################################## # Blocks ################################################## self.vecprobe = blocks.probe_signal_vf(fft_size) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( alpha, fft_size) 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(cfreq, 0) self.rtlsdr_source_0.set_freq_corr(ppm, 0) self.rtlsdr_source_0.set_dc_offset_mode(2, 0) self.rtlsdr_source_0.set_iq_balance_mode(2, 0) self.rtlsdr_source_0.set_gain_mode(True, 0) self.rtlsdr_source_0.set_gain(rfgain, 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(250e3, 0) self.qtgui_vector_sink_f_0 = qtgui.vector_sink_f( fft_size, 0, 1.0, "x-Axis", "y-Axis", "", 1 # Number of inputs ) self.qtgui_vector_sink_f_0.set_update_time(0.10) self.qtgui_vector_sink_f_0.set_y_axis(-140, 10) self.qtgui_vector_sink_f_0.enable_autoscale(False) self.qtgui_vector_sink_f_0.enable_grid(False) self.qtgui_vector_sink_f_0.set_x_axis_units("") self.qtgui_vector_sink_f_0.set_y_axis_units("") self.qtgui_vector_sink_f_0.set_ref_level(0) 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_vector_sink_f_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_vector_sink_f_0.set_line_label(i, labels[i]) self.qtgui_vector_sink_f_0.set_line_width(i, widths[i]) self.qtgui_vector_sink_f_0.set_line_color(i, colors[i]) self.qtgui_vector_sink_f_0.set_line_alpha(i, alphas[i]) self._qtgui_vector_sink_f_0_win = sip.wrapinstance( self.qtgui_vector_sink_f_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_vector_sink_f_0_win) def _prober_probe(): while True: val = self.vecprobe.level() try: self.set_prober(val) except AttributeError: pass time.sleep(1.0 / (1 / (tune_delay + (1 / samp_rate * fft_size * navg_vectors)))) _prober_thread = threading.Thread(target=_prober_probe) _prober_thread.daemon = True _prober_thread.start() self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.blackmanharris(fft_size)), True, 1) self.electrosense_discard_samples_0 = electrosense.discard_samples( int(tune_delay * samp_rate), int(cfreq), pmt.intern("burst_len"), False) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(1, fft_size, 0) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_float * fft_size, navg_vectors) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( fft_size) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.vecprobe, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.qtgui_vector_sink_f_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.electrosense_discard_samples_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.electrosense_discard_samples_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n_0, 0))
def __init__(self): gr.top_block.__init__(self, "HF channel simulation") ################################################## # Variables ################################################## self.snr = snr = 20 self.vol = vol = [1, 1] self.tau_a = tau_a = 1 / 100. self.tau = tau = 0.1 self.snrVecOut = snrVecOut = ([0] * 3) self.samp_rate = samp_rate = 48000 self.outSigRMSVec = outSigRMSVec = ([0] * 2) self.noSpread = noSpread = 0 self.kN = kN = pow(10.0, (-snr / 20.0)) self.freqShift = freqShift = 0.0 self.fd = fd = 1 self.en_noise = en_noise = [0, 0] self.doppler_ir = doppler_ir = [ 0.0016502763167573274, 0.0018854799389366934, 0.002149957633383614, 0.0024466994528029662, 0.002778907461425479, 0.003149998028185868, 0.003563602180973301, 0.00402356375450247, 0.004533935060796761, 0.0050989698117900155, 0.005723113028669535, 0.006410987682800636, 0.007167377828853199, 0.007997208012493867, 0.008905518763040982, 0.00989743801603955, 0.010978148351927763, 0.012152849984840378, 0.013426719489994542, 0.014804864318746317, 0.016292273216847054, 0.01789376273305468, 0.019613920081278834, 0.021457042698902442, 0.023427074925696508, 0.025527542310538734, 0.027761484135525694, 0.030131384827462734, 0.03263910500345486, 0.035285812968654906, 0.03807191754835305, 0.04099700319171279, 0.04405976832879332, 0.04725796799434838, 0.050588361749672524, 0.05404666793605477, 0.057627525278984175, 0.06132446283016882, 0.06512987918400244, 0.0690350318359975, 0.073030037462906, 0.07710388379815894, 0.08124445365265866, 0.08543856149104095, 0.08967200281887802, 0.0939296164688993, 0.09819535969651079, 0.10245239580938088, 0.10668319386560887, 0.1108696397832219, 0.11499315801386097, 0.11903484274903825, 0.12297559745183839, 0.12679628134392928, 0.1304778613306593, 0.13400156771907581, 0.1373490519778611, 0.14050254470705797, 0.14344501193124823, 0.14616030780428022, 0.14863332181791858, 0.15085011864154488, 0.1527980687853246, 0.154465968374505, 0.15584414644656272, 0.15692455833401583, 0.15770086387153975, 0.1581684893637365, 0.15832467246620405, 0.1581684893637365, 0.15770086387153975, 0.15692455833401583, 0.15584414644656272, 0.154465968374505, 0.1527980687853246, 0.15085011864154488, 0.14863332181791858, 0.14616030780428022, 0.14344501193124823, 0.14050254470705797, 0.1373490519778611, 0.13400156771907581, 0.1304778613306593, 0.12679628134392928, 0.12297559745183839, 0.11903484274903825, 0.11499315801386097, 0.1108696397832219, 0.10668319386560887, 0.10245239580938088, 0.09819535969651079, 0.0939296164688993, 0.08967200281887802, 0.08543856149104095, 0.08124445365265866, 0.07710388379815894, 0.073030037462906, 0.0690350318359975, 0.06512987918400244, 0.06132446283016882, 0.057627525278984175, 0.05404666793605477, 0.050588361749672524, 0.04725796799434838, 0.04405976832879332, 0.04099700319171279, 0.03807191754835305, 0.035285812968654906, 0.03263910500345486, 0.030131384827462734, 0.027761484135525694, 0.025527542310538734, 0.023427074925696508, 0.021457042698902442, 0.019613920081278834, 0.01789376273305468, 0.016292273216847054, 0.014804864318746317, 0.013426719489994542, 0.012152849984840378, 0.010978148351927763, 0.00989743801603955, 0.008905518763040982, 0.007997208012493867, 0.007167377828853199, 0.006410987682800636, 0.005723113028669535, 0.0050989698117900155, 0.004533935060796761, 0.00402356375450247, 0.003563602180973301, 0.003149998028185868, 0.002778907461425479, 0.0024466994528029662, 0.002149957633383614, 0.0018854799389366934, 0.0016502763167573274 ] self.ampl = ampl = [[1.0, 1.0], [1.0, 1.0]] ################################################## # Blocks ################################################## self.snrOut = blocks.probe_signal_vf(4) self.outSigRMS = blocks.probe_signal_vf(2) def _snrVecOut_probe(): while True: val = self.snrOut.level() try: self.set_snrVecOut(val) except AttributeError: pass time.sleep(1.0 / (10)) _snrVecOut_thread = threading.Thread(target=_snrVecOut_probe) _snrVecOut_thread.daemon = True _snrVecOut_thread.start() self.single_pole_iir_filter_xx_0_1 = filter.single_pole_iir_filter_ff( 2 * pi * tau_a / samp_rate, 1) self.single_pole_iir_filter_xx_0_0_0 = filter.single_pole_iir_filter_ff( 2 * pi * tau_a / samp_rate, 1) self.single_pole_iir_filter_xx_0_0 = filter.single_pole_iir_filter_ff( 2 * pi * tau_a / samp_rate, 1) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( 2 * pi * tau_a / samp_rate, 1) def _outSigRMSVec_probe(): while True: val = self.outSigRMS.level() try: self.set_outSigRMSVec(val) except AttributeError: pass time.sleep(1.0 / (10)) _outSigRMSVec_thread = threading.Thread(target=_outSigRMSVec_probe) _outSigRMSVec_thread.daemon = True _outSigRMSVec_thread.start() self.low_pass_filter_2_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 1550, 100, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 1550, 100, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1_1 = filter.interp_fir_filter_ccf( int(samp_rate / 100), firdes.low_pass(ampl[1][0] * (samp_rate / 100.0), samp_rate, 50, 25, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1_0_0 = filter.interp_fir_filter_ccf( int(samp_rate / 100), firdes.low_pass(ampl[1][1] * (samp_rate / 100.0), samp_rate, 50, 25, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1_0 = filter.interp_fir_filter_ccf( int(samp_rate / 100), firdes.low_pass(ampl[0][1] * (samp_rate / 100.0), samp_rate, 50, 25, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1 = filter.interp_fir_filter_ccf( int(samp_rate / 100), firdes.low_pass(ampl[0][0] * (samp_rate / 100.0), samp_rate, 50, 25, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 1750 + 100, 600, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 1750 + 100, 600, firdes.WIN_HAMMING, 6.76)) self.fir_filter_xxx_0_0_0_0 = filter.fir_filter_ccc(1, doppler_ir) self.fir_filter_xxx_0_0_0_0.declare_sample_delay(0) self.fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(1, doppler_ir) self.fir_filter_xxx_0_0_0.declare_sample_delay(0) self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(1, doppler_ir) self.fir_filter_xxx_0_0.declare_sample_delay(0) self.fir_filter_xxx_0 = filter.fir_filter_ccc(1, doppler_ir) self.fir_filter_xxx_0.declare_sample_delay(0) self.blocks_streams_to_vector_0_0 = blocks.streams_to_vector( gr.sizeof_float * 1, 2) self.blocks_streams_to_vector_0 = blocks.streams_to_vector( gr.sizeof_float * 1, 4) self.blocks_selector_0_1 = blocks.selector(gr.sizeof_gr_complex * 1, noSpread, 0) self.blocks_selector_0_1.set_enabled(True) self.blocks_selector_0_0_0 = blocks.selector(gr.sizeof_gr_complex * 1, noSpread, 0) self.blocks_selector_0_0_0.set_enabled(True) self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex * 1, noSpread, 0) self.blocks_selector_0_0.set_enabled(True) self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex * 1, noSpread, 0) self.blocks_selector_0.set_enabled(True) self.blocks_rms_xx_0_1 = blocks.rms_cf(2 * pi * tau_a * 100 / samp_rate) self.blocks_rms_xx_0_0_0 = blocks.rms_ff(2 * pi * tau_a * 10 / samp_rate) self.blocks_rms_xx_0_0 = blocks.rms_ff(2 * pi * tau_a * 10 / samp_rate) self.blocks_rms_xx_0 = blocks.rms_cf(2 * pi * tau_a * 100 / samp_rate) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_float * 1) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float * 1) self.blocks_nlog10_ff_0_0 = blocks.nlog10_ff(10, 1, 0) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0) self.blocks_multiply_xx_1_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_2_0 = blocks.multiply_const_cc(vol[1]) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_cc(vol[0]) self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_ff( 2 * sqrt(ampl[1][0]**2 + ampl[1][1]**2) * 2) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_ff( 2 * sqrt(ampl[0][0]**2 + ampl[0][1]**2) * 2) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_ff(0.5) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(0.5) self.blocks_float_to_complex_1_0 = blocks.float_to_complex(1) self.blocks_float_to_complex_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_divide_xx_1_0 = blocks.divide_ff(1) self.blocks_divide_xx_1 = blocks.divide_ff(1) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, int(tau * samp_rate)) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, int(tau * samp_rate)) self.blocks_complex_to_real_0_0 = blocks.complex_to_real(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_mag_squared_2_1 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_2_0_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_2_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_2 = blocks.complex_to_mag_squared(1) self.blocks_add_xx_0_1 = blocks.add_vcc(1) self.blocks_add_xx_0_0_0 = blocks.add_vcc(1) self.blocks_add_xx_0_0 = blocks.add_vcc(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.audio_source_0 = audio.source(samp_rate, 'hw:CARD=Rubix44,DEV=0', False) self.audio_sink_0 = audio.sink(samp_rate, 'hw:CARD=Rubix44,DEV=0', False) self.analog_sig_source_x_2_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0) self.analog_sig_source_x_2 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0) self.analog_sig_source_x_1_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, freqShift, 1, 0, 0) self.analog_sig_source_x_1 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, freqShift, 1, 0, 0) self.analog_sig_source_x_0_0_1 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -1850, 1, 0, 0) self.analog_sig_source_x_0_0_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0) self.analog_sig_source_x_0_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0) self.analog_sig_source_x_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -1850, 1, 0, 0) self.analog_noise_source_x_1_0 = analog.noise_source_c( analog.GR_GAUSSIAN, 1e-0 * kN, 13) self.analog_noise_source_x_1 = analog.noise_source_c( analog.GR_GAUSSIAN, 1e-0 * kN, 3) self.analog_noise_source_x_0_1 = analog.noise_source_c( analog.GR_GAUSSIAN, 1, 10) self.analog_noise_source_x_0_0_0 = analog.noise_source_c( analog.GR_GAUSSIAN, 1, 11) self.analog_fastnoise_source_x_0_0 = analog.fastnoise_source_c( analog.GR_GAUSSIAN, 1, 1, 8192) self.analog_fastnoise_source_x_0 = analog.fastnoise_source_c( analog.GR_GAUSSIAN, 1, 0, 8192) self.analog_const_source_x_2_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_const_source_x_2 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_const_source_x_1_1 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, ampl[1][0]) self.analog_const_source_x_1_0_0 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, ampl[1][1]) self.analog_const_source_x_1_0 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, ampl[0][1]) self.analog_const_source_x_1 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, ampl[0][0]) self.analog_const_source_x_0_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_const_source_x_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.analog_const_source_x_0_0, 0), (self.blocks_float_to_complex_0_0, 1)) self.connect((self.analog_const_source_x_1, 0), (self.blocks_selector_0, 1)) self.connect((self.analog_const_source_x_1_0, 0), (self.blocks_selector_0_0, 1)) self.connect((self.analog_const_source_x_1_0_0, 0), (self.blocks_selector_0_0_0, 1)) self.connect((self.analog_const_source_x_1_1, 0), (self.blocks_selector_0_1, 1)) self.connect((self.analog_const_source_x_2, 0), (self.blocks_float_to_complex_1, 1)) self.connect((self.analog_const_source_x_2_0, 0), (self.blocks_float_to_complex_1_0, 1)) self.connect((self.analog_fastnoise_source_x_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.analog_fastnoise_source_x_0_0, 0), (self.fir_filter_xxx_0_0, 0)) self.connect((self.analog_noise_source_x_0_0_0, 0), (self.fir_filter_xxx_0_0_0_0, 0)) self.connect((self.analog_noise_source_x_0_1, 0), (self.fir_filter_xxx_0_0_0, 0)) self.connect((self.analog_noise_source_x_1, 0), (self.low_pass_filter_2, 0)) self.connect((self.analog_noise_source_x_1_0, 0), (self.low_pass_filter_2_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_0_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.analog_sig_source_x_0_0_0_0, 0), (self.blocks_multiply_xx_0_0_1, 1)) self.connect((self.analog_sig_source_x_0_0_1, 0), (self.blocks_multiply_xx_0_1, 1)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.analog_sig_source_x_1_0, 0), (self.blocks_multiply_xx_1_0, 0)) self.connect((self.analog_sig_source_x_2, 0), (self.blocks_multiply_xx_0_0_0_0_0, 1)) self.connect((self.analog_sig_source_x_2_0, 0), (self.blocks_multiply_xx_0_0_0_0_0_0, 1)) self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.audio_source_0, 1), (self.blocks_float_to_complex_0_0, 0)) self.connect((self.audio_source_0, 2), (self.blocks_null_sink_0, 0)) self.connect((self.audio_source_0, 3), (self.blocks_null_sink_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_add_xx_0_0, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.blocks_add_xx_0_0_0, 0), (self.blocks_multiply_const_vxx_2_0, 0)) self.connect((self.blocks_add_xx_0_1, 0), (self.blocks_multiply_xx_1_0, 1)) self.connect((self.blocks_complex_to_mag_squared_2, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_2_0, 0), (self.single_pole_iir_filter_xx_0_0, 0)) self.connect((self.blocks_complex_to_mag_squared_2_0_0, 0), (self.single_pole_iir_filter_xx_0_0_0, 0)) self.connect((self.blocks_complex_to_mag_squared_2_1, 0), (self.single_pole_iir_filter_xx_0_1, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_complex_to_real_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0_0_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_multiply_xx_0_0_0_0_1, 0)) self.connect((self.blocks_divide_xx_1, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.blocks_divide_xx_1_0, 0), (self.blocks_nlog10_ff_0_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_float_to_complex_0_0, 0), (self.blocks_multiply_xx_0_1, 0)) self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_multiply_xx_0_0_0_0_0, 2)) self.connect((self.blocks_float_to_complex_1_0, 0), (self.blocks_multiply_xx_0_0_0_0_0_0, 2)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 1)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_rms_xx_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_rms_xx_0_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_float_to_complex_1, 0)) self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.blocks_float_to_complex_1_0, 0)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.blocks_multiply_const_vxx_2_0, 0), (self.blocks_complex_to_real_0_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_multiply_xx_0_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_rms_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_xx_0_0_0_0_0, 0), (self.blocks_add_xx_0_0, 1)) self.connect((self.blocks_multiply_xx_0_0_0_0_0, 0), (self.blocks_complex_to_mag_squared_2_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0_0_0_0, 0), (self.blocks_add_xx_0_0_0, 1)) self.connect((self.blocks_multiply_xx_0_0_0_0_0_0, 0), (self.blocks_complex_to_mag_squared_2_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0_0_1, 0), (self.blocks_add_xx_0_1, 1)) self.connect((self.blocks_multiply_xx_0_0_0_1, 0), (self.blocks_add_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0_0_1, 0), (self.blocks_delay_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0_1, 0), (self.blocks_multiply_xx_0_0_0_1, 0)) self.connect((self.blocks_multiply_xx_0_0_1, 0), (self.blocks_rms_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0_1, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_add_xx_0_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_complex_to_mag_squared_2, 0)) self.connect((self.blocks_multiply_xx_1_0, 0), (self.blocks_add_xx_0_0_0, 0)) self.connect((self.blocks_multiply_xx_1_0, 0), (self.blocks_complex_to_mag_squared_2_1, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_streams_to_vector_0, 2)) self.connect((self.blocks_nlog10_ff_0_0, 0), (self.blocks_streams_to_vector_0, 3)) self.connect((self.blocks_null_source_0, 1), (self.audio_sink_0, 3)) self.connect((self.blocks_null_source_0, 0), (self.audio_sink_0, 2)) self.connect((self.blocks_rms_xx_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_rms_xx_0_0, 0), (self.blocks_streams_to_vector_0_0, 0)) self.connect((self.blocks_rms_xx_0_0_0, 0), (self.blocks_streams_to_vector_0_0, 1)) self.connect((self.blocks_rms_xx_0_1, 0), (self.blocks_multiply_const_vxx_1_0, 0)) self.connect((self.blocks_selector_0, 0), (self.blocks_multiply_xx_0_0_0, 1)) self.connect((self.blocks_selector_0_0, 0), (self.blocks_multiply_xx_0_0_0_0, 1)) self.connect((self.blocks_selector_0_0_0, 0), (self.blocks_multiply_xx_0_0_0_0_1, 1)) self.connect((self.blocks_selector_0_1, 0), (self.blocks_multiply_xx_0_0_0_1, 1)) self.connect((self.blocks_streams_to_vector_0, 0), (self.snrOut, 0)) self.connect((self.blocks_streams_to_vector_0_0, 0), (self.outSigRMS, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.low_pass_filter_1_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.low_pass_filter_1_1, 0)) self.connect((self.fir_filter_xxx_0_0_0_0, 0), (self.low_pass_filter_1_0_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_multiply_xx_0_0_1, 0)) self.connect((self.low_pass_filter_1, 0), (self.blocks_selector_0, 0)) self.connect((self.low_pass_filter_1_0, 0), (self.blocks_selector_0_0, 0)) self.connect((self.low_pass_filter_1_0_0, 0), (self.blocks_selector_0_0_0, 0)) self.connect((self.low_pass_filter_1_1, 0), (self.blocks_selector_0_1, 0)) self.connect((self.low_pass_filter_2, 0), (self.blocks_multiply_xx_0_0_0_0_0, 0)) self.connect((self.low_pass_filter_2_0, 0), (self.blocks_multiply_xx_0_0_0_0_0_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_divide_xx_1, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_streams_to_vector_0, 0)) self.connect((self.single_pole_iir_filter_xx_0_0, 0), (self.blocks_divide_xx_1, 1)) self.connect((self.single_pole_iir_filter_xx_0_0, 0), (self.blocks_streams_to_vector_0, 1)) self.connect((self.single_pole_iir_filter_xx_0_0_0, 0), (self.blocks_divide_xx_1_0, 1)) self.connect((self.single_pole_iir_filter_xx_0_1, 0), (self.blocks_divide_xx_1_0, 0))
def __init__(self, ask_samp_rate=4E6, num_demod=4, type_demod=0, hw_args="uhd", freq_correction=0, record=True, play=True): # Call the initialization method from the parent class gr.top_block.__init__(self, "Receiver") # Default values self.center_freq = 144E6 self.gain_db = 10 self.squelch_db = -70 self.volume_db = 0 audio_rate = 8000 # Setup the USRP source, or use the USRP sim self.src = osmosdr.source(args="numchan=" + str(1) + " " + hw_args) self.src.set_sample_rate(ask_samp_rate) self.src.set_gain(self.gain_db) self.src.set_center_freq(self.center_freq) self.src.set_freq_corr(freq_correction) # Get the sample rate and center frequency from the hardware self.samp_rate = self.src.get_sample_rate() self.center_freq = self.src.get_center_freq() # Set the I/Q bandwidth to 80 % of sample rate self.src.set_bandwidth(0.8 * self.samp_rate) # NBFM channel is about 10 KHz wide # Want about 3 FFT bins to span a channel # Use length FFT so 4 Msps / 1024 = 3906.25 Hz/bin # This also means 3906.25 vectors/second # Using below formula keeps FFT size a power of two # Also keeps bin size constant for power of two sampling rates # Use of 256 sets 3906.25 Hz/bin; increase to reduce bin size samp_ratio = self.samp_rate / 1E6 fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio) / np.log(2)))) # -----------Flow for FFT-------------- # Convert USRP steam to vector stream_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex * 1, fft_length) # Want about 1000 vector/sec amount = int(round(self.samp_rate / fft_length / 1000)) keep_one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex * fft_length, amount) # Take FFT fft_vcc = fft.fft_vcc(fft_length, True, window.blackmanharris(fft_length), True, 1) # Compute the power complex_to_mag_squared = blocks.complex_to_mag_squared(fft_length) # Video average and decimate from 1000 vector/sec to 10 vector/sec integrate_ff = blocks.integrate_ff(100, fft_length) # Probe vector self.probe_signal_vf = blocks.probe_signal_vf(fft_length) # Connect the blocks self.connect(self.src, stream_to_vector, keep_one_in_n, fft_vcc, complex_to_mag_squared, integrate_ff, self.probe_signal_vf) # -----------Flow for Demod-------------- # Create N parallel demodulators as a list of objects # Default to NBFM demod self.demodulators = [] for idx in range(num_demod): if type_demod == 1: self.demodulators.append( TunerDemodAM(self.samp_rate, audio_rate, record)) else: self.demodulators.append( TunerDemodNBFM(self.samp_rate, audio_rate, record)) if play: # Create an adder add_ff = blocks.add_ff(1) # Connect the demodulators between the source and adder for idx, demodulator in enumerate(self.demodulators): self.connect(self.src, demodulator, (add_ff, idx)) # Audio sink audio_sink = audio.sink(audio_rate) # Connect the summed outputs to the audio sink self.connect(add_ff, audio_sink) else: # Just connect each demodulator to the receiver source for demodulator in self.demodulators: self.connect(self.src, demodulator)
def __init__(self): gr.top_block.__init__(self, "Ham2Mon AM Receiver Flow Example") Qt.QWidget.__init__(self) self.setWindowTitle("Ham2Mon AM Receiver Flow Example") 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", "am_flow_example") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1E6 self.initial_decim = initial_decim = 5 self.samp_ratio = samp_ratio = samp_rate / 1E6 self.final_rate = final_rate = samp_rate / initial_decim**2 / int( samp_rate / 1E6) self.variable_low_pass_filter_taps_2 = variable_low_pass_filter_taps_2 = firdes.low_pass( 1.0, final_rate, 3500, 500, firdes.WIN_HAMMING, 6.76) self.variable_low_pass_filter_taps_1 = variable_low_pass_filter_taps_1 = firdes.low_pass( 1.0, samp_rate / 25, 12.5E3, 1E3, firdes.WIN_HAMMING, 6.76) self.variable_low_pass_filter_taps_0 = variable_low_pass_filter_taps_0 = firdes.low_pass( 1.0, 1, 0.090, 0.010, firdes.WIN_HAMMING, 6.76) self.squelch_dB = squelch_dB = -70 self.gain_db = gain_db = 30 self.final_decim = final_decim = int(samp_rate / 1E6) self.file_name = file_name = "test.wav" self.fft_length = fft_length = 256 * int( pow(2, np.ceil(np.log(samp_ratio) / np.log(2)))) self.demod_bb_freq = demod_bb_freq = 390E3 self.center_freq = center_freq = 144E6 ################################################## # Blocks ################################################## self._squelch_dB_range = Range(-100, 0, 5, -70, 200) self._squelch_dB_win = RangeWidget(self._squelch_dB_range, self.set_squelch_dB, "Squelch (dB)", "counter_slider", float) self.top_grid_layout.addWidget(self._squelch_dB_win, 5, 1, 1, 3) self._gain_db_range = Range(0, 70, 1, 30, 200) self._gain_db_win = RangeWidget(self._gain_db_range, self.set_gain_db, "HW Gain (dB)", "counter_slider", float) self.top_grid_layout.addWidget(self._gain_db_win, 4, 1, 1, 3) self._demod_bb_freq_range = Range(-samp_rate / 2, samp_rate / 2, 5E3, 390E3, 200) self._demod_bb_freq_win = RangeWidget(self._demod_bb_freq_range, self.set_demod_bb_freq, "Demod BB Freq (Hz)", "counter_slider", float) self.top_grid_layout.addWidget(self._demod_bb_freq_win, 3, 1, 1, 3) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( fft_length, #size samp_rate, #samp_rate "Averaged Spectrum", #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(-60, 40) self.qtgui_time_sink_x_0.set_y_label("Power", "") 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_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", "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(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) 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, 0, 1, 3, 1) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc final_rate, #bw "Decimated Channel", #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(-200, -60) 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_control_panel(False) if not True: self.qtgui_freq_sink_x_0_0.disable_legend() if complex == type(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, 3, 0, 3, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( fft_length, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 144E6, #fc samp_rate, #bw "Spectrum", #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(-120, -20) 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_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if complex == type(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, 0, 0, 3, 1) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_fff( 16E3 / float(final_rate / 5), taps=None, flt_size=32) self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "uhd") self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(center_freq, 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(gain_db, 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(samp_rate * 0.8, 0) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( initial_decim, (variable_low_pass_filter_taps_0), demod_bb_freq, samp_rate) self.fir_filter_xxx_0_1 = filter.fir_filter_fff( initial_decim, (variable_low_pass_filter_taps_0)) self.fir_filter_xxx_0_1.declare_sample_delay(0) self.fir_filter_xxx_0_0 = filter.fir_filter_ccc( int(samp_rate / 1E6), (variable_low_pass_filter_taps_0)) self.fir_filter_xxx_0_0.declare_sample_delay(0) self.fir_filter_xxx_0 = filter.fir_filter_ccc( initial_decim, (variable_low_pass_filter_taps_0)) self.fir_filter_xxx_0.declare_sample_delay(0) self.fft_vxx_0 = fft.fft_vcc(fft_length, True, (window.blackmanharris(fft_length)), True, 1) self.blocks_wavfile_sink_0 = blocks.wavfile_sink( file_name, 1, 16000, 8) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_float * 1, fft_length) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_length) self.blocks_probe_signal_vx_0 = blocks.probe_signal_vf(fft_length) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, fft_length, 0) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_gr_complex * fft_length, int(round(samp_rate / fft_length / 1000))) self.blocks_integrate_xx_0 = blocks.integrate_ff(100, fft_length) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( fft_length) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.audio_sink_0 = audio.sink(16000, "", True) self.analog_pwr_squelch_xx_0_0 = analog.pwr_squelch_ff( -200, 0.1, 0, True) self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc( squelch_dB, 0.1, 0, False) self.analog_agc3_xx_0 = analog.agc3_cc(1e-0, 1e-4, 0.1, 10, 1) self.analog_agc3_xx_0.set_max_gain(10000) ################################################## # Connections ################################################## self.connect((self.analog_agc3_xx_0, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.analog_pwr_squelch_xx_0, 0), (self.analog_agc3_xx_0, 0)) self.connect((self.analog_pwr_squelch_xx_0_0, 0), (self.blocks_wavfile_sink_0, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.fir_filter_xxx_0_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_probe_signal_vx_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.fir_filter_xxx_0_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.analog_pwr_squelch_xx_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.fir_filter_xxx_0_1, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.analog_pwr_squelch_xx_0_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.audio_sink_0, 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.samp_rate = samp_rate = 15e6 self.if_bandwidth_1 = if_bandwidth_1 = 2e6 self.sdr_gain = sdr_gain = 60 self.integration_bandwidth = integration_bandwidth = 5e3 self.if_filter_decimation_rate = if_filter_decimation_rate = int( samp_rate / (1.1 * if_bandwidth_1)) self.sdr_power_offset = sdr_power_offset = 1.0 self.sdr_gain_lin = sdr_gain_lin = 10**(sdr_gain / 20) self.num_channels = num_channels = int( (samp_rate / if_filter_decimation_rate) / integration_bandwidth) self.lna_gain_measured = lna_gain_measured = 33.33 self.integration_time = integration_time = 10 self.if_samp_rate = if_samp_rate = samp_rate / if_filter_decimation_rate self.cable_loss = cable_loss = 0.25 self.variable_function_probe = variable_function_probe = 0 self.sdr_frequency = sdr_frequency = 1420.406e6 self.output_vector_bandwidth = output_vector_bandwidth = samp_rate / if_filter_decimation_rate self.offset_frequency = offset_frequency = if_bandwidth_1 / 2 + 1e5 self.integration_scale_factor = integration_scale_factor = np.full( (num_channels), float(1.0 / (integration_time * integration_bandwidth * 50)), dtype=float) self.integration_dec_rate = integration_dec_rate = int( integration_time * if_samp_rate / num_channels) self.if_filter_gain = if_filter_gain = 1 / ( lna_gain_measured * cable_loss * sdr_gain_lin * sdr_power_offset) self.if_bandwidth_0 = if_bandwidth_0 = 5.5e6 self.channel_skirt = channel_skirt = integration_bandwidth / 100 self.channel_map = channel_map = range( int(num_channels / 2.0 + 1.0), num_channels, 1) + range( 0, int(num_channels / 2.0 + 1.0), 1) self.antenna_gain_estimated = antenna_gain_estimated = 173 ################################################## # Blocks ################################################## self.probe_signal = blocks.probe_signal_vf(num_channels) def _variable_function_probe_probe(): while True: val = self.probe_signal.level() try: self.set_variable_function_probe(val) except AttributeError: pass time.sleep(1.0 / (10)) _variable_function_probe_thread = threading.Thread( target=_variable_function_probe_probe) _variable_function_probe_thread.daemon = True _variable_function_probe_thread.start() self.pfb_channelizer_ccf_0 = pfb.channelizer_ccf( num_channels, (firdes.low_pass(1, if_samp_rate, (integration_bandwidth / 2 - channel_skirt), channel_skirt, firdes.WIN_HAMMING)), 1.0, 0) self.pfb_channelizer_ccf_0.set_channel_map((channel_map)) self.pfb_channelizer_ccf_0.declare_sample_delay(0) self.low_pass_filter_1 = filter.fir_filter_ccf( if_filter_decimation_rate, firdes.low_pass(if_filter_gain, samp_rate, if_bandwidth_1 / 2, 1e5, firdes.WIN_HAMMING, 6.76)) self.limesdr_source_2 = limesdr.source('0009060B00471B22', 0, '') self.limesdr_source_2.set_sample_rate(samp_rate) self.limesdr_source_2.set_center_freq(sdr_frequency - offset_frequency, 0) self.limesdr_source_2.set_bandwidth(if_bandwidth_0, 0) self.limesdr_source_2.set_digital_filter(if_bandwidth_0, 0) self.limesdr_source_2.set_gain(sdr_gain, 0) self.limesdr_source_2.set_antenna(2, 0) self.limesdr_source_2.calibrate(samp_rate, 0) self.blocks_streams_to_vector_0 = blocks.streams_to_vector( gr.sizeof_gr_complex * 1, num_channels) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (integration_scale_factor)) self.blocks_integrate_xx_0_0 = blocks.integrate_ff( integration_dec_rate, num_channels) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1, 'receive_block_sink', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_copy_0_0 = blocks.copy(gr.sizeof_gr_complex * 1) self.blocks_copy_0_0.set_enabled(False) self.blocks_copy_0 = blocks.copy(gr.sizeof_gr_complex * 1) self.blocks_copy_0.set_enabled(True) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( num_channels) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_SIN_WAVE, -offset_frequency, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_copy_0, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.blocks_copy_0_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.probe_signal, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.low_pass_filter_1, 0)) self.connect((self.blocks_streams_to_vector_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.limesdr_source_2, 0), (self.blocks_copy_0, 0)) self.connect((self.limesdr_source_2, 0), (self.blocks_copy_0_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.pfb_channelizer_ccf_0, 0)) for i in range(num_channels): self.connect((self.pfb_channelizer_ccf_0, i), (self.blocks_streams_to_vector_0, i))
def __init__(self, end_f=500e6, start_f=50e6): gr.top_block.__init__(self, "Electosense") ################################################## # Parameters ################################################## self.end_f = end_f self.start_f = start_f ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2e6 self.prober = prober = 1 self.hop_mode = hop_mode = 2 self.tune_delay = tune_delay = 50e-3 self.sensorid = sensorid = 123456 self.rfgain = rfgain = 40 self.ppm = ppm = 0 self.navg_vectors = navg_vectors = 100 self.fft_size = fft_size = 512 self.cfreq = cfreq = scanning.step(start_f, end_f, samp_rate / 1.5, prober, hop_mode, 0.8, 0.8) self.alpha = alpha = 0.75 ################################################## # Blocks ################################################## self.vecprobe = blocks.probe_signal_vf(fft_size) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( alpha, fft_size) 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(cfreq, 0) self.rtlsdr_source_0.set_freq_corr(ppm, 0) self.rtlsdr_source_0.set_dc_offset_mode(2, 0) self.rtlsdr_source_0.set_iq_balance_mode(2, 0) self.rtlsdr_source_0.set_gain_mode(True, 0) self.rtlsdr_source_0.set_gain(rfgain, 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) def _prober_probe(): while True: val = self.vecprobe.level() try: self.set_prober(val) except AttributeError: pass time.sleep(1.0 / (1 / (tune_delay + (1 / samp_rate * fft_size * navg_vectors)))) _prober_thread = threading.Thread(target=_prober_probe) _prober_thread.daemon = True _prober_thread.start() self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.blackmanharris(fft_size)), True, 1) self.electrosense_discard_samples_0 = electrosense.discard_samples( int(tune_delay * samp_rate), int(cfreq), pmt.intern("burst_len"), False) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_float * fft_size, navg_vectors) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( fft_size) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.vecprobe, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.electrosense_discard_samples_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.electrosense_discard_samples_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n_0, 0))
def __init__(self, RF=2.49e9, lowpass_cutoff_freq=1700, speed_samp_rate=1, fft_len=pow(2,20), angle=0, DC_filter_num_elements=4, samp_rate_sink=8000, samp_rate=1e6, max_num_of_targets=10, lo_offset_freq=1e6, highpass_cutoff_freq=0, doppler_signal_bw=20, threshold_dB=-70, rx_gain=30.5, tx_amp=0): grc_wxgui.top_block_gui.__init__(self, title="CW Radar Multiple Targets Receiver") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.RF = RF self.lowpass_cutoff_freq = lowpass_cutoff_freq self.speed_samp_rate = speed_samp_rate self.fft_len = fft_len self.angle = angle self.DC_filter_num_elements = DC_filter_num_elements self.samp_rate_sink = samp_rate_sink self.samp_rate = samp_rate self.max_num_of_targets = max_num_of_targets self.lo_offset_freq = lo_offset_freq self.highpass_cutoff_freq = highpass_cutoff_freq self.doppler_signal_bw = doppler_signal_bw self.threshold_dB = threshold_dB self.rx_gain = rx_gain self.tx_amp = tx_amp ################################################## # Variables ################################################## self.target_speed_vector = target_speed_vector = 0 self.target_direction_vector = target_direction_vector = 0 self.num_targets = num_targets = 0 self.tx_amp_tuner = tx_amp_tuner = tx_amp self.threshold_dB_tuner = threshold_dB_tuner = threshold_dB self.speed_textbox = speed_textbox = target_speed_vector self.rx_gain_tuner = rx_gain_tuner = rx_gain self.num_targets_textbox = num_targets_textbox = num_targets self.max_num_of_targets_tuner = max_num_of_targets_tuner = max_num_of_targets self.lowpass_cutoff_freq_tuner = lowpass_cutoff_freq_tuner = lowpass_cutoff_freq self.highpass_cutoff_freq_tuner = highpass_cutoff_freq_tuner = highpass_cutoff_freq self.doppler_signal_bw_tuner = doppler_signal_bw_tuner = doppler_signal_bw self.direction_textbox = direction_textbox = target_direction_vector self.angle_tuner = angle_tuner = angle self.RF_tuner = RF_tuner = RF ################################################## # Blocks ################################################## _threshold_dB_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_dB_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, label="Detected Target Threshold (dB)", converter=forms.float_converter(), proportion=0, ) self._threshold_dB_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, minimum=-90, maximum=-30, num_steps=60, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_threshold_dB_tuner_sizer, 2, 0, 1, 8) self.speed_vector_probe = blocks.probe_signal_vf(max_num_of_targets) _rx_gain_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, label="USRP RX Gain (dB)", converter=forms.float_converter(), proportion=0, ) self._rx_gain_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, minimum=0, maximum=30.5 + 62, num_steps=185, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rx_gain_tuner_sizer, 0, 0, 1, 8) self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Frequency/Time CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver Full Spectrum") self.GridAdd(self.notebook, 6, 0, 13, 53) _max_num_of_targets_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._max_num_of_targets_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_max_num_of_targets_tuner_sizer, value=self.max_num_of_targets_tuner, callback=self.set_max_num_of_targets_tuner, label="Maximum Number of Targets", converter=forms.int_converter(), proportion=0, ) self._max_num_of_targets_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_max_num_of_targets_tuner_sizer, value=self.max_num_of_targets_tuner, callback=self.set_max_num_of_targets_tuner, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.GridAdd(_max_num_of_targets_tuner_sizer, 2, 8, 1, 21) _lowpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._lowpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, label="Low-Pass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._lowpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, minimum=0, maximum=3000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_lowpass_cutoff_freq_tuner_sizer, 1, 29, 1, 24) _highpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._highpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, label="High-Pass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._highpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, minimum=0, maximum=1600, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_highpass_cutoff_freq_tuner_sizer, 0, 29, 1, 24) _doppler_signal_bw_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._doppler_signal_bw_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_doppler_signal_bw_tuner_sizer, value=self.doppler_signal_bw_tuner, callback=self.set_doppler_signal_bw_tuner, label="Doppler Spectrum Bandwidth (Hz)", converter=forms.float_converter(), proportion=0, ) self._doppler_signal_bw_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_doppler_signal_bw_tuner_sizer, value=self.doppler_signal_bw_tuner, callback=self.set_doppler_signal_bw_tuner, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_doppler_signal_bw_tuner_sizer, 2, 29, 1, 24) self.direction_vector_probe = blocks.probe_signal_vi(max_num_of_targets) _angle_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._angle_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, label="Angle of Approach of the Target (Deg)", converter=forms.float_converter(), proportion=0, ) self._angle_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, minimum=0, maximum=89, num_steps=890, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_angle_tuner_sizer, 1, 8, 1, 21) _RF_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._RF_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, label="Radar Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._RF_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, minimum=2.4e9, maximum=2.5e9, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_RF_tuner_sizer, 1, 0, 1, 8) self.wxgui_waterfallsink = waterfallsink2.waterfall_sink_c( self.notebook.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=100, average=False, avg_alpha=None, title="Time/Frequency CW Doppler Radar Receiver", win=window.blackmanharris, ) self.notebook.GetPage(1).Add(self.wxgui_waterfallsink.win) self.wxgui_fftsink2_full_spectrum = fftsink2.fft_sink_c( self.notebook.GetPage(2).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=4096, fft_rate=15, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver Full Spectrum", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(2).Add(self.wxgui_fftsink2_full_spectrum.win) self.wxgui_fftsink = fftsink2.fft_sink_c( self.notebook.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=100, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver ", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(0).Add(self.wxgui_fftsink.win) self.usrp_receiver = uhd.usrp_source( ",".join(('addr=192.168.10.3', "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.usrp_receiver.set_clock_source("external", 0) self.usrp_receiver.set_samp_rate(samp_rate) self.usrp_receiver.set_center_freq(uhd.tune_request(RF_tuner, lo_offset_freq), 0) self.usrp_receiver.set_gain(rx_gain_tuner, 0) self.usrp_receiver.set_antenna("J1", 0) _tx_amp_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._tx_amp_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, label="TX Signal Amp", converter=forms.float_converter(), proportion=0, ) self._tx_amp_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, minimum=0, maximum=1, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tx_amp_tuner_sizer, 0, 8, 1, 21) def _target_speed_vector_probe(): while True: val = self.speed_vector_probe.level() try: self.set_target_speed_vector(val) except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _target_speed_vector_thread = threading.Thread(target=_target_speed_vector_probe) _target_speed_vector_thread.daemon = True _target_speed_vector_thread.start() def _target_direction_vector_probe(): while True: val = self.direction_vector_probe.level() try: self.set_target_direction_vector(val) except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _target_direction_vector_thread = threading.Thread(target=_target_direction_vector_probe) _target_direction_vector_thread.daemon = True _target_direction_vector_thread.start() self._speed_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.speed_textbox, callback=self.set_speed_textbox, label="Targets Speed (Kph)", converter=forms.str_converter(), ) self.GridAdd(self._speed_textbox_text_box, 4, 0, 1, 53) self.rational_resampler = filter.rational_resampler_ccc( interpolation=1, decimation=int(samp_rate/samp_rate_sink), taps=None, fractional_bw=None, ) self._num_targets_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.num_targets_textbox, callback=self.set_num_targets_textbox, label="Number of Targets Detected", converter=forms.int_converter(), ) self.GridAdd(self._num_targets_textbox_text_box, 3, 0, 1, 4) self.num_targets_probe = blocks.probe_signal_i() def _num_targets_probe(): while True: val = self.num_targets_probe.level() try: self.set_num_targets(val) except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _num_targets_thread = threading.Thread(target=_num_targets_probe) _num_targets_thread.daemon = True _num_targets_thread.start() self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (window.blackmanharris(fft_len)), True, 1) self._direction_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.direction_textbox, callback=self.set_direction_textbox, label="Targets Direction", converter=forms.str_converter(), ) self.GridAdd(self._direction_textbox_text_box, 5, 0, 1, 53) self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len/2) self.cwradar_doppler_velocity_multiple_targets_ff_0 = cwradar.doppler_velocity_multiple_targets_ff(fft_len/2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_tuner, max_num_of_targets_tuner, doppler_signal_bw_tuner) self.complex_to_mag = blocks.complex_to_mag(fft_len) self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_len) self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_len) self.blocks_stream_to_vector_1_0 = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2) self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_len) self.blocks_keep_m_in_n_0_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, fft_len/2) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, 0) self.DC_filter_0 = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements))) self.DC_filter = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements))) ################################################## # Connections ################################################## self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0_0, 0)) self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.usrp_receiver, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.fft_vxx_0, 0), (self.complex_to_mag, 0)) self.connect((self.rational_resampler, 0), (self.wxgui_fftsink, 0)) self.connect((self.rational_resampler, 0), (self.wxgui_waterfallsink, 0)) self.connect((self.usrp_receiver, 0), (self.rational_resampler, 0)) self.connect((self.usrp_receiver, 0), (self.wxgui_fftsink2_full_spectrum, 0)) self.connect((self.DC_filter, 0), (self.cwradar_doppler_velocity_multiple_targets_ff_0, 0)) self.connect((self.DC_filter_0, 0), (self.cwradar_doppler_velocity_multiple_targets_ff_0, 1)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff_0, 2), (self.num_targets_probe, 0)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff_0, 1), (self.direction_vector_probe, 0)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff_0, 0), (self.speed_vector_probe, 0)) self.connect((self.blocks_vector_to_stream_0_0, 0), (self.blocks_keep_m_in_n_0_0, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_stream_to_vector_1, 0)) self.connect((self.blocks_keep_m_in_n_0_0, 0), (self.blocks_stream_to_vector_1_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_stream_to_vector_1_0, 0), (self.DC_filter_0, 0)) self.connect((self.blocks_stream_to_vector_1, 0), (self.cwradar_vector_flip_ff, 0)) self.connect((self.cwradar_vector_flip_ff, 0), (self.DC_filter, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.stop_freq = stop_freq = 180e6 self.step = step = 1000e3 self.start_freq = start_freq = 170e6 self.samp_rate = samp_rate = 1024e3 self.mag_probe = mag_probe = 0 self.decim = decim = 4 self.center_freq = center_freq = 175e6 self.adj_ch_weight = adj_ch_weight = 1 self.Run_DSA = Run_DSA = 'Run' ################################################## # Blocks ################################################## #self.mag = analog.probe_avg_mag_sqrd_c(0, 1) self.fft_probe = blocks.probe_signal_vf(1024) self._stop_freq_text_box = forms.text_box( parent=self.GetWin(), value=self.stop_freq, callback=self.set_stop_freq, label="Frequency Stop", converter=forms.float_converter(), ) self.GridAdd(self._stop_freq_text_box, 1, 2, 1, 1) self._step_text_box = forms.text_box( parent=self.GetWin(), value=self.step, callback=self.set_step, label="Frequency Step", converter=forms.float_converter(), ) self.GridAdd(self._step_text_box, 1, 3, 1, 1) self._start_freq_text_box = forms.text_box( parent=self.GetWin(), value=self.start_freq, callback=self.set_start_freq, label="Frequency Start", converter=forms.float_converter(), ) self.logpwrfft = logpwrfft.logpwrfft_c( sample_rate=samp_rate, fft_size=1024, ref_scale=2, frame_rate=30, avg_alpha=1, average=False, ) self.GridAdd(self._start_freq_text_box, 1, 1, 1, 1) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + 'rtl_tcp=192.168.2.12:1234' ) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(center_freq, 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) #def _mag_probe_probe(): # while True: # val = self.mag.level() # try: self.set_mag_probe(val) # except AttributeError, e: pass # time.sleep(1.0/(10)) #_mag_probe_thread = threading.Thread(target=_mag_probe_probe) #_mag_probe_thread.daemon = True #_mag_probe_thread.start() self._adj_ch_weight_text_box = forms.text_box( parent=self.GetWin(), value=self.adj_ch_weight, callback=self.set_adj_ch_weight, label="Adjacent Channel Weight", converter=forms.float_converter(), ) self.GridAdd(self._adj_ch_weight_text_box, 1, 4, 1, 1) self._Run_DSA_chooser = forms.button( parent=self.GetWin(), value=self.Run_DSA, callback=self.set_Run_DSA, label="DSA", choices=['Run'], labels=[], ) self.GridAdd(self._Run_DSA_chooser, 1, 0, 1, 1) ################################################## # Connections ################################################## self.connect((self.osmosdr_source_0, 0), (self.logpwrfft, 0)) self.connect((self.logpwrfft,0),(self.fft_probe,0))
def __init__(self, freq, rx_callback): gr.top_block.__init__(self) ################################################## # Variables ################################################## self.freq = freq self.samp_rate = 1e6 self.rxgain = 0 self.txgain = 0 self.freq_busy = 0 ################################################## # Blocks ################################################## self.txpath = transmit_path() self.rxpath = receive_path(rx_callback) self.uhd_usrp_sink = uhd.usrp_sink( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink.set_samp_rate(self.samp_rate) self.uhd_usrp_sink.set_center_freq(self.freq, 0) self.uhd_usrp_sink.set_gain(self.rxgain, 0) self.uhd_usrp_sink.set_antenna("J1", 0) self.uhd_usrp_source = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source.set_samp_rate(self.samp_rate) self.uhd_usrp_source.set_center_freq(self.freq, 0) self.uhd_usrp_source.set_gain(self.txgain, 0) self.uhd_usrp_source.set_antenna("J1", 0) # Frequency collision detection stuff self.blocks_probe_signal_vx_0 = blocks.probe_signal_vf(1024) self.fftshift_for_logpower_0 = fftshift_for_logpower(fft_size=1024, ) self.logpwrfft_x_4 = logpwrfft.logpwrfft_c( sample_rate=self.samp_rate, fft_size=1024, ref_scale=2, frame_rate=30, avg_alpha=1, average=True, ) self.blocks_vector_to_stream_2 = blocks.vector_to_stream( gr.sizeof_float * 1, 1024) self.blocks_threshold_ff_2 = blocks.threshold_ff(-60, -45, 0) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_float * 1, 1024) # Probe monitor thread routine def _variable_function_probe_0_probe(): while True: val = self.blocks_probe_signal_vx_0.level() self.busy = val[512] # print(self.busy) try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (10)) _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() ################################################## # Connections ################################################## # self.connect(self.uhd_usrp_source, self.rxpath) self.connect(self.uhd_usrp_source, self.rxpath) self.connect(self.uhd_usrp_source, self.logpwrfft_x_4, self.fftshift_for_logpower_0, self.blocks_vector_to_stream_2, self.blocks_threshold_ff_2, self.blocks_stream_to_vector_0, self.blocks_probe_signal_vx_0) self.connect(self.txpath, self.uhd_usrp_sink)
def __init__(self, angle=0, samp_rate=1e6, fft_len=pow(2,20), samp_rate_sink=8000, tx_amp=10e-3, max_num_of_targets=10, lowpass_cutoff_freq=1700, RF=2.49e9, speed_samp_rate=1, DC_filter_num_elements=4, threshold_dB=-70, rx_gain=0, highpass_cutoff_freq=0, doppler_signal_bw=20): grc_wxgui.top_block_gui.__init__(self, title="CW Doppler Radar Simulator Multiple Targets") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.angle = angle self.samp_rate = samp_rate self.fft_len = fft_len self.samp_rate_sink = samp_rate_sink self.tx_amp = tx_amp self.max_num_of_targets = max_num_of_targets self.lowpass_cutoff_freq = lowpass_cutoff_freq self.RF = RF self.speed_samp_rate = speed_samp_rate self.DC_filter_num_elements = DC_filter_num_elements self.threshold_dB = threshold_dB self.rx_gain = rx_gain self.highpass_cutoff_freq = highpass_cutoff_freq self.doppler_signal_bw = doppler_signal_bw ################################################## # Variables ################################################## self.target_speed_vector = target_speed_vector = 0 self.target_direction_vector = target_direction_vector = 0 self.num_targets = num_targets = 0 self.tx_amp_tuner = tx_amp_tuner = tx_amp self.threshold_dB_tuner = threshold_dB_tuner = threshold_dB self.speed_textbox = speed_textbox = target_speed_vector self.rx_gain_tuner = rx_gain_tuner = rx_gain self.num_targets_textbox = num_targets_textbox = num_targets self.max_num_of_targets_tuner = max_num_of_targets_tuner = max_num_of_targets self.lowpass_cutoff_freq_tuner = lowpass_cutoff_freq_tuner = lowpass_cutoff_freq self.highpass_cutoff_freq_tuner = highpass_cutoff_freq_tuner = highpass_cutoff_freq self.doppler_signal_bw_tuner = doppler_signal_bw_tuner = doppler_signal_bw self.doppler_freq_sim_tuner = doppler_freq_sim_tuner = 100 self.direction_textbox = direction_textbox = target_direction_vector self.angle_tuner = angle_tuner = angle self.RF_tuner = RF_tuner = RF ################################################## # Blocks ################################################## _tx_amp_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._tx_amp_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, label="TX Signal Amp", converter=forms.float_converter(), proportion=0, ) self._tx_amp_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, minimum=0, maximum=100e-3, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tx_amp_tuner_sizer, 0, 8, 1, 21) _threshold_dB_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_dB_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, label="Detected Target Threshold (dB)", converter=forms.float_converter(), proportion=0, ) self._threshold_dB_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, minimum=-90, maximum=-30, num_steps=60, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_threshold_dB_tuner_sizer, 2, 0, 1, 8) self.speed_vector_probe = blocks.probe_signal_vf(max_num_of_targets) self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Frequency/Time CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver Full Spectrum") self.GridAdd(self.notebook, 6, 0, 13, 53) _max_num_of_targets_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._max_num_of_targets_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_max_num_of_targets_tuner_sizer, value=self.max_num_of_targets_tuner, callback=self.set_max_num_of_targets_tuner, label="Maximum Number of Targets", converter=forms.int_converter(), proportion=0, ) self._max_num_of_targets_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_max_num_of_targets_tuner_sizer, value=self.max_num_of_targets_tuner, callback=self.set_max_num_of_targets_tuner, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.GridAdd(_max_num_of_targets_tuner_sizer, 2, 8, 1, 21) _lowpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._lowpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, label="Low-Pass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._lowpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, minimum=0, maximum=3000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_lowpass_cutoff_freq_tuner_sizer, 1, 29, 1, 24) _highpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._highpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, label="High-Pass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._highpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, minimum=0, maximum=1600, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_highpass_cutoff_freq_tuner_sizer, 0, 29, 1, 24) _doppler_signal_bw_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._doppler_signal_bw_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_doppler_signal_bw_tuner_sizer, value=self.doppler_signal_bw_tuner, callback=self.set_doppler_signal_bw_tuner, label="Doppler Spectrum Bandwidth (Hz)", converter=forms.float_converter(), proportion=0, ) self._doppler_signal_bw_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_doppler_signal_bw_tuner_sizer, value=self.doppler_signal_bw_tuner, callback=self.set_doppler_signal_bw_tuner, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_doppler_signal_bw_tuner_sizer, 2, 29, 1, 24) _doppler_freq_sim_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._doppler_freq_sim_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_doppler_freq_sim_tuner_sizer, value=self.doppler_freq_sim_tuner, callback=self.set_doppler_freq_sim_tuner, label="Doppler Frequency Simulator (Hz)", converter=forms.float_converter(), proportion=0, ) self._doppler_freq_sim_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_doppler_freq_sim_tuner_sizer, value=self.doppler_freq_sim_tuner, callback=self.set_doppler_freq_sim_tuner, minimum=-2000, maximum=2000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_doppler_freq_sim_tuner_sizer, 3, 29, 1, 24) self.direction_vector_probe = blocks.probe_signal_vi(max_num_of_targets) _angle_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._angle_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, label="Angle of Approach of the Target (Deg)", converter=forms.float_converter(), proportion=0, ) self._angle_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, minimum=0, maximum=89, num_steps=890, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_angle_tuner_sizer, 1, 8, 1, 21) _RF_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._RF_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, label="Radar Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._RF_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, minimum=2.4e9, maximum=2.5e9, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_RF_tuner_sizer, 1, 0, 1, 8) self.wxgui_waterfallsink2_time_frequency = waterfallsink2.waterfall_sink_c( self.notebook.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=15, average=True, avg_alpha=None, title="Time/Frequency CW Doppler Radar Receiver", win=window.blackmanharris, ) self.notebook.GetPage(1).Add(self.wxgui_waterfallsink2_time_frequency.win) self.wxgui_fftsink2_full_spectrum = fftsink2.fft_sink_c( self.notebook.GetPage(2).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=4096, fft_rate=15, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver Full Spectrum", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(2).Add(self.wxgui_fftsink2_full_spectrum.win) self.wxgui_fftsink2 = fftsink2.fft_sink_c( self.notebook.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver ", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(0).Add(self.wxgui_fftsink2.win) self.vector_to_stream_positive = blocks.vector_to_stream(gr.sizeof_float*1, fft_len) self.vector_to_stream_negative = blocks.vector_to_stream(gr.sizeof_float*1, fft_len) self.tx_signal = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 0, 1, 0) self.throtle_block = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) def _target_speed_vector_probe(): while True: val = self.speed_vector_probe.level() try: ######################################################## #Code to tranlate the vector of speeds to strings: speed = "" if val[0] == 0: #if the value is 0 there is no target in sight. speed = "No Target Detected" elif val[0] != 0: for i in range(len(val)): if val[i] != 0: speed = speed + "Target " + str(i+1) + ": " + str(round(val[i],2)) + " Kph\t" self.set_target_speed_vector(speed) ######################################################## except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _target_speed_vector_thread = threading.Thread(target=_target_speed_vector_probe) _target_speed_vector_thread.daemon = True _target_speed_vector_thread.start() def _target_direction_vector_probe(): while True: val = self.direction_vector_probe.level() try: ######################################################## #Code to tranlate the vector of directions to strings: direction = "" if val[0] == 0: direction = "No Target Detected" elif val[0] != 0: #if the value is 0 there is no target in sight. for i in range(len(val)): if val[i] == 1: #if the value is 1 the target is approaching. direction = direction + "Target " + str(i+1) + ": " + "Approaching\t" elif val[i] == 2: #if the value is 2 the target is receding. direction = direction + "Target " + str(i+1) + ": " + "Receding\t" self.set_target_direction_vector(direction) ######################################################## except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _target_direction_vector_thread = threading.Thread(target=_target_direction_vector_probe) _target_direction_vector_thread.daemon = True _target_direction_vector_thread.start() self.stream_to_vector_positive = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2) self.stream_to_vector_negative = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2) self.stream_to_vector_for_fft = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_len) self._speed_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.speed_textbox, callback=self.set_speed_textbox, label="Targets Speed (Kph)", converter=forms.str_converter(), ) self.GridAdd(self._speed_textbox_text_box, 4, 0, 1, 53) self.rx_signal_2 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, doppler_freq_sim_tuner+15, tx_amp_tuner-5e-3, 0) self.rx_signal_1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, doppler_freq_sim_tuner-1300, tx_amp+10e-3, 0) self.rx_signal_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, doppler_freq_sim_tuner, tx_amp_tuner, 0) _rx_gain_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, label="USRP RX Gain (dB)", converter=forms.float_converter(), proportion=0, ) self._rx_gain_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, minimum=0, maximum=70, num_steps=70, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rx_gain_tuner_sizer, 0, 0, 1, 8) self.rational_resampler = filter.rational_resampler_ccc( interpolation=1, decimation=int(samp_rate/samp_rate_sink), taps=None, fractional_bw=None, ) self._num_targets_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.num_targets_textbox, callback=self.set_num_targets_textbox, label="Number of Targets Detected", converter=forms.int_converter(), ) self.GridAdd(self._num_targets_textbox_text_box, 3, 0, 1, 4) self.num_targets_probe = blocks.probe_signal_i() def _num_targets_probe(): while True: val = self.num_targets_probe.level() try: self.set_num_targets(val) except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _num_targets_thread = threading.Thread(target=_num_targets_probe) _num_targets_thread.daemon = True _num_targets_thread.start() self.mixer = blocks.multiply_vcc(1) self.keep_m_in_n_positive = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, fft_len/2) self.keep_m_in_n_negative = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, 0) self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (window.blackmanharris(fft_len)), True, 1) self._direction_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.direction_textbox, callback=self.set_direction_textbox, label="Targets Direction", converter=forms.str_converter(), ) self.GridAdd(self._direction_textbox_text_box, 5, 0, 1, 53) self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len/2) self.cwradar_doppler_velocity_multiple_targets_ff = cwradar.doppler_velocity_multiple_targets_ff(fft_len/2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_tuner, max_num_of_targets_tuner, doppler_signal_bw_tuner) self.blocks_complex_to_mag = blocks.complex_to_mag(fft_len) self.awgn_channel_simulator = analog.noise_source_c(analog.GR_GAUSSIAN, 1e-3, 0) self.adder_2 = blocks.add_vcc(1) self.adder_1 = blocks.add_vcc(1) self.DC_filter_positive = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements))) self.DC_filter_negative = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements))) ################################################## # Connections ################################################## self.connect((self.DC_filter_negative, 0), (self.cwradar_doppler_velocity_multiple_targets_ff, 0)) self.connect((self.DC_filter_positive, 0), (self.cwradar_doppler_velocity_multiple_targets_ff, 1)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff, 2), (self.num_targets_probe, 0)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff, 1), (self.direction_vector_probe, 0)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff, 0), (self.speed_vector_probe, 0)) self.connect((self.awgn_channel_simulator, 0), (self.adder_2, 0)) self.connect((self.tx_signal, 0), (self.adder_2, 1)) self.connect((self.adder_2, 0), (self.mixer, 0)) self.connect((self.awgn_channel_simulator, 0), (self.adder_1, 0)) self.connect((self.mixer, 0), (self.throtle_block, 0)) self.connect((self.mixer, 0), (self.stream_to_vector_for_fft, 0)) self.connect((self.throtle_block, 0), (self.wxgui_fftsink2_full_spectrum, 0)) self.connect((self.throtle_block, 0), (self.rational_resampler, 0)) self.connect((self.adder_1, 0), (self.mixer, 1)) self.connect((self.rational_resampler, 0), (self.wxgui_waterfallsink2_time_frequency, 0)) self.connect((self.stream_to_vector_for_fft, 0), (self.fft_vxx_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag, 0)) self.connect((self.blocks_complex_to_mag, 0), (self.vector_to_stream_negative, 0)) self.connect((self.blocks_complex_to_mag, 0), (self.vector_to_stream_positive, 0)) self.connect((self.vector_to_stream_positive, 0), (self.keep_m_in_n_positive, 0)) self.connect((self.keep_m_in_n_negative, 0), (self.stream_to_vector_negative, 0)) self.connect((self.keep_m_in_n_positive, 0), (self.stream_to_vector_positive, 0)) self.connect((self.vector_to_stream_negative, 0), (self.keep_m_in_n_negative, 0)) self.connect((self.stream_to_vector_positive, 0), (self.DC_filter_positive, 0)) self.connect((self.stream_to_vector_negative, 0), (self.cwradar_vector_flip_ff, 0)) self.connect((self.cwradar_vector_flip_ff, 0), (self.DC_filter_negative, 0)) self.connect((self.rx_signal_1, 0), (self.adder_1, 3)) self.connect((self.rx_signal_0, 0), (self.adder_1, 2)) self.connect((self.tx_signal, 0), (self.adder_1, 1)) self.connect((self.rx_signal_2, 0), (self.adder_1, 4)) self.connect((self.rational_resampler, 0), (self.wxgui_fftsink2, 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.samp_rate = samp_rate = 15e6 self.integration_bandwidth = integration_bandwidth = 2.5e3 self.if_bandwidth_2 = if_bandwidth_2 = .75e6 self.dec_rate_1 = dec_rate_1 = 5 self.samp_rate_2 = samp_rate_2 = samp_rate / dec_rate_1 self.num_channels = num_channels = int(if_bandwidth_2 / integration_bandwidth) self.samp_rate_3 = samp_rate_3 = samp_rate_2 / num_channels self.integration_time = integration_time = .5 self.variable_function_probe = variable_function_probe = 0 self.output_samp_rate = output_samp_rate = 1.0 / integration_time self.integration_dec_rate = integration_dec_rate = int( integration_time * samp_rate_3 / 2) self.if_bandwidth_0 = if_bandwidth_0 = 4.5e6 self.gain = gain = 60 self.freq = freq = 1.4204e9 self.channel_map = channel_map = range( int(num_channels / 2.0 + 1.0), num_channels, 1) + range( 0, int(num_channels / 2.0 + 1.0), 1) ################################################## # Blocks ################################################## self.probe_signal = blocks.probe_signal_vf(num_channels) self._gain_range = Range(0, 70, 1, 60, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, "gain", "counter_slider", int) self.top_layout.addWidget(self._gain_win) def _variable_function_probe_probe(): while True: val = self.probe_signal.level() try: self.set_variable_function_probe(val) except AttributeError: pass pytime.sleep(1.0 / (10)) _variable_function_probe_thread = threading.Thread( target=_variable_function_probe_probe) _variable_function_probe_thread.daemon = True _variable_function_probe_thread.start() self.pfb_channelizer_ccf_0 = pfb.channelizer_ccf( num_channels, (firdes.low_pass(1, samp_rate_2, integration_bandwidth, 250, firdes.WIN_HAMMING)), 1.0, 0) self.pfb_channelizer_ccf_0.set_channel_map((channel_map)) self.pfb_channelizer_ccf_0.declare_sample_delay(0) self.low_pass_filter_1 = filter.fir_filter_ccf( dec_rate_1, firdes.low_pass(10, samp_rate, if_bandwidth_2, 1e5, firdes.WIN_HAMMING, 6.76)) self.limesdr_source_2 = limesdr.source('0009072C02873717', 2, 1, 0, 0, '', freq - 800e3, samp_rate, 0, 1, 15e6, 0, 10e6, 3, 2, 2, 1, if_bandwidth_0, 1, 5e6, 1, if_bandwidth_0, 0, 0, gain, 30, 0, 0, 0, 0) self.blocks_streams_to_vector_0 = blocks.streams_to_vector( gr.sizeof_gr_complex * 1, num_channels) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_integrate_xx_0_0 = blocks.integrate_ff( integration_dec_rate, num_channels) self.blocks_file_sink_0 = blocks.file_sink( gr.sizeof_gr_complex * 1, '/home/w1xm-admin/Documents/DSP/data_out/recieve_block_sink', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_copy_0_0 = blocks.copy(gr.sizeof_gr_complex * 1) self.blocks_copy_0_0.set_enabled(False) self.blocks_copy_0 = blocks.copy(gr.sizeof_gr_complex * 1) self.blocks_copy_0.set_enabled(True) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( num_channels) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_SIN_WAVE, -800e3, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_copy_0, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.blocks_copy_0_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.probe_signal, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.low_pass_filter_1, 0)) self.connect((self.blocks_streams_to_vector_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.limesdr_source_2, 0), (self.blocks_copy_0, 0)) self.connect((self.limesdr_source_2, 0), (self.blocks_copy_0_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.pfb_channelizer_ccf_0, 0)) for i in range(num_channels): self.connect((self.pfb_channelizer_ccf_0, i), (self.blocks_streams_to_vector_0, i))
def __init__(self): gr.top_block.__init__(self, "RX logic") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 192000 self.mode = mode = 2 self.bw = bw = 3200 self.aud_rate = aud_rate = 22050 self.visualsq = visualsq = 1 self.st = st = 1 self.sq = sq = -700 self.sb_pos = sb_pos = ((bw*mode==2)-(bw*mode==3)) self.rec = rec = 1 self.laj_0 = laj_0 = 0 self.laj = laj = 0 self.lai_0 = lai_0 = 0 self.lai = lai = 0 self.freq = freq = 98500000 self.device = device = "fcd=0,type=2" self.dev = dev = 19000 self.decimation = decimation = samp_rate/aud_rate self.batswitch = batswitch = 0 self.batido = batido = 2950 self.VEC = VEC = 1280 ################################################## # Blocks ################################################## self.rtlsdr_source_0 = osmosdr.source( args="nchan=" + str(1) + " " + device ) 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(7, 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(14, 0) self.rtlsdr_source_0.set_if_gain(14, 0) self.rtlsdr_source_0.set_bb_gain(14, 0) self.rtlsdr_source_0.set_antenna("", 0) self.rtlsdr_source_0.set_bandwidth(0, 0) self.probe_st = analog.probe_avg_mag_sqrd_f(10, 1) self.low_pass_filter_0_2 = filter.fir_filter_ccf(decimation, firdes.low_pass( 1, samp_rate, bw*(2+(mode==2)+(mode==3)), 500, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_1_0_0_0 = filter.fir_filter_fff(1, firdes.low_pass( 1, samp_rate, 14000, 1000, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_1 = filter.fir_filter_fff(1, firdes.low_pass( 30, samp_rate, 14000, 1000, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_0_0_0 = filter.interp_fir_filter_fff(1, firdes.low_pass( visualsq, samp_rate/decimation, bw, 10, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_0_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate/decimation, bw, 10, firdes.WIN_HAMMING, 6.76)) self.high_pass_filter_0 = filter.fir_filter_ccf(1, firdes.high_pass( 1, samp_rate/decimation, bw, 10, firdes.WIN_HAMMING, 6.76)) self.fractional_resampler_xx_0_0_0 = filter.fractional_resampler_ff(0, samp_rate/48000.0) self.fractional_resampler_xx_0_0 = filter.fractional_resampler_ff(0, samp_rate/48000.0) self.fractional_resampler_xx_0 = filter.fractional_resampler_ff(0, (samp_rate/decimation)/48000.0) self.fft_vxx_0 = fft.fft_vcc(VEC, True, (window.blackmanharris(1024)), True, 1) self.fft_probe = blocks.probe_signal_vf(VEC) self.blocks_wavfile_sink_0 = blocks.wavfile_sink("/tmp/CAPTURE.WAV", 2, 48000, 16) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, VEC) self.blocks_multiply_xx_0_1_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_complex_to_real_0_0_0_0 = blocks.complex_to_real(1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(VEC) self.blocks_add_xx_0 = blocks.add_vff(1) self.blocks_add_const_vxx_0 = blocks.add_const_vcc((-complex(lai,laj), )) self.blks2_valve_0_1 = grc_blks2.valve(item_size=gr.sizeof_float*1, open=bool(rec)) self.blks2_valve_0_0_1 = grc_blks2.valve(item_size=gr.sizeof_gr_complex*1, open=bool(mode!=5)) self.blks2_valve_0_0_0 = grc_blks2.valve(item_size=gr.sizeof_gr_complex*1, open=bool(0)) self.blks2_valve_0_0 = grc_blks2.valve(item_size=gr.sizeof_gr_complex*1, open=bool(mode!=4)) self.blks2_valve_0 = grc_blks2.valve(item_size=gr.sizeof_float*1, open=bool(rec)) self.blks2_selector_0_1_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex*1, num_inputs=2, num_outputs=1, input_index=(mode==3), output_index=0, ) self.blks2_selector_0_0_1_0 = grc_blks2.selector( item_size=gr.sizeof_float*1, num_inputs=3, num_outputs=1, input_index=(mode>3)+(mode>4), output_index=0, ) self.blks2_selector_0_0_1 = grc_blks2.selector( item_size=gr.sizeof_float*1, num_inputs=3, num_outputs=1, input_index=(mode>3)+(mode>4), output_index=0, ) self.blks2_selector_0_0 = grc_blks2.selector( item_size=gr.sizeof_float*1, num_inputs=4, num_outputs=1, input_index=mode, output_index=0, ) self.blks2_selector_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex*1, num_inputs=1, num_outputs=4, input_index=0, output_index=mode, ) self.band_pass_filter_0_0_0 = filter.fir_filter_fff(1, firdes.band_pass( 250, samp_rate, 18500, 19500, 500, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0_0 = filter.fir_filter_fff(1, firdes.band_pass( 120, samp_rate, 24000, 52000, 1000, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0 = audio.sink(48000, "dmix:CARD=Pro,DEV=0", False) self.analog_wfm_rcv_1 = analog.wfm_rcv( quad_rate=samp_rate, audio_decimation=1, ) self.analog_sig_source_x_0_0_0 = analog.sig_source_c(samp_rate/decimation, analog.GR_COS_WAVE, -bw, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, dev+(bw*mode==2)+(bw*mode==3), 1, 0) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(0.25) self.analog_fm_demod_cf_0 = analog.fm_demod_cf( channel_rate=samp_rate, audio_decim=samp_rate/48000, deviation=50000, audio_pass=15000, audio_stop=16000, gain=3.0, tau=50e-6, ) self.analog_fm_deemph_0_0 = analog.fm_deemph(fs=48000, tau=50e-6) self.analog_fm_deemph_0 = analog.fm_deemph(fs=48000, tau=50e-6) self.analog_feedforward_agc_cc_0 = analog.feedforward_agc_cc(64, 0.9) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=samp_rate/decimation, audio_decim=samp_rate/decimation/aud_rate, audio_pass=(samp_rate/decimation/2)-500, audio_stop=(samp_rate/decimation/2)-100, ) self.analog_agc3_xx_0 = analog.agc3_cc(0.0001, 0.0001, 0.9, 0.1) self.analog_agc3_xx_0.set_max_gain(200) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.fft_probe, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blks2_valve_0_0_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blks2_valve_0_0, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.blocks_multiply_xx_0_1_0, 0)) self.connect((self.low_pass_filter_0_1, 0), (self.analog_fm_deemph_0, 0)) self.connect((self.analog_fm_deemph_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.analog_wfm_rcv_1, 0), (self.low_pass_filter_0_1, 0)) self.connect((self.analog_wfm_rcv_1, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.analog_wfm_rcv_1, 0), (self.band_pass_filter_0_0_0, 0)) self.connect((self.analog_fm_deemph_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.low_pass_filter_0_1_0_0_0, 0), (self.analog_fm_deemph_0_0, 0)) self.connect((self.analog_agc3_xx_0, 0), (self.analog_wfm_rcv_1, 0)) self.connect((self.blks2_valve_0_0_1, 0), (self.analog_agc3_xx_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blks2_valve_0_0_1, 0)) self.connect((self.blocks_multiply_xx_0_1_0, 0), (self.low_pass_filter_0_1_0_0_0, 0)) self.connect((self.band_pass_filter_0_0_0, 0), (self.blocks_multiply_xx_0_1_0, 1)) self.connect((self.band_pass_filter_0_0_0, 0), (self.blocks_multiply_xx_0_1_0, 2)) self.connect((self.analog_fm_deemph_0_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.analog_fm_deemph_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.fractional_resampler_xx_0_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.fractional_resampler_xx_0_0, 0)) self.connect((self.blks2_valve_0_0, 0), (self.analog_fm_demod_cf_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blks2_valve_0_0_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0_2, 0)) self.connect((self.blocks_complex_to_real_0_0_0_0, 0), (self.blks2_selector_0_0, 3)) self.connect((self.blocks_complex_to_real_0_0_0_0, 0), (self.blks2_selector_0_0, 2)) self.connect((self.blks2_selector_0_1_0, 0), (self.blocks_multiply_xx_0_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0, 0), (self.blocks_complex_to_real_0_0_0_0, 0)) self.connect((self.analog_sig_source_x_0_0_0, 0), (self.blocks_multiply_xx_0_0_0, 1)) self.connect((self.analog_am_demod_cf_0, 0), (self.blks2_selector_0_0, 0)) self.connect((self.blks2_selector_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.blks2_selector_0_0, 1)) self.connect((self.blks2_selector_0, 1), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.blks2_selector_0_0, 0), (self.low_pass_filter_0_0_0_0, 0)) self.connect((self.blks2_selector_0, 2), (self.high_pass_filter_0, 0)) self.connect((self.blks2_selector_0, 3), (self.low_pass_filter_0_0_0, 0)) self.connect((self.high_pass_filter_0, 0), (self.blks2_selector_0_1_0, 0)) self.connect((self.low_pass_filter_0_0_0, 0), (self.blks2_selector_0_1_0, 1)) self.connect((self.analog_fm_demod_cf_0, 0), (self.blks2_selector_0_0_1, 1)) self.connect((self.analog_fm_demod_cf_0, 0), (self.blks2_selector_0_0_1_0, 1)) self.connect((self.fractional_resampler_xx_0_0_0, 0), (self.blks2_selector_0_0_1_0, 2)) self.connect((self.fractional_resampler_xx_0_0, 0), (self.blks2_selector_0_0_1, 2)) self.connect((self.blks2_selector_0_0_1_0, 0), (self.audio_sink_0, 1)) self.connect((self.blks2_selector_0_0_1, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_valve_0, 0), (self.blocks_wavfile_sink_0, 1)) self.connect((self.blks2_selector_0_0_1_0, 0), (self.blks2_valve_0, 0)) self.connect((self.blks2_selector_0_0_1, 0), (self.blks2_valve_0_1, 0)) self.connect((self.blks2_valve_0_1, 0), (self.blocks_wavfile_sink_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.blks2_selector_0_0_1_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.blks2_selector_0_0_1, 0)) self.connect((self.low_pass_filter_0_2, 0), (self.analog_feedforward_agc_cc_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.low_pass_filter_0_0_0_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.analog_feedforward_agc_cc_0, 0), (self.blks2_selector_0, 0)) self.connect((self.band_pass_filter_0_0_0, 0), (self.probe_st, 0))
def __init__(self): gr.top_block.__init__(self, "Wideband Excite") ################################################## # Variables ################################################## self.variable_function_probe_0 = variable_function_probe_0 = 0 self.tx_freq = tx_freq = 1.3e9 self.samp_rate = samp_rate = 10e6 self.rx_freq = rx_freq = 2.6e9 self.fft_size = fft_size = 2**12 ################################################## # Blocks ################################################## self.probe_peak = blocks.probe_signal_vf(fft_size) def _variable_function_probe_0_probe(): while True: val = self.probe_peak.level() try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (10)) _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.peak_hold = peak_hold.blk() self.osmosdr_source_0_0 = osmosdr.source(args="numchan=" + str(1) + " " + 'bladerf=0') self.osmosdr_source_0_0.set_sample_rate(samp_rate) self.osmosdr_source_0_0.set_center_freq(rx_freq, 0) self.osmosdr_source_0_0.set_freq_corr(0, 0) self.osmosdr_source_0_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0_0.set_gain_mode(False, 0) self.osmosdr_source_0_0.set_gain(10, 0) self.osmosdr_source_0_0.set_if_gain(20, 0) self.osmosdr_source_0_0.set_bb_gain(20, 0) self.osmosdr_source_0_0.set_antenna('', 0) self.osmosdr_source_0_0.set_bandwidth(0, 0) self.osmosdr_sink_0_0 = osmosdr.sink(args="numchan=" + str(1) + " " + 'bladerf=0') self.osmosdr_sink_0_0.set_sample_rate(samp_rate) self.osmosdr_sink_0_0.set_center_freq(tx_freq, 0) self.osmosdr_sink_0_0.set_freq_corr(0, 0) self.osmosdr_sink_0_0.set_gain(10, 0) self.osmosdr_sink_0_0.set_if_gain(20, 0) self.osmosdr_sink_0_0.set_bb_gain(20, 0) self.osmosdr_sink_0_0.set_antenna('', 0) self.osmosdr_sink_0_0.set_bandwidth(0, 0) self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.blackmanharris(fft_size)), True, 2) self.divide_by_n = divide_by_n.blk(divisor=4096) self.dc_blocker_xx_0 = filter.dc_blocker_cc(512, True) self.blocks_vco_c_0 = blocks.vco_c(samp_rate, 2 * pi * 5e6, .3) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, fft_size, -30) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( fft_size) self.analog_sig_source_x_0_0 = analog.sig_source_f( samp_rate, analog.GR_SAW_WAVE, .5, 1, -.5) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_vco_c_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.divide_by_n, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.peak_hold, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_vco_c_0, 0), (self.osmosdr_sink_0_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.divide_by_n, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.osmosdr_source_0_0, 0), (self.dc_blocker_xx_0, 0)) self.connect((self.peak_hold, 0), (self.probe_peak, 0))
def __init__(self, ask_samp_rate=4E6, num_demod=4, type_demod=0, hw_args="uhd", freq_correction=0, record=True): # Call the initialization method from the parent class gr.top_block.__init__(self, "Receiver") # Default values self.center_freq = 144E6 self.gain_db = 10 self.squelch_db = -70 self.volume_db = 0 audio_rate = 8000 # Setup the USRP source, or use the USRP sim self.src = osmosdr.source(args="numchan=" + str(1) + " " + hw_args) self.src.set_sample_rate(ask_samp_rate) self.src.set_gain(self.gain_db) self.src.set_center_freq(self.center_freq) self.src.set_freq_corr(freq_correction) # Get the sample rate and center frequency from the hardware self.samp_rate = self.src.get_sample_rate() self.center_freq = self.src.get_center_freq() # Set the I/Q bandwidth to 80 % of sample rate self.src.set_bandwidth(0.8 * self.samp_rate) # NBFM channel is about 10 KHz wide # Want about 3 FFT bins to span a channel # Use length FFT so 4 Msps / 1024 = 3906.25 Hz/bin # This also means 3906.25 vectors/second # Using below formula keeps FFT size a power of two # Also keeps bin size constant for power of two sampling rates # Use of 256 sets 3906.25 Hz/bin; increase to reduce bin size samp_ratio = self.samp_rate / 1E6 fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio)/np.log(2)))) # -----------Flow for FFT-------------- # Convert USRP steam to vector stream_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_length) # Want about 1000 vector/sec amount = int(round(self.samp_rate/fft_length/1000)) keep_one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex* fft_length, amount) # Take FFT fft_vcc = fft.fft_vcc(fft_length, True, window.blackmanharris(fft_length), True, 1) # Compute the power complex_to_mag_squared = blocks.complex_to_mag_squared(fft_length) # Video average and decimate from 1000 vector/sec to 10 vector/sec integrate_ff = blocks.integrate_ff(100, fft_length) # Probe vector self.probe_signal_vf = blocks.probe_signal_vf(fft_length) # Connect the blocks self.connect(self.src, stream_to_vector, keep_one_in_n, fft_vcc, complex_to_mag_squared, integrate_ff, self.probe_signal_vf) # -----------Flow for Demod-------------- # Create N parallel demodulators as a list of objects # Default to NBFM demod self.demodulators = [] for idx in range(num_demod): if type_demod == 1: self.demodulators.append(TunerDemodAM(self.samp_rate, audio_rate, record)) else: self.demodulators.append(TunerDemodNBFM(self.samp_rate, audio_rate, record)) # Create an adder add_ff = blocks.add_ff(1) # Connect the demodulators between the source and adder for idx, demodulator in enumerate(self.demodulators): self.connect(self.src, demodulator, (add_ff, idx)) # Audio sink audio_sink = audio.sink(audio_rate) # Connect the blocks for the demod self.connect(add_ff, audio_sink)
def __init__(self): gr.top_block.__init__(self, "Ham2Mon NBFM Receiver Flow Example") Qt.QWidget.__init__(self) self.setWindowTitle("Ham2Mon NBFM Receiver Flow Example") 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", "nbfm_flow_example") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1E6 self.initial_decim = initial_decim = 5 self.samp_ratio = samp_ratio = samp_rate/1E6 self.final_rate = final_rate = samp_rate/initial_decim**2/int(samp_rate/1E6) self.variable_low_pass_filter_taps_2 = variable_low_pass_filter_taps_2 = firdes.low_pass(1.0, final_rate, 3500, 500, firdes.WIN_HAMMING, 6.76) self.variable_low_pass_filter_taps_1 = variable_low_pass_filter_taps_1 = firdes.low_pass(1.0, samp_rate/25, 12.5E3, 1E3, firdes.WIN_HAMMING, 6.76) self.variable_low_pass_filter_taps_0 = variable_low_pass_filter_taps_0 = firdes.low_pass(1.0, 1, 0.090, 0.010, firdes.WIN_HAMMING, 6.76) self.squelch_dB = squelch_dB = -70 self.gain_db = gain_db = 30 self.final_decim = final_decim = int(samp_rate/1E6) self.file_name = file_name = "test.wav" self.fft_length = fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio)/np.log(2)))) self.demod_bb_freq = demod_bb_freq = 390E3 self.center_freq = center_freq = 144E6 ################################################## # Blocks ################################################## self._squelch_dB_range = Range(-100, 0, 5, -70, 200) self._squelch_dB_win = RangeWidget(self._squelch_dB_range, self.set_squelch_dB, "Squelch (dB)", "counter_slider", float) self.top_grid_layout.addWidget(self._squelch_dB_win, 5,1,1,3) self._gain_db_range = Range(0, 70, 1, 30, 200) self._gain_db_win = RangeWidget(self._gain_db_range, self.set_gain_db, "HW Gain (dB)", "counter_slider", float) self.top_grid_layout.addWidget(self._gain_db_win, 4,1,1,3) self._demod_bb_freq_range = Range(-samp_rate/2, samp_rate/2, 5E3, 390E3, 200) self._demod_bb_freq_win = RangeWidget(self._demod_bb_freq_range, self.set_demod_bb_freq, "Demod BB Freq (Hz)", "counter_slider", float) self.top_grid_layout.addWidget(self._demod_bb_freq_win, 3,1,1,3) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( fft_length, #size samp_rate, #samp_rate "Averaged Spectrum", #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(-60, 40) self.qtgui_time_sink_x_0.set_y_label("Power", "") 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_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", "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(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) 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, 0,1,3,1) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc final_rate, #bw "Decimated Channel", #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(-200, -60) 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_control_panel(False) if not True: self.qtgui_freq_sink_x_0_0.disable_legend() if complex == type(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, 3,0,3,1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( fft_length, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 144E6, #fc samp_rate, #bw "Spectrum", #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(-120, -20) 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_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if complex == type(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, 0,0,3,1) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_fff( 16E3/float(final_rate/5), taps=None, flt_size=32) self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "uhd" ) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(center_freq, 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(gain_db, 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(samp_rate*0.8, 0) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(initial_decim, (variable_low_pass_filter_taps_0), demod_bb_freq, samp_rate) self.fir_filter_xxx_0_1 = filter.fir_filter_fff(initial_decim, (variable_low_pass_filter_taps_0)) self.fir_filter_xxx_0_1.declare_sample_delay(0) self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(int(samp_rate/1E6), (variable_low_pass_filter_taps_0)) self.fir_filter_xxx_0_0.declare_sample_delay(0) self.fir_filter_xxx_0 = filter.fir_filter_ccc(initial_decim, (variable_low_pass_filter_taps_0)) self.fir_filter_xxx_0.declare_sample_delay(0) self.fft_vxx_0 = fft.fft_vcc(fft_length, True, (window.blackmanharris(fft_length)), True, 1) self.blocks_wavfile_sink_0 = blocks.wavfile_sink(file_name, 1, 16000, 8) self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_length) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_length) self.blocks_probe_signal_vx_0 = blocks.probe_signal_vf(fft_length) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, fft_length, 0) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_gr_complex*fft_length, int(round(samp_rate/fft_length/1000))) self.blocks_integrate_xx_0 = blocks.integrate_ff(100, fft_length) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_length) self.audio_sink_0 = audio.sink(16000, "", True) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(0.050) self.analog_pwr_squelch_xx_0_0 = analog.pwr_squelch_ff(-200, 0.1, 0, True) self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc(squelch_dB, 0.1, 0, False) ################################################## # Connections ################################################## self.connect((self.analog_pwr_squelch_xx_0, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.analog_pwr_squelch_xx_0_0, 0), (self.blocks_wavfile_sink_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.fir_filter_xxx_0_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_probe_signal_vx_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.fir_filter_xxx_0_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.analog_pwr_squelch_xx_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.fir_filter_xxx_0_1, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.analog_pwr_squelch_xx_0_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.audio_sink_0, 0))
def __init__(self, fliter_base, intep_deci, auto_gain, samp_rate, cutoff_freq, trans_width, window, beta, dtype): """ Args: [TODO]: complete args docstring. """ self.gain_ratio = auto_gain self.lp_gain = np.float64(1) self.samp_rate = samp_rate self.cutoff_freq = cutoff_freq self.trans_width = trans_width self.window = window self.beta = beta self.amp_gain = None self.filter = fliter_base( intep_deci, firdes.low_pass(self.lp_gain, samp_rate, cutoff_freq, trans_width, window, beta)) if str(dtype) == "<type 'complex'>": gr.log.info("init auto gain low pass filter with complex type") self.samp_vector = blocks.stream_to_vector(gr.sizeof_gr_complex, 1024) self.samp_prob = blocks.probe_signal_vc(1024) else: gr.log.info("init auto gain low pass filter with float type") self.samp_vector = blocks.stream_to_vector(gr.sizeof_float, 1024) self.samp_prob = blocks.probe_signal_vf(1024) gr.hier_block2.__init__( self, "rational_resampler", gr.io_signature( 1, 1, self.filter.input_signature().sizeof_stream_item(0)), gr.io_signature( 1, 1, self.filter.output_signature().sizeof_stream_item(0))) def _auto_gain_function_probe(): while True: try: val = self.samp_prob.level() val = np.abs(np.array(val)) amp_pp = max(val) if amp_pp > 0: if self.amp_gain is None: self.amp_gain = (self.gain_ratio / amp_pp) if abs(self.gain_ratio / amp_pp - 1) > 0.2: self.amp_gain += (self.gain_ratio / amp_pp - 1) * self.amp_gain # gr.log.info('current gain:%f, target: %f.'%(self.get_lp_gain(), self.amp_gain)) self.set_lp_gain(self.amp_gain) # print(amp_pp) # print(amp_pp/0.5) except AttributeError: pass time.sleep(1.0 / (100)) _auto_gain_function_thread = threading.Thread( target=_auto_gain_function_probe) _auto_gain_function_thread.daemon = True _auto_gain_function_thread.start() # connections self.connect((self.filter, 0), (self.samp_vector, 0)) self.connect((self.samp_vector, 0), (self.samp_prob, 0)) self.connect(self, self.filter, self)
def __init__(self): gr.top_block.__init__(self) self.sample_rate = 3000 self.ampl = 1 self.freq = 1900 self.cen_freq = 0 self.counter = 0 # --- Sources ---- self.src0 = analog.sig_source_f(self.sample_rate, analog.GR_COS_WAVE, self.freq, 1, 0) self.src1 = analog.sig_source_f(self.sample_rate, analog.GR_COS_WAVE, self.freq/2, 1, 0) # --- Audio Out --- self.audioOut = audio.sink(32000, "", True) # --- Blocks ----- self.add = blocks.add_vff(1) #Add Block #self.throttle = blocks.throttle(gr.sizeof_float*1, self.sample_rate,True) self.streamToVector = blocks.stream_to_vector_decimator( item_size=gr.sizeof_float, sample_rate=self.sample_rate, vec_rate=30, vec_len=1024, ) self.fft = fft.fft_vfc(1024, True, (window.blackmanharris(1024)), 1) self.complexToMag = blocks.complex_to_mag_squared(1024) self.probe = blocks.probe_signal_vf(1024) # --- Functions ---- def fft_cal(): while 1: val = self.probe.level() print "Index: {}".format(val.index(max(val))) freq = (val.index(max(val))) * (self.sample_rate/1024.0) print freq print len(val) time.sleep(1) #self.set_freq(self.freq+100) pow_ran = [] freq_ran = [] if self.counter: for i in val: pow_ran.append(float(i)/max(val)) for i in range(1024): freq_ran.append(i*self.sample_rate/1024.0) fig = plt.plot(freq_ran,pow_ran) plt.ylim(-0.3,1.2) plt.xlim(min(freq_ran),max(freq_ran)) plt.show() self.counter+=1 # --- Start Thread --- fft_thread = threading.Thread(target=fft_cal) fft_thread.daemon = True fft_thread.start() # --- Conections --- #self.connect((self.src0, 0), (self.add, 0)) #self.connect((self.src1, 0), (self.add, 1)) #self.connect((self.add, 0), (self.audioOut, 0)) #self.connect((self.src0, 0), (self.throttle, 0)) #self.connect((self.throttle, 0), (self.streamToVector, 0)) self.connect((self.src0, 0), (self.streamToVector, 0)) self.connect((self.streamToVector, 0), (self.fft, 0)) self.connect((self.fft, 0),(self.complexToMag, 0)) self.connect((self.complexToMag, 0),(self.probe, 0))
def __init__(self, DC_filter_num_elements=4, samp_rate_sink=8000, lo_offset_freq=1e6, highpass_cutoff_freq=0, doppler_signal_bw=20, rx_gain=30.5, tx_amp=1, max_num_of_targets=10, angle=0, speed_samp_rate=1, lowpass_cutoff_freq=1700, fft_len=pow(2, 20), RF=2.49e9, samp_rate=1e6, threshold_dB=-70): grc_wxgui.top_block_gui.__init__(self, title="CW Radar Multiple Targets") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.DC_filter_num_elements = DC_filter_num_elements self.samp_rate_sink = samp_rate_sink self.lo_offset_freq = lo_offset_freq self.highpass_cutoff_freq = highpass_cutoff_freq self.doppler_signal_bw = doppler_signal_bw self.rx_gain = rx_gain self.tx_amp = tx_amp self.max_num_of_targets = max_num_of_targets self.angle = angle self.speed_samp_rate = speed_samp_rate self.lowpass_cutoff_freq = lowpass_cutoff_freq self.fft_len = fft_len self.RF = RF self.samp_rate = samp_rate self.threshold_dB = threshold_dB ################################################## # Variables ################################################## self.target_speed_vector = target_speed_vector = 0 self.target_direction_vector = target_direction_vector = 0 self.num_targets = num_targets = 0 self.tx_amp_tuner = tx_amp_tuner = tx_amp self.threshold_dB_tuner = threshold_dB_tuner = threshold_dB self.speed_textbox = speed_textbox = target_speed_vector self.rx_gain_tuner = rx_gain_tuner = rx_gain self.num_targets_textbox = num_targets_textbox = num_targets self.max_num_of_targets_tuner = max_num_of_targets_tuner = max_num_of_targets self.lowpass_cutoff_freq_tuner = lowpass_cutoff_freq_tuner = lowpass_cutoff_freq self.highpass_cutoff_freq_tuner = highpass_cutoff_freq_tuner = highpass_cutoff_freq self.doppler_signal_bw_tuner = doppler_signal_bw_tuner = doppler_signal_bw self.direction_textbox = direction_textbox = target_direction_vector self.angle_tuner = angle_tuner = angle self.RF_tuner = RF_tuner = RF ################################################## # Blocks ################################################## _tx_amp_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._tx_amp_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, label="TX Signal Amp", converter=forms.float_converter(), proportion=0, ) self._tx_amp_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, minimum=0, maximum=1, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tx_amp_tuner_sizer, 0, 8, 1, 21) _threshold_dB_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_dB_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, label="Detected Target Threshold (dB)", converter=forms.float_converter(), proportion=0, ) self._threshold_dB_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, minimum=-90, maximum=-30, num_steps=60, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_threshold_dB_tuner_sizer, 2, 0, 1, 8) self.speed_vector_probe = blocks.probe_signal_vf(max_num_of_targets) _rx_gain_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, label="USRP RX Gain (dB)", converter=forms.float_converter(), proportion=0, ) self._rx_gain_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, minimum=0, maximum=30.5 + 62, num_steps=185, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rx_gain_tuner_sizer, 0, 0, 1, 8) self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Frequency/Time CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver Full Spectrum") self.GridAdd(self.notebook, 6, 0, 13, 53) _max_num_of_targets_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._max_num_of_targets_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_max_num_of_targets_tuner_sizer, value=self.max_num_of_targets_tuner, callback=self.set_max_num_of_targets_tuner, label="Maximum Number of Targets", converter=forms.int_converter(), proportion=0, ) self._max_num_of_targets_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_max_num_of_targets_tuner_sizer, value=self.max_num_of_targets_tuner, callback=self.set_max_num_of_targets_tuner, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.GridAdd(_max_num_of_targets_tuner_sizer, 2, 8, 1, 21) _lowpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._lowpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, label="Low-Pass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._lowpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, minimum=0, maximum=3000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_lowpass_cutoff_freq_tuner_sizer, 1, 29, 1, 24) _highpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._highpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, label="High-Pass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._highpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, minimum=0, maximum=1600, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_highpass_cutoff_freq_tuner_sizer, 0, 29, 1, 24) _doppler_signal_bw_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._doppler_signal_bw_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_doppler_signal_bw_tuner_sizer, value=self.doppler_signal_bw_tuner, callback=self.set_doppler_signal_bw_tuner, label="Doppler Spectrum Bandwidth (Hz)", converter=forms.float_converter(), proportion=0, ) self._doppler_signal_bw_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_doppler_signal_bw_tuner_sizer, value=self.doppler_signal_bw_tuner, callback=self.set_doppler_signal_bw_tuner, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_doppler_signal_bw_tuner_sizer, 2, 29, 1, 24) self.direction_vector_probe = blocks.probe_signal_vi( max_num_of_targets) _angle_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._angle_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, label="Angle of Approach of the Target (Deg)", converter=forms.float_converter(), proportion=0, ) self._angle_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, minimum=0, maximum=89, num_steps=890, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_angle_tuner_sizer, 1, 8, 1, 21) _RF_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._RF_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, label="Radar Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._RF_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, minimum=2.4e9, maximum=2.5e9, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_RF_tuner_sizer, 1, 0, 1, 8) self.wxgui_waterfallsink = waterfallsink2.waterfall_sink_c( self.notebook.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=100, average=False, avg_alpha=None, title="Time/Frequency CW Doppler Radar Receiver", win=window.blackmanharris, ) self.notebook.GetPage(1).Add(self.wxgui_waterfallsink.win) self.wxgui_fftsink2_full_spectrum = fftsink2.fft_sink_c( self.notebook.GetPage(2).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=4096, fft_rate=15, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver Full Spectrum", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(2).Add(self.wxgui_fftsink2_full_spectrum.win) self.wxgui_fftsink = fftsink2.fft_sink_c( self.notebook.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=100, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver ", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(0).Add(self.wxgui_fftsink.win) self.usrp_transmitter = uhd.usrp_sink( ",".join(('addr=192.168.10.2', "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.usrp_transmitter.set_clock_source("internal", 0) self.usrp_transmitter.set_samp_rate(samp_rate) self.usrp_transmitter.set_center_freq(RF_tuner, 0) self.usrp_transmitter.set_gain(0, 0) self.usrp_transmitter.set_antenna("TX/RX", 0) self.usrp_receiver = uhd.usrp_source( ",".join(('addr=192.168.10.3', "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.usrp_receiver.set_clock_source("mimo", 0) self.usrp_receiver.set_time_source("mimo", 0) self.usrp_receiver.set_samp_rate(samp_rate) self.usrp_receiver.set_center_freq( uhd.tune_request(RF_tuner, lo_offset_freq), 0) self.usrp_receiver.set_gain(rx_gain_tuner, 0) self.usrp_receiver.set_antenna("J1", 0) self.usrp_receiver.set_bandwidth(15e6, 0) def _target_speed_vector_probe(): while True: val = self.speed_vector_probe.level() try: ######################################################## #Code to tranlate the vector of speeds to strings: speed = "" if val[0] == 0: #if the value is 0 there is no target in sight. speed = "No Target Detected" elif val[0] != 0: for i in range(len(val)): if val[i] != 0: speed = speed + "Target " + str( i + 1) + ": " + str(round(val[i], 2)) + " Kph\t" self.set_target_speed_vector(speed) ######################################################## except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _target_speed_vector_thread = threading.Thread( target=_target_speed_vector_probe) _target_speed_vector_thread.daemon = True _target_speed_vector_thread.start() def _target_direction_vector_probe(): while True: val = self.direction_vector_probe.level() try: ######################################################## #Code to tranlate the vector of directions to strings: direction = "" if val[0] == 0: direction = "No Target Detected" elif val[0] != 0: #if the value is 0 there is no target in sight. for i in range(len(val)): if val[i] == 1: #if the value is 1 the target is approaching. direction = direction + "Target " + str( i + 1) + ": " + "Approaching\t" elif val[ i] == 2: #if the value is 2 the target is receding. direction = direction + "Target " + str( i + 1) + ": " + "Receding\t" self.set_target_direction_vector(direction) ######################################################## except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _target_direction_vector_thread = threading.Thread( target=_target_direction_vector_probe) _target_direction_vector_thread.daemon = True _target_direction_vector_thread.start() self._speed_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.speed_textbox, callback=self.set_speed_textbox, label="Targets Speed (Kph)", converter=forms.str_converter(), ) self.GridAdd(self._speed_textbox_text_box, 4, 0, 1, 53) self.rational_resampler = filter.rational_resampler_ccc( interpolation=1, decimation=int(samp_rate / samp_rate_sink), taps=None, fractional_bw=None, ) self._num_targets_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.num_targets_textbox, callback=self.set_num_targets_textbox, label="Number of Targets Detected", converter=forms.int_converter(), ) self.GridAdd(self._num_targets_textbox_text_box, 3, 0, 1, 4) self.num_targets_probe = blocks.probe_signal_i() def _num_targets_probe(): while True: val = self.num_targets_probe.level() try: self.set_num_targets(val) except AttributeError: pass time.sleep(1.0 / (speed_samp_rate)) _num_targets_thread = threading.Thread(target=_num_targets_probe) _num_targets_thread.daemon = True _num_targets_thread.start() self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (window.blackmanharris(fft_len)), True, 1) self._direction_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.direction_textbox, callback=self.set_direction_textbox, label="Targets Direction", converter=forms.str_converter(), ) self.GridAdd(self._direction_textbox_text_box, 5, 0, 1, 53) self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len / 2) self.cwradar_doppler_velocity_multiple_targets_ff_0 = cwradar.doppler_velocity_multiple_targets_ff( fft_len / 2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_tuner, max_num_of_targets_tuner, doppler_signal_bw_tuner) self.complex_to_mag = blocks.complex_to_mag(fft_len) self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream( gr.sizeof_float * 1, fft_len) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_float * 1, fft_len) self.blocks_stream_to_vector_1_0 = blocks.stream_to_vector( gr.sizeof_float * 1, fft_len / 2) self.blocks_stream_to_vector_1 = blocks.stream_to_vector( gr.sizeof_float * 1, fft_len / 2) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_len) self.blocks_keep_m_in_n_0_0 = blocks.keep_m_in_n( gr.sizeof_float, fft_len / 2, fft_len, fft_len / 2) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len / 2, fft_len, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 0, tx_amp_tuner, 0) self.DC_filter_0 = blocks.multiply_const_vff( ([0] * DC_filter_num_elements + [1] * ((fft_len / 2) - DC_filter_num_elements))) self.DC_filter = blocks.multiply_const_vff( ([0] * DC_filter_num_elements + [1] * ((fft_len / 2) - DC_filter_num_elements))) ################################################## # Connections ################################################## self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0_0, 0)) self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.DC_filter, 0), (self.cwradar_doppler_velocity_multiple_targets_ff_0, 0)) self.connect((self.DC_filter_0, 0), (self.cwradar_doppler_velocity_multiple_targets_ff_0, 1)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff_0, 2), (self.num_targets_probe, 0)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff_0, 1), (self.direction_vector_probe, 0)) self.connect((self.cwradar_doppler_velocity_multiple_targets_ff_0, 0), (self.speed_vector_probe, 0)) self.connect((self.blocks_vector_to_stream_0_0, 0), (self.blocks_keep_m_in_n_0_0, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_stream_to_vector_1, 0)) self.connect((self.blocks_keep_m_in_n_0_0, 0), (self.blocks_stream_to_vector_1_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_stream_to_vector_1_0, 0), (self.DC_filter_0, 0)) self.connect((self.blocks_stream_to_vector_1, 0), (self.cwradar_vector_flip_ff, 0)) self.connect((self.cwradar_vector_flip_ff, 0), (self.DC_filter, 0)) self.connect((self.usrp_receiver, 0), (self.wxgui_fftsink2_full_spectrum, 0)) self.connect((self.usrp_receiver, 0), (self.rational_resampler, 0)) self.connect((self.rational_resampler, 0), (self.wxgui_waterfallsink, 0)) self.connect((self.rational_resampler, 0), (self.wxgui_fftsink, 0)) self.connect((self.fft_vxx_0, 0), (self.complex_to_mag, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.usrp_receiver, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.usrp_transmitter, 0))
def __init__(self): gr.top_block.__init__(self) self.sample_rate = 5000000 self.ampl = 1 self.freq = 144000000 self.counter = 0 # --- Sources ---- self.uhd = uhd.usrp_source( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd.set_samp_rate(self.sample_rate) self.uhd.set_center_freq(self.freq, 0) self.uhd.set_gain(0, 0) self.uhd.set_antenna("RX2", 0) # --- Blocks ----- self.throttle = blocks.throttle(gr.sizeof_gr_complex*1, self.sample_rate,True) self.streamToVector = blocks.stream_to_vector_decimator( item_size=gr.sizeof_gr_complex, sample_rate=self.sample_rate, vec_rate=30, vec_len=1024, ) self.fft = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), 1) self.complexToMag = blocks.complex_to_mag_squared(1024) self.probe = blocks.probe_signal_vf(1024) # --- Functions ---- def fft_cal(): while 1: val = self.probe.level() print "Index: {} Max: {}".format(val.index(max(val)),max(val)) if max(val): pow_ran = [] freq_ran = [] for i in val: pow_ran.append(float(i)/max(val)) for i in range(1024): freq_ran.append((i*self.sample_rate/1024.0) + (self.freq - (self.sample_rate/2.0)) ) fig = plt.plot(freq_ran,pow_ran) plt.ylim(-0.3,1.2) plt.xlim(min(freq_ran),max(freq_ran)) plt.show() time.sleep(1) # --- Start Thread --- fft_thread = threading.Thread(target=fft_cal) fft_thread.daemon = True fft_thread.start() # --- Conections --- self.connect((self.uhd, 0), (self.throttle, 0)) self.connect((self.throttle, 0), (self.streamToVector, 0)) self.connect((self.streamToVector, 0), (self.fft, 0)) self.connect((self.fft, 0),(self.complexToMag, 0)) self.connect((self.complexToMag, 0),(self.probe, 0))
def __init__(self, end_f=2000e6, start_f=50e6): gr.top_block.__init__(self, "Electosense") Qt.QWidget.__init__(self) self.setWindowTitle("Electosense") 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", "electrosense_final") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.end_f = end_f self.start_f = start_f ################################################## # Variables ################################################## self.samp_rate = samp_rate = 5e6 self.prober = prober = 1 self.hop_mode = hop_mode = 0 self.tune_delay = tune_delay = 20e-3 self.sensorid = sensorid = 123456 self.rfgain = rfgain = 40 self.ppm = ppm = 0 self.navg_vectors = navg_vectors = 50 self.fft_size = fft_size = 4096 self.cfreq = cfreq = scanning.step(start_f,end_f,samp_rate/1.5,prober,hop_mode,0.8,0.8) self.alpha = alpha = 0.75 ################################################## # Blocks ################################################## self.vecprobe = blocks.probe_signal_vf(fft_size) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("addr=192.168.10.2", "")), 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(cfreq, 0) self.uhd_usrp_source_0.set_gain(35, 0) self.uhd_usrp_source_0.set_antenna("RX2", 0) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(alpha, fft_size) def _prober_probe(): while True: val = self.vecprobe.level() try: self.set_prober(val) except AttributeError: pass time.sleep(1.0 / (1/(tune_delay+(1/samp_rate*fft_size*navg_vectors)))) _prober_thread = threading.Thread(target=_prober_probe) _prober_thread.daemon = True _prober_thread.start() self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.blackmanharris(fft_size)), True, 1) self.electrosense_sensor_sink_0 = electrosense.sensor_sink("collector.electrosense.org", 5000, fft_size, "float32", "/home/rsreeraj/gnu_work/gr-electrosense/python/rtl-spec.avsc", "/home/rsreeraj/gnu_work/gr-electrosense/python/sensor_cert/Sensor-SSL-SK.pem", "/home/rsreeraj/gnu_work/gr-electrosense/python/sensor_cert/Sensor-SSL-Cert.pem", sensorid, 0, 2, fft_size, int(3/alpha), 0.1, int(samp_rate/fft_size), int(cfreq), rfgain) self.electrosense_discard_samples_0 = electrosense.discard_samples(int(tune_delay * samp_rate), int(cfreq), pmt.intern("burst_len"), False) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float*fft_size, navg_vectors) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.electrosense_sensor_sink_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.vecprobe, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.electrosense_discard_samples_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.electrosense_discard_samples_0, 0))