def __init__(self, pfa, pfd, freq, useless_bw, nframes_to_check, nframes_to_average): gr.top_block.__init__(self) # Constants samp_rate = 2.4e6 fft_size = 4096 samples_per_band = 16 tcme = 1.9528 output_pfa = True debug_stats = False histogram = True primary_user_location = 42 nsegs_to_check = 6 downconverter = 1 # Blocks rtlsdr_source = osmosdr.source_c( args="nchan=" + str(1) + " " + "" ) rtlsdr_source.set_sample_rate(samp_rate) rtlsdr_source.set_center_freq(freq, 0) rtlsdr_source.set_freq_corr(0, 0) rtlsdr_source.set_gain_mode(0, 0) rtlsdr_source.set_gain(10, 0) rtlsdr_source.set_if_gain(24, 0) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check) self.sink = gr.vector_sink_f() # Connections self.connect(rtlsdr_source, s2v, fftb, self.ss, self.sink)
def __init__(self, parent, baseband_freq=0, y_per_div=10, ref_level=50, sample_rate=1, fft_size=512, fft_rate=default_fft_rate, average=False, avg_alpha=None, title='', size=default_fftsink_size, **kwargs): gr.hier_block2.__init__(self, "waterfall_sink_f", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0,0,0)) waterfall_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title) self.s2p = gr.serial_to_parallel(gr.sizeof_float, self.fft_size) self.one_in_n = gr.keep_one_in_n(gr.sizeof_float * self.fft_size, max(1, int(self.sample_rate/self.fft_size/self.fft_rate))) mywindow = window.blackmanharris(self.fft_size) self.fft = gr.fft_vfc(self.fft_size, True, mywindow) self.c2mag = gr.complex_to_mag(self.fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) self.log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size)) self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag, self.avg, self.log, self.sink) self.win = waterfall_window(self, parent, size=size) self.set_average(self.average)
def __init__(self, parent, baseband_freq=0, y_per_div=10, ref_level=50, sample_rate=1, fft_size=512, fft_rate=default_fft_rate, average=False, avg_alpha=None, title='', size=default_fftsink_size): gr.hier_block2.__init__(self, "waterfall_sink_f", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0,0,0)) waterfall_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title) self.s2p = gr.serial_to_parallel(gr.sizeof_float, self.fft_size) self.one_in_n = gr.keep_one_in_n(gr.sizeof_float * self.fft_size, max(1, int(self.sample_rate/self.fft_size/self.fft_rate))) mywindow = window.blackmanharris(self.fft_size) self.fft = gr.fft_vfc(self.fft_size, True, mywindow) self.c2mag = gr.complex_to_mag(self.fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) self.log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size)) self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag, self.avg, self.log, self.sink) self.win = waterfall_window(self, parent, size=size) self.set_average(self.average)
def __init__(self, N_id_1, N_id_2, slot0=True, N_re=128, N_cp_ts=144, freq_corr=0): top = gr.top_block("foo") source = gr.vector_source_c(range(0, N_re), False, N_re) source.set_data(gen_sss_fd(N_id_1, N_id_2, N_re).get_sss(slot0)) fft = gr.fft_vcc(N_re, False, window.blackmanharris(1024), True) cp = digital.ofdm_cyclic_prefixer(N_re, N_re + N_cp_ts * N_re / 2048) if freq_corr != 0: freq_corr = gr.freq_xlating_fir_filter_ccf(1, 1, freq_corr, 15000 * N_re) sink = gr.vector_sink_c(1) top.connect(source, fft, cp) if freq_corr != 0: top.connect(cp, freq_corr, sink) else: top.connect(cp, sink) top.run() self.data = sink.data()
def __init__(self, fg, parent, baseband_freq=0, y_per_div=10, ref_level=100, sample_rate=1, fft_size=512, fft_rate=20, average=False, avg_alpha=None, title='', size=default_fftsink_size): fft_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq, y_per_div=y_per_div, ref_level=ref_level, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title) s2p = gr.serial_to_parallel(gr.sizeof_float, fft_size) one_in_n = gr.keep_one_in_n(gr.sizeof_float * fft_size, int(sample_rate/fft_size/fft_rate)) mywindow = window.blackmanharris(fft_size) fft = gr.fft_vfc(self.fft_size, True, mywindow) #fft = gr.fft_vfc(fft_size, True, True) c2mag = gr.complex_to_mag(fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, fft_size) log = gr.nlog10_ff(20, fft_size) sink = gr.file_descriptor_sink(gr.sizeof_float * fft_size, self.w_fd) fg.connect (s2p, one_in_n, fft, c2mag, self.avg, log, sink) gr.hier_block.__init__(self, fg, s2p, sink) self.fg = fg self.gl_fft_window(self)
def __init__(self,options,Freq): gr.top_block.__init__(self) if options.input_file == "": self.IS_USRP2 = True else: self.IS_USRP2 = False #self.min_freq = options.start #self.max_freq = options.stop self.min_freq = Freq.value-(3*10**6) # same as that of the transmitter bandwidth ie 6MHZ approx for a given value of decimation line option any more self.max_freq = Freq.value+(3*10**6) if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them print "Start and stop frequencies order swapped!" self.fft_size = options.fft_size self.ofdm_bins = options.sense_bins # build graph s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) #log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # modifications for USRP2 if self.IS_USRP2: self.u = uhd.usrp_source(options.args,uhd.io_type.COMPLEX_FLOAT32,num_channels=1) # Modified Line # self.u.set_decim(options.decim) # samp_rate = self.u.adc_rate()/self.u.decim() samp_rate = 100e6/options.decim # modified sampling rate self.u.set_samp_rate(samp_rate) else: self.u = gr.file_source(gr.sizeof_gr_complex,options.input_file, True) samp_rate = 100e6 /options.decim # modified sampling rate self.freq_step =0 #0.75* samp_rate self.min_center_freq = (self.min_freq + self.max_freq)/2 global BW BW = self.max_freq - self.min_freq global size size=self.fft_size global ofdm_bins ofdm_bins = self.ofdm_bins global usr #global thrshold_inorder usr=samp_rate nsteps = 10 self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * samp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * samp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) # thread-safe message queue self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # control scanning and record frequency domain statistics self.connect(self.u, s2v, fft,c2mag,stats) if options.gain is None: g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2 # if no gain was specified, use the mid-point in dB
def __init__(self, dBm, pfa, pfd, useless_bw, plot_histogram): gr.top_block.__init__(self) # Constants samp_rate = 2.4e6 samples_per_band = 16 tcme = 1.9528 output_pfa = True debug_stats = False self.histogram = plot_histogram primary_user_location = 5 mu = 0 fft_size = 4096 nframes_to_check = 1 nframes_to_average = 1 downconverter = 1 src_data = self.generateRandomSignalSource( dBm, fft_size, mu, nframes_to_check * nframes_to_average) # Blocks src = gr.vector_source_c(src_data) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate, fft_size, samples_per_band, pfd, pfa, tcme, output_pfa, debug_stats, primary_user_location, useless_bw, self.histogram, nframes_to_check, nframes_to_average, downconverter) self.sink = gr.vector_sink_f() # Connections self.connect(src, s2v, fftb, self.ss, self.sink)
def __init__(self, fg, parent, baseband_freq=0, y_per_div=10, ref_level=50, sample_rate=1, fft_size=512, fft_rate=default_fft_rate, average=False, avg_alpha=None, title='', size=default_fftsink_size, peak_hold=False): fft_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq, y_per_div=y_per_div, ref_level=ref_level, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title, peak_hold=peak_hold) s2p = gr.stream_to_vector(gr.sizeof_float, self.fft_size) self.one_in_n = gr.keep_one_in_n(gr.sizeof_float * self.fft_size, max(1, int(self.sample_rate/self.fft_size/self.fft_rate))) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vfc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag(self.fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) # FIXME We need to add 3dB to all bins but the DC bin log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) fg.connect (s2p, self.one_in_n, fft, c2mag, self.avg, log, sink) gr.hier_block.__init__(self, fg, s2p, sink) self.win = fft_window(self, parent, size=size) self.set_average(self.average)
def __init__(self, pfa, pfd, freq, useless_bw, nframes_to_check, nframes_to_average): gr.top_block.__init__(self) # Constants samp_rate = 2.4e6 fft_size = 4096 samples_per_band = 16 tcme = 1.9528 output_pfa = False debug_stats = False histogram = False primary_user_location = 20 nsegs_to_check = 6 downconverter = 1 # Blocks rtlsdr_source = osmosdr.source_c( args="nchan=" + str(1) + " " + "" ) rtlsdr_source.set_sample_rate(samp_rate) rtlsdr_source.set_center_freq(freq, 0) rtlsdr_source.set_freq_corr(0, 0) rtlsdr_source.set_gain_mode(0, 0) rtlsdr_source.set_gain(10, 0) rtlsdr_source.set_if_gain(24, 0) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check) self.sink = gr.vector_sink_f() # Connections self.connect(rtlsdr_source, s2v, fftb, self.ss, self.sink)
def __init__(self, dbW, pfa, pfd): gr.top_block.__init__(self) # Parameters samp_rate = 2e6 fft_size = 4096 samples_per_band = 16 tcme = 1.9528 output_pfa = True debug_stats = False primary_user_location = 0 useless_bw = 0.0 # As we are not using any of the dongles it can be set as zero, i.e., all the band can be used. histogram = False nframes_to_check = 1 nframes_to_average = 1 downconverter = 1 nsegs_to_check = 6 # Create AWGN noise noise = awgn(fft_size, dbW) # Blocks src = gr.vector_source_c(noise) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check) self.sink = gr.vector_sink_f() # Connections self.connect(src, s2v, fftb, self.ss, self.sink)
def __init__(self,options,Freq): gr.top_block.__init__(self) if options.input_file == "": self.IS_USRP2 = True else: self.IS_USRP2 = False #self.min_freq = options.start #self.max_freq = options.stop self.min_freq = Freq.value-(3*10**6) # same as that of the transmitter bandwidth ie 6MHZ approx for a given value of decimation line option any more self.max_freq = Freq.value+(3*10**6) if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them print "Start and stop frequencies order swapped!" self.fft_size = options.fft_size self.ofdm_bins = options.sense_bins # build graph s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) #log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # modifications for USRP2 if self.IS_USRP2: self.u = uhd.usrp_source(options.args,uhd.io_type.COMPLEX_FLOAT32,num_channels=1) # Modified Line # self.u.set_decim(options.decim) # samp_rate = self.u.adc_rate()/self.u.decim() samp_rate = 100e6/options.decim # modified sampling rate self.u.set_samp_rate(samp_rate) else: self.u = gr.file_source(gr.sizeof_gr_complex,options.input_file, True) samp_rate = 100e6 /options.decim # modified sampling rate self.freq_step =0 #0.75* samp_rate self.min_center_freq = (self.min_freq + self.max_freq)/2 global BW BW = self.max_freq - self.min_freq global size size=self.fft_size global ofdm_bins ofdm_bins = self.ofdm_bins global usr #global thrshold_inorder usr=samp_rate nsteps = 10 #math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * samp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * samp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) # thread-safe message queue self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # control scanning and record frequency domain statistics self.connect(self.u, s2v, fft,c2mag,stats) if options.gain is None: g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2 # if no gain was specified, use the mid-point in dB
def __init__(self, fg, parent, baseband_freq=0, ref_level=0, sample_rate=1, fft_size=512, fft_rate=default_fft_rate, average=False, avg_alpha=None, title='', size=default_fftsink_size, report=None, span=40, ofunc=None, xydfunc=None): waterfall_sink_base.__init__(self, input_is_real=False, baseband_freq=baseband_freq, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title) s2p = gr.serial_to_parallel(gr.sizeof_gr_complex, self.fft_size) self.one_in_n = gr.keep_one_in_n(gr.sizeof_gr_complex * self.fft_size, max(1, int(self.sample_rate/self.fft_size/self.fft_rate))) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) c2mag = gr.complex_to_mag(self.fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size)) sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) self.block_list = (s2p, self.one_in_n, fft, c2mag, self.avg, log, sink) self.reconnect( fg ) gr.hier_block.__init__(self, fg, s2p, sink) self.win = waterfall_window(self, parent, size=size, report=report, ref_level=ref_level, span=span, ofunc=ofunc, xydfunc=xydfunc) self.set_average(self.average)
def __init__(self, sample_rate, fft_size, ref_scale, frame_rate, avg_alpha, average): """! Create an log10(abs(fft)) stream chain. Provide access to the setting the filter and sample rate. @param sample_rate Incoming stream sample rate @param fft_size Number of FFT bins @param ref_scale Sets 0 dB value input amplitude @param frame_rate Output frame rate @param avg_alpha FFT averaging (over time) constant [0.0-1.0] @param average Whether to average [True, False] """ gr.hier_block2.__init__(self, self._name, gr.io_signature(1, 1, self._item_size), # Input signature gr.io_signature(1, 1, gr.sizeof_float*fft_size)) # Output signature self._sd = stream_to_vector_decimator(item_size=self._item_size, sample_rate=sample_rate, vec_rate=frame_rate, vec_len=fft_size) fft_window = window.blackmanharris(fft_size) fft = self._fft_block[0](fft_size, True, fft_window) window_power = sum(map(lambda x: x*x, fft_window)) c2mag = gr.complex_to_mag(fft_size) self._avg = gr.single_pole_iir_filter_ff(1.0, fft_size) self._log = gr.nlog10_ff(20, fft_size, -10*math.log10(fft_size) # Adjust for number of bins -10*math.log10(window_power/fft_size) # Adjust for windowing loss -20*math.log10(ref_scale/2)) # Adjust for reference scale self.connect(self, self._sd, fft, c2mag, self._avg, self._log, self) self.set_average(average) self.set_avg_alpha(avg_alpha)
def __init__(self, parent, baseband_freq=0, y_per_div=10, sc_y_per_div=0.5, sc_ref_level=40, ref_level=50, sample_rate=1, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title='', size=default_ra_fftsink_size, peak_hold=False, ofunc=None, xydfunc=None): gr.hier_block2.__init__(self, "ra_fft_sink_f", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0, 0, 0)) ra_fft_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq, y_per_div=y_per_div, sc_y_per_div=sc_y_per_div, sc_ref_level=sc_ref_level, ref_level=ref_level, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title, peak_hold=peak_hold, ofunc=ofunc, xydfunc=xydfunc) self.binwidth = float(sample_rate/2.0)/float(fft_size) s2p = gr.serial_to_parallel(gr.sizeof_float, fft_size) one_in_n = gr.keep_one_in_n(gr.sizeof_float * fft_size, max(1, int(sample_rate/fft_size/fft_rate))) mywindow = window.blackmanharris(fft_size) fft = gr.fft_vfc(fft_size, True, mywindow) c2mag = gr.complex_to_mag(fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, fft_size) log = gr.nlog10_ff(20, fft_size, -20*math.log10(fft_size)) sink = gr.message_sink(gr.sizeof_float * fft_size, self.msgq, True) self.connect (self, s2p, one_in_n, fft, c2mag, self.avg, log, sink) self.win = fft_window(self, parent, size=size) self.set_average(self.average)
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 = 2.4e6 ################################################## # Blocks ################################################## self.howto_spectrum_sensing_cf_0 = howto.spectrum_sensing_cf(samp_rate,2048,16,0.001,0.0001,1.9528,True,True,0,200000.0,False,3,4,1,6) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_float*1) self.fft_vxx_0 = fft.fft_vcc(2048, True, (window.blackmanharris(1024)), False, 1) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, 2048) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0) ################################################## # Connections ################################################## self.connect((self.fft_vxx_0, 0), (self.howto_spectrum_sensing_cf_0, 0)) self.connect((self.howto_spectrum_sensing_cf_0, 0), (self.gr_null_sink_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_stream_to_vector_0, 0))
def __init__(self, dBm, pfa, pfd, useless_bw, plot_histogram): gr.top_block.__init__(self) # Constants samp_rate = 2.4e6 samples_per_band = 16 tcme = 1.9528 output_pfa = True debug_stats = False self.histogram = plot_histogram primary_user_location = 5 mu = 0 fft_size = 4096 nframes_to_check = 1 nframes_to_average = 1 downconverter = 1 src_data = self.generateRandomSignalSource(dBm, fft_size, mu, nframes_to_check*nframes_to_average) # Blocks src = gr.vector_source_c(src_data) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,self.histogram,nframes_to_check,nframes_to_average,downconverter) self.sink = gr.vector_sink_f() # Connections self.connect(src, s2v, fftb, self.ss, self.sink)
def __init__(self, dBm, pfa, pfd, nTrials): gr.top_block.__init__(self) # Constants samp_rate = 2.4e6 fft_size = 4096 samples_per_band = 16 tcme = 1.9528 output_pfa = True debug_stats = False histogram = False primary_user_location = 0 useless_bw = 200000.0 src_data = [0+0j]*fft_size*nTrials voltage = self.powerToAmplitude(dBm); # Blocks src = gr.vector_source_c(src_data) noise = gr.noise_source_c(gr.GR_GAUSSIAN, voltage, 42) add = gr.add_vcc() s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram) self.sink = gr.vector_sink_f() # Connections self.connect(src, add, s2v, fftb, ss, self.sink) self.connect(noise, (add, 1))
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): sense_band_start=900*10**6 sense_band_stop=940*10**6 self.fft_size = options.fft_size self.ofdm_bins = options.sense_bins # build graph s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) #log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # modifications for USRP2 print "*******************in sensor init********************" if self.IS_USRP2: self.u = usrp2.source_32fc(options.interface, options.MAC_addr) self.u.set_decim(options.decim) samp_rate = self.u.adc_rate() / self.u.decim() else: self.u = gr.file_source(gr.sizeof_gr_complex,options.input_file, True) samp_rate = 100e6 / options.decim self.freq_step =0.75* samp_rate #self.min_center_freq = (self.min_freq + self.max_freq)/2 global BW BW = 0.75* samp_rate #self.max_freq - self.min_freq global size size=self.fft_size global ofdm_bins ofdm_bins = self.ofdm_bins global usr #global thrshold_inorder usr=samp_rate nsteps = 10 #math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * samp_rate / self.fft_size))) # in fft_frames print tune_delay dwell_delay = max(1, int(round(options.dwell_delay * samp_rate / self.fft_size))) # in fft_frames print dwell_delay self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) self.connect(self.u, s2v, fft,c2mag,stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0]+g[1])/2
def main_loop(tb): if tb.log_file: filename = "spectrum_sense_exp_" + time.strftime('%y%m%d_%H%M%S') + ".csv" f = open(filename, 'w') f.write("detecting on %s BW channels between " %(tb.samp_rate)) f.write("%s and " %(tb.min_freq)) f.write("%s\n" %(tb.max_freq)) f.close() i = 0 mywindow = window.blackmanharris(tb.fft_size) power = 0 for tap in mywindow: power += tap*tap k = -20*math.log10(tb.fft_size)-10*math.log10(power/tb.fft_size) while i < tb.num_tests or tb.num_tests == 0: i = (i+1) # Get the next message sent from the C++ code (blocking call). # It contains the center frequency and the mag squared of the fft m = parse_msg(tb.msgq.delete_head()) #fft_sum_db = 20*math.log10(sum(m.data)/m.vlen) temp_list = [] for item in m.data: temp_list.append(10*math.log10(item) + k) fft_sum_db = sum(temp_list)/m.vlen if tb.log_file: f = open(filename, 'a') if fft_sum_db > tb.threshold: f.write("1,") else: f.write("0,") #f.write(str(m.center_freq)) #f.write(", ") #f.write(str(fft_sum_db)) #f.write("\n") if m.center_freq >= tb.max_center_freq - tb.freq_step: f.write("\n") # break f.close() if not tb.log_file and m.center_freq == tb.min_center_freq: os.system("clear") #tb.next_freq = tb.min_center_freq #tb.msgq.flush() print m.center_freq, fft_sum_db if not tb.log_file and m.center_freq >= tb.max_center_freq - tb.freq_step: time.sleep(.5) tb.next_freq = tb.min_center_freq tb.msgq.flush()
def __init__(self, decim=16): grc_wxgui.top_block_gui.__init__(self, title="File Fft") _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 ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.fft_size = fft_size = 2048 / decim self.N_re = N_re = 62 ################################################## # Blocks ################################################## self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, 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, fft_size) self.gr_stream_to_vector_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re, fft_size, (fft_size - N_re) / 2) self.gr_file_source_0 = gr.file_source( gr.sizeof_gr_complex * 1, "/home/user/git/gr-lte/gr-lte/test/foo_pss0_sss_in.cfile", True) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) ################################################## # Connections ################################################## self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_file_source_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_keep_m_in_n_0, 0), (self.wxgui_scopesink2_0, 0))
def __init__(self, parent, baseband_freq=0, ref_level=0, sample_rate=1, fft_size=512, fft_rate=default_fft_rate, average=False, avg_alpha=None, title='', size=default_fftsink_size, report=None, span=40, ofunc=None, xydfunc=None): gr.hier_block2.__init__(self, "waterfall_sink_c", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) waterfall_sink_base.__init__(self, input_is_real=False, baseband_freq=baseband_freq, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title) s2p = gr.serial_to_parallel(gr.sizeof_gr_complex, self.fft_size) self.one_in_n = gr.keep_one_in_n( gr.sizeof_gr_complex * self.fft_size, max(1, int(self.sample_rate / self.fft_size / self.fft_rate))) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) c2mag = gr.complex_to_mag(self.fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) log = gr.nlog10_ff(20, self.fft_size, -20 * math.log10(self.fft_size)) sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) self.connect(self, s2p, self.one_in_n, fft, c2mag, self.avg, log, sink) self.win = waterfall_window(self, parent, size=size, report=report, ref_level=ref_level, span=span, ofunc=ofunc, xydfunc=xydfunc) self.set_average(self.average)
def fft_channelizer( self, fft_len, channel_bins): #do a fwd fft self.fft_channelizer_s2v = blocks.stream_to_vector( gr.sizeof_gr_complex*1, fft_len) self.fft_channelizer_fft_fwd = fft.fft_vcc( fft_len, True, (window.blackmanharris(1024)), True, 1) self.fft_channelizer_v2s = blocks.vector_to_stream( gr.sizeof_gr_complex*1, fft_len) self.connect( self.fft_channelizer_s2v, self.fft_channelizer_fft_fwd, self.fft_channelizer_v2s) #per channel self.fft_channelizer_skiphead = [] self.fft_channelizer_keep_m_in_n = [] self.fft_channelizer_stream2vector = [] self.fft_channelizer_multiply_const = [] self.fft_channelizer_fft_rev = [] self.fft_channelizer_vector2stream = [] for from_bin, to_bin in channel_bins: #output samp rate: samp_rate / (fft_len/keep) keep = to_bin - from_bin fft_channelizer_taps = taps.taps(keep) self.fft_channelizer_skiphead.append( blocks.skiphead(gr.sizeof_gr_complex*1, from_bin)) self.fft_channelizer_keep_m_in_n.append( blocks.keep_m_in_n(gr.sizeof_gr_complex, keep, fft_len, 0)) self.fft_channelizer_stream2vector.append( blocks.stream_to_vector(gr.sizeof_gr_complex*1, keep)) self.fft_channelizer_multiply_const.append( blocks.multiply_const_vcc(fft_channelizer_taps)) self.fft_channelizer_fft_rev.append( fft.fft_vcc( keep, False, (window.blackmanharris(1024)), True, 1)) self.fft_channelizer_vector2stream.append( blocks.vector_to_stream( gr.sizeof_gr_complex*1, keep)) self.connect( self.fft_channelizer_v2s, self.fft_channelizer_skiphead[-1], self.fft_channelizer_keep_m_in_n[-1], self.fft_channelizer_stream2vector[-1], self.fft_channelizer_multiply_const[-1], self.fft_channelizer_fft_rev[-1], self.fft_channelizer_vector2stream[-1]) return self.fft_channelizer_s2v, self.fft_channelizer_vector2stream
def __init__(self, decim=16): grc_wxgui.top_block_gui.__init__(self, title="File Fft") _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 ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.fft_size = fft_size = 2048/decim self.N_re = N_re = 62 ################################################## # Blocks ################################################## self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, 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, fft_size) self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re, fft_size, (fft_size-N_re)/2) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/home/user/git/gr-lte/gr-lte/test/foo_pss0_sss_in.cfile", True) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) ################################################## # Connections ################################################## self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_file_source_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_keep_m_in_n_0, 0), (self.wxgui_scopesink2_0, 0))
def __init__(self, signal, signal_power, snr, pd, pfd): gr.top_block.__init__(self) # Parameters samp_rate = 2e6 fft_size = 4096 samples_per_band = 16 tcme = 1.9528 output_pfa = False debug_stats = False primary_user_location = 0 useless_bw = 0.0 # As we are not using any of the dongles it can be set as zero, i.e., all the band can be used. histogram = False nframes_to_check = 1 nframes_to_average = 1 downconverter = 1 nsegs_to_check = 6 # Calculate the power of the noise vector to be generated. noise_power = signal_power - snr # in dBW # Create AWGN noise noise = awgn(fft_size, noise_power) effective_noise_power = calculateSignalPower(noise) effective_snr = signal_power - effective_noise_power print "effective_noise_power: %f\n" % effective_noise_power print "effective_snr: %f\n" % effective_snr # Create corrupted signal rx_signal = signal[0:fft_size] + noise # Blocks src = gr.vector_source_c(rx_signal) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf( samp_rate, fft_size, samples_per_band, pfd, pfa, tcme, output_pfa, debug_stats, primary_user_location, useless_bw, histogram, nframes_to_check, nframes_to_average, downconverter, nsegs_to_check) self.sink = gr.vector_sink_f() # Connections self.connect(src, s2v, fftb, self.ss, self.sink)
def __init__(self, pfa, pfd, freq, useless_bw, history): gr.top_block.__init__(self) # Constants samp_rate = 2.4e6 fft_size = 4096 samples_per_band = 16 tcme = 1.9528 output_pfa = True debug_stats = False histogram = True primary_user_location = 5 # Blocks rtl2832_source = baz.rtl_source_c(defer_creation=True, output_size=gr.sizeof_gr_complex) rtl2832_source.set_verbose(True) rtl2832_source.set_vid(0x0) rtl2832_source.set_pid(0x0) rtl2832_source.set_tuner_name("") rtl2832_source.set_default_timeout(0) rtl2832_source.set_use_buffer(True) rtl2832_source.set_fir_coefficients(([])) rtl2832_source.set_read_length(0) if rtl2832_source.create() == False: raise Exception( "Failed to create RTL2832 Source: rtl2832_source_0") rtl2832_source.set_sample_rate(samp_rate) rtl2832_source.set_frequency(freq) rtl2832_source.set_auto_gain_mode(True) rtl2832_source.set_relative_gain(True) rtl2832_source.set_gain(1) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate, fft_size, samples_per_band, pfd, pfa, tcme, output_pfa, debug_stats, primary_user_location, useless_bw, histogram, history) self.sink = gr.vector_sink_f() # Connections self.connect(rtl2832_source, s2v, fftb, self.ss, self.sink)
def __init__(self, N_id_2, N_re=128, N_cp_ts=144, freq_corr=0, repeat=False): gr.hier_block2.__init__( self, "PSS source time-domain", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex), ) self.pss_fd = pss_source_fd(N_id_2, N_re, repeat); self.fft = gr.fft_vcc(N_re, False, window.blackmanharris(1024), True) self.cp = digital.ofdm_cyclic_prefixer(N_re, N_re+N_cp_ts*N_re/2048) if freq_corr != 0: self.freq_corr = gr.freq_xlating_fir_filter_ccf(1, 1, freq_corr, 15000*N_re) self.connect(self.pss_fd, self.fft, self.cp) if freq_corr != 0: self.connect(self.cp, self.freq_corr, self) else: self.connect(self.cp, self)
def __init__(self, N_id_1, N_id_2, slot0=True, N_re=128, N_cp_ts=144, freq_corr=0): top = gr.top_block("foo"); source = gr.vector_source_c(range(0,N_re), False, N_re) source.set_data(gen_sss_fd(N_id_1, N_id_2, N_re).get_sss(slot0)); fft = gr.fft_vcc(N_re, False, window.blackmanharris(1024), True) cp = digital.ofdm_cyclic_prefixer(N_re, N_re+N_cp_ts*N_re/2048) if freq_corr != 0: freq_corr = gr.freq_xlating_fir_filter_ccf(1, 1, freq_corr, 15000*N_re) sink = gr.vector_sink_c(1) top.connect(source, fft, cp) if freq_corr != 0: top.connect(cp, freq_corr, sink) else: top.connect(cp, sink) top.run() self.data = sink.data()
def __init__(self): gr.top_block.__init__(self) gain=0.7 target_freq=930e6 decim=16 interface="" MAC_addr="" fft_size=512 self.u = usrp2.source_32fc() self.u.set_decim(128) self.u.set_center_freq(930e6) self.u.set_gain(0) self.u.config_mimo(usrp2.MC_WE_DONT_LOCK) self.s2v = gr.stream_to_vector(gr.sizeof_gr_complex*1, 512) self.f_sink = gr.file_sink(gr.sizeof_gr_complex*512, "fft_data") self.f_sink.set_unbuffered(False) self.fft = gr.fft_vcc(512, True, (window.blackmanharris(512)), True) self.connect(self.u,self.s2v,self.fft,self.f_sink)
def __init__(self, parent, baseband_freq=0, ref_scale=2.0, y_per_div=10, y_divs=8, ref_level=50, sample_rate=1, fft_size=512, fft_rate=default_fft_rate, average=False, avg_alpha=None, title='', size=default_fftsink_size, peak_hold=False, use_persistence=False,persist_alpha=0.2, **kwargs): gr.hier_block2.__init__(self, "fft_sink_c", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0,0,0)) fft_sink_base.__init__(self, input_is_real=False, baseband_freq=baseband_freq, y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title, peak_hold=peak_hold, use_persistence=use_persistence,persist_alpha=persist_alpha) self.s2p = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) self.one_in_n = gr.keep_one_in_n(gr.sizeof_gr_complex * self.fft_size, max(1, int(self.sample_rate/self.fft_size/self.fft_rate))) mywindow = window.blackmanharris(self.fft_size) self.fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap self.c2mag = gr.complex_to_mag(self.fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) # FIXME We need to add 3dB to all bins but the DC bin self.log = gr.nlog10_ff(20, self.fft_size, -10*math.log10(self.fft_size) # Adjust for number of bins -10*math.log10(power/self.fft_size) # Adjust for windowing loss -20*math.log10(ref_scale/2)) # Adjust for reference scale self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag, self.avg, self.log, self.sink) self.win = fft_window(self, parent, size=size) self.set_average(self.average) self.set_use_persistence(self.use_persistence) self.set_persist_alpha(self.persist_alpha) self.set_peak_hold(self.peak_hold)
def __init__(self, options): gr.hier_block2.__init__(self, "sensing_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose # linklab, fft size for sensing, different from fft length for tx/rx self.fft_size = FFT_SIZE # interpolation rate: sensing fft size / ofdm fft size self.interp_rate = self.fft_size/FFT_SIZE #options.fft_length self._fft_length = FFT_SIZE #options.fft_length self._occupied_tones = FFT_SIZE #options.occupied_tones self.msgq = gr.msg_queue() # linklab , setup the sensing path # FIXME: some components are not necessary self.s2p = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) self.fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap self.c2mag = gr.complex_to_mag(self.fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) # linklab, ref scale value from default ref_scale in usrp_fft.py ref_scale = 13490.0 # FIXME We need to add 3dB to all bins but the DC bin self.log = gr.nlog10_ff(20, self.fft_size, -10*math.log10(self.fft_size) # Adjust for number of bins -10*math.log10(power/self.fft_size) # Adjust for windowing loss -20*math.log10(ref_scale/2)) # Adjust for reference scale self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) self.connect(self, self.s2p, self.fft, self.c2mag, self.avg, self.log, self.sink)
def __init__(self, signal, signal_power, snr, pd, pfd): gr.top_block.__init__(self) # Parameters samp_rate = 2e6 fft_size = 4096 samples_per_band = 16 tcme = 1.9528 output_pfa = False debug_stats = False primary_user_location = 0 useless_bw = 0.0 # As we are not using any of the dongles it can be set as zero, i.e., all the band can be used. histogram = False nframes_to_check = 1 nframes_to_average = 1 downconverter = 1 nsegs_to_check = 6 # Calculate the power of the noise vector to be generated. noise_power = signal_power - snr # in dBW # Create AWGN noise noise = awgn(fft_size, noise_power) effective_noise_power = calculateSignalPower(noise); effective_snr = signal_power - effective_noise_power; print "effective_noise_power: %f\n" % effective_noise_power print "effective_snr: %f\n" % effective_snr # Create corrupted signal rx_signal = signal[0:fft_size] + noise # Blocks src = gr.vector_source_c(rx_signal) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check) self.sink = gr.vector_sink_f() # Connections self.connect(src, s2v, fftb, self.ss, self.sink)
def __init__(self, system, fftwidth=256, n=128, cutoff=100): """ Add blocks to the top_blocks that will be used for extracting the fft from the flow graph for detection. Args: system: A wrapper for the top block. fftwidth: The width of the fft used for detection. n: The fft is only updated every 1 in n times. cutoff: How sharp peaks need to be, to be detected. """ self.system = system self.fftwidth = fftwidth self.n = n self.cutoff = cutoff self.stream_to_vector = gr.stream_to_vector(gr.sizeof_gr_complex, fftwidth) self.keep_one_in_n = gr.keep_one_in_n(gr.sizeof_gr_complex*fftwidth, n) self.fft = gr.fft_vcc(fftwidth, True, window.blackmanharris(fftwidth)) self.probe = gr.probe_signal_vc(fftwidth) system.connect(system.out, self.stream_to_vector, self.keep_one_in_n, self.fft, self.probe)
def __init__(self, ssblock, freq): gr.top_block.__init__(self) # Constants pfa = ssblock.pfa pfd = ssblock.pfd tcme = ssblock.tcme samp_rate = ssblock.samp_rate fft_size = ssblock.fft_size samples_per_band = ssblock.samples_per_band tcme = ssblock.tcme output_pfa = ssblock.output_pfa debug_stats = ssblock.debug_stats histogram = ssblock.histogram primary_user_location = ssblock.primary_user_location nsegs_to_check = ssblock.nsegs_to_check downconverter = ssblock.downconverter useless_bw = ssblock.useless_bw nframes_to_check = ssblock.nframes_to_check nframes_to_average = ssblock.nframes_to_average # Blocks self.rtlsdr_source = osmosdr.source_c( args="nchan=" + str(1) + " " + "" ) self.rtlsdr_source.set_sample_rate(samp_rate) self.rtlsdr_source.set_center_freq(freq, 0) self.rtlsdr_source.set_freq_corr(0, 0) self.rtlsdr_source.set_gain_mode(0, 0) self.rtlsdr_source.set_gain(10, 0) self.rtlsdr_source.set_if_gain(24, 0) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check) self.sink = gr.vector_sink_f() # Connections self.connect(self.rtlsdr_source, s2v, fftb, self.ss, self.sink)
def __init__(self, pfa, pfd, freq, useless_bw, history): gr.top_block.__init__(self) # Constants samp_rate = 2.4e6 fft_size = 4096 samples_per_band = 16 tcme = 1.9528 output_pfa = False debug_stats = False histogram = False primary_user_location = 5 # Blocks rtl2832_source = baz.rtl_source_c(defer_creation=True, output_size=gr.sizeof_gr_complex) rtl2832_source.set_verbose(True) rtl2832_source.set_vid(0x0) rtl2832_source.set_pid(0x0) rtl2832_source.set_tuner_name("") rtl2832_source.set_default_timeout(0) rtl2832_source.set_use_buffer(True) rtl2832_source.set_fir_coefficients(([])) rtl2832_source.set_read_length(0) if rtl2832_source.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") rtl2832_source.set_sample_rate(samp_rate) rtl2832_source.set_frequency(freq) rtl2832_source.set_auto_gain_mode(True) rtl2832_source.set_relative_gain(True) rtl2832_source.set_gain(1) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1) self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,history) self.sink = gr.vector_sink_f() # Connections self.connect(rtl2832_source, s2v, fftb, self.ss, self.sink)
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0,0), help="select USRP Rx side A or B (default=A)") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=10e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequncy [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option("-B", "--fusb-block-size", type="int", default=0, help="specify fast usb block size [default=%default]") parser.add_option("-N", "--fusb-nblocks", type="int", default=0, help="specify number of fast usb blocks [default=%default]") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them self.fft_size = options.fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # If the user hasn't set the fusb_* parameters on the command line, # pick some values that will reduce latency. if 1: if options.fusb_block_size == 0 and options.fusb_nblocks == 0: if realtime: # be more aggressive options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024) options.fusb_nblocks = gr.prefs().get_long('fusb', 'rt_nblocks', 16) else: options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096) options.fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16) #print "fusb_block_size =", options.fusb_block_size #print "fusb_nblocks =", options.fusb_nblocks # build graph self.u = usrp.source_c(fusb_block_size=options.fusb_block_size, fusb_nblocks=options.fusb_nblocks) adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = options.decim self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(),) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = 0.75 * usrp_rate self.min_center_freq = self.min_freq + self.freq_step/2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, fft, c2mag, log, stats) self.connect(self.u, s2v, fft, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0]+g[1])/2 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self, parent, baseband_freq=0, ref_scale=2.0, y_per_div=10, y_divs=8, ref_level=50, sample_rate=1, fft_size=512, fft_rate=default_fft_rate, average=False, avg_alpha=None, title='', size=default_fftsink_size, peak_hold=False, use_persistence=False, persist_alpha=0.2, **kwargs): gr.hier_block2.__init__(self, "fft_sink_c", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) fft_sink_base.__init__(self, input_is_real=False, baseband_freq=baseband_freq, y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level, sample_rate=sample_rate, fft_size=fft_size, fft_rate=fft_rate, average=average, avg_alpha=avg_alpha, title=title, peak_hold=peak_hold, use_persistence=use_persistence, persist_alpha=persist_alpha) self.s2p = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) self.one_in_n = gr.keep_one_in_n( gr.sizeof_gr_complex * self.fft_size, max(1, int(self.sample_rate / self.fft_size / self.fft_rate))) mywindow = window.blackmanharris(self.fft_size) self.fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap * tap self.c2mag = gr.complex_to_mag(self.fft_size) self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) # FIXME We need to add 3dB to all bins but the DC bin self.log = gr.nlog10_ff( 20, self.fft_size, -10 * math.log10(self.fft_size) # Adjust for number of bins - 10 * math.log10(power / self.fft_size) # Adjust for windowing loss - 20 * math.log10(ref_scale / 2)) # Adjust for reference scale self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag, self.avg, self.log, self.sink) self.win = fft_window(self, parent, size=size) self.set_average(self.average) self.set_use_persistence(self.use_persistence) self.set_persist_alpha(self.persist_alpha) self.set_peak_hold(self.peak_hold)
def main_loop(tb): if tb.log_file: #filename = "spectrum_sense_exp_" + time.strftime('%y%m%d_%H%M%S') + ".csv" #f = open(filename, 'w') #f.write("detecting on %s BW channels between " %(tb.samp_rate)) #f.write("%s and " %(tb.min_freq)) #f.write("%s\n" %(tb.max_freq)) #f.close() #filename for the freq pow file filename_p_f = "sensing_" + eng_notation.num_to_str(tb.min_freq) + "_" + eng_notation.num_to_str(tb.max_freq) + time.strftime('%y%m%d_%H%M%S') + ".txt" i = 0 mywindow = window.blackmanharris(tb.fft_size) power = 0 for tap in mywindow: power += tap*tap k = -20*math.log10(tb.fft_size)-10*math.log10(power/tb.fft_size) while i < tb.num_tests or tb.num_tests == 0: i = (i+1) # Get the next message sent from the C++ code (blocking call). # It contains the center frequency and the mag squared of the fft m = parse_msg(tb.msgq.delete_head()) #fft_sum_db = 20*math.log10(sum(m.data)/m.vlen) temp_list = [] temp_list2 = [] for item in m.data: temp_list.append(10*math.log10(item) + k) """in the documentation it says that m.data carries the power squared""" sqr_power = math.sqrt(item) temp_list2.append(10*math.log10(sqr_power) + k) fft_sum_db = sum(temp_list2)/m.vlen avg_power = str(fft_sum_db) current_freq = str(m.center_freq) binary_file = "binary_floats.dat" """the tb.threshold is the rx threshold""" if tb.log_file: #f = open(filename, 'a') d = open(filename_p_f, 'a') """creating a binary file for appending the m.raw_data""" #b = open(binary_file,"ab+") #b.write(m.raw_data) d.write(current_freq + ' ' + avg_power + '\n') #if fft_sum_db > tb.threshold: # f.write("1,") #else: # f.write("0,") #f.write(str(m.center_freq)) #f.write(", ") #f.write(str(fft_sum_db)) #f.write("\n") #if m.center_freq >= tb.max_center_freq - tb.freq_step: # f.write("\n") # break #f.close() #b.close() d.close() if not tb.log_file and m.center_freq == tb.min_center_freq: os.system("clear") #tb.next_freq = tb.min_center_freq #tb.msgq.flush() print m.center_freq, fft_sum_db if not tb.log_file and m.center_freq >= tb.max_center_freq - tb.freq_step: time.sleep(.5) tb.next_freq = tb.min_center_freq tb.msgq.flush()
def __init__(self): gr.top_block.__init__(self) # Build an options parser to bring in information from the user on usage usage = "usage: %prog [options] host min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-g", "--gain", type="eng_float", default=32, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=5e-5, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=50e-5, metavar="SECS", help="time to dwell (in seconds) at a given frequncy [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 3: parser.print_help() sys.exit(1) # get user-provided info on address of MSDD and frequency to sweep self.address = args[0] self.min_freq = eng_notation.str_to_num(args[1]) self.max_freq = eng_notation.str_to_num(args[2]) self.decim = options.decim self.gain = options.gain if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them self.fft_size = options.fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # Sampling rate is hardcoded and cannot be read off device adc_rate = 102.4e6 self.int_rate = adc_rate / self.decim print "Sampling rate: ", self.int_rate # build graph self.port = 10001 # required port for UDP packets # which board, op mode, adx, port # self.src = msdd.source_c(0, 1, self.address, self.port) # build source object self.conv = gr.interleaved_short_to_complex(); self.src = msdd.source_simple(self.address,self.port); self.src.set_decim_rate(self.decim) # set decimation rate # self.src.set_desired_packet_size(0, 1460) # set packet size to collect self.set_gain(self.gain) # set receiver's attenuation self.set_freq(self.min_freq) # set receiver's rx frequency # restructure into vector format for FFT input s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) # set up FFT processing block mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap*tap # calculate magnitude squared of output of FFT c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to % of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.percent = 0.4 # Calculate the frequency steps to use in the collection over the whole bandwidth self.freq_step = self.percent * self.int_rate self.min_center_freq = self.min_freq + self.freq_step/2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq # use these values to set receiver settling time between samples and sampling time # the default values provided seem to work well with the MSDD over 100 Mbps ethernet tune_delay = max(0, int(round(options.tune_delay * self.int_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * self.int_rate / self.fft_size))) # in fft_frames # set up message callback routine to get data from bin_statistics_f block self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd # FIXME this block doesn't like to work with negatives because of the "d_max[i]=0" on line # 151 of gr_bin_statistics_f.cc file. Set this to -10000 or something to get it to work. stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME there's a concern over the speed of the log calculation # We can probably calculate the log inside the stats block self.connect(self.src, self.conv, s2v, fft, c2mag, log, stats)
def __init__(self, N_id_1=134, N_id_2=0, decim=16, frames=1, gain=.08): grc_wxgui.top_block_gui.__init__(self, title="LTE DL synchronization signal") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.N_id_1 = N_id_1 self.N_id_2 = N_id_2 self.decim = decim self.frames = frames self.gain = gain ################################################## # Variables ################################################## self.samp_rate = samp_rate = 30720e3/decim self.fft_size = fft_size = 2048/decim self.N_re = N_re = 2048/decim ################################################## # Blocks ################################################## self.wxgui_scopesink2_0_2 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, 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_2.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, 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_1_0_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size+9) self.gr_vector_source_x_0_0_2_0_0 = gr.vector_source_c((gen_pss_td(N_id_2, N_re, 144).get_data()), True, fft_size+9) self.gr_vector_source_x_0_0_2_0 = gr.vector_source_c((gen_sss_td(N_id_1, N_id_2, True, N_re).get_data()), True, fft_size+9) self.gr_vector_source_x_0_0_0 = gr.vector_source_c((gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0 = gr.vector_source_c((gen_sss_fd( N_id_1, N_id_2, fft_size).get_sss(True)), True, fft_size) self.gr_throttle_0_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate) self.gr_null_sink_1 = gr.null_sink(gr.sizeof_gr_complex*1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1) self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vcc((1, )) self.gr_interleave_0_0 = gr.interleave(gr.sizeof_gr_complex*137) self.gr_interleave_0 = gr.interleave(gr.sizeof_gr_complex*fft_size) self.gr_fft_vxx_1 = gr.fft_vcc(fft_size, False, (window.blackmanharris(1024)), True, 1) self.digital_ofdm_cyclic_prefixer_0 = digital.ofdm_cyclic_prefixer(fft_size, fft_size+144/decim) ################################################## # Connections ################################################## self.connect((self.gr_interleave_0, 0), (self.gr_fft_vxx_1, 0)) self.connect((self.gr_fft_vxx_1, 0), (self.digital_ofdm_cyclic_prefixer_0, 0)) self.connect((self.gr_vector_source_x_0, 0), (self.gr_interleave_0, 1)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_interleave_0, 0)) self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_null_sink_0, 0)) self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.gr_null_sink_1, 0)) self.connect((self.gr_vector_source_x_0_0_2_0, 0), (self.gr_interleave_0_0, 0)) self.connect((self.gr_vector_source_x_0_0_2_0_0, 0), (self.gr_interleave_0_0, 1)) self.connect((self.gr_interleave_0_0, 0), (self.gr_vector_to_stream_1_0_0, 0)) self.connect((self.gr_vector_to_stream_1_0_0, 0), (self.gr_multiply_const_vxx_0_0, 0)) self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.gr_throttle_0_0, 0)) self.connect((self.gr_throttle_0_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_throttle_0, 0), (self.wxgui_scopesink2_0_2, 0))
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0,0), help="select USRP Rx side A or B (default=A)") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=.01, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=.05, metavar="SECS", help="time to dwell (in seconds) at a given frequncy [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=1024, help="specify number of FFT bins [default=%default]") #updated 2011 May 27, MR parser.add_option("-s", "--samp_rate", type="intx", default=6000000, help="set sample rate to SAMP_RATE [default=%default]") parser.add_option("", "--chan-bandwidth", type="intx", default=6000000, help="set channel bw [default=%default]") #parser.add_option("-d", "--decim", type="intx", default=16, # help="set decimation to DECIM [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") #parser.add_option("-B", "--fusb-block-size", type="int", default=0, # help="specify fast usb block size [default=%default]") #parser.add_option("-N", "--fusb-nblocks", type="int", default=0, # help="specify number of fast usb blocks [default=%default]") #options added 2011 May 31, MR parser.add_option("", "--threshold", type="eng_float", default=-70, help="set detection threshold [default=%default]") parser.add_option("", "--num-tests", type="intx", default=200, help="set the number of times to test the frequency band [default=%default]") parser.add_option("", "--log-file", action="store_true", default=False, help="log output to a file") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) self.num_tests = options.num_tests self.threshold = options.threshold self.samp_rate = options.samp_rate self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) self.log_file = options.log_file self.num_channels = int((self.max_freq - self.min_freq)/self.samp_rate) + 2 if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them self.fft_size = options.fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" #removed 2011 May 27, MR # If the user hasn't set the fusb_* parameters on the command line, # pick some values that will reduce latency. #if 1: # if options.fusb_block_size == 0 and options.fusb_nblocks == 0: # if realtime: # be more aggressive # options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024) # options.fusb_nblocks = gr.prefs().get_long('fusb', 'rt_nblocks', 16) # else: # options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096) # options.fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16) #print "fusb_block_size =", options.fusb_block_size #print "fusb_nblocks =", options.fusb_nblocks # build graph #updated 2011 May 27, MR self.u = uhd.usrp_source(device_addr="", io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) self.u.set_subdev_spec("", 0) self.u.set_antenna("TX/RX", 0) self.u.set_samp_rate(options.samp_rate) #self.u = usrp.source_c(fusb_block_size=options.fusb_block_size, # fusb_nblocks=options.fusb_nblocks) #adc_rate = self.u.adc_rate() # 64 MS/s #usrp_decim = options.decim #self.u.set_decim_rate(usrp_decim) self.usrp_rate = self.u.get_samp_rate() #adc_rate / usrp_decim print "sample rate is", self.usrp_rate #self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) #self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.u.get_dboard_sensor_names(chan=0))#(self.subdev.side_and_name(),) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. #changed on 2011 May 31, MR -- maybe change back at some point #self.freq_step = 0.75 * self.usrp_rate self.freq_step = options.chan_bandwidth self.min_center_freq = self.min_freq + self.freq_step/2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * self.usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * self.usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, fft, c2mag, log, stats) self.connect(self.u, s2v, fft, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB # updated 2011 May 31, MR #g = self.subdev.gain_range() g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=10e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequncy [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) if self.min_freq > self.max_freq: # swap them self.min_freq, self.max_freq = self.max_freq, self.min_freq self.fft_size = options.fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) usrp_rate = options.samp_rate self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = 0.75 * usrp_rate self.min_center_freq = self.min_freq + self.freq_step/2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, fft, c2mag, log, stats) self.connect(self.u, s2v, fft, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self, usrp_rate, tuner_callback, options): gr.hier_block2.__init__(self, "sense_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.usrp_rate = usrp_rate self.usrp_tune = tuner_callback self.num_tests = options.num_tests self.threshold = options.threshold self.min_freq = options.start_freq self.max_freq = options.end_freq if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them self.fft_size = options.fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. #changed on 2011 May 31, MR -- maybe change back at some point self.freq_step = self.usrp_rate self.min_center_freq = self.min_freq + self.freq_step/2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * self.usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * self.usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self, s2v, fft, c2mag, log, stats) self.connect(self, s2v, fft, c2mag, stats)
def __init__(self): gr.top_block.__init__(self) # Build an options parser to bring in information from the user on usage usage = "usage: %prog [options] host min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-g", "--gain", type="eng_float", default=32, help="set gain in dB (default is midpoint)") parser.add_option( "", "--tune-delay", type="eng_float", default=5e-5, metavar="SECS", help= "time to delay (in seconds) after changing frequency [default=%default]" ) parser.add_option( "", "--dwell-delay", type="eng_float", default=50e-5, metavar="SECS", help= "time to dwell (in seconds) at a given frequncy [default=%default]" ) parser.add_option("-F", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 3: parser.print_help() sys.exit(1) # get user-provided info on address of MSDD and frequency to sweep self.address = args[0] self.min_freq = eng_notation.str_to_num(args[1]) self.max_freq = eng_notation.str_to_num(args[2]) self.decim = options.decim self.gain = options.gain if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them self.fft_size = options.fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # Sampling rate is hardcoded and cannot be read off device adc_rate = 102.4e6 self.int_rate = adc_rate / self.decim print "Sampling rate: ", self.int_rate # build graph self.port = 10001 # required port for UDP packets # which board, op mode, adx, port # self.src = msdd.source_c(0, 1, self.address, self.port) # build source object self.conv = gr.interleaved_short_to_complex() self.src = msdd.source_simple(self.address, self.port) self.src.set_decim_rate(self.decim) # set decimation rate # self.src.set_desired_packet_size(0, 1460) # set packet size to collect self.set_gain(self.gain) # set receiver's attenuation self.set_freq(self.min_freq) # set receiver's rx frequency # restructure into vector format for FFT input s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) # set up FFT processing block mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap * tap # calculate magnitude squared of output of FFT c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff( 10, self.fft_size, -20 * math.log10(self.fft_size) - 10 * math.log10(power / self.fft_size)) # Set the freq_step to % of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.percent = 0.4 # Calculate the frequency steps to use in the collection over the whole bandwidth self.freq_step = self.percent * self.int_rate self.min_center_freq = self.min_freq + self.freq_step / 2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq # use these values to set receiver settling time between samples and sampling time # the default values provided seem to work well with the MSDD over 100 Mbps ethernet tune_delay = max(0, int( round(options.tune_delay * self.int_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int( round(options.dwell_delay * self.int_rate / self.fft_size))) # in fft_frames # set up message callback routine to get data from bin_statistics_f block self.msgq = gr.msg_queue(16) self._tune_callback = tune( self) # hang on to this to keep it from being GC'd # FIXME this block doesn't like to work with negatives because of the "d_max[i]=0" on line # 151 of gr_bin_statistics_f.cc file. Set this to -10000 or something to get it to work. stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME there's a concern over the speed of the log calculation # We can probably calculate the log inside the stats block self.connect(self.src, self.conv, s2v, fft, c2mag, log, stats)
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 = 10000000 ################################################## # Blocks ################################################## self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.random_source_x_0 = gr.vector_source_b( map(int, numpy.random.randint(0, 2, 1000)), True) self.gr_vector_to_stream_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, 512) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate) self.gr_sub_xx_0 = gr.sub_cc(512) self.gr_stream_to_vector_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, 512) self.gr_file_source_1 = gr.file_source( gr.sizeof_gr_complex * 512, "/home/traviscollins/git/BLISS/Matlab/Spectral_Subtraction/hilbert.txt", True) self.gr_file_source_0 = gr.file_source( gr.sizeof_float * 1, "/home/traviscollins/git/BLISS/Matlab/Spectral_Subtraction/INPUT.txt", True) self.gr_file_sink_0 = gr.file_sink( gr.sizeof_float * 1, "/home/traviscollins/git/BLISS/Matlab/Spectral_Subtraction/OUTPUT.txt" ) self.gr_file_sink_0.set_unbuffered(False) self.gr_add_xx_0 = gr.add_vcc(1) self.fft_vxx_1 = fft.fft_vcc(512, False, (window.blackmanharris(1024)), True, 1) self.fft_vxx_0 = fft.fft_vcc(512, True, (window.blackmanharris(1024)), True, 1) self.digital_ofdm_mod_0 = grc_blks2.packet_mod_f( digital.ofdm_mod(options=grc_blks2.options( modulation="bpsk", fft_length=512, occupied_tones=200, cp_length=128, pad_for_usrp=True, log=None, verbose=None, ), ), payload_length=0, ) self.digital_ofdm_demod_0 = grc_blks2.packet_demod_f( digital.ofdm_demod( options=grc_blks2.options( modulation="bpsk", fft_length=512, occupied_tones=200, cp_length=128, snr=10, log=None, verbose=None, ), callback=lambda ok, payload: self.digital_ofdm_demod_0. recv_pkt(ok, payload), ), ) self.digital_dxpsk_mod_0 = digital.dbpsk_mod(samples_per_symbol=2, excess_bw=0.35, gray_coded=True, verbose=False, log=False) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.digital_ofdm_mod_0, 0)) self.connect((self.digital_ofdm_demod_0, 0), (self.gr_file_sink_0, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.random_source_x_0, 0), (self.digital_dxpsk_mod_0, 0)) self.connect((self.digital_ofdm_mod_0, 0), (self.gr_add_xx_0, 0)) self.connect((self.digital_dxpsk_mod_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_add_xx_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.fft_vxx_0, 0), (self.gr_sub_xx_0, 0)) self.connect((self.gr_file_source_1, 0), (self.gr_sub_xx_0, 1)) self.connect((self.gr_vector_to_stream_0, 0), (self.digital_ofdm_demod_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.wxgui_fftsink2_0_0, 0)) self.connect((self.gr_sub_xx_0, 0), (self.fft_vxx_1, 0)) self.connect((self.fft_vxx_1, 0), (self.gr_vector_to_stream_0, 0))
def __init__(self, freq_corr=0, avg_frames=1, decim=16, N_id_2=0, N_id_1=134): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr5 Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq_corr = freq_corr self.avg_frames = avg_frames self.decim = decim self.N_id_2 = N_id_2 self.N_id_1 = N_id_1 ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720 * 5 / decim self.symbol_start = symbol_start = 144 / decim self.slot_0_10 = slot_0_10 = 1 self.samp_rate = samp_rate = 30720e3 / decim self.rot = rot = 0 self.noise_level = noise_level = 0 self.fft_size = fft_size = 2048 / decim self.N_re = N_re = 62 ################################################## # Blocks ################################################## _rot_sizer = wx.BoxSizer(wx.VERTICAL) self._rot_text_box = forms.text_box( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, label='rot', converter=forms.float_converter(), proportion=0, ) self._rot_slider = forms.slider( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rot_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS ML") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS equ") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS in") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS equ") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS ch est") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "foo") self.Add(self.notebook_0) _noise_level_sizer = wx.BoxSizer(wx.VERTICAL) self._noise_level_text_box = forms.text_box( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, label='noise_level', converter=forms.float_converter(), proportion=0, ) self._noise_level_slider = forms.slider( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_noise_level_sizer) self.wxgui_scopesink2_0_1_0_1 = scopesink2.scope_sink_c( self.notebook_0.GetPage(3).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0_1_0_1.win) self.wxgui_scopesink2_0_1_0_0 = scopesink2.scope_sink_c( self.notebook_0.GetPage(2).GetWin(), title="Scope Plot", sample_rate=samp_rate, 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.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_0_1_0_0.win) self.wxgui_scopesink2_0_1_0 = scopesink2.scope_sink_c( self.notebook_0.GetPage(1).GetWin(), title="Scope Plot", sample_rate=samp_rate, 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.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0_1_0.win) self.wxgui_scopesink2_0_1 = scopesink2.scope_sink_f( self.notebook_0.GetPage(0).GetWin(), title="Scope Plot", sample_rate=100 / avg_frames, 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.notebook_0.GetPage(0).Add(self.wxgui_scopesink2_0_1.win) _symbol_start_sizer = wx.BoxSizer(wx.VERTICAL) self._symbol_start_text_box = forms.text_box( parent=self.GetWin(), sizer=_symbol_start_sizer, value=self.symbol_start, callback=self.set_symbol_start, label='symbol_start', converter=forms.int_converter(), proportion=0, ) self._symbol_start_slider = forms.slider( parent=self.GetWin(), sizer=_symbol_start_sizer, value=self.symbol_start, callback=self.set_symbol_start, minimum=0, maximum=144 / decim, num_steps=144 / decim, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.Add(_symbol_start_sizer) self.sss_ml_fd_0 = sss_ml_fd( decim=decim, avg_frames=avg_frames, N_id_1=N_id_1, N_id_2=N_id_2, slot_0_10=slot_0_10, ) self.pss_chan_est2_0 = pss_chan_est2(N_id_2=N_id_2, ) self.gr_vector_to_stream_0_0_1_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0_1 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_source_x_0_0_0 = gr.vector_source_c( (gen_pss_fd(N_id_2, N_re, False).get_data()), True, N_re) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate) self.gr_stream_to_vector_0_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, N_re) self.gr_stream_to_vector_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.gr_stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex * 1, (N_re / 2, N_re / 2)) self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex * 1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0) self.gr_multiply_xx_1_0 = gr.multiply_vcc(N_re) self.gr_multiply_xx_1 = gr.multiply_vcc(N_re) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc( (0.005 * exp(rot * 2 * numpy.pi * 1j), )) self.gr_keep_m_in_n_0_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re / 2, fft_size, (fft_size - N_re) / 2 - 1) self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re / 2, fft_size, (fft_size) / 2) self.gr_file_source_0 = gr.file_source( gr.sizeof_gr_complex * 1, "/home/user/git/gr-lte/gr-lte/test/octave/foo_sss_td_in.cfile", True) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * N_re) self.gr_channel_model_0 = gr.channel_model( noise_voltage=0.005 * noise_level, frequency_offset=0.0, epsilon=1, taps=(0.005 * exp(rot * 2 * numpy.pi * 1j), ), noise_seed=0, ) self.gr_add_xx_0 = gr.add_vcc(1) self.blks2_selector_0_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex * 1, num_inputs=2, num_outputs=1, input_index=0, output_index=0, ) self.blks2_selector_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex * 1, num_inputs=3, num_outputs=2, input_index=0, output_index=0, ) ################################################## # Connections ################################################## self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.blks2_selector_0, 0), (self.gr_channel_model_0, 0)) self.connect((self.blks2_selector_0, 1), (self.gr_add_xx_0, 0)) self.connect((self.gr_channel_model_0, 0), (self.blks2_selector_0_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_selector_0_0, 1)) self.connect((self.gr_file_source_0, 0), (self.blks2_selector_0, 0)) self.connect((self.blks2_selector_0_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_vector_to_stream_0_0_0, 0)) self.connect((self.gr_vector_to_stream_0_0_0, 0), (self.wxgui_scopesink2_0_1_0_0, 0)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.wxgui_scopesink2_0_1_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0, 0)) self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_vector_to_stream_0_0_1, 0), (self.wxgui_scopesink2_0_1_0_1, 0)) self.connect((self.gr_vector_to_stream_0_0_1_0, 0), (self.wxgui_scopesink2_0_1_0_1, 1)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_0_1_0, 0)) self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.sss_ml_fd_0, 0)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_vector_to_stream_0_0, 0)) self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_multiply_xx_1_0, 1)) self.connect((self.gr_multiply_xx_1_0, 0), (self.gr_vector_to_stream_0_0_1, 0)) self.connect((self.gr_deinterleave_0, 1), (self.pss_chan_est2_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0_0, 0)) self.connect((self.gr_keep_m_in_n_0_0, 0), (self.gr_stream_mux_0, 0)) self.connect((self.gr_keep_m_in_n_0, 0), (self.gr_stream_mux_0, 1)) self.connect((self.gr_stream_mux_0, 0), (self.gr_stream_to_vector_0_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 1)) self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 2)) self.connect((self.sss_ml_fd_0, 0), (self.wxgui_scopesink2_0_1, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_1, 0))
def __init__(self): gr.top_block.__init__(self) global parser parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address [default=%default]") #parser.add_option("-e", "--interface", type="string", default="eth0", help="Select ethernet interface. Default is eth0") #parser.add_option("-m", "--MAC_addr", type="string", default="", help="Select USRP2 by its MAC address.Default is auto-select") parser.add_option("-p", "--start", type="eng_float", default=1e7, help="Start ferquency [default = %default]") parser.add_option("-q", "--stop", type="eng_float", default=1e8, help="Stop ferquency [default = %default]") parser.add_option( "", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS", help= "time to delay (in seconds) after changing frequency[default=%default]" ) parser.add_option( "", "--dwell-delay", type="eng_float", default=10e-3, metavar="SECS", help= "time to dwell (in seconds) at a given frequncy[default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-s", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option( "-S", "--sense-bins", type="int", default=64, help="set number of bins in the OFDM block [default=%default]") (options, args) = parser.parse_args() if options.input_file == "": self.IS_USRP2 = True else: self.IS_USRP2 = False self.min_freq = options.start self.max_freq = options.stop print "min_freq=", self.min_freq print "max_freq=", self.max_freq if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them print "Start and stop frequencies order swapped!" self.fft_size = options.fft_size self.ofdm_bins = options.sense_bins # build graph s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap * tap c2mag = gr.complex_to_mag_squared(self.fft_size) #log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # modifications for USRP2 print "*******************in sensor init********************" if self.IS_USRP2: self.u = uhd.usrp_source(device_addr=options.args, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) samp_rate = 100**6 / options.decim self.u.set_samp_rate(samp_rate) else: self.u = gr.file_source(gr.sizeof_gr_complex, options.input_file, True) samp_rate = 100e6 / options.decim self.freq_step = 0 #0.75* samp_rate self.min_center_freq = (self.min_freq + self.max_freq) / 2 global BW BW = self.max_freq - self.min_freq print "bandwidth=", BW global size size = self.fft_size global ofdm_bins ofdm_bins = self.ofdm_bins global usr #global thrshold_inorder usr = samp_rate nsteps = 10 #math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int( round(options.tune_delay * samp_rate / self.fft_size))) # in fft_frames print tune_delay dwell_delay = max(1, int( round(options.dwell_delay * samp_rate / self.fft_size))) # in fft_frames print dwell_delay self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) self.connect(self.u, s2v, fft, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=10e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequency [default=%default]") parser.add_option("", "--channel-bandwidth", type="eng_float", default=12.5e3, metavar="Hz", help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) if self.min_freq > self.max_freq: # swap them self.min_freq, self.max_freq = self.max_freq, self.min_freq self.fft_size = options.fft_size self.channel_bandwidth = options.channel_bandwidth if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.usrp_rate = usrp_rate = options.samp_rate self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = 0.75 * usrp_rate self.min_center_freq = self.min_freq + self.freq_step/2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, fft, c2mag, log, stats) self.connect(self.u, s2v, fft, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self, tuner_callback, options): gr.hier_block2.__init__( self, "sense_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.usrp_rate = options.channel_rate self.usrp_tune = tuner_callback self.threshold = options.threshold #self.freq_step = options.chan_bandwidth #self.min_freq = options.start_freq #self.max_freq = options.end_freq self.hold_freq = False self.channels = [ 600000000, 620000000, 625000000, 640000000, 645000000, 650000000 ] self.current_chan = 0 self.num_channels = len( self.channels) #(self.max_freq - self.min_freq)/self.freq_step #if self.min_freq > self.max_freq: # self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them self.fft_size = options.sense_fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap * tap c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff( 10, self.fft_size, -20 * math.log10(self.fft_size) - 10 * math.log10(power / self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. #changed on 2011 May 31, MR -- maybe change back at some point #self.min_center_freq = self.min_freq + self.freq_step/2 #nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) #self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.channels[ self.current_chan] #self.min_center_freq tune_delay = max(0, int( round(options.tune_delay * self.usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int( round(options.dwell_delay * self.usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune( self) # hang on to this to keep it from being GC'd self.stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self, s2v, fft, c2mag, log, stats) self.connect(self, s2v, fft, c2mag, self.stats)
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] host min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=5e-5, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=50e-5, metavar="SECS", help="time to dwell (in seconds) at a given frequncy [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 3: parser.print_help() sys.exit(1) self.address = args[0] self.min_freq = eng_notation.str_to_num(args[1]) self.max_freq = eng_notation.str_to_num(args[2]) self.decim = options.decim self.gain = options.gain if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them self.fft_size = options.fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" adc_rate = 102.4e6 self.int_rate = adc_rate / self.decim print "Sampling rate: ", self.int_rate # build graph self.port = 10001 self.src = msdd.source_simple(self.address, self.port) self.src.set_decim_rate(self.decim) self.set_gain(self.gain) self.set_freq(self.min_freq) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap*tap norm = gr.multiply_const_cc(1.0/self.fft_size) c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to % of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.percent = 0.4 self.freq_step = self.percent * self.int_rate self.min_center_freq = self.min_freq + self.freq_step/2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * self.int_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * self.int_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up self.connect(self.src, s2v, fft, c2mag, log, stats)
def __init__(self, demod_class, rx_callback, options, source_block): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) options = copy.copy( options) # make a copy so we can destructively modify self._verbose = options.verbose self._bitrate = options.bitrate # desired bit rate self._rx_callback = rx_callback # this callback is fired when a packet arrives self._demod_class = demod_class # the demodulator_class we're using self._chbw_factor = options.chbw_factor # channel filter bandwidth factor # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) #Give hooks of usrp to blocks downstream self.source_block = source_block ######################################### # Build Blocks ######################################### # Build the demodulator self.demodulator = self._demod_class(**demod_kwargs) # Make sure the channel BW factor is between 1 and sps/2 # or the filter won't work. if (self._chbw_factor < 1.0 or self._chbw_factor > self.samples_per_symbol() / 2): sys.stderr.write( "Channel bandwidth factor ({0}) must be within the range [1.0, {1}].\n" .format(self._chbw_factor, self.samples_per_symbol() / 2)) sys.exit(1) # Design filter to get actual channel we want sw_decim = 1 chan_coeffs = gr.firdes.low_pass( 1.0, # gain sw_decim * self.samples_per_symbol(), # sampling rate self._chbw_factor, # midpoint of trans. band 0.5, # width of trans. band gr.firdes.WIN_HANN) # filter type self.channel_filter = gr.fft_filter_ccc(sw_decim, chan_coeffs) # receiver self.packet_receiver = \ digital.demod_pkts(self.demodulator, access_code=None, callback=self._rx_callback, threshold=-1) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.probe = gr.probe_avg_mag_sqrd_c(thresh, alpha) # Display some information about the setup if self._verbose: self._print_verbage() # More Carrier Sensing with FFT #self.gr_vector_sink = gr.vector_sink_c(1024) #self.gr_stream_to_vector = gr.stream_to_vector(gr.sizeof_gr_complex*1, 1024) #self.gr_head = gr.head(gr.sizeof_gr_complex*1024, 1024) #self.fft = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), True, 1) # Parameters usrp_rate = options.bitrate self.fft_size = 1024 self.min_freq = 2.4e9 - 0.75e6 self.max_freq = 2.4e9 + 0.75e6 self.tune_delay = 0.001 self.dwell_delay = 0.01 s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap * tap c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff( 10, self.fft_size, -20 * math.log10(self.fft_size) - 10 * math.log10(power / self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. #self.freq_step = 0.75 * usrp_rate #self.min_center_freq = self.min_freq + self.freq_step/2 #nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) #self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.freq_step = 1.5e6 self.min_center_freq = self.min_freq nsteps = 1 self.max_center_freq = self.max_freq self.next_freq = self.min_center_freq tune_delay = max(0, int(round(self.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int( round(self.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune( self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) ###################################################### # Connect Blocks Together ###################################################### #channel-filter-->Probe_Avg_Mag_Sqrd # -->Packet_Receiver (Demod Done Here!!) # # connect FFT sampler to system #self.connect(self, self.gr_stream_to_vector, self.fft, self.gr_vector_sink) # connect block input to channel filter self.connect(self, self.channel_filter) # connect the channel input filter to the carrier power detector self.connect(self.channel_filter, self.probe) # connect channel filter to the packet receiver self.connect(self.channel_filter, self.packet_receiver) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, fft, c2mag, log, stats) self.connect(self.channel_filter, s2v, fft, c2mag, stats)