def __init__(self): gr.top_block.__init__(self, "Affinity Set Test") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## vec_len = 1 self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*vec_len, samp_rate) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*vec_len) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*vec_len) self.filter_filt_0 = filter.fir_filter_ccc(1, 40000*[0.2+0.3j,]) self.filter_filt_1 = filter.fir_filter_ccc(1, 40000*[0.2+0.3j,]) self.filter_filt_0.set_processor_affinity([0,]) self.filter_filt_1.set_processor_affinity([0,1]) ################################################## # Connections ################################################## self.connect((self.blocks_null_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.filter_filt_0, 0)) self.connect((self.filter_filt_0, 0), (self.filter_filt_1, 0)) self.connect((self.filter_filt_1, 0), (self.blocks_null_sink_0, 0))
def __init__(self): gr.top_block.__init__(self, "Affinity Set Test") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## vec_len = 1 self.blocks_throttle_0 = blocks.throttle( gr.sizeof_gr_complex * vec_len, samp_rate) self.blocks_null_source_0 = blocks.null_source( gr.sizeof_gr_complex * vec_len) self.blocks_null_sink_0 = blocks.null_sink( gr.sizeof_gr_complex * vec_len) self.filter_filt_0 = filter.fir_filter_ccc(1, 40000 * [0.2 + 0.3j, ]) self.filter_filt_1 = filter.fir_filter_ccc(1, 40000 * [0.2 + 0.3j, ]) self.filter_filt_0.set_processor_affinity([0, ]) self.filter_filt_1.set_processor_affinity([0, 1]) ################################################## # Connections ################################################## self.connect((self.blocks_null_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.filter_filt_0, 0)) self.connect((self.filter_filt_0, 0), (self.filter_filt_1, 0)) self.connect((self.filter_filt_1, 0), (self.blocks_null_sink_0, 0))
def __init__(self, source_data, sampling_rate, carrier_hz, symbol_rate, deviation, access_code): super(FSKDemodulator, self).__init__() self._decoded = {} self._carrier_hz = carrier_hz self._deviation = deviation self._access_code = access_code samp_rate = sampling_rate #symbol_rate = 9920 self.samples_per_symbol = float(samp_rate) / symbol_rate omega = self.samples_per_symbol * 1.0 mu = 0.0 gain_mu = 0.2 gain_omega = 0.25 * gain_mu * gain_mu omega_relative_limit = 0.001 tap_count = int(math.floor(self.samples_per_symbol)) hz_n = (carrier_hz - deviation) taps_n = numpy.exp(numpy.arange(tap_count, dtype=numpy.float32) * 2.0j * numpy.pi * hz_n / samp_rate) hz_p = (carrier_hz + deviation) taps_p = numpy.exp(numpy.arange(tap_count, dtype=numpy.float32) * 2.0j * numpy.pi * hz_p / samp_rate) #source = blocks.file_source(gr.sizeof_gr_complex*1, filepath_in, False) # Concatenate data to compensate for correlate_access_code_bb latency source_data_padding_count = int(math.ceil(self.samples_per_symbol * 64)) source_data = numpy.concatenate((source_data, numpy.zeros((source_data_padding_count,), dtype=numpy.complex64))) source = NumpySource(source_data) filter_n = filter.fir_filter_ccc(1, taps_n.tolist()) self.connect(source, filter_n) filter_p = filter.fir_filter_ccc(1, taps_p.tolist()) self.connect(source, filter_p) mag_n = blocks.complex_to_mag(1) self.connect(filter_n, mag_n) mag_p = blocks.complex_to_mag(1) self.connect(filter_p, mag_p) sub_pn = blocks.sub_ff() self.connect(mag_p, (sub_pn, 0)) self.connect(mag_n, (sub_pn, 1)) clock_recovery = digital.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_relative_limit) self.connect(sub_pn, clock_recovery) slicer = digital.binary_slicer_fb() self.connect(clock_recovery, slicer) access_code_correlator = digital.correlate_access_code_bb(access_code, 0) self.connect(slicer, access_code_correlator) self.packetizer = Packetizer() self.connect(access_code_correlator, self.packetizer)
def __init__(self, which=''): gr.top_block.__init__(self, "Filter Test") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex*1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc( interpolation=3, decimation=7, taps=None, fractional_bw=None, ) self.fir_filter_xxx_0 = filter.fir_filter_ccc(7, ([.7]*23)) if which == 'dfir': self.filter = self.fir_filter_xxx_0 if which == 'resamp': self.filter = self.blks2_rational_resampler_xxx_0 ################################################## # Connections ################################################## self.connect((self.filter, 0), (self.gr_null_sink_0, 0)) self.connect((self.gr_null_source_0, 0), (self.filter, 0))
class BandPassFilterBlock(FlowGraphBlock): def __init__(self): FlowGraphBlock.__init__(self) def setup(self, params): if (len(params) != 4): print "GNURadio: Invalid number of band pass filter parameters" return None try: sampleRate = float(params[0]) lowCutoffFreq = float(params[1]) highCutoffFreq = float(params[2]) gain = float(params[3]) except ValueError, msg: print "GNURadio: Invalid band pass filter parameter - %s" % msg return None if ((lowCutoffFreq <= 0) or (highCutoffFreq >= sampleRate/2) or (lowCutoffFreq >= highCutoffFreq)): print "GNURadio: Band pass cutoff frequencies out of range" return None # Calculate the FIR filter taps using the Blackman-Harris window method. transitionWidth = sampleRate/25 filterTaps = filter.firdes.complex_band_pass(gain, sampleRate, lowCutoffFreq, highCutoffFreq, transitionWidth, filter.firdes.WIN_BLACKMAN_HARRIS) print "Generated FIR filter with %d taps" % len(filterTaps) self.firFilter = filter.fir_filter_ccc(1, filterTaps) return self
def test_001_t(self): fftlen = 128 cell_id = 124 taps = filter.optfir.low_pass(1, fftlen * 15e3, 472.5e3, 900e3, 0.2, 40) samples = t.get_mod_frame(cell_id, 6, 1, fftlen) samps = np.tile(samples[0], 5) src = blocks.vector_source_c(samps, repeat=False, vlen=1) fir = filter.fir_filter_ccc(fftlen / 64, taps) sync = lte.mimo_pss_coarse_sync(4, 1) dbg0 = blocks.message_debug() dbg1 = blocks.message_debug() dbg2 = blocks.message_debug() self.tb.connect(src, fir, sync) self.tb.msg_connect((sync, 'control'), (dbg0, 'store')) self.tb.msg_connect((sync, 'N_id_2'), (dbg1, 'store')) self.tb.msg_connect((sync, 'coarse_pos'), (dbg2, 'store')) # set up fg self.tb.run() # check data self.assertEqual(pmt.to_long(dbg1.get_message(0)), int(cell_id % 3)) ctrl_res = pmt.to_bool(dbg0.get_message(0)) assert ctrl_res offset = 10 + 5 * 9 + 6 * fftlen print(offset) # print() pos = pmt.to_long(dbg2.get_message(0)) print(pos) print(pos * 2 - (len(taps) // 2))
def __init__(self, N, fs, bw, tw, atten, D): """ Nombre de la funcion donde se implementaran las opraciones y contendra todas las variables del programa, basicamente seria el contenedor del programa. """ gr.top_block.__init__(self) self._nsamps = N self._fs = fs self._bw = bw self._tw = tw self._at = atten self._decim = D taps = filter.firdes.low_pass_2(1, self._fs, self._bw, self._tw, self._at) print "Num. Taps: ", len(taps) self.src = analog.noise_source_c(analog.GR_GAUSSIAN, 1) self.head = blocks.head(gr.sizeof_gr_complex, self._nsamps) self.filt0 = filter.fir_filter_ccc(self._decim, taps) self.vsnk_src = blocks.vector_sink_c() self.vsnk_out = blocks.vector_sink_c() self.connect(self.src, self.head, self.vsnk_src) self.connect(self.head, self.filt0, self.vsnk_out)
def __init__(self, delay=0, taps=[]): gr.hier_block2.__init__( self, "Conj FS IQBal", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) ################################################## # Parameters ################################################## self.delay = delay self.taps = taps ################################################## # Blocks ################################################## self.filter_fir_filter_xxx_0 = filter.fir_filter_ccc(1, (taps)) self.delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, delay) self.blocks_conjugate_cc_0 = blocks.conjugate_cc() self.blocks_add_xx_0 = blocks.add_vcc(1) ################################################## # Connections ################################################## self.connect((self.blocks_add_xx_0, 0), (self, 0)) self.connect((self, 0), (self.blocks_conjugate_cc_0, 0)) self.connect((self.filter_fir_filter_xxx_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_conjugate_cc_0, 0), (self.filter_fir_filter_xxx_0, 0)) self.connect((self, 0), (self.delay_0, 0)) self.connect((self.delay_0, 0), (self.blocks_add_xx_0, 0))
def __init__(self, input_rate=48000): gr.hier_block2.__init__( self, "CQPSK Receiver", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_float * 1), ) ################################################## # Parameters ################################################## self.input_rate = input_rate ################################################## # Variables ################################################## self.fa = fa = 6250 self.fb = fb = fa + 0.1 * fa ################################################## # Blocks ################################################## self.short_to_float = blocks.short_to_float(1, 32768) self.p25_symbol_mapper_fb_0 = p25_symbol_mapper_fb( threshold1=-2.0, threshold2=0.0, threshold3=2.0, threshold4=4.0, ) self.p25_cqpsk_demodulator_cf_0 = p25_cqpsk_demodulator_cf( costas_alpha=0.04, gain_mu=0.025, input_rate=48000, output_rate=4800, ) self.op25_frame_assembler_0 = op25_repeater.p25_frame_assembler( "127.0.01", 0, True, True, True, False, gr.msg_queue(1), True, False) self.cutoff = filter.fir_filter_ccc(1, (filter.firdes.low_pass( 1.0, 48000, (fa + fb) / 2, fb - fa, filter.firdes.WIN_HANN))) self.cutoff.declare_sample_delay(0) self.arb_resampler = p25_arb_resampler_cc( input_rate=input_rate, output_rate=48000, ) ################################################## # Connections ################################################## self.connect((self.arb_resampler, 0), (self.cutoff, 0)) self.connect((self.cutoff, 0), (self.p25_cqpsk_demodulator_cf_0, 0)) self.connect((self.op25_frame_assembler_0, 0), (self.short_to_float, 0)) self.connect((self.p25_cqpsk_demodulator_cf_0, 0), (self.p25_symbol_mapper_fb_0, 0)) self.connect((self.p25_symbol_mapper_fb_0, 0), (self.op25_frame_assembler_0, 0)) self.connect((self, 0), (self.arb_resampler, 0)) self.connect((self.short_to_float, 0), (self, 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.samp_rate = samp_rate = 44100 ################################################## # Blocks ################################################## self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="Hz", minval=50, maxval=280, factor=1, decimal_places=2, ref_level=0, sample_rate=samp_rate, number_rate=15, average=False, avg_alpha=None, label="Number Plot", peak_hold=False, show_gauge=True, ) self.Add(self.wxgui_numbersink2_0.win) self.blocks_moving_average_xx_0 = blocks.moving_average_ff( samp_rate / 50, 25 / pi, 200) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_float * 1, 10) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate, 60, 255, 100, firdes.WIN_BLACKMAN, 6.76)) self.audio_source_0 = audio.source(samp_rate, "default", True) self.analog_pll_freqdet_cf_0 = analog.pll_freqdet_cf( 200 * 2.0 * pi / samp_rate, 260 * 2.0 * pi / samp_rate, 60 * 2.0 * pi / samp_rate) ################################################## # Connections ################################################## self.connect((self.blocks_moving_average_xx_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_pll_freqdet_cf_0, 0)) self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.analog_pll_freqdet_cf_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_moving_average_xx_0, 0))
def __init__(self, fft_len, freq_sample_delay_samps, freq_samps_to_avg, mag_samps_to_avg, thresh): gr.hier_block2.__init__(self, "Coarse Dehopper", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1)) ''' Constructor @param fft_len - @param freq_sample_delay_samps - @param freq_samps_to_avg - @param mag_samps_to_avg - @param thresh - ''' ################################################## # Parameters ################################################## self.fft_len = fft_len self.freq_sample_delay_samps = freq_sample_delay_samps self.freq_samps_to_avg = freq_samps_to_avg self.mag_samps_to_avg = mag_samps_to_avg self.thresh = thresh ################################################## # Blocks ################################################## self.s_and_h_detector = s_and_h_detector( freq_sample_delay_samps=freq_sample_delay_samps, freq_samps_to_avg=freq_samps_to_avg, mag_samps_to_avg=mag_samps_to_avg, thresh=thresh, ) self.resamp = pfb.arb_resampler_ccf(1.0 / (fft_len / 4.0), taps=None, flt_size=32) self.resamp.declare_sample_delay(0) self.fir = filter.fir_filter_ccc(2, (firdes.low_pass_2(1,1,.30,.05,60))) self.fir.declare_sample_delay(0) self.fft_peak = fft_peak(fft_len=fft_len) self.vco = blocks.vco_c(1, 2.0 * pi / fft_len, 1) self.mult_conj = blocks.multiply_conjugate_cc(1) self.delay = blocks.delay(gr.sizeof_gr_complex*1, int(freq_samps_to_avg) + freq_sample_delay_samps) self.c2mag = blocks.complex_to_mag(1) ################################################## # Connections ################################################## self.connect((self.c2mag, 0), (self.s_and_h_detector, 0)) self.connect((self.delay, 0), (self.mult_conj, 0)) self.connect((self.mult_conj, 0), (self.fir, 0)) self.connect((self.vco, 0), (self.mult_conj, 1)) self.connect((self.fft_peak, 0), (self.s_and_h_detector, 1)) self.connect((self.fir, 0), (self.resamp, 0)) self.connect((self, 0), (self.c2mag, 0)) self.connect((self, 0), (self.delay, 0)) self.connect((self, 0), (self.fft_peak, 0)) self.connect((self.resamp, 0), (self, 0)) self.connect((self.s_and_h_detector, 0), (self.vco, 0))
def __init__(self, decim=16, N_id_1=134, N_id_2=0): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.decim = decim self.N_id_1 = N_id_1 self.N_id_2 = N_id_2 ################################################## # Variables ################################################## self.sss_start_ts = sss_start_ts = 10608 - 2048 - 144 self.samp_rate = samp_rate = 30720e3/decim ################################################## # Blocks ################################################## self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.GetWin(), title="Scope Plot", sample_rate=200, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.gr_vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, 2048/decim) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate*decim) self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, 2048/decim) self.gr_skiphead_0 = gr.skiphead(gr.sizeof_gr_complex*1, sss_start_ts) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((gen_sss_fd(N_id_1, N_id_2, 2048/decim).get_sss_conj_rev())) self.gr_integrate_xx_0 = gr.integrate_cc(2048/decim) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/home/user/git/gr-lte/gr-lte/test/traces/lte_02_796m_30720k_frame.cfile", True) self.gr_fft_vxx_0 = gr.fft_vcc(2048/decim, True, (window.blackmanharris(1024)), True, 1) self.gr_complex_to_mag_0 = gr.complex_to_mag(1) self.fir_filter_xxx_0 = filter.fir_filter_ccc(decim, (firdes.low_pass(1, decim*samp_rate, 550e3, 100e3))) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_integrate_xx_0, 0)) self.connect((self.gr_integrate_xx_0, 0), (self.gr_complex_to_mag_0, 0)) self.connect((self.gr_complex_to_mag_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_skiphead_0, 0)) self.connect((self.gr_skiphead_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.gr_stream_to_vector_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Ntsc Hackrf") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samples_per_line = samples_per_line = 772 self.samp_rate = samp_rate = samples_per_line * 60 * .999 * 525 / 2 self.rf_gain = rf_gain = 14 self.if_gain = if_gain = 40 self.digital_gain = digital_gain = 0.9 self.center_freq = center_freq = 186000000 + 1250000 ################################################## # Blocks ################################################## self.zero = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0) self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + "hackrf=0") self.osmosdr_sink_0.set_sample_rate(samp_rate) self.osmosdr_sink_0.set_center_freq(center_freq, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(rf_gain, 0) self.osmosdr_sink_0.set_if_gain(if_gain, 0) self.osmosdr_sink_0.set_bb_gain(0, 0) self.osmosdr_sink_0.set_antenna("", 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (digital_gain, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_float * 1, "/home/ubuntu/WAHD-TV/ve3irr-testing.dat", True) self.blocks_add_xx_0 = blocks.add_vcc(1) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate, -2475000 + 1725000, 2475000 + 1725000, 500000, firdes.WIN_HAMMING, 6.76)) self.analog_sig_source_x_1 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 4500000, 0.1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.zero, 0), (self.blocks_float_to_complex_0, 1))
def test_fir_filter_ccc(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) firfilter = filter.fir_filter_ccc(1, [complex(random.random(), random.random()) for _ in range(16)]) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, firfilter, probe) return top, probe
def test_fir_filter_ccc(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) firfilter = filter.fir_filter_ccc(1, [complex(random.random(), random.random()) for _ in range(256)]) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, firfilter, probe) return top, probe
def __init__(self, uhd_address, options): gr.top_block.__init__(self) self.uhd_addr = uhd_address self.freq = options.freq self.samp_rate = options.samp_rate self.gain = options.gain self.threshold = options.threshold self.trigger = options.trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, stream_args=uhd.stream_args('fc32')) self.uhd_src.set_samp_rate(self.samp_rate) self.uhd_src.set_center_freq(self.freq, 0) self.uhd_src.set_gain(self.gain, 0) taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = filter.fir_filter_ccc(10, taps) self.tagger = blocks.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods data = 1000*[0,] + 1000*[1,] self.signal = blocks.vector_source_s(data, True) # Energy detector to get signal burst ## use squelch to detect energy self.det = analog.simple_squelch_cc(self.threshold, 0.01) ## convert to mag squared (float) self.c2m = blocks.complex_to_mag_squared() ## average to debounce self.avg = filter.single_pole_iir_filter_ff(0.01) ## rescale signal for conversion to short self.scale = blocks.multiply_const_ff(2**16) ## signal input uses shorts self.f2s = blocks.float_to_short() # Use file sink burst tagger to capture bursts self.fsnk = blocks.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## # Connections ################################################## self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) else: # Connect an energy detector signaler to the burst tagger self.connect(self.uhd_src, self.det) self.connect(self.det, self.c2m, self.avg, self.scale, self.f2s) self.connect(self.f2s, (self.tagger, 1))
def __init__(self, uhd_address, options): gr.top_block.__init__(self) self.uhd_addr = uhd_address self.freq = options.freq self.samp_rate = options.samp_rate self.gain = options.gain self.threshold = options.threshold self.trigger = options.trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, stream_args=uhd.stream_args('fc32')) self.uhd_src.set_samp_rate(self.samp_rate) self.uhd_src.set_center_freq(self.freq, 0) self.uhd_src.set_gain(self.gain, 0) taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = filter.fir_filter_ccc(10, taps) self.tagger = blocks.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods data = 1000 * [0, ] + 1000 * [1, ] self.signal = blocks.vector_source_s(data, True) # Energy detector to get signal burst # use squelch to detect energy self.det = analog.simple_squelch_cc(self.threshold, 0.01) # convert to mag squared (float) self.c2m = blocks.complex_to_mag_squared() # average to debounce self.avg = filter.single_pole_iir_filter_ff(0.01) # rescale signal for conversion to short self.scale = blocks.multiply_const_ff(2**16) # signal input uses shorts self.f2s = blocks.float_to_short() # Use file sink burst tagger to capture bursts self.fsnk = blocks.tagged_file_sink( gr.sizeof_gr_complex, self.samp_rate) ################################################## # Connections ################################################## self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) else: # Connect an energy detector signaler to the burst tagger self.connect(self.uhd_src, self.det) self.connect(self.det, self.c2m, self.avg, self.scale, self.f2s) self.connect(self.f2s, (self.tagger, 1))
def __init__(self, samp_rate,sps,alpha,mu,nB,nF,nW,description_name,mode): gr.hier_block2.__init__(self, "physical_layer_driver", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature3(3, 3, gr.sizeof_gr_complex, gr.sizeof_gr_complex, gr.sizeof_gr_complex*(1+sps*(nB+nF)))) # Output signature self._sps = sps self._alpha = alpha self._mu = mu self._nB = nB self._nF = nF self._nW = nW m = importlib.import_module('digitalhf.physical_layer.'+description_name) self._physical_layer_driver_description = m.PhysicalLayer(sps) self._physical_layer_driver_description.set_mode(mode) ## TODO: get rrc tap information from physical layer description self._rrc_taps = filter.firdes.root_raised_cosine(1.0, samp_rate, samp_rate/sps, 0.35, 11*sps) preamble_offset,preamble_samples = self._physical_layer_driver_description.get_preamble_z() preamble_length = len(preamble_samples) self._rrc_filter = filter.fir_filter_ccc(1, (self._rrc_taps)) self._corr_est = digital.corr_est_cc(symbols = (preamble_samples.tolist()), sps = sps, mark_delay = preamble_offset, threshold = 0.5, threshold_method = 1) self._doppler_correction = digitalhf.doppler_correction_cc(preamble_length, len(preamble_samples)) self._adaptive_filter = digitalhf.adaptive_dfe(sps, nB, nF, nW, mu, alpha) self._msg_proxy = digitalhf.msg_proxy(self._physical_layer_driver_description) self.connect((self, 0), (self._rrc_filter, 0), (self._corr_est, 0), (self._doppler_correction, 0), (self._adaptive_filter, 0), (self, 0)) self.connect((self._corr_est, 1), ## correlation (self, 1)) self.connect((self._adaptive_filter, 1), ## taps (self, 2)) self.msg_connect((self._doppler_correction, 'doppler'), (self._msg_proxy, 'doppler')) self.msg_connect((self._msg_proxy, 'doppler'), (self._doppler_correction, 'doppler')) self.msg_connect((self._adaptive_filter, 'frame_info'), (self._msg_proxy, 'frame_info')) self.msg_connect((self._msg_proxy, 'frame_info'), (self._adaptive_filter, 'frame_info')) constellations_data = self._physical_layer_driver_description.get_constellations() constellations_msg = pmt.to_pmt([{'idx': idx, 'points': c['points'], 'symbols': c['symbols']} for (idx,c) in enumerate(constellations_data)]) self._adaptive_filter.to_basic_block()._post(pmt.intern('constellations'), constellations_msg) self.message_port_register_hier_out('soft_dec') self.msg_connect((self._adaptive_filter, 'soft_dec'), (self, 'soft_dec')) self.msg_connect((self._msg_proxy, 'soft_dec'), (self, 'soft_dec'))
def __init__(self): gr.top_block.__init__(self, "SSB Transmitter V1 - F1ATB - MAY 2020") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2400000 self.LSB_USB = LSB_USB = 1 self.GainRF_TX = GainRF_TX = 100 self.GainIF_TX = GainIF_TX = 300 self.GainBB_TX = GainBB_TX = 40 self.Fr_TX = Fr_TX = 145100000 ################################################## # Blocks ################################################## self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=240, decimation=1, taps=None, fractional_bw=None) self.hilbert_fc_0 = filter.hilbert_fc(64, firdes.WIN_HAMMING, 6.76) self.hilbert_fc_0.set_min_output_buffer(10) self.hilbert_fc_0.set_max_output_buffer(10) self.blocks_udp_source_0 = blocks.udp_source(gr.sizeof_short * 1, '127.0.0.1', 9005, 512, True) self.blocks_udp_source_0.set_max_output_buffer(2048) self.blocks_short_to_float_0 = blocks.short_to_float(1, 32767) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(LSB_USB) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate / 240, -1300 + LSB_USB * 1500, 1300 + LSB_USB * 1500, 200, firdes.WIN_HAMMING, 6.76)) ################################################## # Connections ################################################## self.connect((self.band_pass_filter_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_short_to_float_0, 0), (self.hilbert_fc_0, 0)) self.connect((self.blocks_udp_source_0, 0), (self.blocks_short_to_float_0, 0)) self.connect((self.hilbert_fc_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_null_sink_0, 0))
def __init__(self, win, sat_name, mode_name): gr.hier_block2.__init__(self, "Channel "+str(sat_name)+" "+str(mode_name)+" SSB", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.trans = trans = 500 self.sample_rate = sample_rate = 2048000 self.low_ssb = low_ssb = 200 self.high_ssb = high_ssb = 2800 self.decim = decim = 8 self.agc_decay = agc_decay = 50e-6 ################################################## # Blocks ################################################## self.fftsink_audio = fftsink2.fft_sink_f( win, baseband_freq=0, y_per_div=5, y_divs=10, ref_level=-20, ref_scale=2.0, sample_rate=32000, fft_size=1024, fft_rate=15, average=True, avg_alpha=None, title="FFT Plot (Audio - "+sat_name+" "+str(mode_name)+")", peak_hold=True, ) self.multiply_const_64 = blocks.multiply_const_vff((0.1, )) self.complex_to_real = blocks.complex_to_real(1) self.rational_resampler = filter.rational_resampler_ccc( interpolation=32, decimation=64, taps=None, fractional_bw=None, ) self.band_pass_filter = filter.fir_filter_ccc(4, filter.firdes.complex_band_pass( 1, sample_rate/decim, low_ssb, high_ssb, trans, filter.firdes.WIN_HAMMING, 6.76)) self.agc = analog.agc2_cc(0.1, agc_decay, 0.9, 1.0) ################################################## # Connections ################################################## #self.connect(self, (self.gr_throttle_0, 0)) self.connect(self, (self.band_pass_filter, 0)) self.connect((self.band_pass_filter, 0), (self.agc, 0)) self.connect((self.agc, 0), (self.rational_resampler, 0)) self.connect((self.rational_resampler, 0), (self.complex_to_real, 0)) self.connect((self.complex_to_real, 0), (self.multiply_const_64, 0)) self.connect((self.multiply_const_64, 0), (self.fftsink_audio, 0)) self.connect((self.multiply_const_64, 0), self)
def create_block(self, taps): assert taps is not None if self.freq_xlating: return grfilter.freq_xlating_fir_filter_ccc( self.decimation, taps, 0, self.input_rate) else: if len(taps) > 10: return grfilter.fft_filter_ccc(self.decimation, taps, 1) else: return grfilter.fir_filter_ccc(self.decimation, taps)
def __init__(self, N_id_2, decim=16, avg_halfframes=2 * 8, freq_corr=0, dump=None): gr.hier_block2.__init__( self, "PSS correlator", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float), ) vec_half_frame = 30720 * 5 / decim self.taps = [] for i in range(0, 3): self.taps.append( gen_pss_td(i, N_re=2048 / decim, freq_corr=freq_corr).get_data_conj_rev()) self.corr = filter.fir_filter_ccc(1, self.taps[N_id_2]) self.mag = gr.complex_to_mag_squared() self.vec = gr.stream_to_vector(gr.sizeof_float * 1, vec_half_frame) self.deint = gr.deinterleave(gr.sizeof_float * vec_half_frame) self.add = gr.add_vff(vec_half_frame) self.argmax = gr.argmax_fs(vec_half_frame) self.null = gr.null_sink(gr.sizeof_short * 1) self.max = gr.max_ff(vec_half_frame) self.to_float = gr.short_to_float(1, 1. / decim) self.interleave = gr.interleave(gr.sizeof_float) #self.framestart = gr.add_const_ii(-160-144*5-2048*6+30720*5) self.connect(self, self.corr, self.mag, self.vec) self.connect((self.argmax, 1), self.null) #self.connect(self.argmax, self.to_float, self.to_int, self.framestart, self) self.connect(self.argmax, self.to_float, self.interleave, self) self.connect(self.max, (self.interleave, 1)) if avg_halfframes == 1: self.connect(self.vec, self.argmax) self.connect(self.vec, self.max) else: self.connect(self.vec, self.deint) self.connect(self.add, self.argmax) self.connect(self.add, self.max) for i in range(0, avg_halfframes): self.connect((self.deint, i), (self.add, i)) if dump != None: self.connect( self.mag, gr.file_sink(gr.sizeof_float, dump + "_pss_corr_f.cfile")) self.connect( self.add, gr.file_sink(gr.sizeof_float * vec_half_frame, dump + "_pss_corr_add_f.cfile"))
def __init__(self): gr.top_block.__init__(self, "Ook Demod") ################################################## # Command Line Arguments ################################################## parser = argparse.ArgumentParser() # Python ook_demod.py -s 1e6 -r 4e3 -f 433.92e6 -m true parser.add_argument("-s", "--samp_rate", default=1e6, help="Sample rate of software-defined radio") parser.add_argument("-r", "--symbol_rate", default=4e3, help="Symbol rate of key fob") parser.add_argument("-f", "--frequency", default=433.92e6, help="Listening frequency") parser.add_argument("-m", "--manchester", default=True, help="Manchester decoder", type=str2bool) parser.add_argument("-o", "--output", default=None, help="Output file") args = parser.parse_args() ################################################## # Variables ################################################## self.frequency = frequency = float(args.frequency) self.symbol_rate = symbol_rate = float(args.symbol_rate) self.samp_rate = samp_rate = float(args.sample_rate) self.manchester = manchester = args.manchester self.output = output = args.output ################################################## # Blocks ################################################## self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' ) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(frequency, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(False, 0) self.osmosdr_source_0.set_gain(10, 0) self.osmosdr_source_0.set_if_gain(20, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna('', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.ook_demod_block = ook_demod_block.blk(symbol_rate=symbol_rate, sample_rate=samp_rate, manchester_decoding=manchester, sink_file=output) self.blocks_threshold_ff_0 = blocks.threshold_ff(1e-3, 1e-3, 0) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.band_pass_filter_0 = filter.fir_filter_ccc(1, firdes.complex_band_pass( 1, samp_rate, 1, 50e3, 20e3, firdes.WIN_HAMMING, 6.76)) ################################################## # Connections ################################################## self.connect((self.band_pass_filter_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.ook_demod_block, 0)) self.connect((self.osmosdr_source_0, 0), (self.band_pass_filter_0, 0))
def __make_sideband_demod(self, upper): first = grfilter.fir_filter_ccc( 1, firdes.complex_band_pass( 1.0, self.__demod_rate, _am_lower_cutoff_freq if upper else -_am_audio_bandwidth, _am_audio_bandwidth if upper else -_am_lower_cutoff_freq, 1000, firdes.WIN_HAMMING)) last = self.__make_dc_blocker() self.connect(first, blocks.complex_to_real(), last) return first, last
def __make_sideband_demod(self, upper): first = grfilter.fir_filter_ccc( 1, firdes.complex_band_pass(1.0, self.__demod_rate, _am_lower_cutoff_freq if upper else -_am_audio_bandwidth, _am_audio_bandwidth if upper else -_am_lower_cutoff_freq, 1000, firdes.WIN_HAMMING)) last = self.__make_dc_blocker() self.connect(first, blocks.complex_to_real(), last) return first, last
def reference_filter_ccc(dec, taps, input): """ compute result using conventional fir filter """ tb = gr.top_block() #src = blocks.vector_source_c(((0,) * (len(taps) - 1)) + input) src = blocks.vector_source_c(input) op = filter.fir_filter_ccc(dec, taps) dst = blocks.vector_sink_c() tb.connect(src, op, dst) tb.run() return dst.data()
def __init__(self, bias, freq_sample_delay_samps, freq_samps_to_avg, mag_samps_to_avg, resamp_rate, thresh): gr.hier_block2.__init__(self, "Fine Dehopper", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1)) ################################################## # Parameters ################################################## self.bias = bias self.freq_sample_delay_samps = freq_sample_delay_samps self.freq_samps_to_avg = freq_samps_to_avg self.mag_samps_to_avg = mag_samps_to_avg self.resamp_rate = resamp_rate self.thresh = thresh ################################################## # Blocks ################################################## self.s_and_h_detector = s_and_h_detector( freq_sample_delay_samps=freq_sample_delay_samps, freq_samps_to_avg=freq_samps_to_avg, mag_samps_to_avg=mag_samps_to_avg, thresh=thresh, ) self.resamp = pfb.arb_resampler_ccf(resamp_rate * 2.0, taps=None, flt_size=32) self.resamp.declare_sample_delay(0) self.fir = filter.fir_filter_ccc(2, (firdes.low_pass_2(1,1,.25,.05,60))) self.fir.declare_sample_delay(0) self.vco = blocks.vco_c(1, 1, 1) self.mult_conj = blocks.multiply_conjugate_cc(1) self.delay = blocks.delay(gr.sizeof_gr_complex*1, int(freq_samps_to_avg) + freq_sample_delay_samps) self.c2mag = blocks.complex_to_mag(1) self.add_const = blocks.add_const_vff((-1.0 * bias * (resamp_rate), )) self.demod = analog.quadrature_demod_cf(1) ################################################## # Connections ################################################## self.connect((self.demod, 0), (self.s_and_h_detector, 1)) self.connect((self.add_const, 0), (self.vco, 0)) self.connect((self.c2mag, 0), (self.s_and_h_detector, 0)) self.connect((self.delay, 0), (self.mult_conj, 0)) self.connect((self.mult_conj, 0), (self.fir, 0)) self.connect((self.vco, 0), (self.mult_conj, 1)) self.connect((self.fir, 0), (self.resamp, 0)) self.connect((self, 0), (self.demod, 0)) self.connect((self, 0), (self.c2mag, 0)) self.connect((self, 0), (self.delay, 0)) self.connect((self.resamp, 0), (self, 0)) self.connect((self.s_and_h_detector, 0), (self.add_const, 0))
def test_fir_filter_ccc_002(self): decim = 1 taps = firdes.low_pass(1, 1, 0.1, 0.01) src_data = [0] * len(taps) + 10 * [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_c(src_data) op = filter.fir_filter_ccc(decim, taps) dst = blocks.vector_sink_c() self.tb.connect((src, op, dst)) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5)
def test_fir_filter_ccc_001(self): decim = 1 taps = 20 * [0.5 + 1j, 0.5 + 1j] src_data = 40 * [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_c(src_data) op = filter.fir_filter_ccc(decim, taps) dst = blocks.vector_sink_c() self.tb.connect((src, op, dst)) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5)
def test_fir_filter_ccc_001(self): decim = 1 taps = 20*[0.5+1j, 0.5+1j] src_data = 40*[1+1j, 2+2j, 3+3j, 4+4j] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_c(src_data) op = filter.fir_filter_ccc(decim, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5)
def test_fir_filter_ccc_002(self): src_data = 10*[1+1j, 2+2j, 3+3j, 4+4j] # results derived from original filter.fir_filter_ccc expected_data = ((7.537424837948042e-20+7.537424837948042e-20j), (9.131923434324563e-05+9.131923434324563e-05j), (0.0003317668742965907+0.0003317668742965907j), (0.0007230418268591166+0.0007230418268591166j), (0.0012087896466255188+0.0012087896466255188j), (0.0013292605290189385+0.0013292605290189385j), (0.001120875240303576+0.001120875240303576j), (0.000744672492146492+0.000744672492146492j), (0.000429437990533188+0.000429437990533188j), (2.283908543176949e-05+2.283908543176949e-05j), (-0.0002245186478830874-0.0002245186478830874j), (-0.0001157080550910905-0.0001157080550910905j), (0.00041409023106098175+0.00041409023106098175j), (0.0009017843985930085+0.0009017843985930085j), (0.0012520025484263897+0.0012520025484263897j), (0.0014116164529696107+0.0014116164529696107j), (0.001393353333696723+0.001393353333696723j), (0.000912194955162704+0.000912194955162704j), (0.00022649182938039303+0.00022649182938039303j), (-0.00031363096786662936-0.00031363096786662936j), (-0.0003966730728279799-0.0003966730728279799j), (-0.00023757052258588374-0.00023757052258588374j), (0.00021952332463115454+0.00021952332463115454j), (0.0009092430118471384+0.0009092430118471384j), (0.001662317430600524+0.001662317430600524j), (0.0019024648936465383+0.0019024648936465383j), (0.0015955769922584295+0.0015955769922584295j), (0.0009144138311967254+0.0009144138311967254j), (0.0001872836146503687+0.0001872836146503687j), (-0.000581968342885375-0.000581968342885375j), (-0.0009886166080832481-0.0009886166080832481j), (-0.0007480768254026771-0.0007480768254026771j), (0.00018211957649327815+0.00018211957649327815j), (0.0012042406015098095+0.0012042406015098095j), (0.0020200139842927456+0.0020200139842927456j), (0.0023816542234271765+0.0023816542234271765j), (0.002195809967815876+0.002195809967815876j), (0.0012113333214074373+0.0012113333214074373j), (-0.00014088614261709154-0.00014088614261709154j), (-0.0012574587017297745-0.0012574587017297745j)) taps = filter.firdes.low_pass(1, 1, 0.1, 0.01) src = blocks.vector_source_c(src_data) op = filter.fir_filter_ccc(1, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 44100 ################################################## # Blocks ################################################## self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="Hz", minval=50, maxval=280, factor=1, decimal_places=2, ref_level=0, sample_rate=samp_rate, number_rate=15, average=False, avg_alpha=None, label="Number Plot", peak_hold=False, show_gauge=True, ) self.Add(self.wxgui_numbersink2_0.win) self.blocks_moving_average_xx_0 = blocks.moving_average_ff(samp_rate / 50, 25 / pi, 200) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float * 1, 10) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate, 60, 255, 100, firdes.WIN_BLACKMAN, 6.76) ) self.audio_source_0 = audio.source(samp_rate, "default", True) self.analog_pll_freqdet_cf_0 = analog.pll_freqdet_cf( 200 * 2.0 * pi / samp_rate, 260 * 2.0 * pi / samp_rate, 60 * 2.0 * pi / samp_rate ) ################################################## # Connections ################################################## self.connect((self.blocks_moving_average_xx_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_pll_freqdet_cf_0, 0)) self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.analog_pll_freqdet_cf_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_moving_average_xx_0, 0))
def __make_audio_filter(self): '''Return a filter which selects just the RTTY signal and shifts to AF. This isn't anywhere in the digital processing chain, so doesn't need to be concerned with signal fidelity as long as it sounds good. ''' taps = firdes.complex_band_pass( gain=1.0, sampling_freq=self.__demod_rate, low_cutoff_freq=self.__low_cutoff, high_cutoff_freq=self.__high_cutoff, transition_width=self.__transition_width) af_filter = grfilter.fir_filter_ccc(decimation=1, taps=taps) return af_filter
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Ntsc Hackrf") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samples_per_line = samples_per_line = 772 self.samp_rate = samp_rate = samples_per_line * 60 * .999 * 525 / 2 self.rf_gain = rf_gain = 14 self.if_gain = if_gain = 40 self.digital_gain = digital_gain = 0.9 self.center_freq = center_freq = 186000000+1250000 ################################################## # Blocks ################################################## self.zero = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0) self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + "hackrf=0" ) self.osmosdr_sink_0.set_sample_rate(samp_rate) self.osmosdr_sink_0.set_center_freq(center_freq, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(rf_gain, 0) self.osmosdr_sink_0.set_if_gain(if_gain, 0) self.osmosdr_sink_0.set_bb_gain(0, 0) self.osmosdr_sink_0.set_antenna("", 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((digital_gain, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_float*1, "/home/ubuntu/WAHD-TV/ve3irr-testing.dat", True) self.blocks_add_xx_0 = blocks.add_vcc(1) self.band_pass_filter_0 = filter.fir_filter_ccc(1, firdes.complex_band_pass( 1, samp_rate, -2475000 + 1725000, 2475000 + 1725000, 500000, firdes.WIN_HAMMING, 6.76)) self.analog_sig_source_x_1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 4500000, 0.1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.zero, 0), (self.blocks_float_to_complex_0, 1))
def __init__(self, mode, audio_rate=0, **kwargs): if mode == 'LSB': lsb = True elif mode == 'USB': lsb = False else: raise ValueError('Not an SSB mode: %r' % (mode,)) demod_rate = audio_rate SimpleAudioDemodulator.__init__(self, mode=mode, audio_rate=audio_rate, demod_rate=demod_rate, band_filter=audio_rate / 2, # unused band_filter_transition=audio_rate / 2, # unused **kwargs) input_rate = self.input_rate half_bandwidth = self.half_bandwidth = 2800 / 2 if lsb: band_mid = -200 - half_bandwidth else: band_mid = 200 + half_bandwidth self.band_filter_low = band_mid - half_bandwidth self.band_filter_high = band_mid + half_bandwidth self.band_filter_width = half_bandwidth / 5 self.sharp_filter_block = grfilter.fir_filter_ccc( 1, firdes.complex_band_pass(1.0, demod_rate, self.band_filter_low, self.band_filter_high, self.band_filter_width, firdes.WIN_HAMMING)) self.agc_block = analog.agc2_cc(reference=0.25) self.ssb_demod_block = blocks.complex_to_real(1) self.connect( self, self.band_filter_block, self.sharp_filter_block, self.rf_squelch_block, self.agc_block, self.ssb_demod_block) self.connect(self.sharp_filter_block, self.rf_probe_block) self.connect_audio_output(self.ssb_demod_block, self.ssb_demod_block)
def __init__(self, decim=16, N_id_2=0, avg_frames=1, freq_corr=0, N_id_1=134, file_name="/home/user/git/gr-lte/gr-lte/test/traces/lte_02_796m_30720k_frame.cfile"): gr.top_block.__init__(self, "Pss Corr Block Gui") ################################################## # Parameters ################################################## self.decim = decim self.N_id_2 = N_id_2 self.avg_frames = avg_frames self.freq_corr = freq_corr self.N_id_1 = N_id_1 self.file_name = file_name ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720*5/decim self.transition_width = transition_width = 100e3 self.samp_rate = samp_rate = 30720e3/decim self.cutoff_freq = cutoff_freq = 550e3 ################################################## # Blocks ################################################## self.gr_vector_sink_sss10 = gr.vector_sink_i(1) self.gr_vector_sink_sss0 = gr.vector_sink_i(1) self.gr_vector_sink_pss = gr.vector_sink_i(1) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate*decim) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, file_name, False) self.fir_filter_xxx_0 = filter.fir_filter_ccc(decim, (firdes.low_pass(1, decim*samp_rate, cutoff_freq, transition_width))) self.any_0_0_0 = sss_corr(N_id_1,N_id_2,False, decim, avg_frames,freq_corr) self.any_0_0 = sss_corr(N_id_1,N_id_2,True, decim, avg_frames,freq_corr) self.any_0 = pss_corr(N_id_2, decim, avg_frames*2,freq_corr) ################################################## # Connections ################################################## self.connect((self.any_0_0_0, 0), (self.gr_vector_sink_sss10, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.any_0_0_0, 0)) self.connect((self.any_0_0, 0), (self.gr_vector_sink_sss0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.any_0_0, 0)) self.connect((self.any_0, 0), (self.gr_vector_sink_pss, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.any_0, 0)) self.connect((self.gr_throttle_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_file_source_0, 0), (self.gr_null_sink_0, 0))
def __init__(self, mode, input_rate=0, context=None): assert input_rate > 0 gr.hier_block2.__init__( self, 'RTTY demodulator', gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_float * 1), ) self.__text = u'' baud = _DEFAULT_BAUD # TODO param self.baud = baud demod_rate = 6000 # TODO optimize this value self.samp_rate = demod_rate # TODO rename self.__channel_filter = MultistageChannelFilter( input_rate=input_rate, output_rate=demod_rate, cutoff_freq=self.__filter_high, transition_width=self.__transition) # TODO optimize filter band self.__sharp_filter = grfilter.fir_filter_ccc( 1, firdes.complex_band_pass(1.0, demod_rate, self.__filter_low, self.__filter_high, self.__transition, firdes.WIN_HAMMING)) self.fsk_demod = RTTYFSKDemodulator(input_rate=demod_rate, baud=baud) self.__real = blocks.complex_to_real(vlen=1) self.__char_queue = gr.msg_queue(limit=100) self.char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True) self.connect( self, self.__channel_filter, self.__sharp_filter, self.fsk_demod, rtty.rtty_decode_ff(rate=demod_rate, baud=baud, polarity=False), self.char_sink) self.connect( self.__sharp_filter, self.__real, self)
def __make_audio_filter(self): '''Return a filter which selects just the RTTY signal and shifts to AF. This isn't anywhere in the digital processing chain, so doesn't need to be concerned with signal fidelity as long as it sounds good. ''' taps = firdes.complex_band_pass( gain=1.0, sampling_freq=self.__demod_rate, low_cutoff_freq=self.__low_cutoff, high_cutoff_freq=self.__high_cutoff, transition_width=self.__transition_width) af_filter = grfilter.fir_filter_ccc( decimation=1, taps=taps) return af_filter
def test_fir_filter_ccc_001(self): src_data = 40*[1+1j, 2+2j, 3+3j, 4+4j] expected_data = ((-0.5+1.5j), (-1.5+4.5j), (-3+9j), (-5+15j), (-5.5+16.5j), (-6.5+19.5j), (-8+24j), (-10+30j), (-10.5+31.5j), (-11.5+34.5j), (-13+39j), (-15+45j), (-15.5+46.5j), (-16.5+49.5j), (-18+54j), (-20+60j), (-20.5+61.5j), (-21.5+64.5j), (-23+69j), (-25+75j), (-25.5+76.5j), (-26.5+79.5j), (-28+84j), (-30+90j), (-30.5+91.5j), (-31.5+94.5j), (-33+99j), (-35+105j), (-35.5+106.5j), (-36.5+109.5j), (-38+114j), (-40+120j), (-40.5+121.5j), (-41.5+124.5j), (-43+129j), (-45+135j), (-45.5+136.5j), (-46.5+139.5j), (-48+144j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j)) src = blocks.vector_source_c(src_data) op = filter.fir_filter_ccc(1, 20*[0.5+1j, 0.5+1j]) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5)
def __init__(self, params, freq, filename): # Super gr.hier_block2.__init__(self, "DirectOutputBranch", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) prev = self # Delay if params.delay: self.delay = blocks.delay( gr.sizeof_gr_complex, int(round(params.delay)), ) self.connect((prev, 0), (self.delay, 0)) prev = self.delay # Freq xlating filter if params.decim1 > 1: self.filt1 = filter.freq_xlating_fir_filter_ccc( params.decim1, params.taps1, freq, params.samp_rate) self.connect((prev, 0), (self.filt1, 0)) prev = self.filt1 # Decimating FIR filter if params.decim2 > 1: self.filt2 = filter.fir_filter_ccc(params.decim2, params.taps2) self.connect((prev, 0), (self.filt2, 0)) prev = self.filt2 # PFB Arb Resampler if params.resamp != 1: self.resamp = pfb.arb_resampler_ccf(params.resamp, params.taps_resamp, flt_size=32) self.connect((prev, 0), (self.resamp, 0)) prev = self.resamp # Output file self.sink = blocks.file_sink(gr.sizeof_gr_complex, filename, False) self.connect((prev, 0), (self.sink, 0))
def __init__(self, N_id_2, decim=16, avg_halfframes=2*8, freq_corr=0, dump=None): gr.hier_block2.__init__( self, "PSS correlator", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float), ) vec_half_frame = 30720*5/decim self.taps = [] for i in range(0,3): self.taps.append(gen_pss_td(i, N_re=2048/decim, freq_corr=freq_corr).get_data_conj_rev()) self.corr = filter.fir_filter_ccc(1, self.taps[N_id_2]) self.mag = gr.complex_to_mag_squared() self.vec = gr.stream_to_vector(gr.sizeof_float*1, vec_half_frame) self.deint = gr.deinterleave(gr.sizeof_float*vec_half_frame) self.add = gr.add_vff(vec_half_frame) self.argmax = gr.argmax_fs(vec_half_frame) self.null = gr.null_sink(gr.sizeof_short*1) self.max = gr.max_ff(vec_half_frame) self.to_float = gr.short_to_float(1, 1./decim) self.interleave = gr.interleave(gr.sizeof_float) #self.framestart = gr.add_const_ii(-160-144*5-2048*6+30720*5) self.connect(self, self.corr, self.mag, self.vec) self.connect((self.argmax,1), self.null) #self.connect(self.argmax, self.to_float, self.to_int, self.framestart, self) self.connect(self.argmax, self.to_float, self.interleave, self) self.connect(self.max, (self.interleave,1)) if avg_halfframes == 1: self.connect(self.vec, self.argmax) self.connect(self.vec, self.max) else: self.connect(self.vec, self.deint) self.connect(self.add, self.argmax) self.connect(self.add, self.max) for i in range(0, avg_halfframes): self.connect((self.deint, i), (self.add, i)) if dump != None: self.connect(self.mag, gr.file_sink(gr.sizeof_float, dump + "_pss_corr_f.cfile")) self.connect(self.add, gr.file_sink(gr.sizeof_float*vec_half_frame, dump + "_pss_corr_add_f.cfile"))
def test_fir_filter_ccc_003(self): src_data = 40*[1+1j, 2+2j, 3+3j, 4+4j] expected_data = ((-0.5+1.5j), (-5.5+16.5j), (-10.5+31.5j), (-15.5+46.5j), (-20.5+61.5j), (-25.5+76.5j), (-30.5+91.5j), (-35.5+106.5j), (-40.5+121.5j), (-45.5+136.5j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j), (-50+150j)) src = blocks.vector_source_c(src_data) op = filter.fir_filter_ccc(4, 20*[0.5+1j, 0.5+1j]) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5)
def __init__(self, mode, input_rate, context): channels = 2 audio_rate = 10000 gr.hier_block2.__init__( self, str('%s demodulator' % (mode,)), gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float * channels)) self.__input_rate = input_rate self.__rec_freq_input = 0.0 self.__signal_type = SignalType(kind='STEREO', sample_rate=audio_rate) # Using agc2 rather than feedforward AGC for efficiency, because this runs at the RF rate rather than the audio rate. agc_block = analog.agc2_cc(reference=dB(-8)) agc_block.set_attack_rate(8e-3) agc_block.set_decay_rate(8e-3) agc_block.set_max_gain(dB(40)) self.connect( self, agc_block) channel_joiner = blocks.streams_to_vector(gr.sizeof_float, channels) self.connect(channel_joiner, self) for channel in six.moves.range(0, channels): self.connect( agc_block, grfilter.fir_filter_ccc(1, design_sawtooth_filter(decreasing=channel == 0)), blocks.complex_to_mag(1), blocks.float_to_complex(), # So we can use the complex-input band filter. TODO eliminate this for efficiency MultistageChannelFilter( input_rate=input_rate, output_rate=audio_rate, cutoff_freq=5000, transition_width=5000), blocks.complex_to_real(), # assuming below 40Hz is not of interest grfilter.dc_blocker_ff(audio_rate // 40, False), (channel_joiner, channel))
def __init__(self, mode, input_rate, context): channels = 2 audio_rate = 10000 gr.hier_block2.__init__( self, str('%s demodulator' % (mode,)), gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float * channels)) self.__input_rate = input_rate self.__rec_freq_input = 0.0 self.__signal_type = SignalType(kind='STEREO', sample_rate=audio_rate) # Using agc2 rather than feedforward AGC for efficiency, because this runs at the RF rate rather than the audio rate. agc_block = analog.agc2_cc(reference=dB(-8)) agc_block.set_attack_rate(8e-3) agc_block.set_decay_rate(8e-3) agc_block.set_max_gain(dB(40)) self.connect( self, agc_block) channel_joiner = blocks.streams_to_vector(gr.sizeof_float, channels) self.connect(channel_joiner, self) for channel in xrange(0, channels): self.connect( agc_block, grfilter.fir_filter_ccc(1, design_sawtooth_filter(decreasing=channel == 0)), blocks.complex_to_mag(1), blocks.float_to_complex(), # So we can use the complex-input band filter. TODO eliminate this for efficiency MultistageChannelFilter( input_rate=input_rate, output_rate=audio_rate, cutoff_freq=5000, transition_width=5000), blocks.complex_to_real(), # assuming below 40Hz is not of interest grfilter.dc_blocker_ff(audio_rate // 40, False), (channel_joiner, channel))
def __init__(self, options): gr.top_block.__init__(self) if(options.to_file is not None): self.file = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) self.sink = blocks.throttle(gr.sizeof_gr_complex,1e6) self.connect( self.sink, self.file ) elif(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) self._setup_tx_path(options) self._setup_rpc_manager() if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff ) self.connect(self.txpath, freq_off) self.txpath = freq_off self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile) else: self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect(self.txpath, self.fad_chan) self.txpath = self.fad_chan self.connect(self.txpath, self.sink)
def __init__(self, N, fs, bw, tw, atten, D): gr.top_block.__init__(self) self._nsamps = N self._fs = fs self._bw = bw self._tw = tw self._at = atten self._decim = D taps = filter.firdes.low_pass_2(1, self._fs, self._bw, self._tw, self._at) print "Num. Taps: ", len(taps) self.src = analog.noise_source_c(analog.GR_GAUSSIAN, 1) self.head = blocks.head(gr.sizeof_gr_complex, self._nsamps) self.filt0 = filter.fir_filter_ccc(self._decim, taps) self.vsnk_src = blocks.vector_sink_c() self.vsnk_out = blocks.vector_sink_c() self.connect(self.src, self.head, self.vsnk_src) self.connect(self.head, self.filt0, self.vsnk_out)
def test_001_t(self): fftlen = 128 cell_id = 124 taps = filter.optfir.low_pass(1, fftlen*15e3, 472.5e3, 900e3, 0.2, 40) samples = t.get_mod_frame(cell_id, 6, 1, fftlen) samps = np.tile(samples[0], 5) src = blocks.vector_source_c(samps, repeat=False, vlen=1) fir = filter.fir_filter_ccc(fftlen/64, taps) sync = lte.mimo_pss_coarse_sync(4, 1) dbg0 = blocks.message_debug() dbg1 = blocks.message_debug() dbg2 = blocks.message_debug() self.tb.connect(src, fir, sync) self.tb.msg_connect((sync, 'control'), (dbg0, 'store')) self.tb.msg_connect((sync, 'N_id_2'), (dbg1, 'store')) self.tb.msg_connect((sync, 'coarse_pos'), (dbg2, 'store')) # set up fg self.tb.run() # check data self.assertEqual(pmt.to_long(dbg1.get_message(0)), int(cell_id % 3)) ctrl_res = pmt.to_bool(dbg0.get_message(0)) assert ctrl_res offset = 10 + 5 * 9 + 6 * fftlen print(offset) # print() pos = pmt.to_long(dbg2.get_message(0)) print(pos) print(pos * 2 - (len(taps) // 2)) import matplotlib.pyplot as plt plt.plot(np.abs(samps)) plt.show()
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.offset_tune_freq = offset_tune_freq = -10E3 self.band_freq = band_freq = 7.055E6 self.usrp_clk_rate = usrp_clk_rate = 200E6 self.usrp_ask_freq = usrp_ask_freq = band_freq+offset_tune_freq self.usrp_DDC_freq = usrp_DDC_freq = np.round(usrp_ask_freq/usrp_clk_rate* 2**32)/2**32 * usrp_clk_rate self.fine_tuner_freq = fine_tuner_freq = 0 self.coarse_tuner_freq = coarse_tuner_freq = 0 self.samp_rate = samp_rate = 250000 self.lo_freq = lo_freq = usrp_DDC_freq + coarse_tuner_freq + fine_tuner_freq - offset_tune_freq self.record_check_box = record_check_box = False self.file_name_string = file_name_string = str(int(time.mktime(time.gmtime())))+"UTC_"+'{:.6f}'.format(lo_freq)+"Hz"+"_"+str(int(samp_rate/100))+"sps"+".raw" self.variable_function_probe_0 = variable_function_probe_0 = 0 self.file_name = file_name = file_name_string if record_check_box==True else "/dev/null" self.volume = volume = 5.0 self.rx_power_label = rx_power_label = '{:.1f}'.format(variable_function_probe_0) self.lo_freq_label = lo_freq_label = '{:.6f}'.format(lo_freq) self.gain_offset_dB = gain_offset_dB = 18.86 self.filter_taps = filter_taps = firdes.low_pass(1.0,2.5,0.1,0.02,firdes.WIN_HAMMING) self.filename_label = filename_label = file_name self.cw_filter_bw = cw_filter_bw = 1000 self.RX_power_offset_dB = RX_power_offset_dB = -35.2 ################################################## # Blocks ################################################## self._volume_layout = Qt.QVBoxLayout() self._volume_knob = Qwt.QwtKnob() self._volume_knob.setRange(0, 10.0, 1.0) self._volume_knob.setValue(self.volume) self._volume_knob.valueChanged.connect(self.set_volume) self._volume_layout.addWidget(self._volume_knob) self._volume_label = Qt.QLabel("Volume") self._volume_label.setAlignment(Qt.Qt.AlignTop | Qt.Qt.AlignHCenter) self._volume_layout.addWidget(self._volume_label) self.top_grid_layout.addLayout(self._volume_layout, 5,6,1,1) self._cw_filter_bw_options = (100, 500, 1000, ) self._cw_filter_bw_labels = ("100 Hz", "500 Hz", "1 kHz", ) self._cw_filter_bw_tool_bar = Qt.QToolBar(self) self._cw_filter_bw_tool_bar.addWidget(Qt.QLabel("CW Filter BW"+": ")) self._cw_filter_bw_combo_box = Qt.QComboBox() self._cw_filter_bw_tool_bar.addWidget(self._cw_filter_bw_combo_box) for label in self._cw_filter_bw_labels: self._cw_filter_bw_combo_box.addItem(label) self._cw_filter_bw_callback = lambda i: Qt.QMetaObject.invokeMethod(self._cw_filter_bw_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._cw_filter_bw_options.index(i))) self._cw_filter_bw_callback(self.cw_filter_bw) self._cw_filter_bw_combo_box.currentIndexChanged.connect( lambda i: self.set_cw_filter_bw(self._cw_filter_bw_options[i])) self.top_grid_layout.addWidget(self._cw_filter_bw_tool_bar, 5,5,1,1) self.blocks_probe_signal_x_0 = blocks.probe_signal_f() def _variable_function_probe_0_probe(): while True: val = self.blocks_probe_signal_x_0.level() try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (5)) _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.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", "addr=192.168.40.2")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_subdev_spec("B:A", 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(usrp_ask_freq, 0) self.uhd_usrp_source_0.set_gain(6, 0) self._rx_power_label_tool_bar = Qt.QToolBar(self) if None: self._rx_power_label_formatter = None else: self._rx_power_label_formatter = lambda x: x self._rx_power_label_tool_bar.addWidget(Qt.QLabel("RX Power (dBm)"+": ")) self._rx_power_label_label = Qt.QLabel(str(self._rx_power_label_formatter(self.rx_power_label))) self._rx_power_label_tool_bar.addWidget(self._rx_power_label_label) self.top_grid_layout.addWidget(self._rx_power_label_tool_bar, 4,7,1,1) _record_check_box_check_box = Qt.QCheckBox("Record") self._record_check_box_choices = {True: True, False: False} self._record_check_box_choices_inv = dict((v,k) for k,v in self._record_check_box_choices.iteritems()) self._record_check_box_callback = lambda i: Qt.QMetaObject.invokeMethod(_record_check_box_check_box, "setChecked", Qt.Q_ARG("bool", self._record_check_box_choices_inv[i])) self._record_check_box_callback(self.record_check_box) _record_check_box_check_box.stateChanged.connect(lambda i: self.set_record_check_box(self._record_check_box_choices[bool(i)])) self.top_grid_layout.addWidget(_record_check_box_check_box, 6,5,1,1) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=48000, decimation=2500, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype usrp_DDC_freq, #fc samp_rate, #bw "Band Waterfall", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.10) self.qtgui_waterfall_sink_x_0.enable_grid(False) if complex == type(float()): self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] colors = [5, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-100, -70) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 4,0,3,5) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype lo_freq, #fc samp_rate/100, #bw str(samp_rate/100) + " Hz Channel Spectrum", #name 2 #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(-120, -70) 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(True) self.qtgui_freq_sink_x_0_0.set_fft_average(1.0) 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(2): 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, 0,5,3,5) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype usrp_DDC_freq, #fc samp_rate, #bw "Band 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(-110, -60) 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(True) self.qtgui_freq_sink_x_0.set_fft_average(0.2) 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,5) self.low_pass_filter_0_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate/100, 0.9*cw_filter_bw, 0.1*cw_filter_bw, firdes.WIN_BLACKMAN, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 10**(gain_offset_dB/20), samp_rate, 100E3, 20E3, firdes.WIN_HAMMING, 6.76)) self._lo_freq_label_tool_bar = Qt.QToolBar(self) if None: self._lo_freq_label_formatter = None else: self._lo_freq_label_formatter = lambda x: x self._lo_freq_label_tool_bar.addWidget(Qt.QLabel("LO Freq (Hz)"+": ")) self._lo_freq_label_label = Qt.QLabel(str(self._lo_freq_label_formatter(self.lo_freq_label))) self._lo_freq_label_tool_bar.addWidget(self._lo_freq_label_label) self.top_grid_layout.addWidget(self._lo_freq_label_tool_bar, 4,6,1,1) self.hilbert_fc_0_0 = filter.hilbert_fc(65, firdes.WIN_HAMMING, 6.76) self.hilbert_fc_0 = filter.hilbert_fc(65, firdes.WIN_HAMMING, 6.76) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(10, (filter_taps), lo_freq - usrp_DDC_freq, samp_rate) self.fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(10, (filter_taps)) self.fir_filter_xxx_0_0_0.declare_sample_delay(0) self._fine_tuner_freq_layout = Qt.QVBoxLayout() self._fine_tuner_freq_tool_bar = Qt.QToolBar(self) self._fine_tuner_freq_layout.addWidget(self._fine_tuner_freq_tool_bar) self._fine_tuner_freq_tool_bar.addWidget(Qt.QLabel("Fine Tuner (Hz)"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._fine_tuner_freq_counter = qwt_counter_pyslot() self._fine_tuner_freq_counter.setRange(-500, 500, 1) self._fine_tuner_freq_counter.setNumButtons(2) self._fine_tuner_freq_counter.setValue(self.fine_tuner_freq) self._fine_tuner_freq_tool_bar.addWidget(self._fine_tuner_freq_counter) self._fine_tuner_freq_counter.valueChanged.connect(self.set_fine_tuner_freq) self._fine_tuner_freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._fine_tuner_freq_slider.setRange(-500, 500, 1) self._fine_tuner_freq_slider.setValue(self.fine_tuner_freq) self._fine_tuner_freq_slider.setMinimumWidth(200) self._fine_tuner_freq_slider.valueChanged.connect(self.set_fine_tuner_freq) self._fine_tuner_freq_layout.addWidget(self._fine_tuner_freq_slider) self.top_grid_layout.addLayout(self._fine_tuner_freq_layout, 3,5,1,5) self._filename_label_tool_bar = Qt.QToolBar(self) if None: self._filename_label_formatter = None else: self._filename_label_formatter = lambda x: x self._filename_label_tool_bar.addWidget(Qt.QLabel("File Name"+": ")) self._filename_label_label = Qt.QLabel(str(self._filename_label_formatter(self.filename_label))) self._filename_label_tool_bar.addWidget(self._filename_label_label) self.top_grid_layout.addWidget(self._filename_label_tool_bar, 6,6,1,3) self._coarse_tuner_freq_layout = Qt.QVBoxLayout() self._coarse_tuner_freq_tool_bar = Qt.QToolBar(self) self._coarse_tuner_freq_layout.addWidget(self._coarse_tuner_freq_tool_bar) self._coarse_tuner_freq_tool_bar.addWidget(Qt.QLabel("Coarse Tuner (Hz)"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._coarse_tuner_freq_counter = qwt_counter_pyslot() self._coarse_tuner_freq_counter.setRange(-samp_rate/2, samp_rate/2, 100) self._coarse_tuner_freq_counter.setNumButtons(2) self._coarse_tuner_freq_counter.setValue(self.coarse_tuner_freq) self._coarse_tuner_freq_tool_bar.addWidget(self._coarse_tuner_freq_counter) self._coarse_tuner_freq_counter.valueChanged.connect(self.set_coarse_tuner_freq) self._coarse_tuner_freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._coarse_tuner_freq_slider.setRange(-samp_rate/2, samp_rate/2, 100) self._coarse_tuner_freq_slider.setValue(self.coarse_tuner_freq) self._coarse_tuner_freq_slider.setMinimumWidth(50) self._coarse_tuner_freq_slider.valueChanged.connect(self.set_coarse_tuner_freq) self._coarse_tuner_freq_layout.addWidget(self._coarse_tuner_freq_slider) self.top_grid_layout.addLayout(self._coarse_tuner_freq_layout, 3,0,1,5) self.blocks_null_sink_1_0_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_null_sink_1_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, RX_power_offset_dB) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_integrate_xx_0 = blocks.integrate_ff(500) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, file_name, False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_float_1_0 = blocks.complex_to_float(1) self.blocks_complex_to_float_0_0 = blocks.complex_to_float(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0 = blocks.add_vff(1) self._band_freq_options = [1.84E6, 3.598E6, 7.055E6, 2.5E6, 5.0E6, 10.0E6] self._band_freq_labels = ["160m", "80m", "40m", "2.5 MHz", "5 MHz", "10 MHz"] self._band_freq_tool_bar = Qt.QToolBar(self) self._band_freq_tool_bar.addWidget(Qt.QLabel("Band"+": ")) self._band_freq_combo_box = Qt.QComboBox() self._band_freq_tool_bar.addWidget(self._band_freq_combo_box) for label in self._band_freq_labels: self._band_freq_combo_box.addItem(label) self._band_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._band_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._band_freq_options.index(i))) self._band_freq_callback(self.band_freq) self._band_freq_combo_box.currentIndexChanged.connect( lambda i: self.set_band_freq(self._band_freq_options[i])) self.top_grid_layout.addWidget(self._band_freq_tool_bar, 4,5,1,1) self.audio_sink_0 = audio.sink(48000, "", True) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate/100, analog.GR_COS_WAVE, 600, 1, 0) self.analog_agc3_xx_0 = analog.agc3_cc(1e-1, 1e-4, volume/100, 1, 1) self.analog_agc3_xx_0.set_max_gain(2**16) ################################################## # Connections ################################################## self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fir_filter_xxx_0_0_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_complex_to_mag_squared_0, 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_nlog10_ff_0, 0), (self.blocks_probe_signal_x_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc3_xx_0, 0)) self.connect((self.analog_agc3_xx_0, 0), (self.blocks_complex_to_float_1_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_complex_to_float_0_0, 1), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_complex_to_float_0_0, 0), (self.blocks_null_sink_1_0_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_null_sink_1_0, 0)) self.connect((self.blocks_complex_to_float_1_0, 1), (self.hilbert_fc_0, 0)) self.connect((self.hilbert_fc_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_complex_to_float_1_0, 0), (self.hilbert_fc_0_0, 0)) self.connect((self.hilbert_fc_0_0, 0), (self.blocks_complex_to_float_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.qtgui_freq_sink_x_0_0, 1))
def run_test(seed,blocksize): tb = gr.top_block() ################################################## # Variables ################################################## M = 2 K = 1 P = 2 h = (1.0*K)/P L = 3 Q = 4 frac = 0.99 f = trellis.fsm(P,M,L) # CPFSK signals #p = numpy.ones(Q)/(2.0) #q = numpy.cumsum(p)/(1.0*Q) # GMSK signals BT=0.3; tt=numpy.arange(0,L*Q)/(1.0*Q)-L/2.0; #print tt p=(0.5*scipy.special.erfc(2*math.pi*BT*(tt-0.5)/math.sqrt(math.log(2.0))/math.sqrt(2.0))-0.5*scipy.special.erfc(2*math.pi*BT*(tt+0.5)/math.sqrt(math.log(2.0))/math.sqrt(2.0)))/2.0; p=p/sum(p)*Q/2.0; #print p q=numpy.cumsum(p)/Q; q=q/q[-1]/2.0; #print q (f0T,SS,S,F,Sf,Ff,N) = fsm_utils.make_cpm_signals(K,P,M,L,q,frac) #print N #print Ff Ffa = numpy.insert(Ff,Q,numpy.zeros(N),axis=0) #print Ffa MF = numpy.fliplr(numpy.transpose(Ffa)) #print MF E = numpy.sum(numpy.abs(Sf)**2,axis=0) Es = numpy.sum(E)/f.O() #print Es constellation = numpy.reshape(numpy.transpose(Sf),N*f.O()) #print Ff #print Sf #print constellation #print numpy.max(numpy.abs(SS - numpy.dot(Ff , Sf))) EsN0_db = 10.0 N0 = Es * 10.0**(-(1.0*EsN0_db)/10.0) #N0 = 0.0 #print N0 head = 4 tail = 4 numpy.random.seed(seed*666) data = numpy.random.randint(0, M, head+blocksize+tail+1) #data = numpy.zeros(blocksize+1+head+tail,'int') for i in range(head): data[i]=0 for i in range(tail+1): data[-i]=0 ################################################## # Blocks ################################################## random_source_x_0 = blocks.vector_source_b(data.tolist(), False) digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf((-1, 1), 1) filter_interp_fir_filter_xxx_0 = filter.interp_fir_filter_fff(Q, p) analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(2*math.pi*h*(1.0/Q)) blocks_add_vxx_0 = blocks.add_vcc(1) analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, (N0/2.0)**0.5, -long(seed)) blocks_multiply_vxx_0 = blocks.multiply_vcc(1) analog_sig_source_x_0 = analog.sig_source_c(Q, analog.GR_COS_WAVE, -f0T, 1, 0) # only works for N=2, do it manually for N>2... filter_fir_filter_xxx_0_0 = filter.fir_filter_ccc(Q, MF[0].conjugate()) filter_fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(Q, MF[1].conjugate()) blocks_streams_to_stream_0 = blocks.streams_to_stream(gr.sizeof_gr_complex*1, int(N)) blocks_skiphead_0 = blocks.skiphead(gr.sizeof_gr_complex*1, int(N*(1+0))) viterbi = trellis.viterbi_combined_cb(f, head+blocksize+tail, 0, -1, int(N), constellation, digital.TRELLIS_EUCLIDEAN) blocks_vector_sink_x_0 = blocks.vector_sink_b() ################################################## # Connections ################################################## tb.connect((random_source_x_0, 0), (digital_chunks_to_symbols_xx_0, 0)) tb.connect((digital_chunks_to_symbols_xx_0, 0), (filter_interp_fir_filter_xxx_0, 0)) tb.connect((filter_interp_fir_filter_xxx_0, 0), (analog_frequency_modulator_fc_0, 0)) tb.connect((analog_frequency_modulator_fc_0, 0), (blocks_add_vxx_0, 0)) tb.connect((analog_noise_source_x_0, 0), (blocks_add_vxx_0, 1)) tb.connect((blocks_add_vxx_0, 0), (blocks_multiply_vxx_0, 0)) tb.connect((analog_sig_source_x_0, 0), (blocks_multiply_vxx_0, 1)) tb.connect((blocks_multiply_vxx_0, 0), (filter_fir_filter_xxx_0_0, 0)) tb.connect((blocks_multiply_vxx_0, 0), (filter_fir_filter_xxx_0_0_0, 0)) tb.connect((filter_fir_filter_xxx_0_0, 0), (blocks_streams_to_stream_0, 0)) tb.connect((filter_fir_filter_xxx_0_0_0, 0), (blocks_streams_to_stream_0, 1)) tb.connect((blocks_streams_to_stream_0, 0), (blocks_skiphead_0, 0)) tb.connect((blocks_skiphead_0, 0), (viterbi, 0)) tb.connect((viterbi, 0), (blocks_vector_sink_x_0, 0)) tb.run() dataest = blocks_vector_sink_x_0.data() #print data #print numpy.array(dataest) perr = 0 err = 0 for i in range(blocksize): if data[head+i] != dataest[head+i]: #print i err += 1 if err != 0 : perr = 1 return (err,perr)
def __init__(self, fft_length, cp_length, snr, kstime, logging): ''' Maximum Likelihood OFDM synchronizer: J. van de Beek, M. Sandell, and P. O. Borjesson, "ML Estimation of Time and Frequency Offset in OFDM Systems," IEEE Trans. Signal Processing, vol. 45, no. 7, pp. 1800-1805, 1997. ''' gr.hier_block2.__init__(self, "ofdm_sync_ml", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature self.input = blocks.add_const_cc(0) SNR = 10.0**(snr / 10.0) rho = SNR / (SNR + 1.0) symbol_length = fft_length + cp_length # ML Sync # Energy Detection from ML Sync self.connect(self, self.input) # Create a delay line self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length) self.connect(self.input, self.delay) # magnitude squared blocks self.magsqrd1 = blocks.complex_to_mag_squared() self.magsqrd2 = blocks.complex_to_mag_squared() self.adder = blocks.add_ff() moving_sum_taps = [rho / 2 for i in range(cp_length)] self.moving_sum_filter = filter.fir_filter_fff(1,moving_sum_taps) self.connect(self.input,self.magsqrd1) self.connect(self.delay,self.magsqrd2) self.connect(self.magsqrd1,(self.adder,0)) self.connect(self.magsqrd2,(self.adder,1)) self.connect(self.adder,self.moving_sum_filter) # Correlation from ML Sync self.conjg = blocks.conjugate_cc(); self.mixer = blocks.multiply_cc(); movingsum2_taps = [1.0 for i in range(cp_length)] self.movingsum2 = filter.fir_filter_ccf(1,movingsum2_taps) # Correlator data handler self.c2mag = blocks.complex_to_mag() self.angle = blocks.complex_to_arg() self.connect(self.input,(self.mixer,1)) self.connect(self.delay,self.conjg,(self.mixer,0)) self.connect(self.mixer,self.movingsum2,self.c2mag) self.connect(self.movingsum2,self.angle) # ML Sync output arg, need to find maximum point of this self.diff = blocks.sub_ff() self.connect(self.c2mag,(self.diff,0)) self.connect(self.moving_sum_filter,(self.diff,1)) #ML measurements input to sampler block and detect self.f2c = blocks.float_to_complex() self.pk_detect = blocks.peak_detector_fb(0.2, 0.25, 30, 0.0005) self.sample_and_hold = blocks.sample_and_hold_ff() # use the sync loop values to set the sampler and the NCO # self.diff = theta # self.angle = epsilon self.connect(self.diff, self.pk_detect) # The DPLL corrects for timing differences between CP correlations use_dpll = 0 if use_dpll: self.dpll = gr.dpll_bb(float(symbol_length),0.01) self.connect(self.pk_detect, self.dpll) self.connect(self.dpll, (self.sample_and_hold,1)) else: self.connect(self.pk_detect, (self.sample_and_hold,1)) self.connect(self.angle, (self.sample_and_hold,0)) ################################ # correlate against known symbol # This gives us the same timing signal as the PN sync block only on the preamble # we don't use the signal generated from the CP correlation because we don't want # to readjust the timing in the middle of the packet or we ruin the equalizer settings. kstime = [k.conjugate() for k in kstime] kstime.reverse() self.kscorr = filter.fir_filter_ccc(1, kstime) self.corrmag = blocks.complex_to_mag_squared() self.div = blocks.divide_ff() # The output signature of the correlation has a few spikes because the rest of the # system uses the repeated preamble symbol. It needs to work that generically if # anyone wants to use this against a WiMAX-like signal since it, too, repeats. # The output theta of the correlator above is multiplied with this correlation to # identify the proper peak and remove other products in this cross-correlation self.threshold_factor = 0.1 self.slice = blocks.threshold_ff(self.threshold_factor, self.threshold_factor, 0) self.f2b = blocks.float_to_char() self.b2f = blocks.char_to_float() self.mul = blocks.multiply_ff() # Normalize the power of the corr output by the energy. This is not really needed # and could be removed for performance, but it makes for a cleaner signal. # if this is removed, the threshold value needs adjustment. self.connect(self.input, self.kscorr, self.corrmag, (self.div,0)) self.connect(self.moving_sum_filter, (self.div,1)) self.connect(self.div, (self.mul,0)) self.connect(self.pk_detect, self.b2f, (self.mul,1)) self.connect(self.mul, self.slice) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) self.connect(self.slice, self.f2b, (self,1)) if logging: self.connect(self.moving_sum_filter, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat")) self.connect(self.diff, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat")) self.connect(self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat")) self.connect(self.corrmag, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat")) self.connect(self.kscorr, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat")) self.connect(self.div, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat")) self.connect(self.mul, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat")) self.connect(self.slice, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat")) self.connect(self.pk_detect, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat")) if use_dpll: self.connect(self.dpll, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat")) self.connect(self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat")) self.connect(self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat"))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Chu") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1200000 self.upconverter_lo_freq = upconverter_lo_freq = 125000000 self.space_tone = space_tone = 2025 self.offset = offset = 100000 self.mark_tone = mark_tone = 2225 self.gain = gain = 10 self.decimation = decimation = samp_rate / 48000 self.chu_freq = chu_freq = 3330000 self.channel_rate = channel_rate = 4800 ################################################## # Blocks ################################################## self.nb = self.nb = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.nb.AddPage(grc_wxgui.Panel(self.nb), "48 kHz") self.nb.AddPage(grc_wxgui.Panel(self.nb), "4.8 kHz") self.nb.AddPage(grc_wxgui.Panel(self.nb), "Data scope") self.GridAdd(self.nb, 2, 0, 1, 1) _gain_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, label="USB tuner gain", converter=forms.float_converter(), proportion=0, ) self._gain_slider = forms.slider( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, minimum=0, maximum=50, num_steps=125, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 1, 0, 1, 1) self._chu_freq_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.chu_freq, callback=self.set_chu_freq, label="CHU frequency", choices=[3330000, 7850000, 14670000], labels=['3.33 MHz', '7.85 MHz', '14.67 MHz'], style=wx.RA_HORIZONTAL, ) self.GridAdd(self._chu_freq_chooser, 0, 0, 1, 1) self.wxgui_waterfallsink2_1 = waterfallsink2.waterfall_sink_c( self.nb.GetPage(1).GetWin(), baseband_freq=(mark_tone + space_tone) / 2, dynamic_range=50, ref_level=-20, ref_scale=2.0, sample_rate=channel_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.nb.GetPage(1).Add(self.wxgui_waterfallsink2_1.win) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.nb.GetPage(0).GetWin(), baseband_freq=chu_freq, dynamic_range=50, ref_level=-60, ref_scale=2.0, sample_rate=samp_rate / decimation, fft_size=2048, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", win=window.hamming, ) self.nb.GetPage(0).Add(self.wxgui_waterfallsink2_0.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.nb.GetPage(2).GetWin(), title="Scope Plot", sample_rate=channel_rate, v_scale=1, v_offset=0, t_scale=0.050, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb.GetPage(2).Add(self.wxgui_scopesink2_0.win) self.root_raised_cosine_filter_0 = filter.fir_filter_fff(1, firdes.root_raised_cosine( 1, channel_rate, 300, 0.35, 100)) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(chu_freq - offset + upconverter_lo_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(0, 0) self.osmosdr_source_0.set_gain(gain, 0) self.osmosdr_source_0.set_if_gain(20, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna("", 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.low_pass_filter_1 = filter.fir_filter_ccf(10, firdes.low_pass( 1000, samp_rate / 25, 200, 50, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(decimation, firdes.low_pass( 1, samp_rate, 20000, 5000, firdes.WIN_HAMMING, 6.76)) self.ham_chu_decode_0 = ham.chu_decode() self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.blocks_multiply_xx_2 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 0.5) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, )) self.band_pass_filter_0 = filter.fir_filter_ccc(1, firdes.complex_band_pass( 1, samp_rate / decimation, 200, 2800, 200, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0_0 = audio.sink(48000, "", True) self.analog_sig_source_x_1 = analog.sig_source_c(samp_rate / decimation, analog.GR_COS_WAVE, -(space_tone + mark_tone) / 2, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -offset, 1, 0) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(channel_rate / (3.1416*(mark_tone - space_tone))) self.analog_pll_carriertracking_cc_0 = analog.pll_carriertracking_cc(3.1416 / 500, 1.8, -1.8) self.analog_agc_xx_0 = analog.agc_ff(1e-1, 0.02, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_2, 1)) self.connect((self.analog_pll_carriertracking_cc_0, 0), (self.blocks_multiply_xx_2, 0)) self.connect((self.analog_pll_carriertracking_cc_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_pll_carriertracking_cc_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.osmosdr_source_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.wxgui_waterfallsink2_1, 0)) self.connect((self.low_pass_filter_1, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.blocks_multiply_xx_2, 0), (self.low_pass_filter_1, 0)) self.connect((self.band_pass_filter_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.audio_sink_0_0, 0)) self.connect((self.analog_pll_carriertracking_cc_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.ham_chu_decode_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.root_raised_cosine_filter_0, 0))