def __init__(self,subdev_spec=None,gain=None,length=1,alpha=1.0,msgq=None,loopback=False,verbose=False,debug=False): self._subdev_spec = subdev_spec self._gain = gain self._length = length self._alpha = alpha self._msgq = msgq self._loopback = loopback self._verbose = verbose self._debug = debug self._fg = gr.flow_graph() self._u = usrp.source_c(fpga_filename='usrp_sounder.rbf') if not self._loopback: if self._subdev_spec == None: self._subdev_spec = pick_subdevice(self._u) self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec)) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) if self._verbose: print "Using", self._subdev.name(), "for sounder receiver." self.set_gain(self._gain) self._vblen = gr.sizeof_gr_complex*self._length if self._debug: print "Generating impulse vectors of length", self._length, "byte length", self._vblen self._s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._length) if self._verbose: print "Using smoothing alpha of", self._alpha self._lpf = gr.single_pole_iir_filter_cc(self._alpha, self._length) self._sink = gr.message_sink(self._vblen, self._msgq, True) self._fg.connect(self._u, self._s2v, self._lpf, self._sink)
def graph (args): nargs = len (args) if nargs == 1: infile = args[0] else: sys.stderr.write('usage: interp.py input_file\n') sys.exit (1) sampling_freq = 6400000 fg = gr.flow_graph () src0 = gr.file_source (gr.sizeof_gr_complex,infile) src1 = gr.sig_source_c (sampling_freq, gr.GR_CONST_WAVE, 1, 0) src2 = gr.sig_source_c (sampling_freq, gr.GR_CONST_WAVE, 1, 0) interlv = gr.interleave(gr.sizeof_gr_complex) lp_coeffs = gr.firdes.low_pass ( 3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING ) lp = gr.fir_filter_ccf ( 1, lp_coeffs ) file = gr.file_sink(gr.sizeof_gr_complex,"/tmp/atsc_pipe_1") fg.connect( src0, (interlv, 0) ) fg.connect( src1, (interlv, 1) ) fg.connect( src2, (interlv, 2) ) fg.connect( interlv, lp, file ) fg.start() raw_input ('Head End: Press Enter to stop') fg.stop()
def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,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 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(); fg.connect (src,src_head,s2fsmi,enc,mod) fg.connect (mod,(add,0)) fg.connect (noise,(add,1)) fg.connect (add,metrics) fg.connect (metrics,va,fsmi2s,dst) fg.run() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () #print ntotal,nright,runlength return (ntotal,ntotal-nright)
def xtest_005_interp_random_vals(self): MAX_TAPS = 9 MAX_INTERP = 7 INPUT_LEN = 9 random.seed(0) # we want reproducibility for ntaps in xrange(1, MAX_TAPS + 1): for interp in xrange(1, MAX_INTERP+1): for ilen in xrange(ntaps, ntaps + INPUT_LEN): src_data = random_floats(ilen) taps = random_floats(ntaps) expected_result = reference_interp_filter(src_data, interp, taps) fg = gr.flow_graph() src = gr.vector_source_f(src_data) op = gr.rational_resampler_base_fff(interp, 1, taps) dst = gr.vector_sink_f() fg.connect(src, op, dst) fg.run() fg = None result_data = dst.data() L1 = len(result_data) L2 = len(expected_result) L = min(L1, L2) #if True or abs(L1-L2) > 1: if False: sys.stderr.write('delta = %2d: ntaps = %d interp = %d ilen = %d\n' % (L2 - L1, ntaps, interp, ilen)) #sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % # (len(result_data), len(expected_result))) #self.assertEqual(expected_result[0:L], result_data[0:L]) # FIXME check first ntaps+1 answers self.assertEqual(expected_result[ntaps+1:L], result_data[ntaps+1:L])
def OnInit( self ): self.graph = gr.flow_graph() self.block = graph( self.graph ) self.frame = radio_frame( self.block, None, -1, "Title" ) self.frame.Show( True ) self.SetTopWindow( self.frame ) return True
def xtest_004_decim_random_vals(self): MAX_TAPS = 9 MAX_DECIM = 7 OUTPUT_LEN = 9 random.seed(0) # we want reproducibility for ntaps in xrange(1, MAX_TAPS + 1): for decim in xrange(1, MAX_DECIM+1): for ilen in xrange(ntaps + decim, ntaps + OUTPUT_LEN*decim): src_data = random_floats(ilen) taps = random_floats(ntaps) expected_result = reference_dec_filter(src_data, decim, taps) fg = gr.flow_graph() src = gr.vector_source_f(src_data) op = gr.rational_resampler_base_fff(1, decim, taps) dst = gr.vector_sink_f() fg.connect(src, op, dst) fg.run() fg = None result_data = dst.data() L1 = len(result_data) L2 = len(expected_result) L = min(L1, L2) if False: sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' % (L2 - L1, ntaps, decim, ilen)) sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % (len(result_data), len(expected_result))) self.assertEqual(expected_result[0:L], result_data[0:L])
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): fg = gr.flow_graph () # 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() fg.connect (src,src_head,s2fsmi,enc,mod) #fg.connect (src,b2s,s2fsmi,enc,mod) fg.connect (mod,(add,0)) fg.connect (noise,(add,1)) fg.connect (add,metrics) fg.connect (metrics,va,fsmi2s,dst) #fg.connect (metrics,va,fsmi2s,s2b,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 () #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 build_graph (freq1, freq2): input_rate = 20e6 cfir_decimation = 125 audio_decimation = 5 quad_rate = input_rate / cfir_decimation audio_rate = quad_rate / audio_decimation fg = gr.flow_graph () # use high speed ADC as input source src = high_speed_adc (fg, input_rate) # compute FIR filter taps for channel selection channel_coeffs = \ gr.firdes.low_pass (1.0, # gain input_rate, # sampling rate 250e3, # low pass cutoff freq 8*100e3, # width of trans. band gr.firdes.WIN_HAMMING) # input: short; output: complex chan_filter1 = \ gr.freq_xlating_fir_filter_scf (cfir_decimation, channel_coeffs, freq1, # 1st station freq input_rate) (head1, tail1) = build_pipeline (fg, quad_rate, audio_decimation) # sound card as final sink audio_sink = audio.sink (int (audio_rate)) # now wire it all together fg.connect (src, chan_filter1) fg.connect (chan_filter1, head1) fg.connect (tail1, (audio_sink, 0)) # two stations at once? if freq2: # Extract the second station and connect # it to a second pipeline... # input: short; output: complex chan_filter2 = \ gr.freq_xlating_fir_filter_scf (cfir_decimation, channel_coeffs, freq2, # 2nd station freq input_rate) (head2, tail2) = build_pipeline (fg, quad_rate, audio_decimation) fg.connect (src, chan_filter2) fg.connect (chan_filter2, head2) fg.connect (tail2, (audio_sink, 1)) return fg
def build_graph(freq1, freq2): input_rate = 20e6 cfir_decimation = 125 audio_decimation = 5 quad_rate = input_rate / cfir_decimation audio_rate = quad_rate / audio_decimation fg = gr.flow_graph() # use high speed ADC as input source src = high_speed_adc(fg, input_rate) # compute FIR filter taps for channel selection channel_coeffs = \ filter.firdes.low_pass(1.0, # gain input_rate, # sampling rate 250e3, # low pass cutoff freq 8*100e3, # width of trans. band filter.firdes.WIN_HAMMING) # input: short; output: complex chan_filter1 = \ filter.freq_xlating_fir_filter_scf(cfir_decimation, channel_coeffs, freq1, # 1st station freq input_rate) (head1, tail1) = build_pipeline(fg, quad_rate, audio_decimation) # sound card as final sink audio_sink = audio.sink(int (audio_rate)) # now wire it all together fg.connect(src, chan_filter1) fg.connect(chan_filter1, head1) fg.connect(tail1, (audio_sink, 0)) # two stations at once? if freq2: # Extract the second station and connect # it to a second pipeline... # input: short; output: complex chan_filter2 = \ filter.freq_xlating_fir_filter_scf(cfir_decimation, channel_coeffs, freq2, # 2nd station freq input_rate) (head2, tail2) = build_pipeline(fg, quad_rate, audio_decimation) fg.connect(src, chan_filter2) fg.connect(chan_filter2, head2) fg.connect(tail2, (audio_sink, 1)) return fg
def reference_interp_filter(src_data, interp, taps): fg = gr.flow_graph() src = gr.vector_source_f(src_data) op = gr.interp_fir_filter_fff(interp, taps) dst = gr.vector_sink_f() fg.connect(src, op, dst) fg.run() result_data = dst.data() fg = None return result_data
def reference_interp_dec_filter(src_data, interp, decim, taps): fg = gr.flow_graph() src = gr.vector_source_f(src_data) up = gr.interp_fir_filter_fff(interp, (1,)) dn = gr.fir_filter_fff(decim, taps) dst = gr.vector_sink_f() fg.connect(src, up, dn, dst) fg.run() result_data = dst.data() fg = None return result_data
def reference_filter_fff(dec, taps, input): """ compute result using conventional fir filter """ fg = gr.flow_graph() #src = gr.vector_source_f(((0,) * (len(taps) - 1)) + input) src = gr.vector_source_f(input) op = gr.fir_filter_fff(dec, taps) dst = gr.vector_sink_f() fg.connect(src, op, dst) fg.run() return dst.data()
def build_graph(): fg = gr.flow_graph() src = audio.source(8000) src_scale = gr.multiply_const_ff(32767) f2s = gr.float_to_short () enc = gsm_full_rate.encode_sp() dec = gsm_full_rate.decode_ps() s2f = gr.short_to_float () sink_scale = gr.multiply_const_ff(1.0/32767.) sink = audio.sink(8000) fg.connect(src, src_scale, f2s, enc, dec, s2f, sink_scale, sink) return fg
def main(): fg = gr.flow_graph() u = gr.file_source(gr.sizeof_float,"/tmp/atsc_pipe_2") input_rate = 19.2e6 IF_freq = 5.75e6 # 1/2 as wide because we're designing lp filter symbol_rate = atsc.ATSC_SYMBOL_RATE/2. NTAPS = 279 tt = gr.firdes.root_raised_cosine (1.0, input_rate, symbol_rate, .115, NTAPS) # heterodyne the low pass coefficients up to the specified bandpass # center frequency. Note that when we do this, the filter bandwidth # is effectively twice the low pass (2.69 * 2 = 5.38) and hence # matches the diagram in the ATSC spec. arg = 2. * math.pi * IF_freq / input_rate t=[] for i in range(len(tt)): t += [tt[i] * 2. * math.cos(arg * i)] rrc = gr.fir_filter_fff(1, t) fpll = atsc.fpll() pilot_freq = IF_freq - 3e6 + 0.31e6 lower_edge = 6e6 - 0.31e6 upper_edge = IF_freq - 3e6 + pilot_freq transition_width = upper_edge - lower_edge lp_coeffs = gr.firdes.low_pass (1.0, input_rate, (lower_edge + upper_edge) * 0.5, transition_width, gr.firdes.WIN_HAMMING); lp_filter = gr.fir_filter_fff (1,lp_coeffs) alpha = 1e-5 iir = gr.single_pole_iir_filter_ff(alpha) remove_dc = gr.sub_ff() out = gr.file_sink(gr.sizeof_float,"/tmp/atsc_pipe_3") # out = gr.file_sink(gr.sizeof_float,"/mnt/sata/atsc_data_float") fg.connect(u, fpll, lp_filter) fg.connect(lp_filter, iir) fg.connect(lp_filter, (remove_dc,0)) fg.connect(iir, (remove_dc,1)) fg.connect(remove_dc, out) fg.run()
def graph(): sampling_freq = 19200000 fg = gr.flow_graph() src0 = gr.file_source(gr.sizeof_gr_complex, "/tmp/atsc_pipe_1") duc_coeffs = gr.firdes.low_pass(1, 19.2e6, 9e6, 1e6, gr.firdes.WIN_HAMMING) duc = gr.freq_xlating_fir_filter_ccf(1, duc_coeffs, 5.75e6, 19.2e6) c2f = gr.complex_to_float() file = gr.file_sink(gr.sizeof_float, "/tmp/atsc_pipe_2") fg.connect(src0, duc, c2f, file) fg.run()
def benchmark(name, creator, dec, ntaps, total_test_size, block_size): block_size = 32768 fg = gr.flow_graph() taps = make_random_complex_tuple(ntaps) src = gr.vector_source_c(make_random_complex_tuple(block_size), True) head = gr.head(gr.sizeof_gr_complex, int(total_test_size)) op = creator(dec, taps) dst = gr.null_sink(gr.sizeof_gr_complex) fg.connect(src, head, op, dst) start = time.time() fg.run() stop = time.time() delta = stop - start print "%16s: taps: %4d input: %4g, time: %6.3f taps/sec: %10.4g" % ( name, ntaps, total_test_size, delta, ntaps*total_test_size/delta)
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): fg = gr.flow_graph () 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(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) dst = gr.vector_sink_s(); fg.connect (src,enc_out,inter,mod) fg.connect (mod,isi,(add,0)) fg.connect (noise,(add,1)) fg.connect (add,head) fg.connect (tail,dst) fg.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 main(args): nargs = len (args) if nargs == 1: outfile = args[0] else: sys.stderr.write ('usage: viterbi_out.py output_file\n') sys.exit (1) fg = gr.flow_graph() src = gr.file_source(atsc.sizeof_atsc_soft_data_segment, "/tmp/atsc_pipe_5") viterbi = atsc.viterbi_decoder() deinter = atsc.deinterleaver() rs_dec = atsc.rs_decoder() derand = atsc.derandomizer() depad = atsc.depad() dst = gr.file_sink(gr.sizeof_char,outfile) fg.connect(src, viterbi, deinter, rs_dec, derand, depad, dst) fg.run ()
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,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 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(); fg.connect (src,src_head,s2fsmi,enc,mod) fg.connect (mod,(add,0)) fg.connect (noise,(add,1)) fg.connect (add,va,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 (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,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 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 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() 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,metrics_in) fg.connect (gnd,(siso_in,0)) fg.connect (metrics_in,(siso_in,1)) fg.connect (siso_in,deinter,va_out,fsmi2s,dst) fg.run() 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): 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 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(fg,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) #(head,tail) = make_rx(fg,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() 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() #print enc_out.ST(), enc_in.ST() ntotal = dst.ntotal () nright = dst.nright () runlength = dst.runlength () return (ntotal,ntotal-nright)
#!/usr/bin/env python # Ruben Undheim 2007 from gnuradio import gr, ais, audio import numpy,time, sys fg = gr.flow_graph() alle = [] alle.append([0,0,0,0,0,1,0,0,0,0,1,1,1,0,1,0,0,1,1,1,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,1,0,1,1,1,1,1,1,1,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,0,1,1,1,1,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,1,0,1,0,0,1,0,1,0,0,0,1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,1,1,1,0,0,0,0]) alle.append([0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,0,0,0,0,0,0,0,1,1,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0,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1,1,0,1,0,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
def setUp(self): self.fg = gr.flow_graph () self.src_data = [int(x) for x in range(65536)]
def main(): parser = OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("-f", "--freq", type="eng_float", default=144.800e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-d", "--do-logging", action="store_true", default=False, help="enable logging on datafiles") parser.add_option("-s", "--use-datafile", action="store_true", default=False, help="use usrp.dat (256kbps) as input") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) markfreq = 2200 spacefreq = 1200 bitrate = 1200 usrp_decim = 250 if_rate = 64e6 / usrp_decim #256e3 sf = (if_rate * 3) / 5 #153600 bit_oversampling = 8 sw_decim = int(sf / bitrate / bit_oversampling) #8 bf = sf / sw_decim symdev = abs(markfreq - spacefreq) / 2 symcf = min(markfreq, spacefreq) + symdev nbfmdev = 3e3 nbfmk = if_rate / (2 * pi * nbfmdev) symk = bf / (2 * pi * symdev) fg = gr.flow_graph() if options.do_logging: logger1 = gr.file_sink(gr.sizeof_gr_complex, "usrpout.dat") logger2 = gr.file_sink(gr.sizeof_float, "demod.dat") logger3 = gr.file_sink(gr.sizeof_float, "clkrec.dat") logger4 = gr.file_sink(gr.sizeof_char, "slicer.dat") if options.use_datafile: src = gr.file_source(gr.sizeof_gr_complex, "usrp.dat") else: u = usrp.source_c() u.set_decim_rate(usrp_decim) if options.rx_subdev_spec is None: subdev_spec = usrp.pick_rx_subdevice(u) else: subdev_spec = options.rx_subdev_spec subdev = usrp.selected_subdev(u, subdev_spec) print "Using RX d'board %s" % (subdev.side_and_name(), ) u.set_mux(usrp.determine_rx_mux_value(u, subdev_spec)) print "MUX:%x" % (usrp.determine_rx_mux_value(u, subdev_spec)) if options.gain is None: g = subdev.gain_range() gain = float(g[0] + g[1]) / 2 else: gain = options.gain subdev.set_gain(gain) print "Gain set to", str(gain) r = usrp.tune(u, 0, subdev, options.freq) if r: print "Frequency set to", options.freq else: print "Frequency set to", options.freq, "failed" src = u chan_taps = gr.firdes.low_pass(1, if_rate, 13e3, 4e3, gr.firdes.WIN_HANN) chan = gr.fir_filter_ccf(1, chan_taps) #256e3 dee = blks.fm_deemph(fg, if_rate, 75e-6) fmdem = gr.quadrature_demod_cf(nbfmk) res_taps = blks.design_filter(3, 5, 0.4) res = blks.rational_resampler_fff(fg, 3, 5, res_taps) #153600 lo = gr.sig_source_c(sf, gr.GR_SIN_WAVE, -symcf, 1) mix = gr.multiply_cc() r2c = gr.float_to_complex() lp_taps = gr.firdes.low_pass(sw_decim, sf, 600, 2e3, gr.firdes.WIN_HANN) lp = gr.fir_filter_ccf(sw_decim, lp_taps) dem = gr.quadrature_demod_cf(symk) alpha = 0.0001 freqoff = gr.single_pole_iir_filter_ff(alpha) sub = gr.sub_ff() _def_gain_mu = 0.05 _def_mu = 0.5 _def_freq_error = 0.00 _def_omega_relative_limit = 0.005 _omega = bit_oversampling * (1 + _def_freq_error) _gain_omega = .25 * _def_gain_mu * _def_gain_mu clkrec = gr.clock_recovery_mm_ff(_omega, _gain_omega, _def_mu, _def_gain_mu, _def_omega_relative_limit) slicer = gr.binary_slicer_fb() pktq = gr.msg_queue() sink = packetradio.hdlc_framer(pktq, 0) watcher = queue_watcher_thread(pktq, rx_callback) fg.connect(src, chan, fmdem, dee, res, r2c, (mix, 0)) fg.connect(lo, (mix, 1)) fg.connect(mix, lp, dem) fg.connect(dem, (sub, 0)) fg.connect(dem, freqoff, (sub, 1)) fg.connect(sub, clkrec, slicer) fg.connect(slicer, sink) if options.do_logging: fg.connect(src, logger1) fg.connect(sub, logger2) fg.connect(clkrec, logger3) fg.connect(slicer, logger4) fg.start() fg.wait()
def setUp(self): self.fg = gr.flow_graph() self.rng = random.Random() self.rng.seed(0)
def setUp (self): ''' override qa_basic_flow_graph setUp in order to use our class''' self.fg = gr.flow_graph ()
def setUp (self): self.fg = gr.flow_graph() self.msgq = gr.msg_queue ()
#file_name = os.environ.get("GSMSPROOT") + "/resources/data/GSMSP_20070218_robert_dbsrx_941MHz_112.cfile" #file_name = os.environ.get("GSMSPROOT") + "/resources/data/GSMSP_20070204_robert_dbsrx_953.6MHz_64.cfile" file_name = "signal.data" #decimation = 64 # the decimation Robert used #decimation = 112 # the decimation Robert used decimation = 118 # the decimation Robert used sps = 64e6 / decimation # samples / second with this decimation filter_cutoff = 150e3 # bandpass filter between +/- 150kHz filter_t_width = 50e3 # width of filter transition offset = 0 # Robert didn't need an offset # create a GNURadio Flow Graph fg = gr.flow_graph() # create a file source from Robert's file source = gr.file_source(gr.sizeof_gr_complex, file_name) # create a filter with the above constants filter_taps = gr.firdes.low_pass(1.0, sps, filter_cutoff, filter_t_width, gr.firdes.WIN_HAMMING) filter = gr.freq_xlating_fir_filter_ccf(1, filter_taps, offset, sps) # create the GMSK demod object gd = gmsk.gmsk_demod(fg, sps / gsm_rate, gain_mu = 0.01, omega_relative_limit = 0.005) #diff = gr.diff_decoder_bb (2)
def setUp(self): self.fg = gr.flow_graph()
def __init__(self, parent, ID, title): wxFrame.__init__(self, parent, ID, title, wxDefaultPosition) self.pga = 0 self.pgaMin = -20 self.pgaMax = 0 self.pgaStep = 0.25 # Parsing options parser = OptionParser(option_class=eng_option, usage="usage: %prog [options] filename1" \ " [-f frequency2 filename2 [...]]") parser.add_option("-a", "--agc", action="store_true", help="enable agc") parser.add_option("-c", "--clockrate", type="eng_float", default=128e6, help="set USRP clock rate (128e6)") parser.add_option("--copy", action="store_true", help="enable real to imag data copy when in real mode") parser.add_option("-e", "--encoding", type="choice", choices=["s", "f"], default="f", help="choose data encoding: [s]igned or [f]loat.") parser.add_option("-f", "--frequency", type="eng_float", action="callback", callback=appendFrequency, help="set output frequency (222.064e6)") parser.add_option("-g", "--gain", type="float", help="set output pga gain") parser.add_option("-l", "--list", action="callback", callback=listUsrp, help="list USRPs and daugtherboards") parser.add_option("-m", "--mode", type="eng_float", default=2, help="mode: 1: real, 2: complex (2)") parser.add_option("-o", "--osc", action="store_true", help="enable oscilloscope") parser.add_option("-r", "--samplingrate", type="eng_float", default=3.2e6, help="set input sampling rate (3200000)") parser.add_option("-s", "--spectrum", action="store_true", help="enable spectrum analyzer") # parser.add_option("-t", "--tx", type="choice", choices=["A", "B"], # default="A", help="choose USRP tx A|B output (A)") parser.add_option("-u", "--usrp", action="store_true", help="enable USRP output") (options, args) = parser.parse_args() if len(args) == 0 : options.filename = [ "/dev/stdin" ] else : options.filename = args # Setting default frequency if options.frequency is None : options.frequency = [ 222.064e6 ] if len(options.filename) != len(options.frequency) : parser.error("Nb input file != nb frequency!") # Status bar # self.CreateStatusBar(3, 0) # msg = "PGA: %.2f dB" % (self.pga * self.pgaStep) # self.SetStatusText(msg, 1) # msg = "Freq: %.3f mHz" % (options.frequency[0] / 1000000.0) # self.SetStatusText(msg, 2) # Menu bar menu = wxMenu() menu.Append(ID_ABOUT, "&About", "More information about this program") menu.AppendSeparator() menu.Append(ID_EXIT, "E&xit", "Terminate the program") menuBar = wxMenuBar() menuBar.Append(menu, "&File") self.SetMenuBar(menuBar) # Main windows mainSizer = wxFlexGridSizer(0, 1) sliderSizer = wxFlexGridSizer(0, 2) buttonSizer = wxBoxSizer(wxHORIZONTAL) if options.usrp : # TX d'board 0 gainLabel = wxStaticText(self, -1, "PGA 0") gainSlider = wxSlider(self, ID_GAIN_SLIDER0, self.pga, self.pgaMin / self.pgaStep, self.pgaMax / self.pgaStep, style = wxSL_HORIZONTAL | wxSL_AUTOTICKS) gainSlider.SetSize((400, -1)) sliderSizer.Add(gainLabel, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) sliderSizer.Add(gainSlider, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) freqLabel = wxStaticText(self, -1, "Frequency 0") freqSlider = wxSlider(self, ID_FREQ_SLIDER0, options.frequency[0] / 16000, 0, 20e3, style = wxSL_HORIZONTAL | wxSL_AUTOTICKS) freqSlider.SetSize((400, -1)) sliderSizer.Add(freqLabel, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) sliderSizer.Add(freqSlider, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) if len(options.frequency) > 1 : # TX d'board 1 gainLabel = wxStaticText(self, -1, "PGA 1") gainSlider = wxSlider(self, ID_GAIN_SLIDER1, self.pga, self.pgaMin / self.pgaStep, self.pgaMax / self.pgaStep, style = wxSL_HORIZONTAL | wxSL_AUTOTICKS) gainSlider.SetSize((400, -1)) sliderSizer.Add(gainLabel, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) sliderSizer.Add(gainSlider, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) freqLabel = wxStaticText(self, -1, "Frequency 1") freqSlider = wxSlider(self, ID_FREQ_SLIDER1, options.frequency[1] / 16000, 0, 20e3, style = wxSL_HORIZONTAL | wxSL_AUTOTICKS) freqSlider.SetSize((400, -1)) sliderSizer.Add(freqLabel, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) sliderSizer.Add(freqSlider, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) mainSizer.Add(sliderSizer, 1, wxEXPAND, 0) start = wxButton(self, ID_START, "Start") stop = wxButton(self, ID_STOP, "Stop") buttonSizer.Add(start, 1, wxALIGN_CENTER, 0) buttonSizer.Add(stop, 1, wxALIGN_CENTER, 0) mainSizer.Add(buttonSizer, 1, wxEXPAND, 0) # GnuRadio self.fg = gr.flow_graph() if options.mode == 1 : print "Source: real" if (options.encoding == "s") : print "Source encoding: short" src = gr.file_source(gr.sizeof_short, options.filename[0], 1) if (options.copy) : print "Imag: copy" imag = src else : print "Imag: null" imag = gr.null_source(gr.sizeof_short) interleaver = gr.interleave(gr.sizeof_short) self.fg.connect(src, (interleaver, 0)) self.fg.connect(imag, (interleaver, 1)) tail = interleaver elif (options.encoding == "f") : print "Source encoding: float" src = gr.file_source(gr.sizeof_gr_complex, options.filename[0], 1) tail = src elif (options.mode == 2) : print "Source: complex" if len(options.frequency) == 1 : if (options.encoding == "s") : print "Source encoding: short" src = gr.file_source(gr.sizeof_short, options.filename[0], 1) elif (options.encoding == "f") : print "Source encoding: float" src = gr.file_source(gr.sizeof_gr_complex, options.filename[0], 1) else : parser.error("Invalid encoding type for complex data!") tail = src elif (len(options.frequency) == 2) : src0 = gr.file_source(gr.sizeof_gr_complex, options.filename[0], 1) src1 = gr.file_source(gr.sizeof_gr_complex, options.filename[1], 1) interleaver = gr.interleave(gr.sizeof_gr_complex) self.fg.connect(src0, (interleaver, 0)) self.fg.connect(src1, (interleaver, 1)) tail = interleaver else : parser.error( "Invalid number of source (> 2) with complex input!") else : parser.error("Invalid mode!") # Interpolation dac_freq = options.clockrate interp = int(dac_freq / options.samplingrate) if interp == 0 : parser.error("Invalid sampling rate!") if options.mode == 2 : print "Input sampling rate: %s complex samples/s" % \ num_to_str(options.samplingrate) else : print "Input sampling rate: %s samples/s" % \ num_to_str(options.samplingrate) print "Interpolation rate: int(%s / %s) = %sx" % \ (num_to_str(dac_freq), num_to_str(options.samplingrate), interp) if interp > 512 : factor = gcd(dac_freq / 512, options.samplingrate) num = int((dac_freq / 512) / factor) den = int(options.samplingrate / factor) print "Resampling by %i / %i" % (num, den) resampler = blks.rational_resampler_ccc(self.fg, num, den) self.fg.connect(tail, resampler) tail = resampler interp = 512 options.samplingrate = dac_freq / 512 # AGC if options.agc : agc = gr.agc_cc() self.fg.connect(tail, agc) tail = agc # USRP if options.usrp : nchan = len(options.frequency) if len(options.frequency) == 1 : if options.mode == 1 : mux = 0x00000098 elif options.mode == 2 : mux = 0x00000098 else : parser.error("Unsupported mode for USRP mux!") elif len(options.frequency) == 2 : if options.mode == 1 : mux = 0x0000ba98 elif options.mode == 2 : mux = 0x0000ba98 else : parser.error("Unsupported mode for USRP mux!") else : parser.error("Invalid number of frequency [0..2]!") # if options.tx == "A" : # mux = 0x00000098 # else : # mux = 0x00009800 print "Nb channels: ", nchan print "Mux: 0x%x" % mux if options.encoding == 's' : dst = usrp.sink_s(0, interp, nchan, mux) elif options.encoding == 'f' : dst = usrp.sink_c(0, interp, nchan, mux) else : parser.error("Unsupported data encoding for USRP!") dst.set_verbose(1) for i in range(len(options.frequency)) : if options.gain is None : print "Setting gain to %f" % dst.pga_max() dst.set_pga(i << 1, dst.pga_max()) else : print "Setting gain to %f" % options.gain dst.set_pga(i << 1, options.gain) tune = false for dboard in dst.db: if (dboard[0].dbid() != -1): device = dboard[0] print "Tuning TX d'board %s to %sHz" % \ (device.side_and_name(), num_to_str(options.frequency[i])) device.lo_offset = 38e6 (min, max, offset) = device.freq_range() print " Frequency" print " Min: %sHz" % num_to_str(min) print " Max: %sHz" % num_to_str(max) print " Offset: %sHz" % num_to_str(offset) #device.set_gain(device.gain_range()[1]) device.set_enable(True) tune = \ dst.tune(device._which, device, options.frequency[i] * 128e6 / dac_freq) if tune: print " Baseband frequency: %sHz" % \ num_to_str(tune.baseband_freq) print " DXC frequency: %sHz" % \ num_to_str(tune.dxc_freq) print " Residual Freqency: %sHz" % \ num_to_str(tune.residual_freq) print " Inverted: ", \ tune.inverted mux = usrp.determine_tx_mux_value(dst, (device._which, 0)) dst.set_mux(mux) break else: print " Failed!" if not tune: print " Failed!" raise SystemExit # int nunderruns () print "USRP" print " Rx halfband: ", dst.has_rx_halfband() print " Tx halfband: ", dst.has_tx_halfband() print " Nb DDC: ", dst.nddc() print " Nb DUC: ", dst.nduc() #dst._write_9862(0, 14, 224) print " DAC frequency: %s samples/s" % num_to_str(dst.dac_freq()) print " Fpga decimation rate: %s -> %s samples/s" % \ (num_to_str(dst.interp_rate()), num_to_str(dac_freq / dst.interp_rate())) print " Nb channels:", if hasattr(dst, "nchannels()") : print dst.nchannels() else: print "N/A" print " Mux:", if hasattr(dst, "mux()") : print "0x%x" % dst.mux() else : print "N/A" print " FPGA master clock frequency:", if hasattr(dst, "fpga_master_clock_freq()") : print "%sHz" % num_to_str(dst.fpga_master_clock_freq()) else : print "N/A" print " Converter rate:", if hasattr(dst, "converter_rate()") : print "%s" % num_to_str(dst.converter_rate()) else : print "N/A" print " DAC rate:", if hasattr(dst, "dac_rate()") : print "%s sample/s" % num_to_str(dst.dac_rate()) else : print "N/A" print " Interp rate: %sx" % num_to_str(dst.interp_rate()) print " DUC frequency 0: %sHz" % num_to_str(dst.tx_freq(0)) print " DUC frequency 1: %sHz" % num_to_str(dst.tx_freq(1)) print " Programmable Gain Amplifier 0: %s dB" % \ num_to_str(dst.pga(0)) print " Programmable Gain Amplifier 1: %s dB" % \ num_to_str(dst.pga(2)) else : dst = gr.null_sink(gr.sizeof_gr_complex) # AGC if options.agc : agc = gr.agc_cc() self.fg.connect(tail, agc) tail = agc self.fg.connect(tail, dst) # oscilloscope if options.osc : oscPanel = wxPanel(self, -1) if (options.encoding == "s") : converter = gr.interleaved_short_to_complex() self.fg.connect(tail, converter) signal = converter elif (options.encoding == "f") : signal = tail else : parser.error("Unsupported data encoding for oscilloscope!") #block = scope_sink_f(fg, parent, title=label, sample_rate=input_rate) #return (block, block.win) oscWin = scopesink.scope_sink_c(self.fg, oscPanel, "Signal", options.samplingrate) self.fg.connect(signal, oscWin) mainSizer.Add(oscPanel, 1, wxEXPAND) # spectrometer if options.spectrum : ymin = 0 ymax = 160 fftPanel = wxPanel(self, -1) if (options.encoding == "s") : converter = gr.interleaved_short_to_complex() self.fg.connect(tail, converter) signal = converter elif (options.encoding == "f") : signal = tail else : parser.error("Unsupported data encoding for oscilloscope!") fftWin = fftsink.fft_sink_c(self.fg, fftPanel, title="Spectrum", fft_size=2048, sample_rate=options.samplingrate, y_per_div=(ymax - ymin) / 8, ref_level=ymax, fft_rate=50, average=True ) self.fg.connect(signal, fftWin) mainSizer.Add(fftPanel, 1, wxEXPAND) # Events EVT_MENU(self, ID_ABOUT, self.OnAbout) EVT_MENU(self, ID_EXIT, self.TimeToQuit) EVT_SLIDER(self, ID_GAIN_SLIDER0, self.slideEvent) EVT_SLIDER(self, ID_FREQ_SLIDER0, self.slideEvent) EVT_SLIDER(self, ID_GAIN_SLIDER1, self.slideEvent) EVT_SLIDER(self, ID_FREQ_SLIDER1, self.slideEvent) EVT_BUTTON(self, ID_START, self.onClick) EVT_BUTTON(self, ID_STOP, self.onClick) #Layout sizers self.SetSizer(mainSizer) self.SetAutoLayout(1) mainSizer.Fit(self) self.fg.start()
def setUp (self): self.fg = gr.flow_graph ()
def main(): parser = OptionParser(option_class=eng_option) parser.add_option("-f", "--freq", type="eng_float", default=144.800e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-m", "--message", type="string", default=":ALL :this is a test", help="message to send", metavar="MESSAGE") parser.add_option("-c", "--mycall", type="string", default="MYCALL", help="source callsign", metavar="CALL") parser.add_option("-t", "--tocall", type="string", default="CQ", help="recipient callsign", metavar="CALL") parser.add_option("-v", "--via", type="string", default="RELAY", help="digipeater callsign", metavar="CALL") parser.add_option("-d", "--do-logging", action="store_true", default=False, help="enable logging on datafiles") parser.add_option("-s", "--use-datafile", action="store_true", default=False, help="use usrp.dat (256kbps) as output") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) bitrate = 9600 dac_rate = 128e6 usrp_interp = 500 cordic_freq = options.freq - dac_rate sf = 153600 syminterp = sf / bitrate #16 nbfmdev = 3e3 fmsens = 2 * pi * nbfmdev / (sf * 5 / 3) bit_oversampling = 8 sw_interp = int(sf / bitrate / bit_oversampling) #2 fg = gr.flow_graph() p = buildpacket(options.mycall, 0, options.tocall, 0, options.via, 0, 0x03, 0xf0, options.message) if options.do_logging: dumppackettofile(p, "packet.dat") v = bits2syms(nrziencode(scrambler(hdlcpacket(p, 100, 1000)))) src = gr.vector_source_f(v) gaussian_taps = gr.firdes.gaussian( 1, # gain bit_oversampling, # symbol_rate 0.3, # bandwidth * symbol time 4 * bit_oversampling # number of taps ) sqwave = (1, ) * syminterp #rectangular window taps = Numeric.convolve(Numeric.array(gaussian_taps), Numeric.array(sqwave)) gaussian = gr.interp_fir_filter_fff(syminterp, taps) #9600*16=153600 res_taps = blks.design_filter(5, 3, 0.4) res = blks.rational_resampler_fff(fg, 5, 3, res_taps) #153600*5/3=256000 fmmod = gr.frequency_modulator_fc(fmsens) amp = gr.multiply_const_cc(32000) if options.use_datafile: dst = gr.file_sink(gr.sizeof_gr_complex, "usrp.dat") else: u = usrp.sink_c(0, usrp_interp) #256000*500=128000000 tx_subdev_spec = usrp.pick_tx_subdevice(u) m = usrp.determine_tx_mux_value(u, tx_subdev_spec) print "mux = %#04x" % (m, ) u.set_mux(m) subdev = usrp.selected_subdev(u, tx_subdev_spec) print "Using TX d'board %s" % (subdev.side_and_name(), ) u.set_tx_freq(0, cordic_freq) u.set_pga(0, 0) print "Actual frequency: ", u.tx_freq(0) dst = u fg.connect(src, gaussian, res, fmmod, amp, dst) fg.start() fg.wait()