def __init__(self, sample_rate, noise_voltage, frequency_offset, seed=False): gr.hier_block2.__init__(self, "awgn_channel", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature # Create the Gaussian noise source if not seed: self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage) else: rseed = int(time.time()) self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage, rseed) self.adder = gr.add_cc() # Create the frequency offset self.offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, frequency_offset, 1.0, 0.0) self.mixer = gr.multiply_cc() # Connect the components self.connect(self, (self.mixer, 0)) self.connect(self.offset, (self.mixer, 1)) self.connect(self.mixer, (self.adder, 0)) self.connect(self.noise, (self.adder, 1)) self.connect(self.adder, self)
def __init__(self, Np=32, P=128, L=2, filename=None, sample_type='complex', verbose=True): gr.top_block.__init__(self) if filename is None: src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) if verbose: print "Using Gaussian noise source." else: if sample_type == 'complex': src = gr.file_source(gr.sizeof_gr_complex, filename, True) else: fsrc = gr.file_source(gr.sizeof_float, filename, True) src = gr.float_to_complex() self.connect(fsrc, src) if verbose: print "Reading data from %s" % filename if verbose: print "FAM configuration:" print "N' = %d" % Np print "P = %d" % P print "L = %d" % L #print "Δf = %f" % asfd sink = gr.null_sink(gr.sizeof_float * 2 * Np) self.cyclo_fam = specest.cyclo_fam(Np, P, L) self.connect(src, self.cyclo_fam, sink)
def __init__(self, rx_callback, SNR): """ @param options Optparse option field for command line arguments. @param rx_callback Callback function for the event when a packet is received. """ gr.flow_graph.__init__(self) self.samples_per_symbol = 2 self.data_rate = 2000000 payload_size = 128 # bytes self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts( self, spb=self.samples_per_symbol, msgq_limit=2) # add some noise print " Setting SNR to ", SNR add = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, pow(10.0, -SNR / 20.0)) self.packet_receiver = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, symbol_rate=self.data_rate, threshold=-1) self.connect(self.packet_transmitter, (add, 0)) self.connect(noise, (add, 1)) self.connect(add, self.packet_receiver)
def __init__(self, N, fs, bw0, bw1, tw, atten, D): gr.top_block.__init__(self) self._nsamps = N self._fs = fs self._bw0 = bw0 self._bw1 = bw1 self._tw = tw self._at = atten self._decim = D taps = filter.firdes.complex_band_pass_2(1, self._fs, self._bw0, self._bw1, self._tw, self._at) print "Num. Taps: ", len(taps) self.src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) self.head = gr.head(gr.sizeof_gr_complex, self._nsamps) self.filt0 = filter.fft_filter_ccc(self._decim, taps) self.vsnk_src = gr.vector_sink_c() self.vsnk_out = gr.vector_sink_c() self.connect(self.src, self.head, self.vsnk_src) self.connect(self.head, self.filt0, self.vsnk_out)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv) pspectrum_len = 1024 # build our flow graph input_rate = 2e6 #Generate some noise noise = gr.noise_source_c(gr.GR_GAUSSIAN, 1.0/10) # Generate a complex sinusoid #source = gr.file_source(gr.sizeof_gr_complex, 'foobar2.dat', repeat=True) src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, -500e3, 1) src2 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 500e3, 1) src3 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, -250e3, 2) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate) sink1 = spectrum_sink_c (panel, title="Spectrum Sink", pspectrum_len=pspectrum_len, sample_rate=input_rate, baseband_freq=0, ref_level=0, y_per_div=20, y_divs=10, m = 70, n = 3, nsamples = 1024) vbox.Add (sink1.win, 1, wx.EXPAND) combine1=gr.add_cc() self.connect(src1,(combine1,0)) self.connect(src2,(combine1,1)) self.connect(src3,(combine1,2)) self.connect(noise, (combine1,3)) self.connect(combine1,thr1, sink1)
def __init__(self, noise_voltage=0.0, frequency_offset=0.0, epsilon=1.0, taps=[1.0,0.0], noise_seed=3021): ''' Creates a channel model that includes: - AWGN noise power in terms of noise voltage - A frequency offest in the channel in ratio - A timing offset ratio to model clock difference (epsilon) - Multipath taps ''' gr.hier_block2.__init__(self, "channel_model", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature #print epsilon self.timing_offset = gr.fractional_interpolator_cc(0, epsilon) self.multipath = gr.fir_filter_ccc(1, taps) self.noise_adder = gr.add_cc() self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage, noise_seed) self.freq_offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, frequency_offset, 1.0, 0.0) self.mixer_offset = gr.multiply_cc() self.connect(self, self.timing_offset, self.multipath) self.connect(self.multipath, (self.mixer_offset,0)) self.connect(self.freq_offset,(self.mixer_offset,1)) self.connect(self.mixer_offset, (self.noise_adder,1)) self.connect(self.noise, (self.noise_adder,0)) self.connect(self.noise_adder, self)
def test_001_detect(self): """ Send two bursts, with zeros in between, and check they are both detected at the correct position and no false alarms occur """ n_zeros = 15 fft_len = 32 cp_len = 4 sig_len = (fft_len + cp_len) * 10 sync_symbol = [(random.randint(0, 1) * 2) - 1 for x in range(fft_len / 2)] * 2 tx_signal = [0,] * n_zeros + \ sync_symbol[-cp_len:] + \ sync_symbol + \ [(random.randint(0, 1)*2)-1 for x in range(sig_len)] tx_signal = tx_signal * 2 add = gr.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = gr.vector_sink_f() sink_detect = gr.vector_sink_b() self.tb.connect(gr.vector_source_c(tx_signal), (add, 0)) self.tb.connect(gr.noise_source_c(gr.GR_GAUSSIAN, .005), (add, 1)) self.tb.connect(add, sync) self.tb.connect((sync, 0), sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() sig1_detect = sink_detect.data()[0:len(tx_signal) / 2] sig2_detect = sink_detect.data()[len(tx_signal) / 2:] self.assertTrue( abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len) self.assertTrue( abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len) self.assertEqual(numpy.sum(sig1_detect), 1) self.assertEqual(numpy.sum(sig2_detect), 1)
def __init__(self, rx_callback, spb, alpha, SNR): # m is constellation size # if diff==True we are doing DxPSK gr.flow_graph.__init__(self) fg = self # transmitter self.packet_transmitter = bbn_80211b_mod_pkts(fg, spb=spb, alpha=alpha, gain=1) # add some noise add = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, pow(10.0,-SNR/20.0)) # channel filter rx_filt_taps = gr.firdes.low_pass(1,spb,0.8,0.1,gr.firdes.WIN_HANN) rx_filt = gr.fir_filter_ccf(1,rx_filt_taps) # receiver self.bit_receiver = bbn_80211b_demod_pkts(self, spb=spb, alpha=alpha, callback=rx_callback) fg.connect(self.packet_transmitter, (add,0)) fg.connect(noise, (add,1)) #xfile=gr.file_sink(gr.sizeof_gr_complex,"txdata"); #fg.connect(add, xfile) fg.connect(add, rx_filt) fg.connect(rx_filt, self.bit_receiver)
def test_002_freq (self): """ Add a fine frequency offset and see if that get's detected properly """ fft_len = 32 cp_len = 4 freq_offset = 0.1 # Must stay < 2*pi/fft_len = 0.196 (otherwise, it's coarse) sig_len = (fft_len + cp_len) * 10 sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2 tx_signal = sync_symbol[-cp_len:] + \ sync_symbol + \ [(random.randint(0, 1)*2)-1 for x in range(sig_len)] mult = gr.multiply_cc() add = gr.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = gr.vector_sink_f() sink_detect = gr.vector_sink_b() self.tb.connect(gr.vector_source_c(tx_signal), (mult, 0), (add, 0)) self.tb.connect(gr.sig_source_c(2 * numpy.pi, gr.GR_SIN_WAVE, freq_offset, 1.0), (mult, 1)) self.tb.connect(gr.noise_source_c(gr.GR_GAUSSIAN, .01), (add, 1)) self.tb.connect(add, sync) self.tb.connect((sync, 0), sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() phi_hat = sink_freq.data()[sink_detect.data().index(1)] est_freq_offset = 2 * phi_hat / fft_len self.assertAlmostEqual(est_freq_offset, freq_offset, places=2)
def run_flow_graph(sync_sym1, sync_sym2, data_sym): top_block = gr.top_block() carr_offset = random.randint(-max_offset/2, max_offset/2) * 2 tx_data = shift_tuple(sync_sym1, carr_offset) + \ shift_tuple(sync_sym2, carr_offset) + \ shift_tuple(data_sym, carr_offset) channel = [rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len)] src = gr.vector_source_c(tx_data, False, fft_len) chan= gr.multiply_const_vcc(channel) noise = gr.noise_source_c(gr.GR_GAUSSIAN, wgn_amplitude) add = gr.add_cc(fft_len) chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1) sink = gr.vector_sink_c(fft_len) top_block.connect(src, chan, (add, 0), chanest, sink) top_block.connect(noise, gr.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1)) top_block.run() channel_est = None carr_offset_hat = 0 rx_sym_est = [0,] * fft_len tags = sink.tags() for tag in tags: if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': carr_offset_hat = pmt.pmt_to_long(tag.value) self.assertEqual(carr_offset, carr_offset_hat) if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': channel_est = shift_tuple(pmt.pmt_c32vector_elements(tag.value), carr_offset) shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset) for i in range(fft_len): if shifted_carrier_mask[i] and channel_est[i]: self.assertAlmostEqual(channel[i], channel_est[i], places=0) rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
def test_001_detect (self): """ Send two bursts, with zeros in between, and check they are both detected at the correct position and no false alarms occur """ n_zeros = 15 fft_len = 32 cp_len = 4 sig_len = (fft_len + cp_len) * 10 sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2 tx_signal = [0,] * n_zeros + \ sync_symbol[-cp_len:] + \ sync_symbol + \ [(random.randint(0, 1)*2)-1 for x in range(sig_len)] tx_signal = tx_signal * 2 add = gr.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = gr.vector_sink_f() sink_detect = gr.vector_sink_b() self.tb.connect(gr.vector_source_c(tx_signal), (add, 0)) self.tb.connect(gr.noise_source_c(gr.GR_GAUSSIAN, .01), (add, 1)) self.tb.connect(add, sync) self.tb.connect((sync, 0), sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() sig1_detect = sink_detect.data()[0:len(tx_signal)/2] sig2_detect = sink_detect.data()[len(tx_signal)/2:] self.assertTrue(abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len) self.assertTrue(abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len) self.assertEqual(numpy.sum(sig1_detect), 1) self.assertEqual(numpy.sum(sig2_detect), 1)
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 setUp (self): print "qa_remove_cp2_cvc SetUp!" self.fftl = fftl = 2048 cpl = 144*fftl/2048 cpl0 = 160*fftl/2048 self.slotl = slotl = 7*fftl+6*cpl+cpl0 self.tb = gr.top_block () #provide test data self.src = gr.noise_source_c(gr.GR_GAUSSIAN,1) self.head = gr.head( gr.sizeof_gr_complex, 10*slotl ) self.tag = lte.pss_tagging_cc(fftl) # set up tagging block self.tag.set_half_frame_start(0) self.tag.set_N_id_2(1) self.tag.lock() # UUT self.rcp = lte.remove_cp2_cvc(fftl) # sinks self.snk = gr.vector_sink_c(fftl) self.tagsnc = gr.tag_debug(gr.sizeof_gr_complex*fftl, "remove_cp2_cvc") # connect blocks self.tb.connect(self.src, self.head, self.tag, self.rcp, self.snk )
def set_waveform(self, type): self.lock() self.disconnect_all() if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE: self._src = gr.sig_source_c( self[SAMP_RATE_KEY], # Sample rate type, # Waveform type self[WAVEFORM_FREQ_KEY], # Waveform frequency self[AMPLITUDE_KEY], # Waveform amplitude self[WAVEFORM_OFFSET_KEY]) # Waveform offset elif type == gr.GR_GAUSSIAN or type == gr.GR_UNIFORM: self._src = gr.noise_source_c(type, self[AMPLITUDE_KEY]) elif type == "2tone": self._src1 = gr.sig_source_c(self[SAMP_RATE_KEY], gr.GR_SIN_WAVE, self[WAVEFORM_FREQ_KEY], self[AMPLITUDE_KEY] / 2.0, 0) if (self[WAVEFORM2_FREQ_KEY] is None): self[WAVEFORM2_FREQ_KEY] = -self[WAVEFORM_FREQ_KEY] self._src2 = gr.sig_source_c(self[SAMP_RATE_KEY], gr.GR_SIN_WAVE, self[WAVEFORM2_FREQ_KEY], self[AMPLITUDE_KEY] / 2.0, 0) self._src = gr.add_cc() self.connect(self._src1, (self._src, 0)) self.connect(self._src2, (self._src, 1)) elif type == "sweep": # rf freq is center frequency # waveform_freq is total swept width # waveform2_freq is sweep rate # will sweep from (rf_freq-waveform_freq/2) to (rf_freq+waveform_freq/2) if self[WAVEFORM2_FREQ_KEY] is None: self[WAVEFORM2_FREQ_KEY] = 0.1 self._src1 = gr.sig_source_f(self[SAMP_RATE_KEY], gr.GR_TRI_WAVE, self[WAVEFORM2_FREQ_KEY], 1.0, -0.5) self._src2 = gr.frequency_modulator_fc( self[WAVEFORM_FREQ_KEY] * 2 * math.pi / self[SAMP_RATE_KEY]) self._src = gr.multiply_const_cc(self[AMPLITUDE_KEY]) self.connect(self._src1, self._src2, self._src) else: raise RuntimeError("Unknown waveform type") self.connect(self._src, self._u) self.unlock() if self._verbose: print "Set baseband modulation to:", waveforms[type] if type == gr.GR_SIN_WAVE: print "Modulation frequency: %sHz" % (n2s( self[WAVEFORM_FREQ_KEY]), ) print "Initial phase:", self[WAVEFORM_OFFSET_KEY] elif type == "2tone": print "Tone 1: %sHz" % (n2s(self[WAVEFORM_FREQ_KEY]), ) print "Tone 2: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]), ) elif type == "sweep": print "Sweeping across %sHz to %sHz" % (n2s( -self[WAVEFORM_FREQ_KEY] / 2.0), n2s(self[WAVEFORM_FREQ_KEY] / 2.0)) print "Sweep rate: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]), ) print "TX amplitude:", self[AMPLITUDE_KEY]
def __init__(self, noise_ampl=0): """ Parameters: noise_ampl: float """ gr.hier_block2.__init__( self, "Additive White Gaussian Noise Generator", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex), ) ################################################## # Parameters ################################################## self.noise_ampl = noise_ampl ################################################## # Blocks ################################################## self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_ampl, 42) self.gr_add_xx_0 = gr.add_vcc(1) ################################################## # Connections ################################################## self.connect((self, 0), (self.gr_add_xx_0, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_add_xx_0, 0), (self, 0))
def __init__(self, fg, noise_voltage=0.0, frequency_offset=0.0, epsilon=1.0, taps=[1.0,0.0]): ''' Creates a channel model that includes: - AWGN noise power in terms of noise voltage - A frequency offest in the channel in ratio - A timing offset ratio to model clock difference (epsilon) - Multipath taps ''' print epsilon self.timing_offset = gr.fractional_interpolator_cc(0, epsilon) self.multipath = gr.fir_filter_ccc(1, taps) self.noise_adder = gr.add_cc() self.noise = gr.noise_source_c(gr.GR_GAUSSIAN,noise_voltage) self.freq_offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, frequency_offset, 1.0, 0.0) self.mixer_offset = gr.multiply_cc() fg.connect(self.timing_offset, self.multipath) fg.connect(self.multipath, (self.mixer_offset,0)) fg.connect(self.freq_offset,(self.mixer_offset,1)) fg.connect(self.mixer_offset, (self.noise_adder,1)) fg.connect(self.noise, (self.noise_adder,0)) gr.hier_block.__init__(self, fg, self.timing_offset, self.noise_adder)
def __init__(self, n_sinusoids = 1, SNR = 10, samp_rate = 32e3, nsamples = 2048): gr.hier_block2.__init__(self, "ESPRIT/MUSIC signal generator", gr.io_signature(0, 0, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_gr_complex)) sigampl = 10.0**(SNR/10.0) # noise power is 1 self.srcs = list() self.n_sinusoids = n_sinusoids self.samp_rate = samp_rate # create our signals ... for s in range(n_sinusoids): self.srcs.append(gr.sig_source_c(samp_rate, gr.GR_SIN_WAVE,1000 * s + 2000, numpy.sqrt(sigampl/n_sinusoids))) seed = ord(os.urandom(1)) self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, 1, seed) self.add = gr.add_cc() self.head = gr.head(gr.sizeof_gr_complex, nsamples) self.sink = gr.vector_sink_f(vlen=n_sinusoids) # wire it up ... for s in range(n_sinusoids): self.connect(self.srcs[s], (self.add, s)) # Additive noise self.connect(self.noise, (self.add, n_sinusoids)) self.connect(self.add, self.head, self)
def __init__(self): gr.top_block.__init__(self, "FFT Sink Test") fft_size = 256 # build our flow graph input_rate = 2048.0e3 #Generate some noise noise = gr.noise_source_c(gr.GR_UNIFORM, 1.0/10) # Generate a complex sinusoid src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2e3, 1) #src1 = gr.sig_source_c(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate) test_fft = zmq_fft_sink_c(title="Complex Data", fft_size=fft_size, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10) combine1 = gr.add_cc() #self.connect(src1, (combine1, 0)) #self.connect(noise,(combine1, 1)) self.connect(src1, thr1, test_fft)
def __init__(self, rx_callback, SNR): """ @param options Optparse option field for command line arguments. @param rx_callback Callback function for the event when a packet is received. """ gr.flow_graph.__init__(self) self.samples_per_symbol = 2 self.data_rate = 2000000 payload_size = 128 # bytes self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self.samples_per_symbol, msgq_limit=2) # add some noise print " Setting SNR to ", SNR add = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, pow(10.0,-SNR/20.0)) self.packet_receiver = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(self, callback=rx_callback, sps=self.samples_per_symbol, symbol_rate=self.data_rate, threshold=-1) self.connect (self.packet_transmitter, (add,0)) self.connect (noise, (add,1)) self.connect(add, self.packet_receiver)
def test_003_multiburst (self): """ Send several bursts, see if the number of detects is correct. Burst lengths and content are random. """ n_bursts = 42 fft_len = 32 cp_len = 4 tx_signal = [] for i in xrange(n_bursts): sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2 tx_signal += [0,] * random.randint(0, 2*fft_len) + \ sync_symbol[-cp_len:] + \ sync_symbol + \ [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))] add = gr.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = gr.vector_sink_f() sink_detect = gr.vector_sink_b() self.tb.connect(gr.vector_source_c(tx_signal), (add, 0)) self.tb.connect(gr.noise_source_c(gr.GR_GAUSSIAN, .005), (add, 1)) self.tb.connect(add, sync) self.tb.connect((sync, 0), sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() self.assertEqual(numpy.sum(sink_detect.data()), n_bursts, msg="""Because of statistics, it is possible (though unlikely) that the number of detected bursts differs slightly. If the number of detects is off by one or two, run the test again and see what happen. Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts) )
def build_graph (input, raw, snr, freq_offset, coeffs, mag): # Initialize empty flow graph fg = gr.top_block () # Set up file source src = gr.file_source (1, input) # Set up GMSK modulator, 2 samples per symbol mod = gmsk_mod(2) # Amplify the signal tx_amp = 1 amp = gr.multiply_const_cc(1) amp.set_k(tx_amp) # Compute proper noise voltage based on SNR SNR = 10.0**(snr/10.0) power_in_signal = abs(tx_amp)**2 noise_power = power_in_signal/SNR noise_voltage = math.sqrt(noise_power) # Generate noise rseed = int(time.time()) noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage, rseed) adder = gr.add_cc() fg.connect(noise, (adder, 1)) # Create the frequency offset, 0 for now offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, freq_offset, 1.0, 0.0) mixer = gr.multiply_cc() fg.connect(offset, (mixer, 1)) # Pass the noisy data to the matched filter dfile = open(coeffs, 'r') data = [] for line in dfile: data.append(complex(*map(float,line.strip().strip("()").split(" "))).conjugate()) dfile.close() data.reverse() mfilter = gr.fir_filter_ccc(1, data) # Connect the flow graph fg.connect(src, mod) fg.connect(mod, (mixer, 0)) fg.connect(mixer, (adder, 0)) if mag: raw_dst = gr.file_sink (gr.sizeof_float, raw) magnitude = gr.complex_to_mag(1) fg.connect(adder, mfilter, magnitude, raw_dst) else: raw_dst = gr.file_sink (gr.sizeof_gr_complex, raw) fg.connect(adder, mfilter, raw_dst) print "SNR(db): " + str(snr) print "Frequency Offset: " + str(freq_offset) return fg
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) fft_size = 256 # build our flow graph input_rate = 2048.0e3 # Generate some noise noise = gr.noise_source_c(gr.GR_UNIFORM, 1.0 / 10) # Generate a complex sinusoid # src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2e3, 1) src1 = gr.sig_source_c(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate) sink1 = fft_sink_c( panel, title="Complex Data", fft_size=fft_size, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10, ) vbox.Add(sink1.win, 1, wx.EXPAND) combine1 = gr.add_cc() self.connect(src1, (combine1, 0)) self.connect(noise, (combine1, 1)) self.connect(combine1, thr1, sink1) # src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1) src2 = gr.sig_source_f(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1) thr2 = gr.throttle(gr.sizeof_float, input_rate) sink2 = fft_sink_f( panel, title="Real Data", fft_size=fft_size * 2, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10, ) vbox.Add(sink2.win, 1, wx.EXPAND) combine2 = gr.add_ff() c2f2 = gr.complex_to_float() self.connect(src2, (combine2, 0)) self.connect(noise, c2f2, (combine2, 1)) self.connect(combine2, thr2, sink2)
def _instantiate_blocks (self): self.src = None self.u = usrp.sink_c (0, self.interp) self.siggen = gr.sig_source_c (self.usb_freq (), gr.GR_SIN_WAVE, self.waveform_freq, self.waveform_ampl, self.waveform_offset) self.noisegen = gr.noise_source_c (gr.GR_UNIFORM, self.waveform_ampl)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) fft_size = 256 # build our flow graph input_rate = 2048.0e3 #Generate some noise noise = gr.noise_source_c(gr.GR_UNIFORM, 1.0 / 10) # Generate a complex sinusoid #src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2e3, 1) src1 = gr.sig_source_c(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate) sink1 = fft_sink_c(panel, title="Complex Data", fft_size=fft_size, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10) vbox.Add(sink1.win, 1, wx.EXPAND) combine1 = gr.add_cc() self.connect(src1, (combine1, 0)) self.connect(noise, (combine1, 1)) self.connect(combine1, thr1, sink1) #src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1) src2 = gr.sig_source_f(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1) thr2 = gr.throttle(gr.sizeof_float, input_rate) sink2 = fft_sink_f(panel, title="Real Data", fft_size=fft_size * 2, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10) vbox.Add(sink2.win, 1, wx.EXPAND) combine2 = gr.add_ff() c2f2 = gr.complex_to_float() self.connect(src2, (combine2, 0)) self.connect(noise, c2f2, (combine2, 1)) self.connect(combine2, thr2, sink2)
def _instantiate_blocks (self): self.src = None self.u = usrp.sink_c (0, self.interp,fpga_filename=gpio.fpga_filename) self.siggen = gr.sig_source_c (self.usb_freq (), gr.GR_SIN_WAVE, self.waveform_freq, self.waveform_ampl, self.waveform_offset) self.noisegen = gr.noise_source_c (gr.GR_UNIFORM, self.waveform_ampl) self.vecgen = gr.vector_source_c ([complex(1.0,0.0),complex(0.0,0.0),complex(1.0,1.0),complex(0.0,1.0)],True)
def _instantiate_blocks(self): self.src = None self.u = usrp.sink_c(0, self.interp) self.siggen = gr.sig_source_c( self.usb_freq(), gr.GR_SIN_WAVE, self.waveform_freq, self.waveform_ampl, self.waveform_offset ) self.noisegen = gr.noise_source_c(gr.GR_UNIFORM, self.waveform_ampl) self.head = None if self.nsamples > 0: self.head = gr.head(gr.sizeof_gr_complex, int(self.nsamples))
def test_002 (self): """ Stream some data through the block to see it all works. """ Np = 128 P = 512 L = 4 src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) head = gr.head(gr.sizeof_gr_complex, P * L) cyclo_fam = specest.cyclo_fam (Np,P,L) dst = gr.vector_sink_f(2*Np) self.tb.connect(src, head, cyclo_fam, dst) try: self.tb.run() except: self.fail("Something's wrong -- an exception was thrown during runtime.")
def test_depuncture_viterbi_cb(self): """ Performs some very basic tests of the depuncture-viterbi block """ # 1. Random data expected_result = () src = gr.noise_source_c(gr.GR_GAUSSIAN, ampl=math.sqrt(1/2), seed=0) head = gr.head(gr.sizeof_gr_complex, 100000) depuncture_viterbi = dvb_swig.depuncture_viterbi_cb([1,1]) dst = gr.vector_sink_b() self.tb.connect(src, head, depuncture_viterbi, dst) self.tb.run() self.assertEqual(expected_result, dst.data());
def test_002(self): """ Stream some data through the block to see it all works. """ Np = 128 P = 512 L = 4 src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) head = gr.head(gr.sizeof_gr_complex, P * L) cyclo_fam = specest.cyclo_fam(Np, P, L) dst = gr.vector_sink_f(2 * Np) self.tb.connect(src, head, cyclo_fam, dst) try: self.tb.run() except: self.fail( "Something's wrong -- an exception was thrown during runtime.")
def __init__(self, noise_dB=-20., fir_taps=[1]): gr.hier_block2.__init__(self, 'my_channel', gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) noise_adder = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, 10**(noise_dB/20.), random.randint(0,2**30)) # normalize taps firtabsum = float(sum(map(abs,fir_taps))) fir_taps = [ i / firtabsum for i in fir_taps] multipath = gr.fir_filter_ccc(1,fir_taps) self.connect(noise, (noise_adder,1)) self.connect(self, noise_adder, multipath, self) self.__dict__.update(locals()) # didn't feel like using self all over the place
def test_002_stream(self): """ Stream some data through the block to see it all works. """ block_len = 256 fft_len = 128 order = 6 n_blocks = 100 src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) head = gr.head(gr.sizeof_gr_complex, n_blocks * block_len) burg = specest.burg(block_len, fft_len, order) dst = gr.vector_sink_f(fft_len) self.tb.connect(src, head, burg, dst) try: self.tb.run() except: self.fail("Something's wrong -- an exception was thrown during runtime.")
def test_002_stream (self): """ Monkey test """ block_len = 256 fft_len = 128 order = 6 n_blocks = 100 src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) head = gr.head(gr.sizeof_gr_complex, n_blocks * block_len) fmcov = specest.fmcov(block_len, fft_len, order) dst = gr.vector_sink_f(fft_len) self.tb.connect(src, head, fmcov, dst) try: self.tb.run() except: self.fail("Something's wrong -- an exception was thrown during runtime.")
def __init__(self, noise_dB=-20., fir_taps=[1]): gr.hier_block2.__init__(self, 'my_channel', gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) noise_adder = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, 10**(noise_dB / 20.), random.randint(0, 2**30)) # normalize taps firtabsum = float(sum(map(abs, fir_taps))) fir_taps = [i / firtabsum for i in fir_taps] multipath = gr.fir_filter_ccc(1, fir_taps) self.connect(noise, (noise_adder, 1)) self.connect(self, noise_adder, multipath, self) self.__dict__.update( locals()) # didn't feel like using self all over the place
def __init__(self, EbN0): gr.top_block.__init__(self) self.const = digital.qpsk_constellation() # Source is N_BITS bits, non-repeated data = map(int, numpy.random.randint(0, self.const.arity(), N_BITS/self.const.bits_per_symbol())) src = gr.vector_source_b(data, False) mod = gr.chunks_to_symbols_bc((self.const.points()), 1) add = gr.add_vcc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, self.EbN0_to_noise_voltage(EbN0), RAND_SEED) demod = digital.constellation_decoder_cb(self.const.base()) ber = BitErrors(self.const.bits_per_symbol()) self.sink = gr.vector_sink_f() self.connect(src, mod, add, demod, ber, self.sink) self.connect(noise, (add, 1)) self.connect(src, (ber, 1))
def __init__(self, constellation, f, N0=0.25, seed=-666L): """ constellation - a constellation object used for modulation. f - a finite state machine specification used for coding. N0 - noise level seed - random seed """ super(trellis_tb, self).__init__() # packet size in bits (make it multiple of 16 so it can be packed in a short) packet_size = 1024 * 16 # bits per FSM input symbol bitspersymbol = int(round(math.log(f.I()) / math.log(2))) # bits per FSM input symbol # packet size in trellis steps K = packet_size / bitspersymbol # TX src = gr.lfsr_32k_source_s() # packet size in shorts src_head = gr.head(gr.sizeof_short, packet_size / 16) # unpack shorts to symbols compatible with the FSM input cardinality s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST) # initial FSM state = 0 enc = trellis.encoder_ss(f, 0) mod = gr.chunks_to_symbols_sc(constellation.points(), 1) # CHANNEL add = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX # data preprocessing to generate metrics for Viterbi metrics = trellis.constellation_metrics_cf( constellation.base(), digital_swig.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_s(f, K, 0, -1) # pack FSM input symbols to shorts fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # check the output self.dst = gr.check_lfsr_32k_s() self.connect(src, src_head, s2fsmi, enc, mod) self.connect(mod, (add, 0)) self.connect(noise, (add, 1)) self.connect(add, metrics, va, fsmi2s, self.dst)
def run_flow_graph(sync_sym1, sync_sym2, data_sym): top_block = gr.top_block() carr_offset = random.randint(-max_offset / 2, max_offset / 2) * 2 tx_data = shift_tuple(sync_sym1, carr_offset) + \ shift_tuple(sync_sym2, carr_offset) + \ shift_tuple(data_sym, carr_offset) channel = [ rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len) ] src = gr.vector_source_c(tx_data, False, fft_len) chan = gr.multiply_const_vcc(channel) noise = gr.noise_source_c(gr.GR_GAUSSIAN, wgn_amplitude) add = gr.add_cc(fft_len) chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1) sink = gr.vector_sink_c(fft_len) top_block.connect(src, chan, (add, 0), chanest, sink) top_block.connect( noise, gr.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1)) top_block.run() channel_est = None carr_offset_hat = 0 rx_sym_est = [ 0, ] * fft_len tags = sink.tags() for tag in tags: if pmt.pmt_symbol_to_string( tag.key) == 'ofdm_sync_carr_offset': carr_offset_hat = pmt.pmt_to_long(tag.value) self.assertEqual(carr_offset, carr_offset_hat) if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': channel_est = shift_tuple( pmt.pmt_c32vector_elements(tag.value), carr_offset) shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset) for i in range(fft_len): if shifted_carrier_mask[i] and channel_est[i]: self.assertAlmostEqual(channel[i], channel_est[i], places=0) rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
def test_002_stream(self): """ Stream some data through the block to see it all works. """ block_len = 256 fft_len = 128 order = 6 n_blocks = 100 src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) head = gr.head(gr.sizeof_gr_complex, n_blocks * block_len) fcov = specest.fcov(block_len, fft_len, order) dst = gr.vector_sink_f(fft_len) self.tb.connect(src, head, fcov, dst) try: self.tb.run() except: self.fail( "Something's wrong -- an exception was thrown during runtime.")
def __init__(self,ampl_i,band,symbol_rate,sps): gr.hier_block2.__init__(self,"Channel", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.symbol_rate = symbol_rate self.sample_rate=symbol_rate*sps self.fading = False self.adder = gr.add_cc() self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, 1, -42) self.ampl = gr.multiply_const_cc(ampl_i) self.taps = gr.firdes.low_pass_2 (1,280,band/2,5,80,gr.firdes.WIN_KAISER) self.filter=gr.fir_filter_ccf(1,self.taps) #Connects self.connect(self,self.filter,(self.adder,0)) self.connect(self.noise, self.ampl, (self.adder,1)) self.connect(self.adder, self)
def __init__(self, constellation, f, N0=0.25, seed=-666L): """ constellation - a constellation object used for modulation. f - a finite state machine specification used for coding. N0 - noise level seed - random seed """ super(trellis_tb, self).__init__() # packet size in bits (make it multiple of 16 so it can be packed in a short) packet_size = 1024*16 # bits per FSM input symbol bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol # packet size in trellis steps K = packet_size/bitspersymbol # TX src = gr.lfsr_32k_source_s() # packet size in shorts src_head = gr.head (gr.sizeof_short, packet_size/16) # unpack shorts to symbols compatible with the FSM input cardinality s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST) # initial FSM state = 0 enc = trellis.encoder_ss(f, 0) mod = gr.chunks_to_symbols_sc(constellation.points(), 1) # CHANNEL add = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX # data preprocessing to generate metrics for Viterbi metrics = trellis.constellation_metrics_cf(constellation.base(), digital_swig.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_s(f, K, 0, -1) # pack FSM input symbols to shorts fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # check the output self.dst = gr.check_lfsr_32k_s() self.connect (src, src_head, s2fsmi, enc, mod) self.connect (mod, (add, 0)) self.connect (noise, (add, 1)) self.connect (add, metrics, va, fsmi2s, self.dst)
def __init__(self, EbN0): gr.top_block.__init__(self) self.const = digital.qpsk_constellation() # Source is N_BITS bits, non-repeated data = map( int, numpy.random.randint(0, self.const.arity(), N_BITS / self.const.bits_per_symbol())) src = gr.vector_source_b(data, False) mod = gr.chunks_to_symbols_bc((self.const.points()), 1) add = gr.add_vcc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, self.EbN0_to_noise_voltage(EbN0), RAND_SEED) demod = digital.constellation_decoder_cb(self.const.base()) ber = BitErrors(self.const.bits_per_symbol()) self.sink = gr.vector_sink_f() self.connect(src, mod, add, demod, ber, self.sink) self.connect(noise, (add, 1)) self.connect(src, (ber, 1))
def __init__(self, ampl_i, band, symbol_rate, sps): gr.hier_block2.__init__(self, "Channel", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.symbol_rate = symbol_rate self.sample_rate = symbol_rate * sps self.fading = False self.adder = gr.add_cc() self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, 1, -42) self.ampl = gr.multiply_const_cc(ampl_i) self.taps = gr.firdes.low_pass_2(1, 280, band / 2, 5, 80, gr.firdes.WIN_KAISER) self.filter = gr.fir_filter_ccf(1, self.taps) #Connects self.connect(self, self.filter, (self.adder, 0)) self.connect(self.noise, self.ampl, (self.adder, 1)) self.connect(self.adder, self)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(usage="%prog: [options]") parser.add_option("-N", "--dpsslength", type="int", help="Length of the DPSS", default="512") parser.add_option("-B", "--timebandwidthproduct", type="float", help="Time Bandwidthproduct used to calculate the DPSS", default="3") parser.add_option("-K", "--tapers", type="int", help="Number of Tapers used to calculate the Spectrum", default="5") parser.add_option("-W", "--weighting", type="choice", choices=("unity", "eigenvalues" ,"adaptive" ), help="weighting-type to be used (unity, eigenvalues, adaptive) ", default="adaptive") (options, args) = parser.parse_args () self.options = options #setting up our signal self.samplingrate = 48000 self.source = gr.sig_source_c(self.samplingrate, gr.GR_SIN_WAVE, 3000, 1) self.noise = gr.noise_source_c(gr.GR_GAUSSIAN,0.5) self.add = gr.add_cc() self.throttle = gr.throttle(gr.sizeof_gr_complex, self.samplingrate) #the actual spectrum estimator self.v2s = gr.vector_to_stream(gr.sizeof_float, self.options.dpsslength) self.mtm = specest.mtm(N = self.options.dpsslength, NW = self.options.timebandwidthproduct, K = self.options.tapers, weighting = self.options.weighting) self.scope = specest.spec_sink_f(panel, title='Spectrum with %s weighting, Length %i and %i Tapers' % ( self.options.weighting, self.options.dpsslength, self.options.tapers ), spec_size=self.options.dpsslength, sample_rate=self.samplingrate, ref_level=80, avg_alpha=0.8, y_per_div=20) self.connect(self.source, (self.add, 0) ) self.connect(self.noise, (self.add, 1) ) self.connect(self.add, self.throttle, self.mtm) self.connect(self.mtm, self.v2s, self.scope) self._build_gui(vbox)
def __init__(self): gr.top_block.__init__(self) # Make a local QtApp so we can start it from our side self.qapp = QtGui.QApplication(sys.argv) fftsize = 2048 self.src = gr.sig_source_c(1, gr.GR_SIN_WAVE, 0.1, 1) self.nse = gr.noise_source_c(gr.GR_GAUSSIAN, 0.0) self.add = gr.add_cc() self.thr = gr.throttle(gr.sizeof_gr_complex, 100 * fftsize) self.snk = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS) self.connect(self.src, (self.add, 0)) self.connect(self.nse, (self.add, 1)) self.connect(self.add, self.thr, self.snk) # Tell the sink we want it displayed self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) self.pyobj.show()
def __init__(self, noise_voltage, frequency_offset): gr.hier_block2.__init__(self, "awgn_channel", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.noise_adder = gr.add_cc() self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage) self.offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, frequency_offset, 1.0, 0.0) self.mixer_offset = gr.multiply_cc() self.connect(self, (self.mixer_offset, 0)) self.connect(self.offset, (self.mixer_offset, 1)) self.connect(self.mixer_offset, (self.noise_adder, 1)) self.connect(self.noise, (self.noise_adder, 0)) self.connect(self.noise_adder, self) try: gr.hier_block.update_var_names(self, "awgn_channel", vars()) gr.hier_block.update_var_names(self, "awgn_channel", vars(self)) except: pass
def __init__(self, N, fs, fd, ca_shift, snr=0): gr.hier_block2.__init__(self, "simulated_source", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) code = ca_code(svn=1, fs=fs, ca_shift=ca_shift) code = ravel(array([code for _ in range(N)])) n = arange(len(code)) f = e**(2j * pi * fd * n / fs) x = (code * f) # Add noise. signal_power = sum(sqrt(abs(x))) / len(x) noise_voltage = sqrt(signal_power / 10**(snr / 10.0)) src = gr.vector_source_c(x) noise = gr.noise_source_c(gr.GR_UNIFORM, noise_voltage) add = gr.add_cc() self.connect(src, (add, 0)) self.connect(noise, (add, 1)) self.connect(add, self)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.usrp2_sink_xxxx_0 = usrp2.sink_32fc() self.usrp2_sink_xxxx_0.set_interp(16) self.usrp2_sink_xxxx_0.set_center_freq(900e6) self.usrp2_sink_xxxx_0.set_gain(0) self.usrp2_sink_xxxx_0.config_mimo(usrp2.MC_WE_DONT_LOCK) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, 1, 42) ################################################## # Connections ################################################## self.connect((self.gr_noise_source_x_0, 0), (self.usrp2_sink_xxxx_0, 0))
def __init__(self, noise_voltage, sensitivity): gr.hier_block2.__init__(self, "variable_awgn_channel", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.noise_adder = gr.add_cc() self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage) self.noise_amp = gr.multiply_cc() self.offset = gr.frequency_modulator_fc(sensitivity) self.mixer_offset = gr.multiply_cc() self.connect(self, (self.mixer_offset, 0)) self.connect(self.offset, (self.mixer_offset, 1)) self.connect(self.mixer_offset, (self.noise_adder, 1)) self.connect(self.noise, (self.noise_amp, 0)) self.connect(self.noise_amp, (self.noise_adder, 0)) self.connect(self.noise_adder, self) try: gr.hier_block.update_var_names(self, "var_awgn_channel", vars()) gr.hier_block.update_var_names(self, "var_awgn_channel", vars(self)) except: pass
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): 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 = 192000 self.Noise = Noise = 0.01 self.Loudness = Loudness = 0.7 self.Frequency = Frequency = 5000 ################################################## # Blocks ################################################## _Noise_sizer = wx.BoxSizer(wx.VERTICAL) self._Noise_text_box = forms.text_box( parent=self.GetWin(), sizer=_Noise_sizer, value=self.Noise, callback=self.set_Noise, label="Noise", converter=forms.float_converter(), proportion=0, ) self._Noise_slider = forms.slider( parent=self.GetWin(), sizer=_Noise_sizer, value=self.Noise, callback=self.set_Noise, minimum=0.0, maximum=1, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_Noise_sizer) _Loudness_sizer = wx.BoxSizer(wx.VERTICAL) self._Loudness_text_box = forms.text_box( parent=self.GetWin(), sizer=_Loudness_sizer, value=self.Loudness, callback=self.set_Loudness, label="Loudness", converter=forms.float_converter(), proportion=0, ) self._Loudness_slider = forms.slider( parent=self.GetWin(), sizer=_Loudness_sizer, value=self.Loudness, callback=self.set_Loudness, minimum=0.0, maximum=1.0, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_Loudness_sizer) _Frequency_sizer = wx.BoxSizer(wx.VERTICAL) self._Frequency_text_box = forms.text_box( parent=self.GetWin(), sizer=_Frequency_sizer, value=self.Frequency, callback=self.set_Frequency, label="Frequency", converter=forms.int_converter(), proportion=0, ) self._Frequency_slider = forms.slider( parent=self.GetWin(), sizer=_Frequency_sizer, value=self.Frequency, callback=self.set_Frequency, minimum=10, maximum=20000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.Add(_Frequency_sizer) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=4.0, sample_rate=samp_rate, fft_size=2048, fft_rate=15, average=False, avg_alpha=0.1, title="Waterfall Plot", size=(900,200), ) self.Add(self.wxgui_waterfallsink2_0.win) def wxgui_waterfallsink2_0_callback(x, y): self.set_Frequency(x) self.wxgui_waterfallsink2_0.set_callback(wxgui_waterfallsink2_0_callback) 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=4.0, sample_rate=samp_rate, fft_size=2048, fft_rate=15, average=True, avg_alpha=0.1, title="FFT Plot", peak_hold=True, ) self.Add(self.wxgui_fftsink2_0.win) self.gr_sig_source_x_2 = gr.sig_source_c(samp_rate, gr.GR_SIN_WAVE, Frequency, Loudness, 0) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, Noise, 0) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_add_xx_1 = gr.add_vcc(1) self.audio_sink_0 = audio.sink(samp_rate, "", True) ################################################## # Connections ################################################## self.connect((self.gr_complex_to_real_0, 0), (self.audio_sink_0, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_1, 0)) self.connect((self.gr_sig_source_x_2, 0), (self.gr_add_xx_1, 1)) self.connect((self.gr_add_xx_1, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_add_xx_1, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.gr_add_xx_1, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self): gr.top_block.__init__(self, "Simple QAM Simulation") Qt.QWidget.__init__(self) self.setWindowTitle("Simple QAM Simulation") self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) ################################################## # Variables ################################################## self.constellation_cardinality = constellation_cardinality = 16 self.const_object = const_object = constellations()['qam']( constellation_cardinality) self.snr_db = snr_db = 20 self.constellation = constellation = const_object.points() self.sps = sps = 8 self.samp_rate = samp_rate = 250000 self.noise_amp = noise_amp = sqrt((10**(-snr_db / 10.)) / 2.) self.constellation_power = constellation_power = sqrt( sum([abs(i)**2 for i in constellation]) / constellation_cardinality) ################################################## # Blocks ################################################## self.tabid_0 = Qt.QTabWidget() self.tabid_0_widget_0 = Qt.QWidget() self.tabid_0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_0_widget_0) self.tabid_0_grid_layout_0 = Qt.QGridLayout() self.tabid_0_layout_0.addLayout(self.tabid_0_grid_layout_0) self.tabid_0.addTab(self.tabid_0_widget_0, "TX") self.tabid_0_widget_1 = Qt.QWidget() self.tabid_0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_0_widget_1) self.tabid_0_grid_layout_1 = Qt.QGridLayout() self.tabid_0_layout_1.addLayout(self.tabid_0_grid_layout_1) self.tabid_0.addTab(self.tabid_0_widget_1, "CHANNEL") self.tabid_0_widget_2 = Qt.QWidget() self.tabid_0_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_0_widget_2) self.tabid_0_grid_layout_2 = Qt.QGridLayout() self.tabid_0_layout_2.addLayout(self.tabid_0_grid_layout_2) self.tabid_0.addTab(self.tabid_0_widget_2, "RX") self.top_grid_layout.addWidget(self.tabid_0, 30, 0, 10, 100) self.tabid_2 = Qt.QTabWidget() self.tabid_2_widget_0 = Qt.QWidget() self.tabid_2_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_2_widget_0) self.tabid_2_grid_layout_0 = Qt.QGridLayout() self.tabid_2_layout_0.addLayout(self.tabid_2_grid_layout_0) self.tabid_2.addTab(self.tabid_2_widget_0, "symbol-based") self.tabid_2_widget_1 = Qt.QWidget() self.tabid_2_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_2_widget_1) self.tabid_2_grid_layout_1 = Qt.QGridLayout() self.tabid_2_layout_1.addLayout(self.tabid_2_grid_layout_1) self.tabid_2.addTab(self.tabid_2_widget_1, "bit-based") self.tabid_2_widget_2 = Qt.QWidget() self.tabid_2_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_2_widget_2) self.tabid_2_grid_layout_2 = Qt.QGridLayout() self.tabid_2_layout_2.addLayout(self.tabid_2_grid_layout_2) self.tabid_2.addTab(self.tabid_2_widget_2, "BER") self.tabid_0_layout_2.addWidget(self.tabid_2) self.tabid_1 = Qt.QTabWidget() self.tabid_1_widget_0 = Qt.QWidget() self.tabid_1_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_1_widget_0) self.tabid_1_grid_layout_0 = Qt.QGridLayout() self.tabid_1_layout_0.addLayout(self.tabid_1_grid_layout_0) self.tabid_1.addTab(self.tabid_1_widget_0, "bit-based") self.tabid_1_widget_1 = Qt.QWidget() self.tabid_1_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_1_widget_1) self.tabid_1_grid_layout_1 = Qt.QGridLayout() self.tabid_1_layout_1.addLayout(self.tabid_1_grid_layout_1) self.tabid_1.addTab(self.tabid_1_widget_1, "scrambled") self.tabid_1_widget_2 = Qt.QWidget() self.tabid_1_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabid_1_widget_2) self.tabid_1_grid_layout_2 = Qt.QGridLayout() self.tabid_1_layout_2.addLayout(self.tabid_1_grid_layout_2) self.tabid_1.addTab(self.tabid_1_widget_2, "symbol-based") self.tabid_0_grid_layout_0.addWidget(self.tabid_1, 0, 0, 10, 10) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #bw "QT GUI Plot", #name 1 #number of inputs ) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.tabid_2_layout_2.addWidget(self._qtgui_time_sink_x_0_win) self.qtgui_sink_x_0_1_0_0 = qtgui.sink_f( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "QT GUI Plot", #name False, #plotfreq False, #plotwaterfall True, #plottime True, #plotconst ) self._qtgui_sink_x_0_1_0_0_win = sip.wrapinstance( self.qtgui_sink_x_0_1_0_0.pyqwidget(), Qt.QWidget) self.tabid_1_layout_0.addWidget(self._qtgui_sink_x_0_1_0_0_win) self.qtgui_sink_x_0_1_0 = qtgui.sink_f( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "QT GUI Plot", #name True, #plotfreq False, #plotwaterfall True, #plottime True, #plotconst ) self._qtgui_sink_x_0_1_0_win = sip.wrapinstance( self.qtgui_sink_x_0_1_0.pyqwidget(), Qt.QWidget) self.tabid_1_layout_1.addWidget(self._qtgui_sink_x_0_1_0_win) self.qtgui_sink_x_0_1 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "QT GUI Plot", #name False, #plotfreq False, #plotwaterfall True, #plottime True, #plotconst ) self._qtgui_sink_x_0_1_win = sip.wrapinstance( self.qtgui_sink_x_0_1.pyqwidget(), Qt.QWidget) self.tabid_1_layout_2.addWidget(self._qtgui_sink_x_0_1_win) self.qtgui_sink_x_0_0_0_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "QT GUI Plot", #name True, #plotfreq False, #plotwaterfall True, #plottime True, #plotconst ) self._qtgui_sink_x_0_0_0_0_win = sip.wrapinstance( self.qtgui_sink_x_0_0_0_0.pyqwidget(), Qt.QWidget) self.tabid_2_layout_0.addWidget(self._qtgui_sink_x_0_0_0_0_win) self.qtgui_sink_x_0_0_0 = qtgui.sink_f( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "QT GUI Plot", #name False, #plotfreq False, #plotwaterfall True, #plottime True, #plotconst ) self._qtgui_sink_x_0_0_0_win = sip.wrapinstance( self.qtgui_sink_x_0_0_0.pyqwidget(), Qt.QWidget) self.tabid_2_layout_1.addWidget(self._qtgui_sink_x_0_0_0_win) self.qtgui_sink_x_0_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "QT GUI Plot", #name True, #plotfreq False, #plotwaterfall True, #plottime False, #plotconst ) self._qtgui_sink_x_0_0_win = sip.wrapinstance( self.qtgui_sink_x_0_0.pyqwidget(), Qt.QWidget) self.tabid_0_layout_1.addWidget(self._qtgui_sink_x_0_0_win) self.gr_vector_source_x_0_0 = gr.vector_source_b(([1, 0]), True, 1) self.gr_vector_source_x_0 = gr.vector_source_b(([1, 0]), True, 1) self.gr_unpack_k_bits_bb_0 = gr.unpack_k_bits_bb( int(log2(constellation_cardinality))) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate) self.gr_pack_k_bits_bb_0 = gr.pack_k_bits_bb( int(log2(constellation_cardinality))) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char * 1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_amp, 0) self.gr_nlog10_ff_0 = gr.nlog10_ff(1, 1, 0) self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vcc( (1. / constellation_power, )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc( (constellation_power, )) self.gr_file_sink_0_1_0 = gr.file_sink(gr.sizeof_gr_complex * 1, "rx_sym.32fc") self.gr_file_sink_0_1_0.set_unbuffered(False) self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_gr_complex * 1, "tx_sym.32fc") self.gr_file_sink_0_1.set_unbuffered(False) self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_char * 1, "rx.8b") self.gr_file_sink_0_0.set_unbuffered(False) self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char * 1, "tx.8b") self.gr_file_sink_0.set_unbuffered(False) self.gr_descrambler_bb_0 = gr.descrambler_bb(0xe4001, 0x7ffff, 19) self.gr_char_to_float_1_0 = gr.char_to_float(1, 1) self.gr_char_to_float_1 = gr.char_to_float(1, 1) self.gr_char_to_float_0 = gr.char_to_float(1, 1) self.gr_add_xx_0 = gr.add_vcc(1) self.digital_scrambler_bb_0 = digital.scrambler_bb( 0xe4001, 0x7fffF, 19) self.digital_constellation_receiver_cb_0 = digital.constellation_receiver_cb( const_object.base(), 6.28 / 100, -0.25, +0.25) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( (constellation), 1) self.blks2_error_rate_0 = grc_blks2.error_rate( type='BER', win_size=samp_rate, bits_per_symbol=1, ) ################################################## # Connections ################################################## self.connect((self.gr_vector_source_x_0, 0), (self.digital_scrambler_bb_0, 0)) self.connect((self.digital_scrambler_bb_0, 0), (self.gr_pack_k_bits_bb_0, 0)) self.connect((self.gr_pack_k_bits_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_constellation_receiver_cb_0, 0), (self.gr_file_sink_0_0, 0)) self.connect((self.digital_constellation_receiver_cb_0, 0), (self.gr_unpack_k_bits_bb_0, 0)) self.connect((self.gr_unpack_k_bits_bb_0, 0), (self.gr_descrambler_bb_0, 0)) self.connect((self.gr_descrambler_bb_0, 0), (self.gr_null_sink_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.digital_constellation_receiver_cb_0, 0)) self.connect((self.gr_descrambler_bb_0, 0), (self.gr_char_to_float_0, 0)) self.connect((self.gr_char_to_float_0, 0), (self.qtgui_sink_x_0_0_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.gr_multiply_const_vxx_0_0, 0)) self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_file_sink_0_1, 0)) self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.qtgui_sink_x_0_1, 0)) self.connect((self.gr_char_to_float_1, 0), (self.qtgui_sink_x_0_1_0, 0)) self.connect((self.gr_pack_k_bits_bb_0, 0), (self.gr_char_to_float_1, 0)) self.connect((self.gr_pack_k_bits_bb_0, 0), (self.gr_file_sink_0, 0)) self.connect((self.gr_char_to_float_1_0, 0), (self.qtgui_sink_x_0_1_0_0, 0)) self.connect((self.gr_vector_source_x_0, 0), (self.gr_char_to_float_1_0, 0)) self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_add_xx_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.qtgui_sink_x_0_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_0_1_0, 0)) self.connect((self.gr_throttle_0, 0), (self.qtgui_sink_x_0_0_0_0, 0)) self.connect((self.gr_nlog10_ff_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blks2_error_rate_0, 0), (self.gr_nlog10_ff_0, 0)) self.connect((self.gr_vector_source_x_0_0, 0), (self.blks2_error_rate_0, 0)) self.connect((self.gr_descrambler_bb_0, 0), (self.blks2_error_rate_0, 1))
def main(): N = 1000000 fs = 8000 freqs = [100, 200, 300, 400, 500] nchans = 7 sigs = list() fmtx = list() for fi in freqs: s = gr.sig_source_f(fs, gr.GR_SIN_WAVE, fi, 1) fm = blks2.nbfm_tx (fs, 4*fs, max_dev=10000, tau=75e-6) sigs.append(s) fmtx.append(fm) syntaps = gr.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100) print "Synthesis Num. Taps = %d (taps per filter = %d)" % (len(syntaps), len(syntaps)/nchans) chtaps = gr.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100) print "Channelizer Num. Taps = %d (taps per filter = %d)" % (len(chtaps), len(chtaps)/nchans) filtbank = gr.pfb_synthesizer_ccf(nchans, syntaps) channelizer = blks2.pfb_channelizer_ccf(nchans, chtaps) noise_level = 0.01 head = gr.head(gr.sizeof_gr_complex, N) noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level) addnoise = gr.add_cc() snk_synth = gr.vector_sink_c() tb = gr.top_block() tb.connect(noise, (addnoise,0)) tb.connect(filtbank, head, (addnoise, 1)) tb.connect(addnoise, channelizer) tb.connect(addnoise, snk_synth) snk = list() for i,si in enumerate(sigs): tb.connect(si, fmtx[i], (filtbank, i)) for i in xrange(nchans): snk.append(gr.vector_sink_c()) tb.connect((channelizer, i), snk[i]) tb.run() if 1: channel = 1 data = snk[channel].data()[1000:] f1 = pylab.figure(1) s1 = f1.add_subplot(1,1,1) s1.plot(data[10000:10200] ) s1.set_title(("Output Signal from Channel %d" % channel)) fftlen = 2048 winfunc = scipy.blackman #winfunc = scipy.hamming f2 = pylab.figure(2) s2 = f2.add_subplot(1,1,1) s2.psd(data, NFFT=fftlen, Fs = nchans*fs, noverlap=fftlen/4, window = lambda d: d*winfunc(fftlen)) s2.set_title(("Output PSD from Channel %d" % channel)) f3 = pylab.figure(3) s3 = f3.add_subplot(1,1,1) s3.psd(snk_synth.data()[1000:], NFFT=fftlen, Fs = nchans*fs, noverlap=fftlen/4, window = lambda d: d*winfunc(fftlen)) s3.set_title("Output of Synthesis Filter") pylab.show()
# set up some common es components arb = es.es_make_arbiter() queue = es.queue() # most packets will got out as scheduled # but if we are ever later just send it as soon as possible queue.set_early_behavior(1) #queue.set_early_behavior(0); # set up the main flow graph tb = gr.top_block() src = es.source(arb, queue, [gr.sizeof_gr_complex]) #sink = gr.file_sink(gr.sizeof_gr_complex , "outfile.dat" ); sink = gr.udp_sink(gr.sizeof_gr_complex, "localhost", 12345) summer = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_amp) throttle = gr.throttle(gr.sizeof_gr_complex, fs) tb.connect(src, summer, sink) tb.connect(noise, throttle, (summer, 1)) # create initial event, set up event bindings, handlers e1 = es.event_create("burst_transmit", 10, 1000) e1 = es.event_args_add(e1, key_sym, pmt.intern("1")) queue.register_event_type(es.event_type(e1)) queue.bind_handler(es.event_type(e1), es.make_handler_pmt(key_handler_graph)) # start the main flowgraph tb.start() import Tkinter as tk import sys
def run_test(seed, blocksize): tb = gr.top_block() ################################################## # Variables ################################################## M = 2 K = 1 P = 2 h = (1.0 * K) / P L = 3 Q = 4 frac = 0.99 f = trellis.fsm(P, M, L) # CPFSK signals #p = numpy.ones(Q)/(2.0) #q = numpy.cumsum(p)/(1.0*Q) # GMSK signals BT = 0.3 tt = numpy.arange(0, L * Q) / (1.0 * Q) - L / 2.0 #print tt p = (0.5 * scipy.stats.erfc(2 * math.pi * BT * (tt - 0.5) / math.sqrt( math.log(2.0)) / math.sqrt(2.0)) - 0.5 * scipy.stats.erfc( 2 * math.pi * BT * (tt + 0.5) / math.sqrt(math.log(2.0)) / math.sqrt(2.0))) / 2.0 p = p / sum(p) * Q / 2.0 #print p q = numpy.cumsum(p) / Q q = q / q[-1] / 2.0 #print q (f0T, SS, S, F, Sf, Ff, N) = fsm_utils.make_cpm_signals(K, P, M, L, q, frac) #print N #print Ff Ffa = numpy.insert(Ff, Q, numpy.zeros(N), axis=0) #print Ffa MF = numpy.fliplr(numpy.transpose(Ffa)) #print MF E = numpy.sum(numpy.abs(Sf)**2, axis=0) Es = numpy.sum(E) / f.O() #print Es constellation = numpy.reshape(numpy.transpose(Sf), N * f.O()) #print Ff #print Sf #print constellation #print numpy.max(numpy.abs(SS - numpy.dot(Ff , Sf))) EsN0_db = 10.0 N0 = Es * 10.0**(-(1.0 * EsN0_db) / 10.0) #N0 = 0.0 #print N0 head = 4 tail = 4 numpy.random.seed(seed * 666) data = numpy.random.randint(0, M, head + blocksize + tail + 1) #data = numpy.zeros(blocksize+1+head+tail,'int') for i in range(head): data[i] = 0 for i in range(tail + 1): data[-i] = 0 ################################################## # Blocks ################################################## random_source_x_0 = gr.vector_source_b(data.tolist(), False) gr_chunks_to_symbols_xx_0 = gr.chunks_to_symbols_bf((-1, 1), 1) gr_interp_fir_filter_xxx_0 = gr.interp_fir_filter_fff(Q, p) gr_frequency_modulator_fc_0 = gr.frequency_modulator_fc(2 * math.pi * h * (1.0 / Q)) gr_add_vxx_0 = gr.add_vcc(1) gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, (N0 / 2.0)**0.5, -long(seed)) gr_multiply_vxx_0 = gr.multiply_vcc(1) gr_sig_source_x_0 = gr.sig_source_c(Q, gr.GR_COS_WAVE, -f0T, 1, 0) # only works for N=2, do it manually for N>2... gr_fir_filter_xxx_0_0 = gr.fir_filter_ccc(Q, MF[0].conjugate()) gr_fir_filter_xxx_0_0_0 = gr.fir_filter_ccc(Q, MF[1].conjugate()) gr_streams_to_stream_0 = gr.streams_to_stream(gr.sizeof_gr_complex * 1, int(N)) gr_skiphead_0 = gr.skiphead(gr.sizeof_gr_complex * 1, int(N * (1 + 0))) viterbi = trellis.viterbi_combined_cb(f, head + blocksize + tail, 0, -1, int(N), constellation, digital.TRELLIS_EUCLIDEAN) gr_vector_sink_x_0 = gr.vector_sink_b() ################################################## # Connections ################################################## tb.connect((random_source_x_0, 0), (gr_chunks_to_symbols_xx_0, 0)) tb.connect((gr_chunks_to_symbols_xx_0, 0), (gr_interp_fir_filter_xxx_0, 0)) tb.connect((gr_interp_fir_filter_xxx_0, 0), (gr_frequency_modulator_fc_0, 0)) tb.connect((gr_frequency_modulator_fc_0, 0), (gr_add_vxx_0, 0)) tb.connect((gr_noise_source_x_0, 0), (gr_add_vxx_0, 1)) tb.connect((gr_add_vxx_0, 0), (gr_multiply_vxx_0, 0)) tb.connect((gr_sig_source_x_0, 0), (gr_multiply_vxx_0, 1)) tb.connect((gr_multiply_vxx_0, 0), (gr_fir_filter_xxx_0_0, 0)) tb.connect((gr_multiply_vxx_0, 0), (gr_fir_filter_xxx_0_0_0, 0)) tb.connect((gr_fir_filter_xxx_0_0, 0), (gr_streams_to_stream_0, 0)) tb.connect((gr_fir_filter_xxx_0_0_0, 0), (gr_streams_to_stream_0, 1)) tb.connect((gr_streams_to_stream_0, 0), (gr_skiphead_0, 0)) tb.connect((gr_skiphead_0, 0), (viterbi, 0)) tb.connect((viterbi, 0), (gr_vector_sink_x_0, 0)) tb.run() dataest = gr_vector_sink_x_0.data() #print data #print numpy.array(dataest) perr = 0 err = 0 for i in range(blocksize): if data[head + i] != dataest[head + i]: #print i err += 1 if err != 0: perr = 1 return (err, perr)