def __init__(self, N=512 , NW=3 , K=5, weighting='adaptive', fftshift=False): gr.hier_block2.__init__(self, "mtm", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float*N)) self.check_parameters(N, NW, K) self.s2v = gr.stream_to_vector(gr.sizeof_gr_complex, N) self.connect(self, self.s2v) dpss = specest_gendpss.gendpss(N=N, NW=NW, K=K) self.mtm = [eigenspectrum(dpss.dpssarray[i], fftshift) for i in xrange(K)] if weighting == 'adaptive': self.sum = specest_swig.adaptiveweighting_vff(N, dpss.lambdas) self.connect_mtm(K) self.connect(self.sum, self) elif weighting == 'unity': self.sum = gr.add_ff(N) self.divide = gr.multiply_const_vff([1./K]*N) self.connect_mtm(K) self.connect(self.sum, self.divide, self) elif weighting == 'eigenvalues': self.eigvalmulti = [] self.lambdasum = 0 for i in xrange(K): self.eigvalmulti.append(gr.multiply_const_vff([dpss.lambdas[i]]*N)) self.lambdasum += dpss.lambdas[i] self.divide = gr.multiply_const_vff([1./self.lambdasum]*N) self.sum = gr.add_ff(N) self.connect_mtm(K) self.connect(self.sum, self.divide, self) else: raise ValueError, 'weighting-type should be: adaptive, unity or eigenvalues'
def __init__(self, fd, M, sample_rate): gr.hier_block2.__init__(self, "Rayleigh Channel", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.M = M self.sample_rate = sample_rate n = range(1, M + 1) N = 4 * M + 2 f_n = [fd * math.cos(2 * math.pi * x / N) for x in n] beta_n = [math.pi / M * x for x in n] a_n = [2 * math.cos(x) for x in beta_n] a_n.append(math.sqrt(2) * math.cos(math.pi / 4)) a_n = [x * 2 / math.sqrt(N) for x in a_n] b_n = [2 * math.sin(x) for x in beta_n] b_n.append(math.sqrt(2) * math.sin(math.pi / 4)) b_n = [x * 2 / math.sqrt(N) for x in b_n] f_n.append(fd) self.sin_real = [ gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, f_n[i], a_n[i]) for i in range(M + 1) ] self.sin_imag = [ gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, f_n[i], b_n[i]) for i in range(M + 1) ] self.add_real = gr.add_ff(1) self.add_imag = gr.add_ff(1) for i in range(M + 1): self.connect(self.sin_real[i], (self.add_real, i)) for i in range(M + 1): self.connect(self.sin_imag[i], (self.add_imag, i)) self.ftoc = gr.float_to_complex(1) self.connect(self.add_real, (self.ftoc, 0)) self.connect(self.add_imag, (self.ftoc, 1)) self.mulc = gr.multiply_const_cc((0.5)) #self.divide = gr.divide_cc(1) #self.connect(self,(self.divide,0)) #self.connect(self.ftoc,(self.divide,1)) #self.connect(self.divide, self) self.prod = gr.multiply_cc(1) self.connect(self, (self.prod, 0)) self.connect(self.ftoc, self.mulc, (self.prod, 1)) self.connect(self.prod, self)
def _get_gauss_rand_proc_c(self): """ Returns the Gaussian random process. """ spec_getter = getattr(self.model, 'get_' + self.spec_type) if self.spec_type in self.model.specs_odd: from winelo.channel import spec2soc soc = spec2soc(spec_getter(), method=self.method, N=self.N) sources = [] adder = gr.add_cc() for idx, (freq, ampl) in enumerate(soc.get_soc()): sources.append(gr.sig_source_c(self.sample_rate, gr.GR_COS_WAVE, freq, ampl)) self.connect(sources[idx], gr.skiphead(gr.sizeof_gr_complex, randint(low=0, high=self.sample_rate)), (adder, idx)) return adder elif self.spec_type in self.model.specs_even: from winelo.channel import spec2sos # real part of the gaussian random process sos_real = spec2sos(spec_getter(), method=self.method, N=self.N) sources_real = [] adder_real = gr.add_ff() for idx, (freq, ampl) in enumerate(sos_real.get_sos()): sources_real.append(gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, freq, ampl)) self.connect(sources_real[idx], gr.skiphead(gr.sizeof_float, randint(low=0, high=self.sample_rate)), (adder_real, idx)) # imaginary part of the gaussian random process sos_imaginary = spec2sos(spec_getter(), method=self.method, N=self.N + 1) sources_imag = [] adder_imag = gr.add_ff() for idx, (freq, ampl) in enumerate(sos_imaginary.get_sos()): sources_imag.append(gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, freq, ampl)) self.connect(sources_imag[idx], gr.skiphead(gr.sizeof_float, randint(low=0, high=self.sample_rate)), (adder_imag, idx)) float2complex = gr.float_to_complex() self.connect(adder_real, (float2complex, 0)) self.connect(adder_imag, (float2complex, 1)) return float2complex else: print 'You picked a non-existant Doppler spectrum' print 'Pick one of the following: ', \ self.model.specs_even + self.model.specs_odd return None
def __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 100 f2 = 200 npts = 2048 self.qapp = QtGui.QApplication(sys.argv) src1 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0) src2 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0) src = gr.add_ff() thr = gr.throttle(gr.sizeof_float, 100*npts) noise = gr.noise_source_f(gr.GR_GAUSSIAN, 0.001) add = gr.add_ff() self.snk1 = qtgui.time_sink_f(npts, Rs, "Complex Time Example", 3) self.connect(src1, (src,0)) self.connect(src2, (src,1)) self.connect(src, thr, (add,0)) self.connect(noise, (add,1)) self.connect(add, self.snk1) self.connect(src1, (self.snk1, 1)) self.connect(src2, (self.snk1, 2)) self.ctrl_win = control_box() self.ctrl_win.attach_signal1(src1) self.ctrl_win.attach_signal2(src2) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.pyqwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) # Example of using signal/slot to set the title of a curve pyWin.connect(pyWin, QtCore.SIGNAL("setTitle(int, QString)"), pyWin, QtCore.SLOT("setTitle(int, QString)")) pyWin.emit(QtCore.SIGNAL("setTitle(int, QString)"), 0, "sum") self.snk1.set_title(1, "src1") self.snk1.set_title(2, "src2") # Can also set the color of a curve #self.snk1.set_color(5, "blue") #pyWin.show() self.main_box = dialog_box(pyWin, self.ctrl_win) self.main_box.show()
def __init__(self,fd,M,sample_rate): gr.hier_block2.__init__(self,"Rayleigh Channel", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.M = M self.sample_rate = sample_rate n=range(1,M+1) N = 4*M+2 f_n= [fd*math.cos(2*math.pi*x/N) for x in n] beta_n = [math.pi/M*x for x in n] a_n = [2*math.cos(x) for x in beta_n] a_n.append(math.sqrt(2)*math.cos(math.pi/4)) a_n = [x*2/math.sqrt(N) for x in a_n] b_n= [2*math.sin(x) for x in beta_n] b_n.append(math.sqrt(2)*math.sin(math.pi/4)) b_n = [x*2/math.sqrt(N) for x in b_n] f_n.append(fd) self.sin_real = [gr.sig_source_f(self.sample_rate,gr.GR_COS_WAVE,f_n[i],a_n[i]) for i in range(M+1)] self.sin_imag = [gr.sig_source_f(self.sample_rate,gr.GR_COS_WAVE,f_n[i],b_n[i]) for i in range(M+1)] self.add_real = gr.add_ff(1) self.add_imag = gr.add_ff(1) for i in range (M+1): self.connect(self.sin_real[i],(self.add_real,i)) for i in range (M+1): self.connect(self.sin_imag[i],(self.add_imag,i)) self.ftoc = gr.float_to_complex(1) self.connect(self.add_real,(self.ftoc,0)) self.connect(self.add_imag,(self.ftoc,1)) self.mulc = gr.multiply_const_cc((0.5)) #self.divide = gr.divide_cc(1) #self.connect(self,(self.divide,0)) #self.connect(self.ftoc,(self.divide,1)) #self.connect(self.divide, self) self.prod = gr.multiply_cc(1) self.connect(self,(self.prod,0)) self.connect(self.ftoc,self.mulc,(self.prod,1)) self.connect(self.prod, self)
def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed): tb = gr.top_block () # TX src = gr.lfsr_32k_source_s() src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality enc = trellis.encoder_ss(f,0) # initial state = 0 # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the FSM) mod = gr.chunks_to_symbols_sf(tot_constellation,dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s(); tb.connect (src,src_head,s2fsmi,enc,mod) tb.connect (mod,(add,0)) tb.connect (noise,(add,1)) tb.connect (add,metrics) tb.connect (metrics,va,fsmi2s,dst) tb.run() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () #print ntotal,nright,runlength return (ntotal,ntotal-nright)
def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed): tb = gr.top_block () # TX src = gr.lfsr_32k_source_s() src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality enc = trellis.encoder_ss(f,0) # initial state = 0 # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the FSM) mod = gr.chunks_to_symbols_sf(tot_constellation,dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s(); tb.connect (src,src_head,s2fsmi,enc,mod) tb.connect (mod,(add,0)) tb.connect (noise,(add,1)) tb.connect (add,metrics) tb.connect (metrics,va,fsmi2s,dst) tb.run() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () #print ntotal,nright,runlength return (ntotal,ntotal-nright)
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed): tb = gr.top_block () # TX src = gr.lfsr_32k_source_s() src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality enc = trellis.sccc_encoder_ss(fo,0,fi,0,interleaver,K) mod = gr.chunks_to_symbols_sf(constellation,dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX dec = trellis.sccc_decoder_combined_fs(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN,1.0) fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() #tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod) tb.connect (src,src_head,s2fsmi,enc,mod) tb.connect (mod,(add,0)) tb.connect (noise,(add,1)) #tb.connect (add,head) #tb.connect (tail,fsmi2s,dst) tb.connect (add,dec,fsmi2s,dst) tb.run() #print enc_out.ST(), enc_in.ST() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () return (ntotal,ntotal-nright)
def __init__( self, if_rate, af_rate ): gr.hier_block2.__init__(self, "ssb_demod", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_float)) self.if_rate = int(if_rate) self.af_rate = int(af_rate) self.if_decim = int(if_rate / af_rate) self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = gr.firdes.low_pass( 1.0, self.af_rate, 3e3, 600, gr.firdes.WIN_HAMMING ) self.xlate = gr.freq_xlating_fir_filter_ccc( self.if_decim, self.xlate_taps, 0, self.if_rate ) self.split = gr.complex_to_float() self.lpf = gr.fir_filter_fff( 1, self.audio_taps ) self.sum = gr.add_ff( ) self.am_sel = gr.multiply_const_ff( 0 ) self.sb_sel = gr.multiply_const_ff( 1 ) self.mixer = gr.add_ff() self.am_det = gr.complex_to_mag() self.connect(self, self.xlate) self.connect(self.xlate, self.split) self.connect((self.split, 0), (self.sum, 0)) self.connect((self.split, 1), (self.sum, 1)) self.connect(self.sum, self.sb_sel) self.connect(self.xlate, self.am_det) self.connect(self.sb_sel, (self.mixer, 0)) self.connect(self.am_det, self.am_sel) self.connect(self.am_sel, (self.mixer, 1)) self.connect(self.mixer, self.lpf) self.connect(self.lpf, self)
def run_test(f, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed): tb = gr.top_block() # TX # packet = [0]*Kb # for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0 # packet[i] = random.randint(0, 1) # random 0s and 1s # src = gr.vector_source_s(packet,False) src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts # b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the FSM input cardinality enc = trellis.encoder_ss(f, 0) # initial state = 0 mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX metrics = trellis.metrics_f( f.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN ) # data preprocessing to generate metrics for Viterbi va = trellis.viterbi_s(f, K, 0, -1) # Put -1 if the Initial/Final states are not set. fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts # s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits # dst = gr.vector_sink_s(); dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, enc, mod) # tb.connect (src,b2s,s2fsmi,enc,mod) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, metrics) tb.connect(metrics, va, fsmi2s, dst) # tb.connect (metrics,va,fsmi2s,s2b,dst) tb.run() # A bit of cheating: run the program once and print the # final encoder state.. # Then put it as the last argument in the viterbi block # print "final state = " , enc.ST() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() # ntotal = len(packet) # if len(dst.data()) != ntotal: # print "Error: not enough data\n" # nright = 0; # for i in range(ntotal): # if packet[i]==dst.data()[i]: # nright=nright+1 # else: # print "Error in ", i return (ntotal, ntotal - nright)
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): tb = gr.top_block () # TX #packet = [0]*Kb #for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0 #packet[i] = random.randint(0, 1) # random 0s and 1s #src = gr.vector_source_s(packet,False) src = gr.lfsr_32k_source_s() src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts #b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality enc = trellis.encoder_ss(f,0) # initial state = 0 mod = gr.chunks_to_symbols_sf(constellation,dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts #s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits #dst = gr.vector_sink_s(); dst = gr.check_lfsr_32k_s() tb.connect (src,src_head,s2fsmi,enc,mod) #tb.connect (src,b2s,s2fsmi,enc,mod) tb.connect (mod,(add,0)) tb.connect (noise,(add,1)) tb.connect (add,metrics) tb.connect (metrics,va,fsmi2s,dst) #tb.connect (metrics,va,fsmi2s,s2b,dst) tb.run() # A bit of cheating: run the program once and print the # final encoder state.. # Then put it as the last argument in the viterbi block #print "final state = " , enc.ST() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () #ntotal = len(packet) #if len(dst.data()) != ntotal: #print "Error: not enough data\n" #nright = 0; #for i in range(ntotal): #if packet[i]==dst.data()[i]: #nright=nright+1 #else: #print "Error in ", i return (ntotal,ntotal-nright)
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 __init__(self, subdev_spec, audio_input): gr.hier_block2.__init__( self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self.if_rate = 320e3 # 320 kS/s self.usrp_interp = int(dac_rate // self.if_rate) self.u.set_interp_rate(self.usrp_interp) self.sw_interp = 10 self.audio_rate = self.if_rate // self.sw_interp # 32 kS/s self.audio_gain = 10 self.normal_gain = 32000 self.audio = audio.source(int(self.audio_rate), audio_input) self.audio_amp = gr.multiply_const_ff(self.audio_gain) lpf = gr.firdes.low_pass( 1, # gain self.audio_rate, # sampling rate 3800, # low pass cutoff freq 300, # width of trans. band gr.firdes.WIN_HANN) # filter type hpf = gr.firdes.high_pass( 1, # gain self.audio_rate, # sampling rate 325, # low pass cutoff freq 50, # width of trans. band gr.firdes.WIN_HANN) # filter type audio_taps = convolve(array(lpf), array(hpf)) self.audio_filt = gr.fir_filter_fff(1, audio_taps) self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0) self.add_pl = gr.add_ff() self.connect(self.pl, (self.add_pl, 1)) self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate) self.amp = gr.multiply_const_cc(self.normal_gain) # determine the daughterboard subdevice we're using if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec)) self.subdev = usrp.selected_subdev(self.u, subdev_spec) print "TX using", self.subdev.name() self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain
def __init__( self, fg, if_rate, af_rate ): self.if_rate = if_rate self.af_rate = af_rate self.if_decim = if_rate / af_rate self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = gr.firdes.low_pass( 1.0, self.af_rate, 3e3, 600, gr.firdes.WIN_HAMMING ) self.xlate = gr.freq_xlating_fir_filter_ccc( self.if_decim, self.xlate_taps, 0, self.if_rate ) self.split = gr.complex_to_float() self.lpf = gr.fir_filter_fff( 1, self.audio_taps ) self.sum = gr.add_ff( ) self.am_sel = gr.multiply_const_ff( 0 ) self.sb_sel = gr.multiply_const_ff( 1 ) self.mixer = gr.add_ff() self.am_det = gr.complex_to_mag() fg.connect( self.xlate, self.split ) fg.connect( ( self.split,0 ), ( self.sum,0 ) ) fg.connect( ( self.split,1 ), ( self.sum,1 ) ) fg.connect( self.sum, self.sb_sel ) fg.connect( self.xlate, self.am_det ) fg.connect( self.sb_sel, ( self.mixer, 0 ) ) fg.connect( self.am_det, self.am_sel ) fg.connect( self.am_sel, ( self.mixer, 1 ) ) fg.connect( self.mixer, self.lpf ) gr.hier_block.__init__( self, fg, self.xlate, self.lpf )
def __init__(self, subdev_spec, audio_input): gr.hier_block2.__init__( self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0) # Input signature ) # Output signature self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self.if_rate = 320e3 # 320 kS/s self.usrp_interp = int(dac_rate // self.if_rate) self.u.set_interp_rate(self.usrp_interp) self.sw_interp = 10 self.audio_rate = self.if_rate // self.sw_interp # 32 kS/s self.audio_gain = 10 self.normal_gain = 32000 self.audio = audio.source(int(self.audio_rate), audio_input) self.audio_amp = gr.multiply_const_ff(self.audio_gain) lpf = gr.firdes.low_pass( 1, # gain self.audio_rate, # sampling rate 3800, # low pass cutoff freq 300, # width of trans. band gr.firdes.WIN_HANN, ) # filter type hpf = gr.firdes.high_pass( 1, # gain self.audio_rate, # sampling rate 325, # low pass cutoff freq 50, # width of trans. band gr.firdes.WIN_HANN, ) # filter type audio_taps = convolve(array(lpf), array(hpf)) self.audio_filt = gr.fir_filter_fff(1, audio_taps) self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0) self.add_pl = gr.add_ff() self.connect(self.pl, (self.add_pl, 1)) self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate) self.amp = gr.multiply_const_cc(self.normal_gain) # determine the daughterboard subdevice we're using if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec)) self.subdev = usrp.selected_subdev(self.u, subdev_spec) print "TX using", self.subdev.name() self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain
def __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 1000 f2 = 2000 fftsize = 2048 self.qapp = QtGui.QApplication(sys.argv) src1 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0) src2 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0) src = gr.add_ff() thr = gr.throttle(gr.sizeof_float, 100*fftsize) noise = gr.noise_source_f(gr.GR_GAUSSIAN, 0.001) add = gr.add_ff() self.snk1 = qtgui.sink_f(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, 0, Rs, "Float Signal Example", True, True, True, False) self.connect(src1, (src,0)) self.connect(src2, (src,1)) self.connect(src, thr, (add,0)) self.connect(noise, (add,1)) self.connect(add, self.snk1) self.ctrl_win = control_box() self.ctrl_win.attach_signal1(src1) self.ctrl_win.attach_signal2(src2) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.pyqwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) self.main_box = dialog_box(pyWin, self.ctrl_win) self.main_box.show()
def run_test(f, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed, P): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16 * P) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the FSM input cardinality s2p = gr.stream_to_streams(gr.sizeof_short, P) # serial to parallel enc = trellis.encoder_ss(f, 0) # initiali state = 0 mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = [] noise = [] for i in range(P): add.append(gr.add_ff()) noise.append(gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)) # RX metrics = trellis.metrics_f( f.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN ) # data preprocessing to generate metrics for Viterbi va = trellis.viterbi_s( f, K, 0, -1) # Put -1 if the Initial/Final states are not set. p2s = gr.streams_to_stream(gr.sizeof_short, P) # parallel to serial fsmi2s = gr.unpacked_to_packed_ss( bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, s2p) for i in range(P): tb.connect((s2p, i), (enc, i), (mod, i)) tb.connect((mod, i), (add[i], 0)) tb.connect(noise[i], (add[i], 1)) tb.connect(add[i], (metrics, i)) tb.connect((metrics, i), (va, i), (p2s, i)) tb.connect(p2s, fsmi2s, dst) tb.run() # A bit of cheating: run the program once and print the # final encoder state. # Then put it as the last argument in the viterbi block #print "final state = " , enc.ST() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)
def __init__(self): gr.top_block.__init__(self, "FSK Demod Demo") # Variables self.symbol_rate = symbol_rate = 125e3 self.samp_rate = samp_rate = symbol_rate self.f_center = f_center = 868e6 self.sps = sps = 2 self.sensitivity = sensitivity = (pi / 2) / sps self.alpha = alpha = 0.0512 / sps self.bandwidth = bandwidth = 100e3 # Blocks self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(f_center, 0) self.uhd_usrp_source_0.set_gain(0, 0) self.uhd_usrp_source_0.set_bandwidth(bandwidth, 0) self.fm_demod = gr.quadrature_demod_cf(1 / sensitivity) self.freq_offset = gr.single_pole_iir_filter_ff(alpha) self.sub = gr.sub_ff() self.add = gr.add_ff() self.multiply = gr.multiply_ff() self.invert = gr.multiply_const_vff((-1, )) # recover the clock omega = sps gain_mu = 0.03 mu = 0.5 omega_relative_limit = 0.0002 freq_error = 0.0 gain_omega = .25 * gain_mu * gain_mu # critically damped self.clock_recovery = digital.clock_recovery_mm_ff( omega, gain_omega, mu, gain_mu, omega_relative_limit) self.slice = digital.binary_slicer_fb() self.sink = gr.vector_sink_b(1) self.file_sink = gr.file_sink(gr.sizeof_char, 'fsk_dump.log') # Connections self.connect(self.fm_demod, (self.add, 0)) self.connect(self.fm_demod, self.freq_offset, (self.add, 1)) self.connect(self.uhd_usrp_source_0, self.fm_demod) self.connect(self.add, self.clock_recovery, self.invert, self.slice, self.file_sink) self.connect(self.slice, self.sink)
def run_test(f, Kb, bitspersymbol, K, channel, modulation, dimensionality, tot_constellation, N0, seed): tb = gr.top_block() L = len(channel) # TX # this for loop is TOO slow in python!!! packet = [0] * (K + 2 * L) random.seed(seed) for i in range(len(packet)): packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols for i in range(L): # first/last L symbols set to 0 packet[i] = 0 packet[len(packet) - i - 1] = 0 src = gr.vector_source_s(packet, False) mod = gr.chunks_to_symbols_sf(modulation[1], modulation[0]) # CHANNEL isi = gr.fir_filter_fff(1, channel) add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX skip = gr.skiphead( gr.sizeof_float, L ) # skip the first L samples since you know they are coming from the L zero symbols #metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi #va = trellis.viterbi_s(f,K+L,0,0) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_combined_s( f, K + L, 0, 0, dimensionality, tot_constellation, trellis.TRELLIS_EUCLIDEAN ) # using viterbi_combined_s instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application... dst = gr.vector_sink_s() tb.connect(src, mod) tb.connect(mod, isi, (add, 0)) tb.connect(noise, (add, 1)) #tb.connect (add,metrics) #tb.connect (metrics,va,dst) tb.connect(add, skip, va, dst) tb.run() data = dst.data() ntotal = len(data) - L nright = 0 for i in range(ntotal): if packet[i + L] == data[i]: nright = nright + 1 #else: #print "Error in ", i return (ntotal, ntotal - nright)
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 __init__(self, if_rate, af_rate): gr.hier_block2.__init__(self, "ssb_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float)) self.if_rate = int(if_rate) self.af_rate = int(af_rate) self.if_decim = int(if_rate / af_rate) self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = gr.firdes.low_pass(1.0, self.af_rate, 3e3, 600, gr.firdes.WIN_HAMMING) self.xlate = gr.freq_xlating_fir_filter_ccc(self.if_decim, self.xlate_taps, 0, self.if_rate) self.split = gr.complex_to_float() self.lpf = gr.fir_filter_fff(1, self.audio_taps) self.sum = gr.add_ff() self.am_sel = gr.multiply_const_ff(0) self.sb_sel = gr.multiply_const_ff(1) self.mixer = gr.add_ff() self.am_det = gr.complex_to_mag() self.connect(self, self.xlate) self.connect(self.xlate, self.split) self.connect((self.split, 0), (self.sum, 0)) self.connect((self.split, 1), (self.sum, 1)) self.connect(self.sum, self.sb_sel) self.connect(self.xlate, self.am_det) self.connect(self.sb_sel, (self.mixer, 0)) self.connect(self.am_det, self.am_sel) self.connect(self.am_sel, (self.mixer, 1)) self.connect(self.mixer, self.lpf) self.connect(self.lpf, self)
def __init__(self): gr.top_block.__init__(self, "FSK Demod Demo") # Variables self.symbol_rate = symbol_rate = 125e3 self.samp_rate = samp_rate = symbol_rate self.f_center = f_center = 868e6 self.sps = sps = 2 self.sensitivity = sensitivity = (pi / 2) / sps self.alpha = alpha = 0.0512/sps self.bandwidth = bandwidth = 100e3 # Blocks self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(f_center, 0) self.uhd_usrp_source_0.set_gain(0, 0) self.uhd_usrp_source_0.set_bandwidth(bandwidth, 0) self.fm_demod = gr.quadrature_demod_cf(1 / sensitivity) self.freq_offset = gr.single_pole_iir_filter_ff(alpha) self.sub = gr.sub_ff() self.add = gr.add_ff() self.multiply = gr.multiply_ff() self.invert = gr.multiply_const_vff((-1, )) # recover the clock omega = sps gain_mu = 0.03 mu = 0.5 omega_relative_limit = 0.0002 freq_error = 0.0 gain_omega = .25 * gain_mu * gain_mu # critically damped self.clock_recovery = digital.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_relative_limit) self.slice = digital.binary_slicer_fb() self.sink = gr.vector_sink_b(1) self.file_sink = gr.file_sink(gr.sizeof_char, 'fsk_dump.log') # Connections self.connect(self.fm_demod, (self.add, 0)) self.connect(self.fm_demod, self.freq_offset, (self.add, 1)) self.connect(self.uhd_usrp_source_0, self.fm_demod) self.connect(self.add, self.clock_recovery, self.invert, self.slice, self.file_sink) self.connect(self.slice, self.sink)
def __init__(self, host, port, pkt_size, sample_rate, eof): gr.top_block.__init__(self, "dial_tone_source") amplitude = 0.3 src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, amplitude) src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, amplitude) add = gr.add_ff() # Throttle needed here to account for the other side's audio card sampling rate thr = gr.throttle(gr.sizeof_float, sample_rate) sink = gr.udp_sink(gr.sizeof_float, host, port, pkt_size, eof=eof) self.connect(src0, (add, 0)) self.connect(src1, (add, 1)) self.connect(add, thr, sink)
def __init__(self, src, dst, port, pkt_size, sample_rate): gr.top_block.__init__(self, "dial_tone_source") amplitude = 0.3 src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, amplitude) src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, amplitude) add = gr.add_ff() # Throttle needed here to account for the other side's audio card sampling rate thr = gr.throttle(gr.sizeof_float, sample_rate) sink = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size) self.connect(src0, (add, 0)) self.connect(src1, (add, 1)) self.connect(add, thr, sink)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the outer FSM input cardinality enc_out = trellis.encoder_ss(fo, 0) # initial state = 0 inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1, gr.sizeof_short) enc_in = trellis.encoder_ss(fi, 0) # initial state = 0 mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX metrics_in = trellis.metrics_f( fi.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN ) # data preprocessing to generate metrics for innner Viterbi gnd = gr.vector_source_f([0], True) siso_in = trellis.siso_f( fi, K, 0, -1, True, False, trellis.TRELLIS_MIN_SUM ) # Put -1 if the Initial/Final states are not set. deinter = trellis.permutation(interleaver.K(), interleaver.DEINTER(), fi.I(), gr.sizeof_float) va_out = trellis.viterbi_s( fo, K, 0, -1) # Put -1 if the Initial/Final states are not set. fsmi2s = gr.unpacked_to_packed_ss( bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, metrics_in) tb.connect(gnd, (siso_in, 0)) tb.connect(metrics_in, (siso_in, 1)) tb.connect(siso_in, deinter, va_out, fsmi2s, dst) tb.run() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)
def __init__(self, fg, if_rate, af_rate): self.if_rate = if_rate self.af_rate = af_rate self.if_decim = if_rate / af_rate self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = gr.firdes.low_pass(1.0, self.af_rate, 3e3, 600, gr.firdes.WIN_HAMMING) self.xlate = gr.freq_xlating_fir_filter_ccc(self.if_decim, self.xlate_taps, 0, self.if_rate) self.split = gr.complex_to_float() self.lpf = gr.fir_filter_fff(1, self.audio_taps) self.sum = gr.add_ff() self.am_sel = gr.multiply_const_ff(0) self.sb_sel = gr.multiply_const_ff(1) self.mixer = gr.add_ff() self.am_det = gr.complex_to_mag() fg.connect(self.xlate, self.split) fg.connect((self.split, 0), (self.sum, 0)) fg.connect((self.split, 1), (self.sum, 1)) fg.connect(self.sum, self.sb_sel) fg.connect(self.xlate, self.am_det) fg.connect(self.sb_sel, (self.mixer, 0)) fg.connect(self.am_det, self.am_sel) fg.connect(self.am_sel, (self.mixer, 1)) fg.connect(self.mixer, self.lpf) gr.hier_block.__init__(self, fg, self.xlate, self.lpf)
def __init__(self, audio_rate): gr.hier_block2.__init__( self, "standard_squelch", gr.io_signature(1, 1, gr.sizeof_float), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self.input_node = gr.add_const_ff(0) # FIXME kludge self.low_iir = gr.iir_filter_ffd((0.0193, 0, -0.0193), (1, 1.9524, -0.9615)) self.low_square = gr.multiply_ff() self.low_smooth = gr.single_pole_iir_filter_ff( 1 / (0.01 * audio_rate)) # 100ms time constant self.hi_iir = gr.iir_filter_ffd((0.0193, 0, -0.0193), (1, 1.3597, -0.9615)) self.hi_square = gr.multiply_ff() self.hi_smooth = gr.single_pole_iir_filter_ff(1 / (0.01 * audio_rate)) self.sub = gr.sub_ff() self.add = gr.add_ff() self.gate = gr.threshold_ff(0.3, 0.43, 0) self.squelch_lpf = gr.single_pole_iir_filter_ff(1 / (0.01 * audio_rate)) self.div = gr.divide_ff() self.squelch_mult = gr.multiply_ff() self.connect(self, self.input_node) self.connect(self.input_node, (self.squelch_mult, 0)) self.connect(self.input_node, self.low_iir) self.connect(self.low_iir, (self.low_square, 0)) self.connect(self.low_iir, (self.low_square, 1)) self.connect(self.low_square, self.low_smooth, (self.sub, 0)) self.connect(self.low_smooth, (self.add, 0)) self.connect(self.input_node, self.hi_iir) self.connect(self.hi_iir, (self.hi_square, 0)) self.connect(self.hi_iir, (self.hi_square, 1)) self.connect(self.hi_square, self.hi_smooth, (self.sub, 1)) self.connect(self.hi_smooth, (self.add, 1)) self.connect(self.sub, (self.div, 0)) self.connect(self.add, (self.div, 1)) self.connect(self.div, self.gate, self.squelch_lpf, (self.squelch_mult, 1)) self.connect(self.squelch_mult, self)
def test_031_multiple_internal_inputs(self): tb = gr.top_block() src = gr.vector_source_f([1.0]) hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) m1 = gr.multiply_const_ff(1.0) m2 = gr.multiply_const_ff(2.0) add = gr.add_ff() hb.connect(hb, m1) # m1 is connected to hb external input #0 hb.connect(hb, m2) # m2 is also connected to hb external input #0 hb.connect(m1, (add, 0)) hb.connect(m2, (add, 1)) hb.connect(add, hb) # add is connected to hb external output #0 dst = gr.vector_sink_f() tb.connect(src, hb, dst) tb.run() self.assertEquals(dst.data(), (3.0,))
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, constellation, Es, N0, IT, seed): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the outer FSM input cardinality #src = gr.vector_source_s([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],False) enc = trellis.pccc_encoder_ss(fo, 0, fi, 0, interleaver, K) code = gr.vector_sink_s() mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX metrics_in = trellis.metrics_f( fi.O() * fo.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN ) # data preprocessing to generate metrics for innner SISO scale = gr.multiply_const_ff(1.0 / N0) dec = trellis.pccc_decoder_s(fo, 0, -1, fi, 0, -1, interleaver, K, IT, trellis.TRELLIS_MIN_SUM) fsmi2s = gr.unpacked_to_packed_ss( bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, enc, mod) #tb.connect (src,enc,mod) #tb.connect(enc,code) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, metrics_in, scale, dec, fsmi2s, dst) tb.run() #print code.data() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P): fg = gr.flow_graph () # TX src = gr.lfsr_32k_source_s() src_head = gr.head (gr.sizeof_short,Kb/16*P) # packet size in shorts s2fsmi=gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality s2p = gr.stream_to_streams(gr.sizeof_short,P) # serial to parallel enc = trellis.encoder_ss(f,0) # initiali state = 0 mod = gr.chunks_to_symbols_sf(constellation,dimensionality) # CHANNEL add=[] noise=[] for i in range(P): add.append(gr.add_ff()) noise.append(gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)) # RX metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. p2s = gr.streams_to_stream(gr.sizeof_short,P) # parallel to serial fsmi2s=gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() fg.connect (src,src_head,s2fsmi,s2p) for i in range(P): fg.connect ((s2p,i),(enc,i),(mod,i)) fg.connect ((mod,i),(add[i],0)) fg.connect (noise[i],(add[i],1)) fg.connect (add[i],(metrics,i)) fg.connect ((metrics,i),(va,i),(p2s,i)) fg.connect (p2s,fsmi2s,dst) fg.run() # A bit of cheating: run the program once and print the # final encoder state. # Then put it as the last argument in the viterbi block #print "final state = " , enc.ST() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () return (ntotal,ntotal-nright)
def run_test (f,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,N0,seed): fg = gr.flow_graph () L = len(channel) # TX # this for loop is TOO slow in python!!! packet = [0]*(K+2*L) random.seed(seed) for i in range(len(packet)): packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols for i in range(L): # first/last L symbols set to 0 packet[i] = 0 packet[len(packet)-i-1] = 0 src = gr.vector_source_s(packet,False) mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0]) # CHANNEL isi = gr.fir_filter_fff(1,channel) add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX skip = gr.skiphead(gr.sizeof_float, L) # skip the first L samples since you know they are coming from the L zero symbols #metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi #va = trellis.viterbi_s(f,K+L,-1,0) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_combined_fs(f,K+L,0,0,dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # using viterbi_combined_fs instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application... dst = gr.vector_sink_s() fg.connect (src,mod) fg.connect (mod,isi,(add,0)) fg.connect (noise,(add,1)) #fg.connect (add,metrics) #fg.connect (metrics,va,dst) fg.connect (add,skip,va,dst) fg.run() data = dst.data() ntotal = len(data) - L nright=0 for i in range(ntotal): if packet[i+L]==data[i]: nright=nright+1 #else: #print "Error in ", i return (ntotal,ntotal-nright)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, channel, modulation, dimensionality, tot_constellation, Es, N0, IT, seed): tb = gr.top_block() L = len(channel) # TX # this for loop is TOO slow in python!!! packet = [0] * (K) random.seed(seed) for i in range(len(packet)): packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols src = gr.vector_source_s(packet, False) enc_out = trellis.encoder_ss(fo, 0) # initial state = 0 inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1, gr.sizeof_short) mod = gr.chunks_to_symbols_sf(modulation[1], modulation[0]) # CHANNEL isi = gr.fir_filter_fff(1, channel) add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX (head, tail) = make_rx(tb, fo, fi, dimensionality, tot_constellation, K, interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM) dst = gr.vector_sink_s() tb.connect(src, enc_out, inter, mod) tb.connect(mod, isi, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, head) tb.connect(tail, dst) tb.run() data = dst.data() ntotal = len(data) nright = 0 for i in range(ntotal): if packet[i] == data[i]: nright = nright + 1 #else: #print "Error in ", i return (ntotal, ntotal - nright)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the outer FSM input cardinality enc_out = trellis.encoder_ss(fo, 0) # initial state = 0 inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1, gr.sizeof_short) enc_in = trellis.encoder_ss(fi, 0) # initial state = 0 mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX metrics_in = trellis.metrics_f( fi.O(), dimensionality, constellation, trellis.TRELLIS_EUCLIDEAN ) # data preprocessing to generate metrics for innner Viterbi va_in = trellis.viterbi_s(fi, K, 0, -1) # Put -1 if the Initial/Final states are not set. deinter = trellis.permutation(interleaver.K(), interleaver.DEINTER(), 1, gr.sizeof_short) metrics_out = trellis.metrics_s( fo.O(), 1, [0, 1, 2, 3], trellis.TRELLIS_HARD_SYMBOL ) # data preprocessing to generate metrics for outer Viterbi (hard decisions) va_out = trellis.viterbi_s(fo, K, 0, -1) # Put -1 if the Initial/Final states are not set. fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, metrics_in) tb.connect(metrics_in, va_in, deinter, metrics_out, va_out, fsmi2s, dst) tb.run() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)
def __init__(self): gr.hier_block2.__init__(self,"BER Estimator", gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,1,gr.sizeof_float)) #TODO Implement a polynomial block in C++ and approximate with polynomials #of arbitrary order self.add = gr.add_const_vff((-1, )) self.square = gr.multiply_ff() self.mult_lin = gr.multiply_const_ff(-0.20473967) self.mult_sq = gr.multiply_const_ff(1.5228658) self.sum = gr.add_ff() self.connect(self,self.add) self.connect(self.add,(self.square,0)) self.connect(self.add,(self.square,1)) self.connect(self.square,self.mult_sq,(self.sum,0)) self.connect(self.add,self.mult_lin,(self.sum,1)) self.connect(self.sum,self)
def test_031_multiple_internal_inputs(self): tb = gr.top_block() src = gr.vector_source_f([ 1.0, ]) hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) m1 = gr.multiply_const_ff(1.0) m2 = gr.multiply_const_ff(2.0) add = gr.add_ff() hb.connect(hb, m1) # m1 is connected to hb external input #0 hb.connect(hb, m2) # m2 is also connected to hb external input #0 hb.connect(m1, (add, 0)) hb.connect(m2, (add, 1)) hb.connect(add, hb) # add is connected to hb external output #0 dst = gr.vector_sink_f() tb.connect(src, hb, dst) tb.run() self.assertEquals(dst.data(), (3.0, ))
def __init__(self): gr.hier_block2.__init__(self, "BER Estimator", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) #TODO Implement a polynomial block in C++ and approximate with polynomials #of arbitrary order self.add = gr.add_const_vff((-1, )) self.square = gr.multiply_ff() self.mult_lin = gr.multiply_const_ff(-0.20473967) self.mult_sq = gr.multiply_const_ff(1.5228658) self.sum = gr.add_ff() self.connect(self, self.add) self.connect(self.add, (self.square, 0)) self.connect(self.add, (self.square, 1)) self.connect(self.square, self.mult_sq, (self.sum, 0)) self.connect(self.add, self.mult_lin, (self.sum, 1)) self.connect(self.sum, self)
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,Es,N0,IT,seed): tb = gr.top_block () L = len(channel) # TX # this for loop is TOO slow in python!!! packet = [0]*(K) random.seed(seed) for i in range(len(packet)): packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols src = gr.vector_source_s(packet,False) enc_out = trellis.encoder_ss(fo,0) # initial state = 0 inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short) mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0]) # CHANNEL isi = gr.fir_filter_fff(1,channel) add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX (head,tail) = make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) dst = gr.vector_sink_s(); tb.connect (src,enc_out,inter,mod) tb.connect (mod,isi,(add,0)) tb.connect (noise,(add,1)) tb.connect (add,head) tb.connect (tail,dst) tb.run() data = dst.data() ntotal = len(data) nright=0 for i in range(ntotal): if packet[i]==data[i]: nright=nright+1 #else: #print "Error in ", i return (ntotal,ntotal-nright)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, constellation, Es, N0, IT, seed): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the outer FSM input cardinality enc = trellis.sccc_encoder_ss(fo, 0, fi, 0, interleaver, K) mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX dec = trellis.sccc_decoder_combined_fs(fo, 0, -1, fi, 0, -1, interleaver, K, IT, trellis.TRELLIS_MIN_SUM, dimensionality, constellation, digital.TRELLIS_EUCLIDEAN, 1.0) fsmi2s = gr.unpacked_to_packed_ss( bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() #tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod) tb.connect(src, src_head, s2fsmi, enc, mod) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) #tb.connect (add,head) #tb.connect (tail,fsmi2s,dst) tb.connect(add, dec, fsmi2s, dst) tb.run() #print enc_out.ST(), enc_in.ST() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, constellation, Es, N0, IT, seed): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the outer FSM input cardinality enc_out = trellis.encoder_ss(fo, 0) # initial state = 0 inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1, gr.sizeof_short) enc_in = trellis.encoder_ss(fi, 0) # initial state = 0 mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX (head, tail) = make_rx(tb, fo, fi, dimensionality, constellation, K, interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM) #(head,tail) = make_rx(tb,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_SUM_PRODUCT) fsmi2s = gr.unpacked_to_packed_ss( bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, head) tb.connect(tail, fsmi2s, dst) tb.run() #print enc_out.ST(), enc_in.ST() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)
def __init__(self, audio_rate): gr.hier_block2.__init__(self, "standard_squelch", gr.io_signature(1, 1, gr.sizeof_float), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self.input_node = gr.add_const_ff(0) # FIXME kludge self.low_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.9524,-0.9615)) self.low_square = gr.multiply_ff() self.low_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) # 100ms time constant self.hi_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.3597,-0.9615)) self.hi_square = gr.multiply_ff() self.hi_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.sub = gr.sub_ff(); self.add = gr.add_ff(); self.gate = gr.threshold_ff(0.3,0.43,0) self.squelch_lpf = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.div = gr.divide_ff() self.squelch_mult = gr.multiply_ff() self.connect (self, self.input_node) self.connect (self.input_node, (self.squelch_mult, 0)) self.connect (self.input_node,self.low_iir) self.connect (self.low_iir,(self.low_square,0)) self.connect (self.low_iir,(self.low_square,1)) self.connect (self.low_square,self.low_smooth,(self.sub,0)) self.connect (self.low_smooth, (self.add,0)) self.connect (self.input_node,self.hi_iir) self.connect (self.hi_iir,(self.hi_square,0)) self.connect (self.hi_iir,(self.hi_square,1)) self.connect (self.hi_square,self.hi_smooth,(self.sub,1)) self.connect (self.hi_smooth, (self.add,1)) self.connect (self.sub, (self.div, 0)) self.connect (self.add, (self.div, 1)) self.connect (self.div, self.gate, self.squelch_lpf, (self.squelch_mult,1)) self.connect (self.squelch_mult, self)
def __init__(self): """ Hierarchical block for FSK demodulation. The input is the complex modulated signal at baseband and the output is a stream of floats. """ # Initialize base class gr.hier_block2.__init__(self, "fsk_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float)) # Variables self.sps = sps = 2 self.sensitivity = sensitivity = (pi / 2) / sps self.alpha = alpha = 0.0512 / sps self.fm_demod = gr.quadrature_demod_cf(1 / sensitivity) self.freq_offset = gr.single_pole_iir_filter_ff(alpha) self.sub = gr.sub_ff() self.add = gr.add_ff() self.multiply = gr.multiply_ff() self.invert = gr.multiply_const_vff((-1, )) # recover the clock omega = sps gain_mu = 0.03 mu = 0.5 omega_relative_limit = 0.0002 freq_error = 0.0 gain_omega = .25 * gain_mu * gain_mu # critically damped self.clock_recovery = digital.clock_recovery_mm_ff( omega, gain_omega, mu, gain_mu, omega_relative_limit) self.slice = digital.binary_slicer_fb() # Connections self.connect(self.fm_demod, (self.add, 0)) self.connect(self.fm_demod, self.freq_offset, (self.add, 1)) self.connect(self, self.fm_demod) self.connect(self.add, self.clock_recovery, self.invert, self)
def run_test(f, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the FSM input cardinality enc = trellis.encoder_ss(f, 0) # initial state = 0 mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX va = trellis.viterbi_combined_fs( f, K, 0, -1, dimensionality, constellation, trellis.TRELLIS_EUCLIDEAN ) # Put -1 if the Initial/Final states are not set. fsmi2s = gr.unpacked_to_packed_ss( bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, enc, mod) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, va, fsmi2s, dst) tb.run() # A bit of cheating: run the program once and print the # final encoder state.. # Then put it as the last argument in the viterbi block #print "final state = " , enc.ST() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)
def __init__(self): """ Hierarchical block for FSK demodulation. The input is the complex modulated signal at baseband and the output is a stream of floats. """ # Initialize base class gr.hier_block2.__init__( self, "fsk_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float) ) # Variables self.sps = sps = 2 self.sensitivity = sensitivity = (pi / 2) / sps self.alpha = alpha = 0.0512 / sps self.fm_demod = gr.quadrature_demod_cf(1 / sensitivity) self.freq_offset = gr.single_pole_iir_filter_ff(alpha) self.sub = gr.sub_ff() self.add = gr.add_ff() self.multiply = gr.multiply_ff() self.invert = gr.multiply_const_vff((-1,)) # recover the clock omega = sps gain_mu = 0.03 mu = 0.5 omega_relative_limit = 0.0002 freq_error = 0.0 gain_omega = 0.25 * gain_mu * gain_mu # critically damped self.clock_recovery = digital.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_relative_limit) self.slice = digital.binary_slicer_fb() # Connections self.connect(self.fm_demod, (self.add, 0)) self.connect(self.fm_demod, self.freq_offset, (self.add, 1)) self.connect(self, self.fm_demod) self.connect(self.add, self.clock_recovery, self.invert, self)
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed): tb = gr.top_block () # TX src = gr.lfsr_32k_source_s() src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality #src = gr.vector_source_s([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],False) enc = trellis.pccc_encoder_ss(fo,0,fi,0,interleaver,K) code = gr.vector_sink_s() mod = gr.chunks_to_symbols_sf(constellation,dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX metrics_in = trellis.metrics_f(fi.O()*fo.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO scale = gr.multiply_const_ff(1.0/N0) dec = trellis.pccc_decoder_s(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM) fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect (src,src_head,s2fsmi,enc,mod) #tb.connect (src,enc,mod) #tb.connect(enc,code) tb.connect (mod,(add,0)) tb.connect (noise,(add,1)) tb.connect (add,metrics_in,scale,dec,fsmi2s,dst) tb.run() #print code.data() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () return (ntotal,ntotal-nright)
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): tb = gr.top_block () # TX src = gr.lfsr_32k_source_s() src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality enc = trellis.encoder_ss(f,0) # initial state = 0 mod = gr.chunks_to_symbols_sf(constellation,dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX va = trellis.viterbi_combined_fs(f,K,0,-1,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s(); tb.connect (src,src_head,s2fsmi,enc,mod) tb.connect (mod,(add,0)) tb.connect (noise,(add,1)) tb.connect (add,va,fsmi2s,dst) tb.run() # A bit of cheating: run the program once and print the # final encoder state.. # Then put it as the last argument in the viterbi block #print "final state = " , enc.ST() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () return (ntotal,ntotal-nright)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, constellation, Es, N0, IT, seed): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the outer FSM input cardinality enc_out = trellis.encoder_ss(fo, 0) # initial state = 0 inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1, gr.sizeof_short) enc_in = trellis.encoder_ss(fi, 0) # initial state = 0 mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX (head, tail) = make_rx( tb, fo, fi, dimensionality, constellation, K, interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM ) # (head,tail) = make_rx(tb,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_SUM_PRODUCT) fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, head) tb.connect(tail, fsmi2s, dst) tb.run() # print enc_out.ST(), enc_in.ST() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)
def __init__(self, fg, audio_rate): self.input_node = gr.add_const_ff(0) # FIXME kludge self.low_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.9524,-0.9615)) self.low_square = gr.multiply_ff() self.low_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) # 100ms time constant self.hi_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.3597,-0.9615)) self.hi_square = gr.multiply_ff() self.hi_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.sub = gr.sub_ff(); self.add = gr.add_ff(); self.gate = gr.threshold_ff(0.3,0.43,0) self.squelch_lpf = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.div = gr.divide_ff() self.squelch_mult = gr.multiply_ff() fg.connect (self.input_node, (self.squelch_mult, 0)) fg.connect (self.input_node,self.low_iir) fg.connect (self.low_iir,(self.low_square,0)) fg.connect (self.low_iir,(self.low_square,1)) fg.connect (self.low_square,self.low_smooth,(self.sub,0)) fg.connect (self.low_smooth, (self.add,0)) fg.connect (self.input_node,self.hi_iir) fg.connect (self.hi_iir,(self.hi_square,0)) fg.connect (self.hi_iir,(self.hi_square,1)) fg.connect (self.hi_square,self.hi_smooth,(self.sub,1)) fg.connect (self.hi_smooth, (self.add,1)) fg.connect (self.sub, (self.div, 0)) fg.connect (self.add, (self.div, 1)) fg.connect (self.div, self.gate, self.squelch_lpf, (self.squelch_mult,1)) gr.hier_block.__init__(self, fg, self.input_node, self.squelch_mult)
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,tot_constellation,Es,N0,IT,seed): fg = gr.flow_graph () # TX src = gr.lfsr_32k_source_s() src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the iouter FSM input cardinality enc_out = trellis.encoder_ss(fo,0) # initial state = 0 inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short) enc_in = trellis.encoder_ss(fi,0) # initial state = 0 # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the innner FSM) mod = gr.chunks_to_symbols_sf(tot_constellation,dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX (head,tail) = make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s(); fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod) fg.connect (mod,(add,0)) fg.connect (noise,(add,1)) fg.connect (add,head) fg.connect (tail,fsmi2s,dst) fg.run() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () #print ntotal,nright,runlength return (ntotal,ntotal-nright)
def add_ff(N): op = gr.add_ff() tb = helper(N, op, gr.sizeof_float, gr.sizeof_float, 2, 1) return tb
def __init__(self): gr.top_block.__init__ (self) parser=OptionParser(option_class=eng_option) parser.add_option("-H", "--hostname", type="string", default="localhost", help="set hostname of generic sdr") parser.add_option("-P", "--portnum", type="int", default=None, help="set portnum of generic sdr") parser.add_option("-r", "--sdr_rate", type="eng_float", default=250e3, help="set sample rate of generic sdr") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="plughw:0,0", help="pcm device name (default is plughw:0,0)") # print help when called with wrong arguments (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.vol = options.volume if self.vol is None: self.vol = 0.1 # connect to generic SDR sdr_rate = options.sdr_rate audio_decim = 8 audio_rate = int(sdr_rate/audio_decim) print "audio_rate = ", audio_rate self.interleaved_short_to_complex = gr.interleaved_short_to_complex() self.char_to_short = gr.char_to_short(1) self.sdr_source = grc_blks2.tcp_source( itemsize=gr.sizeof_char*1, addr=options.hostname, port=options.portnum, server=False ) # self.sdr_source = gr.file_source(1, 'sdrs_baseband.dat') # self.throttle = gr.throttle(1, 500e3) # self.connect(self.sdr_source, self.file_sink) self.logger = gr.file_sink(1, 'log.out') self.connect(self.sdr_source, self.logger) # channel filter chan_filter_coeffs = gr.firdes.low_pass( 1.0, # gain sdr_rate, # sampling rate 80e3, # passband cutoff 35e3, # transition width gr.firdes.WIN_HAMMING) self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs) # print "# channel filter:", len(chan_filter_coeffs), "taps" # PLL-based WFM demod fm_alpha = 0.25 * 250e3 * math.pi / sdr_rate # 0.767 fm_beta = fm_alpha * fm_alpha / 4.0 # 0.147 fm_max_freq = 2.0 * math.pi * 90e3 / sdr_rate # 2.209 self.fm_demod = gr.pll_freqdet_cf( 1.0, # Loop BW fm_max_freq, # in radians/sample -fm_max_freq) self.fm_demod.set_alpha(fm_alpha) self.fm_demod.set_beta(fm_beta) self.connect(self.sdr_source, self.char_to_short) self.connect(self.char_to_short, self.interleaved_short_to_complex) self.connect(self.interleaved_short_to_complex, self.chan_filter, self.fm_demod) # L+R, pilot, L-R, RDS filters lpr_filter_coeffs = gr.firdes.low_pass( 1.0, # gain sdr_rate, # sampling rate 15e3, # passband cutoff 1e3, # transition width gr.firdes.WIN_HAMMING) self.lpr_filter = gr.fir_filter_fff(audio_decim, lpr_filter_coeffs) pilot_filter_coeffs = gr.firdes.band_pass( 1.0, # gain sdr_rate, # sampling rate 19e3-500, # low cutoff 19e3+500, # high cutoff 1e3, # transition width gr.firdes.WIN_HAMMING) self.pilot_filter = gr.fir_filter_fff(1, pilot_filter_coeffs) dsbsc_filter_coeffs = gr.firdes.band_pass( 1.0, # gain sdr_rate, # sampling rate 38e3-15e3/2, # low cutoff 38e3+15e3/2, # high cutoff 1e3, # transition width gr.firdes.WIN_HAMMING) self.dsbsc_filter = gr.fir_filter_fff(1, dsbsc_filter_coeffs) rds_filter_coeffs = gr.firdes.band_pass( 1.0, # gain sdr_rate, # sampling rate 57e3-3e3, # low cutoff 57e3+3e3, # high cutoff 3e3, # transition width gr.firdes.WIN_HAMMING) self.rds_filter = gr.fir_filter_fff(1, rds_filter_coeffs) # print "# lpr filter:", len(lpr_filter_coeffs), "taps" # print "# pilot filter:", len(pilot_filter_coeffs), "taps" # print "# dsbsc filter:", len(dsbsc_filter_coeffs), "taps" # print "# rds filter:", len(rds_filter_coeffs), "taps" self.connect(self.fm_demod, self.lpr_filter) self.connect(self.fm_demod, self.pilot_filter) self.connect(self.fm_demod, self.dsbsc_filter) self.connect(self.fm_demod, self.rds_filter) # down-convert L-R, RDS self.stereo_baseband = gr.multiply_ff() self.connect(self.pilot_filter, (self.stereo_baseband, 0)) self.connect(self.pilot_filter, (self.stereo_baseband, 1)) self.connect(self.dsbsc_filter, (self.stereo_baseband, 2)) self.rds_baseband = gr.multiply_ff() self.connect(self.pilot_filter, (self.rds_baseband, 0)) self.connect(self.pilot_filter, (self.rds_baseband, 1)) self.connect(self.pilot_filter, (self.rds_baseband, 2)) self.connect(self.rds_filter, (self.rds_baseband, 3)) # low-pass and downsample L-R lmr_filter_coeffs = gr.firdes.low_pass( 1.0, # gain sdr_rate, # sampling rate 15e3, # passband cutoff 1e3, # transition width gr.firdes.WIN_HAMMING) self.lmr_filter = gr.fir_filter_fff(audio_decim, lmr_filter_coeffs) self.connect(self.stereo_baseband, self.lmr_filter) # create L, R from L-R, L+R self.left = gr.add_ff() self.right = gr.sub_ff() self.connect(self.lpr_filter, (self.left, 0)) self.connect(self.lmr_filter, (self.left, 1)) self.connect(self.lpr_filter, (self.right, 0)) self.connect(self.lmr_filter, (self.right, 1)) # volume control, complex2flot, audio sink self.volume_control_l = gr.multiply_const_ff(self.vol) self.volume_control_r = gr.multiply_const_ff(self.vol) output_audio_rate = 48000 self.resamp_L = blks2.rational_resampler_fff(interpolation=output_audio_rate,decimation=audio_rate,taps=None,fractional_bw=None,) self.resamp_R = blks2.rational_resampler_fff(interpolation=output_audio_rate,decimation=audio_rate,taps=None,fractional_bw=None,) self.connect(self.left, self.volume_control_l, self.resamp_L) self.connect(self.right, self.volume_control_r, self.resamp_R) # self.audio_sink = audio.sink(int(output_audio_rate), # options.audio_output, False) # self.connect(self.resamp_L, (self.audio_sink, 0)) # self.connect(self.resamp_R, (self.audio_sink, 1)) self.file_sink1 = gr.file_sink(gr.sizeof_float, 'audioL.dat') self.file_sink2 = gr.file_sink(gr.sizeof_float, 'audioR.dat') self.file_sink3 = gr.file_sink(gr.sizeof_float, 'fmDemod.dat') self.connect(self.resamp_L, self.file_sink1) self.connect(self.resamp_R, self.file_sink2) self.connect(self.fm_demod, self.file_sink3) # low-pass the baseband RDS signal at 1.5kHz rds_bb_filter_coeffs = gr.firdes.low_pass( 1, # gain sdr_rate, # sampling rate 1.5e3, # passband cutoff 2e3, # transition width gr.firdes.WIN_HAMMING) self.rds_bb_filter = gr.fir_filter_fff(audio_decim, rds_bb_filter_coeffs) # print "# rds bb filter:", len(rds_bb_filter_coeffs), "taps" self.connect(self.rds_baseband, self.rds_bb_filter) # 1187.5bps = 19kHz/16 self.clock_divider = rds.freq_divider(16) rds_clock_taps = gr.firdes.low_pass( 1, # gain sdr_rate, # sampling rate 1.2e3, # passband cutoff 1.5e3, # transition width gr.firdes.WIN_HAMMING) self.rds_clock = gr.fir_filter_fff(audio_decim, rds_clock_taps) # print "# rds clock filter:", len(rds_clock_taps), "taps" self.connect(self.pilot_filter, self.clock_divider, self.rds_clock) # bpsk_demod, diff_decoder, rds_decoder self.bpsk_demod = rds.bpsk_demod(audio_rate) self.differential_decoder = gr.diff_decoder_bb(2) self.msgq = gr.msg_queue() self.rds_decoder = rds.data_decoder(self.msgq) self.connect(self.rds_bb_filter, (self.bpsk_demod, 0)) self.connect(self.rds_clock, (self.bpsk_demod, 1)) self.connect(self.bpsk_demod, self.differential_decoder) self.connect(self.differential_decoder, self.rds_decoder)
def __init__(self, args, spec, antenna, gain, audio_input): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.u = uhd.usrp_sink(device_addr=args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(spec): self.u.set_subdev_spec(spec, 0) # Set the antenna if(antenna): self.u.set_antenna(antenna, 0) self.if_rate = 320e3 self.audio_rate = 32e3 self.u.set_samp_rate(self.if_rate) dev_rate = self.u.get_samp_rate() self.audio_gain = 10 self.normal_gain = 32000 self.audio = audio.source(int(self.audio_rate), audio_input) self.audio_amp = gr.multiply_const_ff(self.audio_gain) lpf = gr.firdes.low_pass (1, # gain self.audio_rate, # sampling rate 3800, # low pass cutoff freq 300, # width of trans. band gr.firdes.WIN_HANN) # filter type hpf = gr.firdes.high_pass (1, # gain self.audio_rate, # sampling rate 325, # low pass cutoff freq 50, # width of trans. band gr.firdes.WIN_HANN) # filter type audio_taps = convolve(array(lpf),array(hpf)) self.audio_filt = gr.fir_filter_fff(1,audio_taps) self.pl = blks2.ctcss_gen_f(self.audio_rate,123.0) self.add_pl = gr.add_ff() self.connect(self.pl,(self.add_pl,1)) self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate) self.amp = gr.multiply_const_cc (self.normal_gain) rrate = dev_rate / self.if_rate self.resamp = blks2.pfb_arb_resampler_ccf(rrate) self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl,0), self.fmtx, self.amp, self.resamp, self.u) if gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() gain = float(g.start() + g.stop())/2.0 self.set_gain(gain) self.set_enable(False)
def __init__(self, fft_length, cp_length, snr, kstime, logging): ''' Maximum Likelihood OFDM synchronizer: J. van de Beek, M. Sandell, and P. O. Borjesson, "ML Estimation of Time and Frequency Offset in OFDM Systems," IEEE Trans. Signal Processing, vol. 45, no. 7, pp. 1800-1805, 1997. ''' gr.hier_block2.__init__(self, "ofdm_sync_ml", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature self.input = gr.add_const_cc(0) SNR = 10.0**(snr/10.0) rho = SNR / (SNR + 1.0) symbol_length = fft_length + cp_length # ML Sync # Energy Detection from ML Sync self.connect(self, self.input) # Create a delay line self.delay = gr.delay(gr.sizeof_gr_complex, fft_length) self.connect(self.input, self.delay) # magnitude squared blocks self.magsqrd1 = gr.complex_to_mag_squared() self.magsqrd2 = gr.complex_to_mag_squared() self.adder = gr.add_ff() moving_sum_taps = [rho/2 for i in range(cp_length)] self.moving_sum_filter = gr.fir_filter_fff(1,moving_sum_taps) self.connect(self.input,self.magsqrd1) self.connect(self.delay,self.magsqrd2) self.connect(self.magsqrd1,(self.adder,0)) self.connect(self.magsqrd2,(self.adder,1)) self.connect(self.adder,self.moving_sum_filter) # Correlation from ML Sync self.conjg = gr.conjugate_cc(); self.mixer = gr.multiply_cc(); movingsum2_taps = [1.0 for i in range(cp_length)] self.movingsum2 = gr.fir_filter_ccf(1,movingsum2_taps) # Correlator data handler self.c2mag = gr.complex_to_mag() self.angle = gr.complex_to_arg() self.connect(self.input,(self.mixer,1)) self.connect(self.delay,self.conjg,(self.mixer,0)) self.connect(self.mixer,self.movingsum2,self.c2mag) self.connect(self.movingsum2,self.angle) # ML Sync output arg, need to find maximum point of this self.diff = gr.sub_ff() self.connect(self.c2mag,(self.diff,0)) self.connect(self.moving_sum_filter,(self.diff,1)) #ML measurements input to sampler block and detect self.f2c = gr.float_to_complex() self.pk_detect = gr.peak_detector_fb(0.2, 0.25, 30, 0.0005) self.sample_and_hold = gr.sample_and_hold_ff() # use the sync loop values to set the sampler and the NCO # self.diff = theta # self.angle = epsilon self.connect(self.diff, self.pk_detect) # The DPLL corrects for timing differences between CP correlations use_dpll = 0 if use_dpll: self.dpll = gr.dpll_bb(float(symbol_length),0.01) self.connect(self.pk_detect, self.dpll) self.connect(self.dpll, (self.sample_and_hold,1)) else: self.connect(self.pk_detect, (self.sample_and_hold,1)) self.connect(self.angle, (self.sample_and_hold,0)) ################################ # correlate against known symbol # This gives us the same timing signal as the PN sync block only on the preamble # we don't use the signal generated from the CP correlation because we don't want # to readjust the timing in the middle of the packet or we ruin the equalizer settings. kstime = [k.conjugate() for k in kstime] kstime.reverse() self.kscorr = gr.fir_filter_ccc(1, kstime) self.corrmag = gr.complex_to_mag_squared() self.div = gr.divide_ff() # The output signature of the correlation has a few spikes because the rest of the # system uses the repeated preamble symbol. It needs to work that generically if # anyone wants to use this against a WiMAX-like signal since it, too, repeats. # The output theta of the correlator above is multiplied with this correlation to # identify the proper peak and remove other products in this cross-correlation self.threshold_factor = 0.1 self.slice = gr.threshold_ff(self.threshold_factor, self.threshold_factor, 0) self.f2b = gr.float_to_char() self.b2f = gr.char_to_float() self.mul = gr.multiply_ff() # Normalize the power of the corr output by the energy. This is not really needed # and could be removed for performance, but it makes for a cleaner signal. # if this is removed, the threshold value needs adjustment. self.connect(self.input, self.kscorr, self.corrmag, (self.div,0)) self.connect(self.moving_sum_filter, (self.div,1)) self.connect(self.div, (self.mul,0)) self.connect(self.pk_detect, self.b2f, (self.mul,1)) self.connect(self.mul, self.slice) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) self.connect(self.slice, self.f2b, (self,1)) if logging: self.connect(self.moving_sum_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat")) self.connect(self.diff, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat")) self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat")) self.connect(self.corrmag, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat")) self.connect(self.kscorr, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat")) self.connect(self.div, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat")) self.connect(self.mul, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat")) self.connect(self.slice, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat")) self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat")) if use_dpll: self.connect(self.dpll, gr.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat")) self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat")) self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat"))
def __init__(self, demod_rate, audio_decimation): """ Hierarchical block for demodulating a broadcast FM signal. The input is the downconverted complex baseband signal (gr_complex). The output is two streams of the demodulated audio (float) 0=Left, 1=Right. @param demod_rate: input sample rate of complex baseband input. @type demod_rate: float @param audio_decimation: how much to decimate demod_rate to get to audio. @type audio_decimation: integer """ gr.hier_block2.__init__( self, "wfm_rcv_fmdet", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(2, 2, gr.sizeof_float)) # Output signature lowfreq = -125e3 / demod_rate highfreq = 125e3 / demod_rate audio_rate = demod_rate / audio_decimation # We assign to self so that outsiders can grab the demodulator # if they need to. E.g., to plot its output. # # input: complex; output: float self.fm_demod = gr.fmdet_cf(demod_rate, lowfreq, highfreq, 0.05) # input: float; output: float self.deemph_Left = fm_deemph(audio_rate) self.deemph_Right = fm_deemph(audio_rate) # compute FIR filter taps for audio filter width_of_transition_band = audio_rate / 32 audio_coeffs = gr.firdes.low_pass( 1.0, # gain demod_rate, # sampling rate 15000, width_of_transition_band, gr.firdes.WIN_HAMMING) # input: float; output: float self.audio_filter = gr.fir_filter_fff(audio_decimation, audio_coeffs) if 1: # Pick off the stereo carrier/2 with this filter. It # attenuated 10 dB so apply 10 dB gain We pick off the # negative frequency half because we want to base band by # it! ## NOTE THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO ## DEEMPHASIS stereo_carrier_filter_coeffs = gr.firdes.complex_band_pass( 10.0, demod_rate, -19020, -18980, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs) #print "stereo carrier filter ", stereo_carrier_filter_coeffs #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate # Pick off the double side band suppressed carrier # Left-Right audio. It is attenuated 10 dB so apply 10 dB # gain stereo_dsbsc_filter_coeffs = gr.firdes.complex_band_pass( 20.0, demod_rate, 38000 - 15000 / 2, 38000 + 15000 / 2, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs # construct overlap add filter system from coefficients # for stereo carrier self.stereo_carrier_filter = gr.fir_filter_fcc( audio_decimation, stereo_carrier_filter_coeffs) # carrier is twice the picked off carrier so arrange to do # a commplex multiply self.stereo_carrier_generator = gr.multiply_cc() # Pick off the rds signal stereo_rds_filter_coeffs = gr.firdes.complex_band_pass( 30.0, demod_rate, 57000 - 1500, 57000 + 1500, width_of_transition_band, gr.firdes.WIN_HAMMING) #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs # construct overlap add filter system from coefficients for stereo carrier self.rds_signal_filter = gr.fir_filter_fcc( audio_decimation, stereo_rds_filter_coeffs) self.rds_carrier_generator = gr.multiply_cc() self.rds_signal_generator = gr.multiply_cc() self_rds_signal_processor = gr.null_sink(gr.sizeof_gr_complex) loop_bw = 2 * math.pi / 100.0 max_freq = -2.0 * math.pi * 18990 / audio_rate min_freq = -2.0 * math.pi * 19010 / audio_rate self.stereo_carrier_pll_recovery = gr.pll_refout_cc( loop_bw, max_freq, min_freq) #self.stereo_carrier_pll_recovery.squelch_enable(False) ##pll_refout does not have squelch yet, so disabled for #now # set up mixer (multiplier) to get the L-R signal at # baseband self.stereo_basebander = gr.multiply_cc() # pick off the real component of the basebanded L-R # signal. The imaginary SHOULD be zero self.LmR_real = gr.complex_to_real() self.Make_Left = gr.add_ff() self.Make_Right = gr.sub_ff() self.stereo_dsbsc_filter = gr.fir_filter_fcc( audio_decimation, stereo_dsbsc_filter_coeffs) if 1: # send the real signal to complex filter to pick off the # carrier and then to one side of a multiplier self.connect(self, self.fm_demod, self.stereo_carrier_filter, self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator, 0)) # send the already filtered carrier to the otherside of the carrier # the resulting signal from this multiplier is the carrier # with correct phase but at -38000 Hz. self.connect(self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator, 1)) # send the new carrier to one side of the mixer (multiplier) self.connect(self.stereo_carrier_generator, (self.stereo_basebander, 0)) # send the demphasized audio to the DSBSC pick off filter, the complex # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier # the result is BASEBANDED DSBSC with phase zero! self.connect(self.fm_demod, self.stereo_dsbsc_filter, (self.stereo_basebander, 1)) # Pick off the real part since the imaginary is # theoretically zero and then to one side of a summer self.connect(self.stereo_basebander, self.LmR_real, (self.Make_Left, 0)) #take the same real part of the DSBSC baseband signal and #send it to negative side of a subtracter self.connect(self.LmR_real, (self.Make_Right, 1)) # Make rds carrier by taking the squared pilot tone and # multiplying by pilot tone self.connect(self.stereo_basebander, (self.rds_carrier_generator, 0)) self.connect(self.stereo_carrier_pll_recovery, (self.rds_carrier_generator, 1)) # take signal, filter off rds, send into mixer 0 channel self.connect(self.fm_demod, self.rds_signal_filter, (self.rds_signal_generator, 0)) # take rds_carrier_generator output and send into mixer 1 # channel self.connect(self.rds_carrier_generator, (self.rds_signal_generator, 1)) # send basebanded rds signal and send into "processor" # which for now is a null sink self.connect(self.rds_signal_generator, self_rds_signal_processor) if 1: # pick off the audio, L+R that is what we used to have and # send it to the summer self.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1)) # take the picked off L+R audio and send it to the PLUS # side of the subtractor self.connect(self.audio_filter, (self.Make_Right, 0)) # The result of Make_Left gets (L+R) + (L-R) and results in 2*L # The result of Make_Right gets (L+R) - (L-R) and results in 2*R self.connect(self.Make_Left, self.deemph_Left, (self, 0)) self.connect(self.Make_Right, self.deemph_Right, (self, 1))
def __init__(self, fft_length, block_length, block_header, range, options): gr.hier_block2.__init__(self, "integer_fo_estimator", gr.io_signature3(3,3,gr.sizeof_gr_complex,gr.sizeof_float,gr.sizeof_char), gr.io_signature2(3,3,gr.sizeof_float,gr.sizeof_char)) raise NotImplementedError,"Obsolete class" self._range = range # threshold after integer part frequency offset estimation # if peak value below threshold, assume false triggering self._thr_lo = 0.4 #0.19 # empirically found threshold. see ioe_metric.float self._thr_hi = 0.4 #0.2 # stuff to be removed after bugfix for hierblock2s self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.time_sync = gr.kludge_copy(gr.sizeof_char) self.epsilon = (self,1) self.connect((self,0),self.input) self.connect((self,2),self.time_sync) delay(gr.sizeof_char, block_header.schmidl_fine_sync[0]*block_length) # sample ofdm symbol (preamble 1 and 2) sampler_symbol1 = vector_sampler(gr.sizeof_gr_complex,fft_length) sampler_symbol2 = vector_sampler(gr.sizeof_gr_complex,fft_length) time_delay1 = delay(gr.sizeof_char,block_length*block_header.schmidl_fine_sync[1]) self.connect(self.input, (sampler_symbol1,0)) self.connect(self.input, (sampler_symbol2,0)) if block_header.schmidl_fine_sync[0] > 0: time_delay0 = delay(gr.sizeof_char,block_length*block_header.schmidl_fine_sync[0]) self.connect(self.time_sync, time_delay0, (sampler_symbol1,1)) else: self.connect(self.time_sync, (sampler_symbol1,1)) self.connect(self.time_sync, time_delay1, (sampler_symbol2,1)) # negative fractional frequency offset estimate epsilon = gr.multiply_const_ff(-1.0) self.connect(self.epsilon, epsilon) # compensate for fractional frequency offset on per symbol base # freq_shift: vector length, modulator sensitivity # freq_shift third input: reset phase accumulator # symbol/preamble 1 freq_shift_sym1 = frequency_shift_vcc(fft_length, 1.0/fft_length) self.connect(sampler_symbol1, (freq_shift_sym1,0)) self.connect(epsilon, (freq_shift_sym1,1)) self.connect(gr.vector_source_b([1], True), (freq_shift_sym1,2)) # symbol/preamble 2 freq_shift_sym2 = frequency_shift_vcc(fft_length, 1.0/fft_length) self.connect(sampler_symbol2, (freq_shift_sym2,0)) self.connect(epsilon, (freq_shift_sym2,1)) self.connect(gr.vector_source_b([1], True), (freq_shift_sym2,2)) # fourier transfrom on both preambles fft_sym1 = gr.fft_vcc(fft_length, True, [], True) # Forward + Blockshift fft_sym2 = gr.fft_vcc(fft_length, True, [], True) # Forward + Blockshift # calculate schmidl's metric for estimation of freq. offset's integer part assert(hasattr(block_header, "schmidl_fine_sync")) pre1 = block_header.pilotsym_fd[block_header.schmidl_fine_sync[0]] pre2 = block_header.pilotsym_fd[block_header.schmidl_fine_sync[1]] diff_pn = concatenate([[conjugate(math.sqrt(2)*pre2[2*i]/pre1[2*i]),0.0j] for i in arange(len(pre1)/2)]) cfo_estimator = schmidl_cfo_estimator(fft_length, len(pre1), self._range, diff_pn) self.connect(freq_shift_sym1, fft_sym1, (cfo_estimator,0)) # preamble 1 self.connect(freq_shift_sym2, fft_sym2, (cfo_estimator,1)) # preamble 2 # search for maximum and its argument in interval [-range .. +range] #arg_max = arg_max_vff(2*self._range + 1) arg_max_s = gr.argmax_fs(2*self._range+1) arg_max = gr.short_to_float() ifo_max = gr.max_ff(2*self._range + 1) # vlen ifo_estimate = gr.add_const_ff(-self._range) self.connect(cfo_estimator, arg_max_s, arg_max, ifo_estimate) self.connect(cfo_estimator, ifo_max) self.connect((arg_max_s,1),gr.null_sink(gr.sizeof_short)) # threshold maximal value ifo_threshold = gr.threshold_ff(self._thr_lo, self._thr_hi, 0.0) ifo_thr_f2b = gr.float_to_char() self.connect(ifo_max, ifo_threshold, ifo_thr_f2b) # gating the streams ifo_estimate (integer part) and epsilon (frac. part) # if the metric's peak value was above the chosen threshold, assume to have # found a new burst. peak value below threshold results in blocking the # streams self.gate = gate_ff() self.connect(ifo_thr_f2b, (self.gate,0)) # threshold stream self.connect(ifo_estimate, (self.gate,1)) self.connect(epsilon, (self.gate,2)) # peak filtering # resynchronize and suppress peaks that didn't match a preamble filtered_time_sync = peak_resync_bb(True) # replace self.connect(self.time_sync, (filtered_time_sync,0)) self.connect(ifo_thr_f2b, (filtered_time_sync,1)) # find complete estimation for frequency offset # add together fractional and integer part freq_offset = gr.add_ff() self.connect((self.gate,1), gr.multiply_const_ff(-1.0), (freq_offset,0)) # integer offset self.connect((self.gate,2), (freq_offset,1)) # frac offset # output connections self.connect(freq_offset, (self,0)) self.connect(filtered_time_sync, (self,1)) self.connect((self.gate,0), (self,2)) # used for frame trigger ######################################### # debugging if options.log: self.epsilon2_sink = gr.vector_sink_f() self.connect(epsilon, self.epsilon2_sink) self.connect(cfo_estimator, gr.file_sink(gr.sizeof_float*(self._range*2+1), "data/ioe_metric.float")) # output joint stream preamble_stream = gr.streams_to_vector(fft_length * gr.sizeof_gr_complex, 2) self.connect(fft_sym1, (preamble_stream,0)) self.connect(fft_sym2, (preamble_stream,1)) self.connect(preamble_stream, gr.file_sink(gr.sizeof_gr_complex * 2 * fft_length, "data/preambles.compl")) # output, preambles before and after correction, magnitude and complex spectrum self.connect(sampler_symbol1, gr.fft_vcc(fft_length, True, [], True), gr.file_sink(gr.sizeof_gr_complex * fft_length, "data/pre1_bef.compl")) self.connect(sampler_symbol1, gr.fft_vcc(fft_length, True, [], True), gr.complex_to_mag(fft_length), gr.file_sink(gr.sizeof_float * fft_length, "data/pre1_bef.float")) self.connect(sampler_symbol2, gr.fft_vcc(fft_length, True, [], True), gr.file_sink(gr.sizeof_gr_complex * fft_length, "data/pre2_bef.compl")) self.connect(sampler_symbol2, gr.fft_vcc(fft_length, True, [], True), gr.complex_to_mag(fft_length), gr.file_sink(gr.sizeof_float * fft_length, "data/pre2_bef.float")) self.connect(freq_shift_sym1, gr.fft_vcc(fft_length, True, [], True), gr.file_sink(gr.sizeof_gr_complex * fft_length,"data/pre1.compl")) self.connect(freq_shift_sym1, gr.fft_vcc(fft_length, True, [], True), gr.complex_to_mag(fft_length), gr.file_sink(gr.sizeof_float * fft_length,"data/pre1.float")) self.connect(freq_shift_sym2, gr.fft_vcc(fft_length, True, [], True), gr.file_sink(gr.sizeof_gr_complex * fft_length,"data/pre2.compl")) self.connect(freq_shift_sym2, gr.fft_vcc(fft_length, True, [], True), gr.complex_to_mag(fft_length), gr.file_sink(gr.sizeof_float * fft_length,"data/pre2.float")) # calculate epsilon from corrected source to check function test_cp = cyclic_prefixer(fft_length, block_length) test_eps = foe(fft_length) self.connect(freq_shift_sym1, test_cp, test_eps, gr.file_sink(gr.sizeof_float, "data/eps_after.float")) try: gr.hier_block.update_var_names(self, "ifo_estimator", vars()) gr.hier_block.update_var_names(self, "ifo_estimator", vars(self)) except: pass
def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.frame_1_menubar = wx.MenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wx.Menu() self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.frame_1_menubar.Append(wxglade_tmp_menu, "File") # Menu Bar end self.panel_1 = wx.Panel(self, -1) self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB") self.button_2 = wx.Button(self, ID_BUTTON_2, "USB") self.button_3 = wx.Button(self, ID_BUTTON_3, "AM") self.button_4 = wx.Button(self, ID_BUTTON_4, "CW") self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper") self.slider_1 = wx.Slider(self, ID_SLIDER_1, 0, -15799, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower") self.slider_2 = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_5 = wx.Panel(self, -1) self.label_1 = wx.StaticText(self, -1, " Band\nCenter") self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "") self.panel_6 = wx.Panel(self, -1) self.panel_7 = wx.Panel(self, -1) self.panel_2 = wx.Panel(self, -1) self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq") self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000) self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100) self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol") self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500) self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20) self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time") self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew") self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd") self.panel_3 = wx.Panel(self, -1) self.label_2 = wx.StaticText(self, -1, "PGA ") self.panel_4 = wx.Panel(self, -1) self.panel_8 = wx.Panel(self, -1) self.panel_9 = wx.Panel(self, -1) self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier") self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.label_4 = wx.StaticText(self, -1, "Antenna Tune") self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_10 = wx.Panel(self, -1) self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune") self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate") self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset") self.panel_11 = wx.Panel(self, -1) self.panel_12 = wx.Panel(self, -1) self.__set_properties() self.__do_layout() # end wxGlade parser = OptionParser(option_class=eng_option) parser.add_option( "-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ" ) parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE") parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option("-d", "--decim", type="int", default=250, help="USRP decimation") parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=first one with a daughterboard)", ) (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq usb_rate = 64e6 / options.decim self.slider_range = usb_rate * 0.9375 self.f_lo = self.usrp_center - (self.slider_range / 2) self.f_hi = self.usrp_center + (self.slider_range / 2) self.af_sample_rate = 32000 fir_decim = long(usb_rate / self.af_sample_rate) # data point arrays for antenna tuner self.xdata = [] self.ydata = [] self.tb = gr.top_block() # radio variables, initial conditions self.frequency = self.usrp_center # these map the frequency slider (0-6000) to the actual range self.f_slider_offset = self.f_lo self.f_slider_scale = 10000 / options.decim self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi) self.text_ctrl_1.SetValue(str(int(self.usrp_center))) self.slider_5.SetValue(0) self.AM_mode = False self.slider_3.SetValue((self.frequency - self.f_slider_offset) / self.f_slider_scale) self.spin_ctrl_1.SetValue(int(self.frequency)) POWERMATE = True try: self.pm = powermate.powermate(self) except: sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n") POWERMATE = False if POWERMATE: powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate) powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton) self.active_button = 7 # command line options if options.audio_file == "": SAVE_AUDIO_TO_FILE = False else: SAVE_AUDIO_TO_FILE = True if options.radio_file == "": SAVE_RADIO_TO_FILE = False else: SAVE_RADIO_TO_FILE = True if options.input_file == "": self.PLAY_FROM_USRP = True else: self.PLAY_FROM_USRP = False if self.PLAY_FROM_USRP: self.src = usrp.source_s(decim_rate=options.decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.src) self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.src, options.rx_subdev_spec) self.src.tune(0, self.subdev, self.usrp_center) self.tune_offset = 0 # -self.usrp_center - self.src.rx_freq(0) else: self.src = gr.file_source(gr.sizeof_short, options.input_file) self.tune_offset = 2200 # 2200 works for 3.5-4Mhz band # save radio data to a file if SAVE_RADIO_TO_FILE: file = gr.file_sink(gr.sizeof_short, options.radio_file) self.tb.connect(self.src, file) # 2nd DDC xlate_taps = gr.firdes.low_pass(1.0, usb_rate, 16e3, 4e3, gr.firdes.WIN_HAMMING) self.xlate = gr.freq_xlating_fir_filter_ccf(fir_decim, xlate_taps, self.tune_offset, usb_rate) # convert rf data in interleaved short int form to complex s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src_f2c = gr.float_to_complex() self.tb.connect(self.src, s2ss) self.tb.connect((s2ss, 0), s2f1) self.tb.connect((s2ss, 1), s2f2) self.tb.connect(s2f1, (src_f2c, 0)) self.tb.connect(s2f2, (src_f2c, 1)) # Complex Audio filter audio_coeffs = gr.firdes.complex_band_pass( 1.0, # gain self.af_sample_rate, # sample rate -3000, # low cutoff 0, # high cutoff 100, # transition gr.firdes.WIN_HAMMING, ) # window self.slider_1.SetValue(0) self.slider_2.SetValue(-3000) self.audio_filter = gr.fir_filter_ccc(1, audio_coeffs) # Main +/- 16Khz spectrum display self.fft = fftsink2.fft_sink_c( self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240) ) # AM Sync carrier if AM_SYNC_DISPLAY: self.fft2 = fftsink.fft_sink_c( self.tb, self.panel_9, y_per_div=20, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240), ) c2f = gr.complex_to_float() # AM branch self.sel_am = gr.multiply_const_cc(0) # the following frequencies turn out to be in radians/sample # gr.pll_refout_cc(alpha,beta,min_freq,max_freq) # suggested alpha = X, beta = .25 * X * X pll = gr.pll_refout_cc( 0.5, 0.0625, (2.0 * math.pi * 7.5e3 / self.af_sample_rate), (2.0 * math.pi * 6.5e3 / self.af_sample_rate) ) self.pll_carrier_scale = gr.multiply_const_cc(complex(10, 0)) am_det = gr.multiply_cc() # these are for converting +7.5kHz to -7.5kHz # for some reason gr.conjugate_cc() adds noise ?? c2f2 = gr.complex_to_float() c2f3 = gr.complex_to_float() f2c = gr.float_to_complex() phaser1 = gr.multiply_const_ff(1) phaser2 = gr.multiply_const_ff(-1) # filter for pll generated carrier pll_carrier_coeffs = gr.firdes.complex_band_pass( 2.0, # gain self.af_sample_rate, # sample rate 7400, # low cutoff 7600, # high cutoff 100, # transition gr.firdes.WIN_HAMMING, ) # window self.pll_carrier_filter = gr.fir_filter_ccc(1, pll_carrier_coeffs) self.sel_sb = gr.multiply_const_ff(1) combine = gr.add_ff() # AGC sqr1 = gr.multiply_ff() intr = gr.iir_filter_ffd([0.004, 0], [0, 0.999]) offset = gr.add_const_ff(1) agc = gr.divide_ff() self.scale = gr.multiply_const_ff(0.00001) dst = audio.sink(long(self.af_sample_rate)) self.tb.connect(src_f2c, self.xlate, self.fft) self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0)) self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3) self.tb.connect((c2f3, 0), phaser1, (f2c, 0)) self.tb.connect((c2f3, 1), phaser2, (f2c, 1)) self.tb.connect(f2c, (am_det, 1)) self.tb.connect(am_det, c2f2, (combine, 0)) self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1)) if AM_SYNC_DISPLAY: self.tb.connect(self.pll_carrier_filter, self.fft2) self.tb.connect(combine, self.scale) self.tb.connect(self.scale, (sqr1, 0)) self.tb.connect(self.scale, (sqr1, 1)) self.tb.connect(sqr1, intr, offset, (agc, 1)) self.tb.connect(self.scale, (agc, 0)) self.tb.connect(agc, dst) if SAVE_AUDIO_TO_FILE: f_out = gr.file_sink(gr.sizeof_short, options.audio_file) sc1 = gr.multiply_const_ff(64000) f2s1 = gr.float_to_short() self.tb.connect(agc, sc1, f2s1, f_out) self.tb.start() # for mouse position reporting on fft display em.eventManager.Register(self.Mouse, wx.EVT_MOTION, self.fft.win) # and left click to re-tune em.eventManager.Register(self.Click, wx.EVT_LEFT_DOWN, self.fft.win) # start a timer to check for web commands if WEB_CONTROL: self.timer = UpdateTimer(self, 1000) # every 1000 mSec, 1 Sec wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb) wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb) wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am) wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw) wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd) wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew) wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate) wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button) wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune) wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume) wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga) wx.EVT_SLIDER(self, ID_SLIDER_6, self.am_carrier) wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune) wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune) wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.frame_1_menubar = wx.MenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wx.Menu() self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.frame_1_menubar.Append(wxglade_tmp_menu, "File") # Menu Bar end self.panel_1 = wx.Panel(self, -1) self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB") self.button_2 = wx.Button(self, ID_BUTTON_2, "USB") self.button_3 = wx.Button(self, ID_BUTTON_3, "AM") self.button_4 = wx.Button(self, ID_BUTTON_4, "CW") self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper") self.slider_fcutoff_hi = wx.Slider(self, ID_SLIDER_1, 0, -15798, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower") self.slider_fcutoff_lo = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15798, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_5 = wx.Panel(self, -1) self.label_1 = wx.StaticText(self, -1, " Band\nCenter") self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "") self.panel_6 = wx.Panel(self, -1) self.panel_7 = wx.Panel(self, -1) self.panel_2 = wx.Panel(self, -1) self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq") self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000) self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100) self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol") self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500) self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20) self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time") self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew") self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd") self.panel_3 = wx.Panel(self, -1) self.label_2 = wx.StaticText(self, -1, "PGA ") self.panel_4 = wx.Panel(self, -1) self.panel_8 = wx.Panel(self, -1) self.panel_9 = wx.Panel(self, -1) self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier") self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.label_4 = wx.StaticText(self, -1, "Antenna Tune") self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_10 = wx.Panel(self, -1) self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune") self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate") self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset") self.panel_11 = wx.Panel(self, -1) self.panel_12 = wx.Panel(self, -1) self.__set_properties() self.__do_layout() # end wxGlade parser = OptionParser(option_class=eng_option) parser.add_option("", "--address", type="string", default="addr=192.168.10.2", help="Address of UHD device, [default=%default]") parser.add_option("-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ") parser.add_option( "-s", "--samp-rate", type="eng_float", default=256e3, help="set sample rate (bandwidth) [default=%default]") parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE") parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option( "-O", "--audio-output", type="string", default="", help="audio output device name. E.g., hw:0,0, /dev/dsp, or pulse") (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq input_rate = options.samp_rate self.slider_range = input_rate * 0.9375 self.f_lo = self.usrp_center - (self.slider_range / 2) self.f_hi = self.usrp_center + (self.slider_range / 2) self.af_sample_rate = 32000 fir_decim = long(input_rate / self.af_sample_rate) # data point arrays for antenna tuner self.xdata = [] self.ydata = [] self.tb = gr.top_block() # radio variables, initial conditions self.frequency = self.usrp_center # these map the frequency slider (0-6000) to the actual range self.f_slider_offset = self.f_lo self.f_slider_scale = 10000 self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi) self.text_ctrl_1.SetValue(str(int(self.usrp_center))) self.slider_5.SetValue(0) self.AM_mode = False self.slider_3.SetValue( (self.frequency - self.f_slider_offset) / self.f_slider_scale) self.spin_ctrl_1.SetValue(int(self.frequency)) POWERMATE = True try: self.pm = powermate.powermate(self) except: sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n") POWERMATE = False if POWERMATE: powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate) powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton) self.active_button = 7 # command line options if options.audio_file == "": SAVE_AUDIO_TO_FILE = False else: SAVE_AUDIO_TO_FILE = True if options.radio_file == "": SAVE_RADIO_TO_FILE = False else: SAVE_RADIO_TO_FILE = True if options.input_file == "": self.PLAY_FROM_USRP = True else: self.PLAY_FROM_USRP = False if self.PLAY_FROM_USRP: self.src = uhd.usrp_source(device_addr=options.address, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) self.src.set_samp_rate(input_rate) input_rate = self.src.get_samp_rate() self.src.set_center_freq(self.usrp_center, 0) self.tune_offset = 0 else: self.src = gr.file_source(gr.sizeof_short, options.input_file) self.tune_offset = 2200 # 2200 works for 3.5-4Mhz band # convert rf data in interleaved short int form to complex s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src_f2c = gr.float_to_complex() self.tb.connect(self.src, s2ss) self.tb.connect((s2ss, 0), s2f1) self.tb.connect((s2ss, 1), s2f2) self.tb.connect(s2f1, (src_f2c, 0)) self.tb.connect(s2f2, (src_f2c, 1)) # save radio data to a file if SAVE_RADIO_TO_FILE: radio_file = gr.file_sink(gr.sizeof_short, options.radio_file) self.tb.connect(self.src, radio_file) # 2nd DDC xlate_taps = gr.firdes.low_pass ( \ 1.0, input_rate, 16e3, 4e3, gr.firdes.WIN_HAMMING ) self.xlate = gr.freq_xlating_fir_filter_ccf ( \ fir_decim, xlate_taps, self.tune_offset, input_rate ) # Complex Audio filter audio_coeffs = gr.firdes.complex_band_pass( 1.0, # gain self.af_sample_rate, # sample rate -3000, # low cutoff 0, # high cutoff 100, # transition gr.firdes.WIN_HAMMING) # window self.slider_fcutoff_hi.SetValue(0) self.slider_fcutoff_lo.SetValue(-3000) self.audio_filter = gr.fir_filter_ccc(1, audio_coeffs) # Main +/- 16Khz spectrum display self.fft = fftsink2.fft_sink_c(self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)) # AM Sync carrier if AM_SYNC_DISPLAY: self.fft2 = fftsink.fft_sink_c(self.tb, self.panel_9, y_per_div=20, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)) c2f = gr.complex_to_float() # AM branch self.sel_am = gr.multiply_const_cc(0) # the following frequencies turn out to be in radians/sample # gr.pll_refout_cc(alpha,beta,min_freq,max_freq) # suggested alpha = X, beta = .25 * X * X pll = gr.pll_refout_cc(.5, .0625, (2. * math.pi * 7.5e3 / self.af_sample_rate), (2. * math.pi * 6.5e3 / self.af_sample_rate)) self.pll_carrier_scale = gr.multiply_const_cc(complex(10, 0)) am_det = gr.multiply_cc() # these are for converting +7.5kHz to -7.5kHz # for some reason gr.conjugate_cc() adds noise ?? c2f2 = gr.complex_to_float() c2f3 = gr.complex_to_float() f2c = gr.float_to_complex() phaser1 = gr.multiply_const_ff(1) phaser2 = gr.multiply_const_ff(-1) # filter for pll generated carrier pll_carrier_coeffs = gr.firdes.complex_band_pass( 2.0, # gain self.af_sample_rate, # sample rate 7400, # low cutoff 7600, # high cutoff 100, # transition gr.firdes.WIN_HAMMING) # window self.pll_carrier_filter = gr.fir_filter_ccc(1, pll_carrier_coeffs) self.sel_sb = gr.multiply_const_ff(1) combine = gr.add_ff() #AGC sqr1 = gr.multiply_ff() intr = gr.iir_filter_ffd([.004, 0], [0, .999]) offset = gr.add_const_ff(1) agc = gr.divide_ff() self.scale = gr.multiply_const_ff(0.00001) dst = audio.sink(long(self.af_sample_rate), options.audio_output) if self.PLAY_FROM_USRP: self.tb.connect(self.src, self.xlate, self.fft) else: self.tb.connect(src_f2c, self.xlate, self.fft) self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0)) self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3) self.tb.connect((c2f3, 0), phaser1, (f2c, 0)) self.tb.connect((c2f3, 1), phaser2, (f2c, 1)) self.tb.connect(f2c, (am_det, 1)) self.tb.connect(am_det, c2f2, (combine, 0)) self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1)) if AM_SYNC_DISPLAY: self.tb.connect(self.pll_carrier_filter, self.fft2) self.tb.connect(combine, self.scale) self.tb.connect(self.scale, (sqr1, 0)) self.tb.connect(self.scale, (sqr1, 1)) self.tb.connect(sqr1, intr, offset, (agc, 1)) self.tb.connect(self.scale, (agc, 0)) self.tb.connect(agc, dst) if SAVE_AUDIO_TO_FILE: f_out = gr.file_sink(gr.sizeof_short, options.audio_file) sc1 = gr.multiply_const_ff(64000) f2s1 = gr.float_to_short() self.tb.connect(agc, sc1, f2s1, f_out) self.tb.start() # for mouse position reporting on fft display self.fft.win.Bind(wx.EVT_LEFT_UP, self.Mouse) # and left click to re-tune self.fft.win.Bind(wx.EVT_LEFT_DOWN, self.Click) # start a timer to check for web commands if WEB_CONTROL: self.timer = UpdateTimer(self, 1000) # every 1000 mSec, 1 Sec wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb) wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb) wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am) wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw) wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd) wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew) wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate) wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button) wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune) wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume) wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga) wx.EVT_SLIDER(self, ID_SLIDER_6, self.am_carrier) wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune) wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune) wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)