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 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, 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 test_002(self): # Test get methods set_type = gr.GR_GAUSSIAN set_ampl = 10 op = gr.noise_source_f(set_type, set_ampl, 10) get_type = op.type() get_ampl = op.amplitude() self.assertEqual(get_type, set_type) self.assertEqual(get_ampl, set_ampl)
def test_002(self): # Test get methods set_type = gr.GR_GAUSSIAN set_ampl = 10 op = gr.noise_source_f(set_type, set_ampl, 10) get_type = op.type get_ampl = op.amplitude self.assertEqual(get_type, set_type) self.assertEqual(get_ampl, set_ampl)
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 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): 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 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, alpha=0.1, noise_mag=0): """ Parameters: alpha: float noise_mag: float """ gr.hier_block2.__init__( self, "Phase Noise Generator", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex), ) ################################################## # Parameters ################################################## self.alpha = alpha self.noise_mag = noise_mag ################################################## # Blocks ################################################## self.gr_transcendental_0_0 = gr.transcendental("sin", "float") self.gr_transcendental_0 = gr.transcendental("cos", "float") self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff( alpha, 1) self.gr_noise_source_x_0 = gr.noise_source_f(gr.GR_GAUSSIAN, noise_mag, 42) self.gr_multiply_xx_0 = gr.multiply_vcc(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) ################################################## # Connections ################################################## self.connect((self.gr_float_to_complex_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_single_pole_iir_filter_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self, 0)) self.connect((self, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_transcendental_0, 0)) self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_transcendental_0_0, 0)) self.connect((self.gr_transcendental_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_transcendental_0_0, 0), (self.gr_float_to_complex_0, 1))
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(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,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 __init__(self): gr.top_block.__init__(self) self.sample_rate = 10e3 s0 = gr.noise_source_f (gr.GR_UNIFORM, MAX) s1 = foo.ct_source_f (100000) u = foo.peak_fv (MAX, 80, "an identifier") self.connect(s0, (u,0)) self.connect(s1, (u,1)) v = foo.wait_vv () self.connect(u, v) t = gr.null_sink (4 * 1024) self.connect(v, t)
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 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): 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 (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(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 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 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 #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 __init__(self, N, fs, bw, tw, atten, D): gr.top_block.__init__(self) self._nsamps = N self._fs = fs self._bw = bw self._tw = tw self._at = atten self._decim = D taps = filter.firdes.low_pass_2(1, self._fs, self._bw, self._tw, self._at) print "Num. Taps: ", len(taps) self.src = gr.noise_source_f(gr.GR_GAUSSIAN, 1) self.head = gr.head(gr.sizeof_float, self._nsamps) self.filt0 = filter.fir_filter_fff(self._decim, taps) self.vsnk_src = gr.vector_sink_f() self.vsnk_out = gr.vector_sink_f() self.connect(self.src, self.head, self.vsnk_src) self.connect(self.head, self.filt0, self.vsnk_out)
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 __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) ################################################## # Variables ################################################## self.snr_db = snr_db = 3 self.noiseAmplitude = noiseAmplitude = sqrt(1 / (10**(0.1 * snr_db))) self.constellation = constellation = [-1.3416, -0.4472, 0.4472, 1.3416] self.bits = bits = 2 ################################################## # Blocks ################################################## self.random_source_x_0 = gr.vector_source_b( map(int, numpy.random.randint(0, 4, 10000)), True) self.qtgui_sink_x_0_0_1 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc 400, #bw "QT GUI Plot", #name False, #plotfreq False, #plotwaterfall False, #plottime True, #plotconst ) self.qtgui_sink_x_0_0_1.set_update_time(1.0 / 100) self._qtgui_sink_x_0_0_1_win = sip.wrapinstance( self.qtgui_sink_x_0_0_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_0_1_win) self.gr_tag_debug_0 = gr.tag_debug(gr.sizeof_float * 1, "") self.gr_noise_source_x_0 = gr.noise_source_f(gr.GR_GAUSSIAN, noiseAmplitude, 0) self.gr_file_sink_1 = gr.file_sink(gr.sizeof_gr_complex * 1, "symbols.bin") self.gr_file_sink_1.set_unbuffered(False) self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_char * 1, "output.bin") self.gr_file_sink_0_0.set_unbuffered(False) self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char * 1, "input.bin") self.gr_file_sink_0.set_unbuffered(False) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( digital.constellation_calcdist([-3, -1, 1, 3], [], 1, 1).base()) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf( (constellation), 1) self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, 100) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.blks2_error_rate_0 = grc_blks2.error_rate( type='BER', win_size=10000, bits_per_symbol=bits, ) ################################################## # Connections ################################################## self.connect((self.random_source_x_0, 0), (self.blks2_error_rate_0, 0)) self.connect((self.random_source_x_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blks2_error_rate_0, 1)) self.connect((self.random_source_x_0, 0), (self.gr_file_sink_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.gr_file_sink_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.const_source_x_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.qtgui_sink_x_0_0_1, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.gr_file_sink_1, 0)) self.connect((self.blks2_error_rate_0, 0), (self.gr_tag_debug_0, 0))
def test_001(self): # Just confirm that we can instantiate a noise source op = gr.noise_source_f(gr.GR_GAUSSIAN, 10, 10)
def make_noise_gronly(): global tb n = gr.noise_source_f(gr.GR_UNIFORM,1) ftob = gr.binary_slicer_fb() tb.connect(n,ftob) return ftob
def make_noise_gronly(): global tb n = gr.noise_source_f(gr.GR_UNIFORM, 1) ftob = gr.binary_slicer_fb() tb.connect(n, ftob) return ftob
def __init__(self, frame, panel, vbox, argv, panel_info): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) signal_type = default_signal_type # not yet an option # command line options parser = OptionParser(option_class=eng_option) parser.add_option("-r", "--sample-rate",type="eng_float", default=default_rate, help="set flow graph sample rate [default=%s]" % default_rate) parser.add_option ("-f", "--freq", type="eng_float", default=default_freq, help="set signal frequency [default=%s]" % default_freq) parser.add_option ("-a", "--amplitude", type="eng_float", default=default_ampl, help="set signal amplitude [default %s]" % default_ampl) parser.add_option ("--gaussian", dest="noise_type", action="store_const", const=gr.GR_GAUSSIAN, help="generate Gaussian noise (-x is variance)", default=default_noise_type) parser.add_option ("--uniform", dest="noise_type", action="store_const", const=gr.GR_UNIFORM, help="generate Uniform noise (-x is peak-to-peak)") parser.add_option ("-x", "--noise_amplitude", type="eng_float", default=default_noise_ampl, help="set noise amplitude (variance or p-p) [default %s]" % default_noise_ampl) parser.add_option("-n", "--frame_decim", type="int", default=default_frame_decim, help="set oscope frame decimation factor to DECIM [default=%s]" % default_frame_decim) parser.add_option("-v", "--v_scale", type="eng_float", default=default_v_scale, help="set oscope initial V/div [default=%s]" % default_v_scale) parser.add_option("-t", "--t_scale", type="eng_float", default=default_t_scale, help="set oscope initial s/div [default=%s]" % default_t_scale) parser.add_option("-l", "--ref_level", type="eng_float", default=default_ref_level, help="set fft reference level [default=%sdB]" % default_ref_level) (options, args) = parser.parse_args () if len(args) != 0: parser.print_help() raise SystemExit, 1 # flow graph, including scope and fft frames sample_rate = int(options.sample_rate) # signal, noise sources need to be attributes so callbacks can get them self.signal = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, options.freq, options.amplitude, 0.0) # Seed copied from example at cswiger/noise_source.html self.noise = gr.noise_source_f(options.noise_type, options.noise_amplitude, 2482) add = gr.add_ff() throttle = gr.throttle(gr.sizeof_float, sample_rate) (scope_title, scope_panel, scope_vbox) = panel_info[1] #0 is ctrl panel scope = scopesink2.scope_sink_f(scope_panel, sample_rate=sample_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale) scope_vbox.Add (scope.win, 1, wx.EXPAND) fft_size = 256 (fft_title, fft_panel, fft_vbox) = panel_info[2] # 0 is control panel fft = fftsink2.fft_sink_f (fft_panel,title=fft_title, fft_size=fft_size*2, sample_rate=sample_rate, baseband_freq=0, ref_level=options.ref_level, y_per_div=10) fft_vbox.Add (fft.win, 1, wx.EXPAND) self.connect (self.signal, (add,0)) self.connect (self.noise, (add,1)) self.connect (add, throttle) # self.connect (throttle, (scope, 0)) # self.connect (throttle, (scope, 1)) # can't leave scope in unconnected self.connect (throttle, scope) self.connect (throttle, fft) # control panel frame sliders = form.form() vbox.Add((0,10), 0) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add((10,0), 0) sliders['signal_type'] = form.static_text_field(parent=panel,sizer=hbox) vbox.Add(hbox, 0, wx.EXPAND) vbox.Add((0,10), 0) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add((10,0), 0) sliders['signal_freq'] = form.slider_field(parent=panel, sizer=hbox, label="Frequency", weight=3, min=0, max=2*options.freq, callback=self.set_signal_freq) vbox.Add(hbox, 0, wx.EXPAND) vbox.Add((0,10), 0) hbox = wx.BoxSizer(wx.HORIZONTAL) # apparently you can rebind hbox hbox.Add((10,0), 0) sliders['signal_ampl'] = form.slider_field(parent=panel, sizer=hbox, label="Amplitude", weight=3, min=0, max=usrp_full_scale, callback=self.set_signal_ampl) vbox.Add(hbox, 0, wx.EXPAND) vbox.Add((0,20), 0) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add((10,0), 0) sliders['noise_type'] = form.static_text_field(parent=panel,sizer=hbox) vbox.Add(hbox, 0, wx.EXPAND) vbox.Add((0,10), 0) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add((10,0), 0) sliders['noise_ampl'] = form.slider_field(parent=panel, sizer=hbox, label="Amplitude", weight=3, min=0, max=usrp_full_scale, callback=self.set_noise_ampl) vbox.Add(hbox, 0, wx.EXPAND) vbox.Add((0,10), 0) sliders['signal_type'].set_value("Signal: %s" % signal_string[signal_type]) sliders['noise_type'].set_value("Noise: %s" % noise_string[options.noise_type]) sliders['signal_freq'].set_value(options.freq) sliders['signal_ampl'].set_value(options.amplitude) sliders['noise_ampl'].set_value(options.noise_amplitude)