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: 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.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, lo_offset_freq=1e6, threshold_dB=-70, RF=2.49e9, DC_filter_num_elements=4, speed_samp_rate=1, samp_rate=1e6, highpass_cutoff_freq=0, lowpass_cutoff_freq=1700, fft_len=pow(2,20), samp_rate_sink=8000, angle=0, tx_amp=1, rx_gain=30.5): grc_wxgui.top_block_gui.__init__(self, title="CW Radar Single Target") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.lo_offset_freq = lo_offset_freq self.threshold_dB = threshold_dB self.RF = RF self.DC_filter_num_elements = DC_filter_num_elements self.speed_samp_rate = speed_samp_rate self.samp_rate = samp_rate self.highpass_cutoff_freq = highpass_cutoff_freq self.lowpass_cutoff_freq = lowpass_cutoff_freq self.fft_len = fft_len self.samp_rate_sink = samp_rate_sink self.angle = angle self.tx_amp = tx_amp self.rx_gain = rx_gain ################################################## # Variables ################################################## self.target_speed = target_speed = 0 self.target_direction = target_direction = 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 self.rx_gain_tuner = rx_gain_tuner = rx_gain 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.direction_textbox = direction_textbox = target_direction 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, 17, 1, 26) _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, 17) self.speed_probe = blocks.probe_signal_f() _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, 17) 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, 5, 0, 13, 75) _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="Lowpass 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, 43, 1, 32) _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, 43, 1, 32) self.direction_probe = blocks.probe_signal_i() _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, 17, 1, 26) _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, 17) 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", 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_probe(): while True: val = self.speed_probe.level() try: self.set_target_speed(val) except AttributeError: pass time.sleep(1.0 / (2)) _target_speed_thread = threading.Thread(target=_target_speed_probe) _target_speed_thread.daemon = True _target_speed_thread.start() def _target_direction_probe(): while True: val = self.direction_probe.level() try: self.set_target_direction(val) except AttributeError: pass time.sleep(1.0 / (2)) _target_direction_thread = threading.Thread(target=_target_direction_probe) _target_direction_thread.daemon = True _target_direction_thread.start() self._speed_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.speed_textbox, callback=self.set_speed_textbox, label="Target Speed (Kph)", converter=forms.float_converter(), ) self.GridAdd(self._speed_textbox_text_box, 3, 0, 1, 17) self.rational_resampler = filter.rational_resampler_ccc( interpolation=1, decimation=int(samp_rate/samp_rate_sink), taps=None, fractional_bw=None, ) 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="Target Direction", converter=forms.str_converter(), ) self.GridAdd(self._direction_textbox_text_box, 4, 0, 1, 17) self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len/2) self.cwradar_doppler_velocity_single_target_ff_0 = cwradar.doppler_velocity_single_target_ff(fft_len/2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_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.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.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.complex_to_mag, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0_0, 0)) self.connect((self.DC_filter_0, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 1)) self.connect((self.DC_filter, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 0)) self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 0), (self.speed_probe, 0)) self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 1), (self.direction_probe, 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.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, 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, 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: 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.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, 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: ######################################################## #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.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))