def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset): gr.top_block.__init__(self) rrc_taps = gr.firdes.root_raised_cosine( sps, sps, 1.0, rolloff, ntaps) data = 2.0*scipy.random.randint(0, 2, N) - 1.0 data = scipy.exp(1j*poffset) * data self.src = gr.vector_source_c(data.tolist(), False) self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps) self.chn = gr.channel_model(noise, foffset, toffset) self.fll = digital.fll_band_edge_cc(sps, rolloff, ntaps, bw) self.vsnk_src = gr.vector_sink_c() self.vsnk_fll = gr.vector_sink_c() self.vsnk_frq = gr.vector_sink_f() self.vsnk_phs = gr.vector_sink_f() self.vsnk_err = gr.vector_sink_f() self.connect(self.src, self.rrc, self.chn, self.fll, self.vsnk_fll) self.connect(self.rrc, self.vsnk_src) self.connect((self.fll,1), self.vsnk_frq) self.connect((self.fll,2), self.vsnk_phs) self.connect((self.fll,3), self.vsnk_err)
def __init__(self, gain, samp_freq, sym_rat, roll_off, pern): ''' in: - gain = gain of the filter - samp_freq = sampling rate of each pulse period, (samples per symbol) - sym_rat = per n times samp freq, how much symbols? - roll_off = squared root raised cosine's roll off factor - pern = periods number ''' gr.hier_block2.__init__(self, "Pulse shaping", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) # instance variables sps = int(samp_freq/sym_rat) print "i: IF sample rate:", n2s(samp_freq) print "i: Symbol rate:", n2s(sym_rat) print "i: Samples/symbol:", sps print "i: RRC bandwidth:", roll_off # matched filter taps = gr.firdes.root_raised_cosine(gain, samp_freq, sym_rat, roll_off, pern*samp_freq) self.rrc = gr.interp_fir_filter_ccf(1, # Interpolation rate taps) # connections self.connect((self, 0), (self.rrc, 0), (self, 0))
def graph (args): print os.getpid() nargs = len (args) if nargs == 1: infile = args[0] else: sys.stderr.write('usage: interp.py input_file\n') sys.exit (1) tb = gr.top_block () srcf = gr.file_source (gr.sizeof_short,infile) s2ss = gr.stream_to_streams(gr.sizeof_short,2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src0 = gr.float_to_complex() lp_coeffs = gr.firdes.low_pass ( 3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING ) lp = gr.interp_fir_filter_ccf ( 3, lp_coeffs ) file = gr.file_sink(gr.sizeof_gr_complex,"/tmp/atsc_pipe_1") tb.connect( srcf, s2ss ) tb.connect( (s2ss, 0), s2f1, (src0,0) ) tb.connect( (s2ss, 1), s2f2, (src0,1) ) tb.connect( src0, lp, file) tb.start() raw_input ('Head End: Press Enter to stop') tb.stop()
def key_factory(index): print "FACTORY CALLED index = %d"%(index); r = es.es_pyhandler(); excess_bw = 0.5; sps = 4; amplitude = sig_amp; taps = gr.firdes.root_raised_cosine(sps*amplitude, # Gain sps, # Sampling rate 1.0, # Symbol rate excess_bw, # Roll-off factor 11*sps) # Number of taps blocks = {}; blocks["src"] = es.vector_source([1]) blocks["scrambler"] = gr.scrambler_bb(0x8A, 0x7F, 7); blocks["mapper"] = gr.chunks_to_symbols_bc( [-1+0j, 0+1j, 1+0j, 0-1j] ); blocks["rrc"] = gr.interp_fir_filter_ccf(sps, taps); r.sink = es.vector_sink([gr.sizeof_gr_complex]); r.set_pyb2(blocks); tb = gr.top_block(); tb.connect( blocks["src"], blocks["scrambler"], blocks["mapper"], blocks["rrc"], r.sink ); r.tb = tb.to_top_block(); return r;
def __init__(self): gr.top_block.__init__(self) self.samp_rate = samp_rate = 1000000 self.dump_freq = dump_freq = 2400490000 self._u = uhd.usrp_source( device_addr="%default", io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) self._u.set_gain(0, 0) self._u.set_samp_rate(self.samp_rate) treq = uhd.tune_request(self.dump_freq, 0) tr = self._u.set_center_freq(treq) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 self.filter1 = gr.interp_fir_filter_ccf(1, firdes.low_pass(1, samp_rate, 500000, 10000, firdes.WIN_HAMMING, 6.76)) self.squelch = gr.pwr_squelch_cc(-100, 0.001, 0, True) self.demod = gr.quadrature_demod_cf(1) self.sync = digital.clock_recovery_mm_ff(2, 0.0076562, 0.5, 0.175, 0.005) self.slicer = digital.binary_slicer_fb() self.detect_seq = digital.correlate_access_code_bb("01010101010101010101010101010101", 1) self.dump = flysky.dumpsync() self.connect(self._u,self.filter1,self.squelch,self.demod,self.sync,self.slicer,self.detect_seq, self.dump)
def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset, mode=0): gr.top_block.__init__(self) rrc_taps = gr.firdes.root_raised_cosine(sps, sps, 1.0, rolloff, ntaps) gain = 2 * scipy.pi / 100.0 nfilts = 32 rrc_taps_rx = gr.firdes.root_raised_cosine(nfilts, sps * nfilts, 1.0, rolloff, ntaps * nfilts) data = 2.0 * scipy.random.randint(0, 2, N) - 1.0 data = scipy.exp(1j * poffset) * data self.src = gr.vector_source_c(data.tolist(), False) self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps) self.chn = gr.channel_model(noise, foffset, toffset) self.off = gr.fractional_interpolator_cc(0.20, 1.0) if mode == 0: self.clk = gr.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx, nfilts, nfilts // 2, 3.5) self.taps = self.clk.get_taps() self.dtaps = self.clk.get_diff_taps() self.vsnk_err = gr.vector_sink_f() self.vsnk_rat = gr.vector_sink_f() self.vsnk_phs = gr.vector_sink_f() self.connect((self.clk, 1), self.vsnk_err) self.connect((self.clk, 2), self.vsnk_rat) self.connect((self.clk, 3), self.vsnk_phs) else: # mode == 1 mu = 0.5 gain_mu = 0.1 gain_omega = 0.25 * gain_mu * gain_mu omega_rel_lim = 0.02 self.clk = digital.clock_recovery_mm_cc(sps, gain_omega, mu, gain_mu, omega_rel_lim) self.vsnk_err = gr.vector_sink_f() self.connect((self.clk, 1), self.vsnk_err) self.vsnk_src = gr.vector_sink_c() self.vsnk_clk = gr.vector_sink_c() self.connect(self.src, self.rrc, self.chn, self.off, self.clk, self.vsnk_clk) self.connect(self.off, self.vsnk_src)
def graph(args): print os.getpid() nargs = len(args) if nargs == 1: infile = args[0] else: sys.stderr.write('usage: interp.py input_file\n') sys.exit(1) tb = gr.top_block() srcf = gr.file_source(gr.sizeof_short, infile) s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src0 = gr.float_to_complex() lp_coeffs = gr.firdes.low_pass(3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING) lp = gr.interp_fir_filter_ccf(3, lp_coeffs) file = gr.file_sink(gr.sizeof_gr_complex, "/tmp/atsc_pipe_1") tb.connect(srcf, s2ss) tb.connect((s2ss, 0), s2f1, (src0, 0)) tb.connect((s2ss, 1), s2f2, (src0, 1)) tb.connect(src0, lp, file) tb.start() raw_input('Head End: Press Enter to stop') tb.stop()
def __init__(self, sps, # Samples per symbol excess_bw, # RRC filter excess bandwidth (typically 0.35-0.5) amplitude, # DAC output level, 0-32767, typically 2000-8000 vector_source, # Indicate if it's the infinite sequence of 1, or by use the code to change the amplitude ): gr.hier_block2.__init__(self, "bpsk_modulator", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature # Create BERT data bit stream self.vector_source = vector_source self._scrambler = gr.scrambler_bb(0x8A, 0x7F, 31) # CCSDS 7-bit scrambler # Map to constellation self._constellation = [-1+0j, 1+0j] self._mapper = gr.chunks_to_symbols_bc(self._constellation) # Create RRC with specified excess bandwidth taps = gr.firdes.root_raised_cosine(sps, # Gain sps, # Sampling rate 1.0, # Symbol rate excess_bw, # Roll-off factor 11*sps) # Number of taps self._rrc = gr.interp_fir_filter_ccf(sps, # Interpolation rate taps) # FIR taps self.amp = gr.multiply_const_cc(amplitude) # Wire block inputs and outputs self.connect(self.vector_source, self._scrambler, self._mapper, self._rrc, self.amp, self)
def __init__(self, sps, # Samples per symbol excess_bw, # RRC filter excess bandwidth (typically 0.35-0.5) amplitude # DAC output level, 0-32767, typically 2000-8000 ): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature # Create BERT data bit stream self._bits = gr.vector_source_b([1,], True) # Infinite stream of ones self._scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit scrambler # Map to constellation self._constellation = [-1+0j, 1+0j] self._mapper = gr.chunks_to_symbols_bc(self._constellation) # Create RRC with specified excess bandwidth taps = gr.firdes.root_raised_cosine(sps*amplitude, # Gain sps, # Sampling rate 1.0, # Symbol rate excess_bw, # Roll-off factor 11*sps) # Number of taps self._rrc = gr.interp_fir_filter_ccf(sps, # Interpolation rate taps) # FIR taps # Wire block inputs and outputs self.connect(self._bits, self._scrambler, self._mapper, self._rrc, self)
def test_002_square2_ff (self): #src_data = (7, -3, 4, -5.5, 2, 3, 5) #src_coeff = (1, 1, 2, 2, 3) src_data0 = (0.01+0.11j, 0.02+0.22j, 0.03+0.33j, 0.04+0.44j, 0.05+0.55j, 0.06+0.66j, 0.07+0.77j, 0.08+0.88j, 0.09+0.99j) #src_data1 = (0.11, 0.22, 0.33, 0.44, 0.55, 0.66, 0.77, 0.88, 0.99) src_coeff = (0.101, 0.102, 0.103, 0.104, 0.105) scale = 1000 #expected_result = (9, 16, 30.25, 4, 9) #expected_result = (49, 9, 16, 30.20000076, 4, 9, 25) expected_result = (245, 320, 395, 470, 445, 400, 334, 246, 135) src0 = gr.vector_source_c (src_data0) #src1 = gr.vector_source_f (src_data1) #sqr = dsp.fir_ccf (src_coeff, scale, 2) ftoc = gr.float_to_complex () ctof = gr.complex_to_float () gccf = gr.interp_fir_filter_ccf (2, src_coeff) dst0 = gr.vector_sink_c () #dst1 = gr.vector_sink_f () mpoints = 4 taps = gr.firdes.low_pass(1, 1, 1.0/mpoints * 0.4, 1.0/mpoints * 0.1, gr.firdes.WIN_HANN) #print "The length of FILTER is" #print len(taps) #print "The length of FILTER is %d." %len(taps) #print taps #howto.set_taps() #self.tb.connect (src0, (sqr, 0)) #self.tb.connect (src1, (sqr, 1)) #self.tb.connect ((sqr, 0), dst0) #self.tb.connect ((sqr, 1), dst1) #self.tb.connect (src0, (ftoc, 0)) #self.tb.connect (src1, (ftoc, 1)) #self.tb.connect (ftoc, gccf) #self.tb.connect (gccf, ctof) #self.tb.connect ((ctof, 0), dst0) #self.tb.connect ((ctof, 1), dst1) self.tb.connect (src0, gccf) self.tb.connect (gccf, dst0) #self.tb.connect (src0, sqr) #self.tb.connect (sqr, dst0) self.tb.run () result_data0 = dst0.data () print result_data0
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1000000 self.dec_rate = dec_rate = 2 ################################################## # 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(1000000) self.uhd_usrp_source_0.set_center_freq(2400490000, 0) self.uhd_usrp_source_0.set_gain(0, 0) self.low_pass_filter_0_0 = gr.interp_fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 500000, 10000, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = gr.fir_filter_fff( 1, firdes.low_pass(1, samp_rate, 500000, 10000, firdes.WIN_HAMMING, 6.76)) self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf(1) self.gr_pwr_squelch_xx_0 = gr.pwr_squelch_cc(-100, 0.001, 0, True) self.flysky_dumpsync_0 = flysky.dumpsync() self.digital_correlate_access_code_bb_0_1 = digital.correlate_access_code_bb( "010101010101010101010101010101010101010001110101", 1) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff( 2, 0.0076562, 0.5, 0.175, 0.005) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() ################################################## # Connections ################################################## self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.gr_quadrature_demod_cf_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.gr_pwr_squelch_xx_0, 0), (self.gr_quadrature_demod_cf_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.gr_pwr_squelch_xx_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.digital_correlate_access_code_bb_0_1, 0)) self.connect((self.digital_correlate_access_code_bb_0_1, 0), (self.flysky_dumpsync_0, 0))
def __init__(self, principal_gui, options): gr.hier_block2.__init__(self, "bpsk_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature #Enter the parameters of modulation self._samples_per_symbol = options.samples_per_symbol self.verbose = options.verbose self._gray_code =_def_gray_code if self._samples_per_symbol < 2: raise TypeError, "samples_per_symbol must be >= 2, is %r" % (self._samples_per_symbol,) arity = pow(2,self.bits_per_symbol()) # Automatic gain control #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100) self.agc = gr.agc_cc(1e-5, 1.0,1.0,1.0) #self.agc = gr.feedforward_agc_cc(16, 2.0) # RRC data filter ntaps = 11 * self._samples_per_symbol self.rrc_taps = gr.firdes.root_raised_cosine( 1.0, # gain self._samples_per_symbol, # sampling rate 1.0, # symbol rate 0.35, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter=gr.interp_fir_filter_ccf(1, self.rrc_taps) self._costas = digital.costas_loop_cc(6.28/100.0, 2) self.gr_null_sink = gr.null_sink(gr.sizeof_float*1) self.connect((self._costas, 1), (self.gr_null_sink, 0)) self._mm = digital.clock_recovery_mm_cc(self._samples_per_symbol, # Initial samples/symbol 1e-06, # Second order gain 0.5, # Initial symbol phase 0.001, # First order gain 0.0001) # Maximum timing offset if self.verbose: self._print_verbage() # Do differential decoding based on phase change of symbols #self.diffdec = gr.diff_phasor_cc() # Connect and Initialize base class self.connect(self, self.agc, self.rrc_filter, (self._costas,0), self._mm, self)
def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset, mode=0): gr.top_block.__init__(self) rrc_taps = gr.firdes.root_raised_cosine( sps, sps, 1.0, rolloff, ntaps) gain = 2*scipy.pi/100.0 nfilts = 32 rrc_taps_rx = gr.firdes.root_raised_cosine( nfilts, sps*nfilts, 1.0, rolloff, ntaps*nfilts) data = 2.0*scipy.random.randint(0, 2, N) - 1.0 data = scipy.exp(1j*poffset) * data self.src = gr.vector_source_c(data.tolist(), False) self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps) self.chn = gr.channel_model(noise, foffset, toffset) self.off = gr.fractional_interpolator_cc(0.20, 1.0) if mode == 0: self.clk = gr.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx, nfilts, nfilts//2, 3.5) self.taps = self.clk.get_taps() self.dtaps = self.clk.get_diff_taps() self.vsnk_err = gr.vector_sink_f() self.vsnk_rat = gr.vector_sink_f() self.vsnk_phs = gr.vector_sink_f() self.connect((self.clk,1), self.vsnk_err) self.connect((self.clk,2), self.vsnk_rat) self.connect((self.clk,3), self.vsnk_phs) else: # mode == 1 mu = 0.5 gain_mu = 0.1 gain_omega = 0.25*gain_mu*gain_mu omega_rel_lim = 0.02 self.clk = digital.clock_recovery_mm_cc(sps, gain_omega, mu, gain_mu, omega_rel_lim) self.vsnk_err = gr.vector_sink_f() self.connect((self.clk,1), self.vsnk_err) self.vsnk_src = gr.vector_sink_c() self.vsnk_clk = gr.vector_sink_c() self.connect(self.src, self.rrc, self.chn, self.off, self.clk, self.vsnk_clk) self.connect(self.off, self.vsnk_src)
def test01(self): sps = 4 rolloff = 0.35 bw = 2 * math.pi / 100.0 ntaps = 45 # Create pulse shape filter #rrc_taps = gr.firdes.root_raised_cosine( # sps, sps, 1.0, rolloff, ntaps) rrc_taps = taps # The frequency offset to correct foffset = 0.2 / (2.0 * math.pi) # Create a set of 1's and -1's, pulse shape and interpolate to sps random.seed(0) data = [2.0 * random.randint(0, 2) - 1.0 for i in xrange(200)] self.src = gr.vector_source_c(data, False) self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps) # Mix symbols with a complex sinusoid to spin them self.nco = gr.sig_source_c(1, gr.GR_SIN_WAVE, foffset, 1) self.mix = gr.multiply_cc() # FLL will despin the symbols to an arbitrary phase self.fll = digital_swig.fll_band_edge_cc(sps, rolloff, ntaps, bw) # Create sinks for all outputs of the FLL # we will only care about the freq and error outputs self.vsnk_frq = gr.vector_sink_f() self.nsnk_fll = gr.null_sink(gr.sizeof_gr_complex) self.nsnk_phs = gr.null_sink(gr.sizeof_float) self.nsnk_err = gr.null_sink(gr.sizeof_float) # Connect the blocks self.tb.connect(self.nco, (self.mix, 1)) self.tb.connect(self.src, self.rrc, (self.mix, 0)) self.tb.connect(self.mix, self.fll, self.nsnk_fll) self.tb.connect((self.fll, 1), self.vsnk_frq) self.tb.connect((self.fll, 2), self.nsnk_phs) self.tb.connect((self.fll, 3), self.nsnk_err) self.tb.run() N = 700 dst_data = self.vsnk_frq.data()[N:] expected_result = len(dst_data) * [ -0.20, ] self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 4)
def __init__(self, fg, spb, alpha, gain, use_barker=0): if not isinstance(spb, int) or spb < 2: raise TypeError, "sbp must be an integer >= 2" self.spb = spb self.bits_per_chunk = 1 ntaps = 2 * spb - 1 alpha = 0.5 self.bytes2chunks = gr.packed_to_unpacked_bb(self.bits_per_chunk, gr.GR_MSB_FIRST) constellation = ( (), ( -1-0j,1+0j ), ( 0.707+0.707j,-0.707-0.707j ), ( 0.707+0j,-0.707-0.707j ), ( -1+0j,-1j, 1j, 1+0j ), ( 1+0j,0+1j,-1+0j,0-1j ), ( 0+0j,1+0j ) ) self.chunks2symbols = gr.chunks_to_symbols_bc(constellation[2]) self.scrambler = bbn.scrambler_bb(True) self.diff_encode = gr.diff_encoder_bb(2); self.barker_taps = bbn.firdes_barker(spb) self.rrc_taps = gr.firdes.root_raised_cosine(4 * gain, spb, 1.0, alpha, ntaps) if use_barker: self.tx_filter = gr.interp_fir_filter_ccf(spb, self.barker_taps) else: self.tx_filter = gr.interp_fir_filter_ccf(spb, self.rrc_taps) fg.connect(self.scrambler, self.bytes2chunks) fg.connect(self.bytes2chunks, self.diff_encode) fg.connect(self.diff_encode, self.chunks2symbols) fg.connect(self.chunks2symbols,self.tx_filter) gr.hier_block.__init__(self, fg, self.scrambler, self.tx_filter) bbn.crc16_init()
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-c", "--calibration", type="int", default=0, help="freq offset") parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file") parser.add_option("-l", "--log", action="store_true", default=False, help="dump debug .dat files") parser.add_option("-L", "--low-pass", type="eng_float", default=15e3, help="low pass cut-off", metavar="Hz") parser.add_option("-o", "--output-file", type="string", default="out.dat", help="specify the output file") parser.add_option("-s", "--sample-rate", type="int", default=250000, help="input sample rate") parser.add_option("-v", "--verbose", action="store_true", default=False, help="dump demodulation data") (options, args) = parser.parse_args() sample_rate = options.sample_rate symbol_rate = 4800 sps = 10 # output rate will be 48,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps lcm = gru.lcm(sample_rate, new_sample_rate) interp = lcm // sample_rate decim = lcm // new_sample_rate channel_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("interp: %d decim: %d\n" %(interp, decim)) bpf_taps = gr.firdes.low_pass(1.0, sample_rate * interp, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) INTERPOLATOR = gr.interp_fir_filter_ccf (int(interp), bpf_taps) DECIMATOR = blks2.rational_resampler_ccf(1, int(decim)) IN = gr.file_source(gr.sizeof_gr_complex, options.input_file) DEMOD = blks2.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) msgq = gr.msg_queue() DECODER = fsk4.apco25_f(msgq,0) self.connect(IN, FILTER, INTERPOLATOR, DECIMATOR, DEMOD, DECODER)
def test01 (self): sps = 4 rolloff = 0.35 bw = 2*math.pi/100.0 ntaps = 45 # Create pulse shape filter #rrc_taps = gr.firdes.root_raised_cosine( # sps, sps, 1.0, rolloff, ntaps) rrc_taps = taps # The frequency offset to correct foffset = 0.2 / (2.0*math.pi) # Create a set of 1's and -1's, pulse shape and interpolate to sps random.seed(0) data = [2.0*random.randint(0, 2) - 1.0 for i in xrange(200)] self.src = gr.vector_source_c(data, False) self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps) # Mix symbols with a complex sinusoid to spin them self.nco = gr.sig_source_c(1, gr.GR_SIN_WAVE, foffset, 1) self.mix = gr.multiply_cc() # FLL will despin the symbols to an arbitrary phase self.fll = digital_swig.fll_band_edge_cc(sps, rolloff, ntaps, bw) # Create sinks for all outputs of the FLL # we will only care about the freq and error outputs self.vsnk_frq = gr.vector_sink_f() self.nsnk_fll = gr.null_sink(gr.sizeof_gr_complex) self.nsnk_phs = gr.null_sink(gr.sizeof_float) self.nsnk_err = gr.null_sink(gr.sizeof_float) # Connect the blocks self.tb.connect(self.nco, (self.mix,1)) self.tb.connect(self.src, self.rrc, (self.mix,0)) self.tb.connect(self.mix, self.fll, self.nsnk_fll) self.tb.connect((self.fll,1), self.vsnk_frq) self.tb.connect((self.fll,2), self.nsnk_phs) self.tb.connect((self.fll,3), self.nsnk_err) self.tb.run() N = 700 dst_data = self.vsnk_frq.data()[N:] expected_result = len(dst_data)* [-0.20,] self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1000000 self.dec_rate = dec_rate = 2 ################################################## # 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(1000000) self.uhd_usrp_source_0.set_center_freq(2400490000, 0) self.uhd_usrp_source_0.set_gain(0, 0) self.low_pass_filter_0_0 = gr.interp_fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 500000, 10000, firdes.WIN_HAMMING, 6.76) ) self.low_pass_filter_0 = gr.fir_filter_fff( 1, firdes.low_pass(1, samp_rate, 500000, 10000, firdes.WIN_HAMMING, 6.76) ) self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf(1) self.gr_pwr_squelch_xx_0 = gr.pwr_squelch_cc(-100, 0.001, 0, True) self.flysky_dumpsync_0 = flysky.dumpsync() self.digital_correlate_access_code_bb_0_1 = digital.correlate_access_code_bb( "010101010101010101010101010101010101010001110101", 1 ) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(2, 0.0076562, 0.5, 0.175, 0.005) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() ################################################## # Connections ################################################## self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.gr_quadrature_demod_cf_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.gr_pwr_squelch_xx_0, 0), (self.gr_quadrature_demod_cf_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.gr_pwr_squelch_xx_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.digital_correlate_access_code_bb_0_1, 0)) self.connect((self.digital_correlate_access_code_bb_0_1, 0), (self.flysky_dumpsync_0, 0))
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) tb = gr.top_block () src0 = gr.file_source (gr.sizeof_gr_complex,infile) lp_coeffs = gr.firdes.low_pass ( 3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING ) lp = gr.interp_fir_filter_ccf ( 1, lp_coeffs ) file = gr.file_sink(gr.sizeof_gr_complex,"/tmp/atsc_pipe_1") tb.connect( src0, lp, file ) tb.start() raw_input ('Head End: Press Enter to stop') tb.stop()
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) tb = gr.top_block() src0 = gr.file_source(gr.sizeof_gr_complex, infile) lp_coeffs = gr.firdes.low_pass(3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING) lp = gr.interp_fir_filter_ccf(1, lp_coeffs) file = gr.file_sink(gr.sizeof_gr_complex, "/tmp/atsc_pipe_1") tb.connect(src0, lp, file) tb.start() raw_input('Head End: Press Enter to stop') tb.stop()
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-c", "--calibration", type="int", default=0, help="freq offset") parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file") parser.add_option("-l", "--log", action="store_true", default=False, help="dump debug .dat files") parser.add_option("-L", "--low-pass", type="eng_float", default=15e3, help="low pass cut-off", metavar="Hz") parser.add_option("-o", "--output-file", type="string", default="out.dat", help="specify the output file") parser.add_option("-s", "--sample-rate", type="int", default=250000, help="input sample rate") parser.add_option("-v", "--verbose", action="store_true", default=False, help="dump demodulation data") (options, args) = parser.parse_args() sample_rate = options.sample_rate symbol_rate = 4800 sps = 10 # output rate will be 48,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps lcm = gru.lcm(sample_rate, new_sample_rate) interp = lcm // sample_rate decim = lcm // new_sample_rate channel_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("interp: %d decim: %d\n" % (interp, decim)) bpf_taps = gr.firdes.low_pass(1.0, sample_rate * interp, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) INTERPOLATOR = gr.interp_fir_filter_ccf(int(interp), bpf_taps) DECIMATOR = blks2.rational_resampler_ccf(1, int(decim)) IN = gr.file_source(gr.sizeof_gr_complex, options.input_file) DEMOD = blks2.cqpsk_demod(samples_per_symbol=sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) msgq = gr.msg_queue() DECODER = fsk4.apco25_f(msgq, 0) self.connect(IN, FILTER, INTERPOLATOR, DECIMATOR, DEMOD, DECODER)
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, costas_alpha=_def_costas_alpha, gain_mu=_def_gain_mu, mu=_def_mu, omega_relative_limit=_def_omega_relative_limit, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered DQPSK demodulation The input is the complex modulated signal at baseband. The output is a stream of bits packed 1 bit per byte (LSB) @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: float @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param costas_alpha: loop filter gain @type costas_alphas: float @param gain_mu: for M&M block @type gain_mu: float @param mu: for M&M block @type mu: float @param omega_relative_limit: for M&M block @type omega_relative_limit: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__( self, "dqpsk_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._costas_alpha = costas_alpha self._mm_gain_mu = gain_mu self._mm_mu = mu self._mm_omega_relative_limit = omega_relative_limit self._gray_code = gray_code if samples_per_symbol < 2: raise TypeError, "sbp must be >= 2, is %d" % samples_per_symbol arity = pow(2, self.bits_per_symbol()) # Automatic gain control scale = (1.0 / 16384.0) self.pre_scaler = gr.multiply_const_cc( scale) # scale the signal from full-range to +-1 #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100) self.agc = gr.feedforward_agc_cc(16, 2.0) # RRC data filter ntaps = 11 * samples_per_symbol self.rrc_taps = gr.firdes.root_raised_cosine( 1.0, # gain self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(1, self.rrc_taps) if not self._mm_gain_mu: sbs_to_mm = { 2: 0.050, 3: 0.075, 4: 0.11, 5: 0.125, 6: 0.15, 7: 0.15 } self._mm_gain_mu = sbs_to_mm[samples_per_symbol] self._mm_omega = self._samples_per_symbol self._mm_gain_omega = .25 * self._mm_gain_mu * self._mm_gain_mu self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha fmin = -0.25 fmax = 0.25 self.receiver = gr.mpsk_receiver_cc( arity, pi / 4.0, self._costas_alpha, self._costas_beta, fmin, fmax, self._mm_mu, self._mm_gain_mu, self._mm_omega, self._mm_gain_omega, self._mm_omega_relative_limit) # Perform Differential decoding on the constellation self.diffdec = gr.diff_phasor_cc() # find closest constellation point rot = 1 rotated_const = map(lambda pt: pt * rot, psk.constellation[arity]) self.slicer = gr.constellation_decoder_cb(rotated_const, range(arity)) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.gray_to_binary[arity]) else: self.symbol_mapper = gr.map_bb(psk.ungray_to_binary[arity]) # unpack the k bit vector into a stream of bits self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol()) if verbose: self._print_verbage() if log: self._setup_logging() # Connect & Initialize base class self.connect(self, self.pre_scaler, self.agc, self.rrc_filter, self.receiver, self.diffdec, self.slicer, self.symbol_mapper, self.unpack, self)
def __init__(self, options): gr.top_block.__init__(self, "ofdm_mrrc_benchmark") ##self._tx_freq = options.tx_freq # tranmitter's center frequency ##self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use ##self._fusb_block_size = options.fusb_block_size # usb info for USRP ##self._fusb_nblocks = options.fusb_nblocks # usb info for USRP ##self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose ##self._interface = options.interface ##self._mac_addr = options.mac_addr self._options = copy.copy(options) self._interpolation = 1 f1 = numpy.array([ -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0, 82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959, 0, -1271, 0, 445, 0, -107 ], numpy.float64) / 262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0 / self._interpolation tb = bw / 5 if self._interpolation > 1: self.tx_filter = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.tx_filter2 = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.tx_filter.connect(self.tx_filter, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.tx_filter) self.tx_filter2.connect(self.tx_filter2, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.tx_filter2) print "New" else: self.tx_filter = None self.tx_filter2 = None self.decimation = 1 if self.decimation > 1: bw = 0.5 / self.decimation * 1 tb = bw / 5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw + tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation, filt_coeff) self.rx_filter2 = gr.fir_filter_ccf(self.decimation, filt_coeff) else: self.rx_filter = None self.rx_filter2 = None ## if not options.from_file is None: ## # sent captured file to usrp ## self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file) ## self._setup_usrp_sink() ## if hasattr(self, "filter"): ## self.connect(self.src,self.filter,self.u) #,self.filter ## else: ## self.connect(self.src,self.u) ## ## return self._setup_tx_path(options) self._setup_rx_path(options) self._setup_rpc_manager() config = self.config = station_configuration() #self.enable_txfreq_adjust("txfreq") if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() self.dst = (self.rxpath, 0) self.dst2 = (self.rxpath, 1) if options.force_rx_filter: print "Forcing rx filter usage" self.connect(self.rx_filter, self.dst) self.connect(self.rx_filter2, self.dst2) self.dst = self.rx_filter self.dst2 = self.rx_filter2 if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.m2 = throughput_measure(gr.sizeof_gr_complex) self.connect(self.m, self.dst) self.connect(self.m2, self.dst2) self.dst = self.m self.dst2 = self.m2 if options.snr is not None: if options.berm is not None: noise_sigma = 380 / 32767.0 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py print " Noise St. Dev. %f" % (noise_sigma ) #check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db / 10.0) noise_sigma = sqrt(config.rms_amplitude**2 / snr) print " Noise St. Dev. %f" % (noise_sigma) awgn_chan = blocks.add_cc() awgn_chan2 = blocks.add_cc() awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192) awgn_noise_src2 = analog.fastnoise_source_c( analog.GR_GAUSSIAN, noise_sigma * 2, 0, 2192) self.connect(awgn_chan, self.dst) self.connect(awgn_chan2, self.dst2) self.connect(awgn_noise_src, (awgn_chan, 1)) self.connect(awgn_noise_src2, (awgn_chan2, 1)) self.dst = awgn_chan self.dst2 = awgn_chan2 if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff) freq_off2 = self.freq_off2 = channel.freq_offset(options.freqoff) dst = self.dst dst2 = self.dst2 self.connect(freq_off, dst) self.connect(freq_off2, dst2) self.dst = freq_off self.dst2 = freq_off2 self.rpc_mgr_tx.add_interface("set_freq_offset", self.freq_off.set_freqoff) self.rpc_mgr_tx.add_interface("set_freq_offset2", self.freq_off2.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) self.fad_chan2 = channel.itpp_channel(options.bandwidth) self.fad_chan.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8) self.fad_chan.set_norm_doppler(1e-8) self.fad_chan2.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8) self.fad_chan2.set_norm_doppler(1e-8) self.rpc_mgr_tx.add_interface( "set_channel_profile", self.fad_chan.set_channel_profile) self.rpc_mgr_tx.add_interface( "set_channel_profile", self.fad_chan2.set_channel_profile) else: fad_chan = filter.fir_filter_ccc( 1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j]) fad_chan2 = filter.fir_filter_ccc( 1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j]) self.connect(self.fad_chan, self.dst) self.connect(self.fad_chan2, self.dst2) self.dst = self.fad_chan self.dst2 = self.fad_chan2 if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000 * (1.0 + soff), 1000000) interp2 = moms(1000000 * (1.0 + soff), 1000000) self.connect(interp, self.dst) self.connect(interp2, self.dst2) self.dst = interp self.dst2 = interp2 if options.record: log_to_file(self, interp, "data/interp_out.compl") log_to_file(self, interp2, "data/interp2_out.compl") tmm = blocks.throttle(gr.sizeof_gr_complex, 1e6) #tmm2 =blocks.throttle(gr.sizeof_gr_complex, 1e6) #self.connect( tmm, self.dst ) #self.connect( tmm2, self.dst2 ) #self.dst = tmm #self.dst2 = tmm2 #inter = blocks.interleave(gr.sizeof_gr_complex) #deinter = blocks.deinterleave(gr.sizeof_gr_complex) # Interleaving input/output streams ##self.connect(inter, deinter) #self.connect((deinter,0),self.dst) #self.connect((deinter,1),self.dst2) #self.dst = inter #self.dst2 = (inter,1) if options.force_tx_filter: print "Forcing tx filter usage" self.connect(self.tx_filter, self.dst) self.connect(self.tx_filter2, self.dst2) self.dst = self.tx_filter self.dst2 = self.tx_filter2 if options.record: log_to_file(self, self.txpath, "data/txpath_out.compl") log_to_file(self, self.txpath2, "data/txpath2_out.compl") if options.nullsink: self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst) self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2) self.dst = gr.null_sink(gr.sizeof_gr_complex) self.dst2 = gr.null_sink(gr.sizeof_gr_complex) self.connect(self.txpath, tmm, self.dst) self.connect(tmm, self.dst2) #self.connect( self.txpath,self.dst2 ) print "Hit Strg^C to terminate" if self._verbose: self._print_verbage()
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered QPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__( self, "qam8_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._gray_code = gray_code if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % samples_per_symbol) ntaps = 11 * samples_per_symbol arity = pow(2, self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(qam.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(qam.binary_to_ungray[arity]) self.diffenc = gr.diff_encoder_bb(arity) rot = 1.0 print "constellation with %d arity" % arity rotated_const = map(lambda pt: pt * rot, qam.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_bc(rotated_const) # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self. _samples_per_symbol, # gain (sps since we're interpolating by sps) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) if verbose: self._print_verbage() if log: self._setup_logging() # Connect self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter, self)
def __init__(self, options): gr.top_block.__init__(self, "ofdm_tx") self._tx_freq = options.tx_freq # tranmitter's center frequency self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use self._fusb_block_size = options.fusb_block_size # usb info for USRP self._fusb_nblocks = options.fusb_nblocks # usb info for USRP self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._interface = options.interface self._mac_addr = options.mac_addr self._options = copy.copy(options) self._interpolation = 1 f1 = numpy.array([ -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0, 82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959, 0, -1271, 0, 445, 0, -107 ], numpy.float64) / 262144. print "Software interpolation: %d" % (self._interpolation) bw = 0.5 / self._interpolation tb = bw / 5 if self._interpolation > 1: self.filter = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.filter.connect(self.filter, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.filter) print "New" # # # self.filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.2, 60.0, 0) # self.filter = gr.interp_fir_filter_ccf(self._interpolation,self.filt_coeff) # print "Software interpolation filter length: %d" % (len(self.filt_coeff)) else: self.filter = None if not options.from_file is None: # sent captured file to usrp self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file) self._setup_usrp_sink() if hasattr(self, "filter"): self.connect(self.src, self.filter, self.u) #,self.filter else: self.connect(self.src, self.u) return self._setup_tx_path(options) config = station_configuration() self.enable_info_tx("info_tx", "pa_user") # if not options.no_cheat: # self.txpath.enable_channel_cheating("channelcheat") self.txpath.enable_txpower_adjust("txpower") self.txpath.publish_txpower("txpower_info") #self.enable_txfreq_adjust("txfreq") if options.nullsink: self.dst = gr.null_sink(gr.sizeof_gr_complex) self.dst_2 = gr.null_sink(gr.sizeof_gr_complex) else: if not options.to_file is None: # capture transmitter's stream to disk self.dst = gr.file_sink(gr.sizeof_gr_complex, options.to_file) self.dst_2 = gr.file_sink(gr.sizeof_gr_complex, options.to_file) tmp = gr.throttle(gr.sizeof_gr_complex, 1e5) tmp_2 = gr.throttle(gr.sizeof_gr_complex, 1e5) self.connect(tmp, self.dst) self.connect(tmp_2, self.dst_2) self.dst = tmp self.dst_2 = tmp_2 if options.force_filter: print "Forcing filter usage" self.connect(self.filter, self.dst) self.dst = self.filter else: # connect transmitter to usrp self._setup_usrp_sink() if options.dyn_freq: self.enable_txfreq_adjust("txfreq") if self.filter is not None: self.connect(self.filter, self.dst) self.dst = self.filter if options.record: log_to_file(self, self.txpath, "data/txpath_out.compl") #self.publish_spectrum( 256 ) if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.connect(self.m, self.dst) self.dst = self.m if options.samplingoffset is not None: soff = options.samplingoffset interp = gr.fractional_interpolator_cc(0.0, soff) self.connect(interp, self.dst) self.dst = interp if options.snr is not None: # if options.berm is not None: # noise_sigma = 380 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py # #check for fading channel # else: snr_db = options.snr snr = 10.0**(snr_db / 10.0) noise_sigma = sqrt(config.rms_amplitude**2 / snr) print " Noise St. Dev. %d" % (noise_sigma) awgn_chan = gr.add_cc() awgn_noise_src = ofdm.complex_white_noise(0.0, noise_sigma) self.connect(awgn_noise_src, (awgn_chan, 1)) self.connect(awgn_chan, self.dst) self.dst = awgn_chan if options.berm is False: fad_chan = itpp.tdl_channel() #[0, -7, -20], [0, 2, 6] #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) fad_chan.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8) fad_chan.set_norm_doppler(1e-8) # fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect(fad_chan, self.dst) self.dst = fad_chan if options.freqoff is not None: freq_shift = gr.multiply_cc() norm_freq = options.freqoff / config.fft_length freq_off_src = gr.sig_source_c(1.0, gr.GR_SIN_WAVE, norm_freq, 1.0, 0.0) self.connect(freq_off_src, (freq_shift, 1)) dst = self.dst self.connect(freq_shift, dst) self.dst = freq_shift self.connect((self.txpath, 0), self.dst) self.connect((self.txpath, 1), self.dst_2) if options.cheat: self.txpath.enable_channel_cheating("channelcheat") print "Hit Strg^C to terminate"
def __init__(self, principal_gui, options): gr.hier_block2.__init__(self, "bpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = options.sps self.amplitude = options.amplitude self.verbose = options.verbose self._excess_bw = _def_excess_bw self._gray_code = _def_gray_code if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: raise TypeError, ("sample per symbol must be an integer >= 2, is %d" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) #arity = pow (2, 2) # turn bytes into k-bit vectors self.packed_to_unpacked_bb = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: map_param = psk.binary_to_gray[arity] self.symbol_mapper = gr.map_bb(map_param) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diff_encoder_bb = gr.diff_encoder_bb(arity) #This bloc allow to decode the stream #self.scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) #Transform symbols to chips self.symbols_to_chips = ieee.symbols_to_chips_bs() #self.chunks2symbols = gr.chunks_to_symbols_ic(psk.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_sc([-1+0j, 1+0j]) self.chunks2symbols_b = gr.chunks_to_symbols_bc([-1+0j, 1+0j]) # transform chips to symbols print "bits_per_symbol", self.bits_per_symbol() self.packed_to_unpacked_ss = \ gr.packed_to_unpacked_ss(self.bits_per_symbol(), gr.GR_MSB_FIRST) ntaps = 11 * self._samples_per_symbol # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol, # gain (samples_per_symbol since we're # interpolating by samples_per_symbol) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) # Connect #self.connect(self, self.bytes2chunks, self.symbol_mapper,self.scrambler, self.chunks2symbols, self.rrc_filter, self) #Modefied for IEEE 802.15.4 #self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.diff_encoder_bb, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #For IEEE 802.15.4 915 868 MHz standard self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #case when we use a stream of bits #self.connect(self, self.chunks2symbols_b, self.rrc_filter, self) if self.verbose: self._print_verbage()
def __init__(self, options): gr.top_block.__init__(self, "ofdm_benchmark") self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose self._options = copy.copy(options) self.ideal = options.ideal self.ideal2 = options.ideal2 rms_amp = options.rms_amplitude self._interpolation = 1 f1 = numpy.array([ -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0, 82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959, 0, -1271, 0, 445, 0, -107 ], numpy.float64) / 262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0 / self._interpolation tb = bw / 5 if self._interpolation > 1: self.tx_filter = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.tx_filter.connect(self.tx_filter, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.tx_filter) print "New" else: self.tx_filter = None self.decimation = 1 if self.decimation > 1: bw = 0.5 / self.decimation * 1 tb = bw / 5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw + tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation, filt_coeff) else: self.rx_filter = None self._setup_tx_path(options) self._setup_rx_path(options) self._setup_rpc_manager() config = self.config = station_configuration() if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() # capture transmitter's stream to disk #self.dst = gr.file_sink(gr.sizeof_gr_complex,options.to_file) self.dst = self.rxpath if options.force_rx_filter: print "Forcing rx filter usage" self.connect(self.rx_filter, self.dst) self.dst = self.rx_filter if options.ideal or self.ideal2: self._amplifier = ofdm.multiply_const_ccf(1.0) self.connect(self._amplifier, self.dst) self.dst = self._amplifier self.set_rms_amplitude(rms_amp) if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.connect(self.m, self.dst) self.dst = self.m if options.snr is not None: if options.berm is not None: noise_sigma = 380 / 32767.0 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py #check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db / 10.0) noise_sigma = sqrt(config.rms_amplitude**2 / snr) print " Noise St. Dev. %f" % (noise_sigma) awgn_chan = blocks.add_cc() #awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma ) awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192) self.connect(awgn_noise_src, (awgn_chan, 1)) self.connect(awgn_chan, self.dst) self.dst = awgn_chan if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff) dst = self.dst self.connect(freq_off, dst) self.dst = freq_off self.rpc_mgr_tx.add_interface("set_freq_offset", self.freq_off.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) self.rpc_mgr_tx.add_interface( "set_channel_profile", self.fad_chan.set_channel_profile) self.rpc_mgr_tx.add_interface("set_norm_doppler", self.fad_chan.set_norm_doppler) else: #self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) # filter coefficients for the lab exercise self.fad_chan = filter.fir_filter_ccc(1, [0.3267, 0.8868, 0.3267]) #self.fad_chan = filter.fir_filter_ccc(1,[0,0,0.1,0.2,0.01,0.3])#0.3267,0.8868,0.3267]) #self.fad_chan = channels.selective_fading_model(5, 0.1, False, 1, -1, [0, 0, 0], [0.3267,0.8868,0.3267], 10 ) #self.fad_chan = channels.fading_model(6, 0.05, False); #self.fad_chan = channels.dynamic_channel_model(1000000, 0, 0, 0, 0, 3, 0.01, False, 0, [2e-6,4e-6,8e-6],[0.3267,0.8868,0.3267], 20, 0, 0) self.connect(self.fad_chan, self.dst) self.dst = self.fad_chan if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000 * (1.0 + soff), 1000000) #interp = filter.fractional_resampler_cc(0,1000000*(1.0+soff)/1000000.0) self.connect(interp, self.dst) self.dst = interp if options.record: log_to_file(self, interp, "data/interp_out.compl") tmm = blocks.throttle(gr.sizeof_gr_complex, options.bandwidth) self.connect(tmm, self.dst) self.dst = tmm if options.force_tx_filter: print "Forcing tx filter usage" self.connect(self.tx_filter, self.dst) self.dst = self.tx_filter if options.record: log_to_file(self, self.txpath, "data/txpath_out.compl") if options.scatterplot: print "Scatterplot enabled" self.connect(self.txpath, self.dst) print "Hit Strg^C to terminate" print "Hit Strg^C to terminate" # Display some information about the setup if self._verbose: self._print_verbage()
def __init__(self, fg, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, costas_alpha=_def_costas_alpha, gain_mu=_def_gain_mu, mu=_def_mu, omega_relative_limit=_def_omega_relative_limit, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered DQPSK demodulation The input is the complex modulated signal at baseband. The output is a stream of bits packed 1 bit per byte (LSB) @param fg: flow graph @type fg: flow graph @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: float @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param costas_alpha: loop filter gain @type costas_alphas: float @param gain_mu: for M&M block @type gain_mu: float @param mu: for M&M block @type mu: float @param omega_relative_limit: for M&M block @type omega_relative_limit: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ self._fg = fg self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._costas_alpha = costas_alpha self._mm_gain_mu = gain_mu self._mm_mu = mu self._mm_omega_relative_limit = omega_relative_limit self._gray_code = gray_code if samples_per_symbol < 2: raise TypeError, "sbp must be >= 2, is %d" % samples_per_symbol arity = pow(2,self.bits_per_symbol()) # Automatic gain control scale = (1.0/16384.0) self.pre_scaler = gr.multiply_const_cc(scale) # scale the signal from full-range to +-1 #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100) self.agc = gr.feedforward_agc_cc(16, 2.0) # RRC data filter ntaps = 11 * samples_per_symbol self.rrc_taps = gr.firdes.root_raised_cosine( 1.0, # gain self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter=gr.interp_fir_filter_ccf(1, self.rrc_taps) if not self._mm_gain_mu: sbs_to_mm = {2: 0.050, 3: 0.075, 4: 0.11, 5: 0.125, 6: 0.15, 7: 0.15} self._mm_gain_mu = sbs_to_mm[samples_per_symbol] self._mm_omega = self._samples_per_symbol self._mm_gain_omega = .25 * self._mm_gain_mu * self._mm_gain_mu self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha fmin = -0.025 fmax = 0.025 self.receiver=gr.mpsk_receiver_cc(arity, pi/4.0, self._costas_alpha, self._costas_beta, fmin, fmax, self._mm_mu, self._mm_gain_mu, self._mm_omega, self._mm_gain_omega, self._mm_omega_relative_limit) # Perform Differential decoding on the constellation self.diffdec = gr.diff_phasor_cc() # find closest constellation point rot = 1 rotated_const = map(lambda pt: pt * rot, psk.constellation[arity]) self.slicer = gr.constellation_decoder_cb(rotated_const, range(arity)) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.gray_to_binary[arity]) else: self.symbol_mapper = gr.map_bb(psk.ungray_to_binary[arity]) # unpack the k bit vector into a stream of bits self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol()) if verbose: self._print_verbage() if log: self._setup_logging() # Connect & Initialize base class self._fg.connect(self.pre_scaler, self.agc, self.rrc_filter, self.receiver, self.diffdec, self.slicer, self.symbol_mapper, self.unpack) gr.hier_block.__init__(self, self._fg, self.pre_scaler, self.unpack)
def __init__ (self, options): gr.top_block.__init__(self, "ofdm_tx") self._tx_freq = options.tx_freq # tranmitter's center frequency self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use self._fusb_block_size = options.fusb_block_size # usb info for USRP self._fusb_nblocks = options.fusb_nblocks # usb info for USRP self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._interface = options.interface self._mac_addr = options.mac_addr self._options = copy.copy( options ) self._interpolation = 1 f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953, 0,-24706,0,82359,262144/2,82359,0,-24706,0, 11953,0,-6107,0,2959,0,-1271,0,445,0,-107], numpy.float64)/262144. print "Software interpolation: %d" % (self._interpolation) bw = 0.5/self._interpolation tb = bw/5 if self._interpolation > 1: self.filter = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.filter.connect( self.filter, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.filter ) print "New" # # # self.filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.2, 60.0, 0) # self.filter = gr.interp_fir_filter_ccf(self._interpolation,self.filt_coeff) # print "Software interpolation filter length: %d" % (len(self.filt_coeff)) else: self.filter = None if not options.from_file is None: # sent captured file to usrp self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file) self._setup_usrp_sink() if hasattr(self, "filter"): self.connect(self.src,self.filter,self.u) #,self.filter else: self.connect(self.src,self.u) return self._setup_tx_path(options) config = station_configuration() self.enable_info_tx("info_tx", "pa_user") # if not options.no_cheat: # self.txpath.enable_channel_cheating("channelcheat") self.txpath.enable_txpower_adjust("txpower") self.txpath.publish_txpower("txpower_info") #self.enable_txfreq_adjust("txfreq") if options.nullsink: self.dst = gr.null_sink( gr.sizeof_gr_complex ) else: if not options.to_file is None: # capture transmitter's stream to disk self.dst = gr.file_sink(gr.sizeof_gr_complex,options.to_file) tmp = gr.throttle(gr.sizeof_gr_complex,1e5) self.connect( tmp, self.dst ) self.dst = tmp if options.force_filter: print "Forcing filter usage" self.connect( self.filter, self.dst ) self.dst = self.filter else: # connect transmitter to usrp self._setup_usrp_sink() if options.dyn_freq: self.enable_txfreq_adjust("txfreq") if self.filter is not None: self.connect( self.filter,self.dst ) self.dst = self.filter if options.record: log_to_file( self, self.txpath, "data/txpath_out.compl" ) #self.publish_spectrum( 256 ) if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.connect( self.m, self.dst ) self.dst = self.m if options.samplingoffset is not None: soff = options.samplingoffset interp = gr.fractional_interpolator_cc(0.0,soff) self.connect( interp, self.dst ) self.dst = interp if options.snr is not None: # if options.berm is not None: # noise_sigma = 380 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py # #check for fading channel # else: snr_db = options.snr snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( config.rms_amplitude**2 / snr ) print " Noise St. Dev. %d" % (noise_sigma) awgn_chan = gr.add_cc() awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma ) self.connect( awgn_noise_src, (awgn_chan,1) ) self.connect( awgn_chan, self.dst ) self.dst = awgn_chan if options.berm is False: fad_chan = itpp.tdl_channel( ) #[0, -7, -20], [0, 2, 6] #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) fad_chan.set_norm_doppler( 1e-8 ) # fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect( fad_chan, self.dst ) self.dst = fad_chan if options.freqoff is not None: freq_shift = gr.multiply_cc() norm_freq = options.freqoff / config.fft_length freq_off_src = gr.sig_source_c(1.0, gr.GR_SIN_WAVE, norm_freq, 1.0, 0.0 ) self.connect( freq_off_src, ( freq_shift, 1 ) ) dst = self.dst self.connect( freq_shift, dst ) self.dst = freq_shift self.connect( self.txpath, self.dst ) if options.cheat: self.txpath.enable_channel_cheating("channelcheat") print "Hit Strg^C to terminate"
def __init__(self, fg, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered differential BPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param fg: flow graph @type fg: flow graph @param samples_per_symbol: samples per baud >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param log: Log modulation data to files? @type log: bool """ self._fg = fg self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._gray_code = gray_code if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % self._samples_per_symbol) ntaps = 11 * self._samples_per_symbol arity = pow(2,self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diffenc = gr.diff_encoder_bb(arity) self.chunks2symbols = gr.chunks_to_symbols_bc(psk.constellation[arity]) # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol, # gain (samples_per_symbol since we're # interpolating by samples_per_symbol) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) # Connect fg.connect(self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter) if verbose: self._print_verbage() if log: self._setup_logging() # Initialize base class gr.hier_block.__init__(self, self._fg, self.bytes2chunks, self.rrc_filter)
def __init__(self, fg, spb, alpha, gain, use_barker=0): """ Hierarchical block for RRC-filtered PSK modulation modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param fg: flow graph @type fg: flow graph @param spb: samples per baud >= 2 @type spb: integer @param alpha: Root-raised cosine filter excess bandwidth @type alpha: float """ if not isinstance(spb, int) or spb < 2: raise TypeError, "sbp must be an integer >= 2" self.spb = spb self.bits_per_chunk = 1 ntaps = 2 * spb - 1 alpha = 0.5 # turn bytes into symbols self.bytes2chunks = gr.packed_to_unpacked_bb(self.bits_per_chunk, gr.GR_MSB_FIRST) constellation = ( (), ( -1-0j,1+0j ), ( 0.707+0.707j,-0.707-0.707j ), ( 0.707+0j,-0.707-0.707j ), ( -1+0j,-1j, 1j, 1+0j), ( 1+0j,0+1j,-1+0j,0-1j ), ( 0+0j,1+0j ), ) self.chunks2symbols = gr.chunks_to_symbols_bc(constellation[2]) self.scrambler = bbn.scrambler_bb(True) self.diff_encode = gr.diff_encoder_bb(2); self.barker_taps = bbn.firdes_barker(spb) # Form Raised Cosine filter self.rrc_taps = gr.firdes.root_raised_cosine( 4 * gain, # gain FIXME may need to be spb spb, # sampling freq 1.0, # symbol_rate alpha, ntaps) if use_barker: self.tx_filter = gr.interp_fir_filter_ccf(spb, self.barker_taps) else: self.tx_filter = gr.interp_fir_filter_ccf(spb, self.rrc_taps) # Connect fg.connect(self.scrambler, self.bytes2chunks) fg.connect(self.bytes2chunks, self.diff_encode) fg.connect(self.diff_encode, self.chunks2symbols) fg.connect(self.chunks2symbols,self.tx_filter) # Initialize base class gr.hier_block.__init__(self, fg, self.scrambler, self.tx_filter) bbn.crc16_init()
def graph (args): nargs = len(args) if nargs == 2: infile = args[0] outfile = args[1] else: raise ValueError('usage: interp.py input_file output_file\n') tb = gr.top_block () # Convert to a from shorts to a stream of complex numbers. srcf = gr.file_source (gr.sizeof_short,infile) s2ss = gr.stream_to_streams(gr.sizeof_short,2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src0 = gr.float_to_complex() tb.connect(srcf, s2ss) tb.connect((s2ss, 0), s2f1, (src0, 0)) tb.connect((s2ss, 1), s2f2, (src0, 1)) # Low pass filter it and increase sample rate by a factor of 3. lp_coeffs = gr.firdes.low_pass ( 3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING ) lp = gr.interp_fir_filter_ccf ( 3, lp_coeffs ) tb.connect(src0, lp) # Upconvert it. 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 ) # Discard the imaginary component. c2f = gr.complex_to_float() tb.connect(lp, duc, c2f) # Frequency Phase Lock Loop 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() tb.connect(c2f, fpll, lp_filter) tb.connect(lp_filter, iir) tb.connect(lp_filter, (remove_dc,0)) tb.connect(iir, (remove_dc,1)) # Bit Timing Loop, Field Sync Checker and Equalizer btl = atsc.bit_timing_loop() fsc = atsc.fs_checker() eq = atsc.equalizer() fsd = atsc.field_sync_demux() tb.connect(remove_dc, btl) tb.connect((btl, 0),(fsc, 0),(eq, 0),(fsd, 0)) tb.connect((btl, 1),(fsc, 1),(eq, 1),(fsd, 1)) # Viterbi 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) tb.connect(fsd, viterbi, deinter, rs_dec, derand, depad, dst) dst2 = gr.file_sink(gr.sizeof_gr_complex, "atsc_complex.data") tb.connect(src0, dst2) tb.run ()
def graph(args): nargs = len(args) if nargs == 2: infile = args[0] outfile = args[1] else: raise ValueError('usage: interp.py input_file output_file\n') tb = gr.top_block() # Convert to a from shorts to a stream of complex numbers. srcf = gr.file_source(gr.sizeof_short, infile) s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src0 = gr.float_to_complex() tb.connect(srcf, s2ss) tb.connect((s2ss, 0), s2f1, (src0, 0)) tb.connect((s2ss, 1), s2f2, (src0, 1)) # Low pass filter it and increase sample rate by a factor of 3. lp_coeffs = gr.firdes.low_pass(3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING) lp = gr.interp_fir_filter_ccf(3, lp_coeffs) tb.connect(src0, lp) # Upconvert it. 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) # Discard the imaginary component. c2f = gr.complex_to_float() tb.connect(lp, duc, c2f) # Frequency Phase Lock Loop 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() tb.connect(c2f, fpll, lp_filter) tb.connect(lp_filter, iir) tb.connect(lp_filter, (remove_dc, 0)) tb.connect(iir, (remove_dc, 1)) # Bit Timing Loop, Field Sync Checker and Equalizer btl = atsc.bit_timing_loop() fsc = atsc.fs_checker() eq = atsc.equalizer() fsd = atsc.field_sync_demux() tb.connect(remove_dc, btl) tb.connect((btl, 0), (fsc, 0), (eq, 0), (fsd, 0)) tb.connect((btl, 1), (fsc, 1), (eq, 1), (fsd, 1)) # Viterbi 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) tb.connect(fsd, viterbi, deinter, rs_dec, derand, depad, dst) dst2 = gr.file_sink(gr.sizeof_gr_complex, "atsc_complex.data") tb.connect(src0, dst2) tb.run()
def __init__ (self, options): gr.top_block.__init__(self, "ofdm_benchmark") self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose self._options = copy.copy( options ) self.ideal = options.ideal self.ideal2 = options.ideal2 rms_amp = options.rms_amplitude self._interpolation = 1 f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953, 0,-24706,0,82359,262144/2,82359,0,-24706,0, 11953,0,-6107,0,2959,0,-1271,0,445,0,-107], numpy.float64)/262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0/self._interpolation tb = bw/5 if self._interpolation > 1: self.tx_filter = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter ) print "New" else: self.tx_filter = None self.decimation = 1 if self.decimation > 1: bw = 0.5/self.decimation * 1 tb = bw/5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff) else: self.rx_filter = None self._setup_tx_path(options) self._setup_rx_path(options) self._setup_rpc_manager() config = self.config = station_configuration() if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() # capture transmitter's stream to disk #self.dst = gr.file_sink(gr.sizeof_gr_complex,options.to_file) self.dst= self.rxpath if options.force_rx_filter: print "Forcing rx filter usage" self.connect( self.rx_filter, self.dst ) self.dst = self.rx_filter if options.ideal or self.ideal2: self._amplifier = ofdm.multiply_const_ccf( 1.0 ) self.connect( self._amplifier, self.dst ) self.dst = self._amplifier self.set_rms_amplitude(rms_amp) if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.connect( self.m, self.dst ) self.dst = self.m if options.snr is not None: if options.berm is not None: # empirically determined to reach 30db SNR max in simulation mode noise_sigma = 0.0035 else: snr_db = options.snr snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( config.rms_amplitude**2 / snr ) print " Noise St. Dev. %f" % (noise_sigma) awgn_chan = blocks.add_cc() #awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma ) awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192) self.connect( awgn_noise_src, (awgn_chan,1) ) self.connect( awgn_chan, self.dst ) self.dst = awgn_chan if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff ) dst = self.dst self.connect(freq_off, dst) self.dst = freq_off self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile) self.rpc_mgr_tx.add_interface("set_norm_doppler",self.fad_chan.set_norm_doppler) else: #self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) # filter coefficients for the lab exercise self.fad_chan = filter.fir_filter_ccc(1,[0.3267,0.8868,0.3267]) #self.fad_chan = filter.fir_filter_ccc(1,[0,0,0.1,0.2,0.01,0.3])#0.3267,0.8868,0.3267]) #self.fad_chan = channels.selective_fading_model(5, 0.1, False, 1, -1, [0, 0, 0], [0.3267,0.8868,0.3267], 10 ) #self.fad_chan = channels.fading_model(6, 0.05, False); #self.fad_chan = channels.dynamic_channel_model(1000000, 0, 0, 0, 0, 3, 0.01, False, 0, [2e-6,4e-6,8e-6],[0.3267,0.8868,0.3267], 20, 0, 0) self.connect(self.fad_chan, self.dst) self.dst = self.fad_chan if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000*(1.0+soff),1000000) #interp = filter.fractional_resampler_cc(0,1000000*(1.0+soff)/1000000.0) self.connect( interp, self.dst ) self.dst = interp if options.record: log_to_file( self, interp, "data/interp_out.compl" ) tmm =blocks.throttle(gr.sizeof_gr_complex,options.bandwidth) self.connect( tmm, self.dst ) self.dst = tmm if options.force_tx_filter: print "Forcing tx filter usage" self.connect( self.tx_filter, self.dst ) self.dst = self.tx_filter if options.record: log_to_file( self, self.txpath, "data/txpath_out.compl" ) if options.scatterplot: print "Scatterplot enabled" self.connect( self.txpath,self.dst ) print "Hit Strg^C to terminate" print "Hit Strg^C to terminate" # Display some information about the setup if self._verbose: self._print_verbage()
def __init__(self, principal_gui, options): gr.hier_block2.__init__( self, "bpsk_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex), ) # Output signature # Enter the parameters of modulation self._samples_per_symbol = options.samples_per_symbol self._costas_alpha = _def_costas_alpha self._excess_bw = _def_excess_bw self.verbose = options.verbose self._mm_gain_mu = _def_gain_mu self._mm_mu = _def_mu self._mm_omega_relative_limit = _def_omega_relative_limit self._gray_code = _def_gray_code if self._samples_per_symbol < 2: raise TypeError, "samples_per_symbol must be >= 2, is %r" % (self._samples_per_symbol,) arity = pow(2, self.bits_per_symbol()) # Automatic gain control # self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100) self.agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0) # self.agc = gr.feedforward_agc_cc(16, 2.0) # RRC data filter ntaps = 11 * self._samples_per_symbol self.rrc_taps = gr.firdes.root_raised_cosine( 1.0, # gain self._samples_per_symbol, # sampling rate 1.0, # symbol rate 0.35, # excess bandwidth (roll-off factor) ntaps, ) self.rrc_filter = gr.interp_fir_filter_ccf(1, self.rrc_taps) # symbol clock recovery if not self._mm_gain_mu: self._mm_gain_mu = 0.1 self._mm_omega = self._samples_per_symbol self._mm_gain_omega = 0.25 * self._mm_gain_mu * self._mm_gain_mu self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha fmin = -0.25 fmax = 0.25 self._costas = gr.costas_loop_cc( 0.05, # PLL first order gain 0.00025, # PLL second order gain 0.05, # Max frequency offset rad/sample -0.05, # Min frequency offset rad/sample 2, ) # BPSK # Create a M&M bit synchronization retiming block self._mm = gr.clock_recovery_mm_cc( self._samples_per_symbol, # Initial samples/symbol 1e-06, # Second order gain 0.5, # Initial symbol phase 0.001, # First order gain 0.0001, ) # Maximum timing offset # self.receiver_sync=gr.mpsk_receiver_cc(arity, 0, # self._costas_alpha, self._costas_beta, # fmin, fmax, # self._mm_mu, self._mm_gain_mu, # self._mm_omega, self._mm_gain_omega, # self._mm_omega_relative_limit) # Do differential decoding based on phase change of symbols # This bloc allow to decode the stream # self.descrambler = gr.descrambler_bb(0x8A, 0x7F, 7) # find closest constellation point # rot = 1 # rotated_const = map(lambda pt: pt * rot, psk.constellation[arity]) # self.slicer = gr.constellation_decoder_cb(rotated_const, range(arity)) # if self._gray_code: # self.symbol_mapper = gr.map_bb(psk.gray_to_binary[arity]) # else: # self.symbol_mapper = gr.map_bb(psk.ungray_to_binary[arity]) # unpack the k bit vector into a stream of bits # self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol()) if self.verbose: self._print_verbage() # Do differential decoding based on phase change of symbols self.diffdec = gr.diff_phasor_cc() # Connect and Initialize base class self.connect(self, self.agc, self.rrc_filter, self._costas, self._mm, self)
def __init__ (self, options): gr.top_block.__init__(self, "ofdm_mrrc_benchmark") ##self._tx_freq = options.tx_freq # tranmitter's center frequency ##self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use ##self._fusb_block_size = options.fusb_block_size # usb info for USRP ##self._fusb_nblocks = options.fusb_nblocks # usb info for USRP ##self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose ##self._interface = options.interface ##self._mac_addr = options.mac_addr self._options = copy.copy( options ) self._interpolation = 1 f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953, 0,-24706,0,82359,262144/2,82359,0,-24706,0, 11953,0,-6107,0,2959,0,-1271,0,445,0,-107], numpy.float64)/262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0/self._interpolation tb = bw/5 if self._interpolation > 1: self.tx_filter = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter2 = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter ) self.tx_filter2.connect( self.tx_filter2, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter2 ) print "New" else: self.tx_filter = None self.tx_filter2 = None self.decimation = 1 if self.decimation > 1: bw = 0.5/self.decimation * 1 tb = bw/5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff) self.rx_filter2 = gr.fir_filter_ccf(self.decimation,filt_coeff) else: self.rx_filter = None self.rx_filter2 = None ## if not options.from_file is None: ## # sent captured file to usrp ## self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file) ## self._setup_usrp_sink() ## if hasattr(self, "filter"): ## self.connect(self.src,self.filter,self.u) #,self.filter ## else: ## self.connect(self.src,self.u) ## ## return self._setup_tx_path(options) self._setup_rx_path(options) self._setup_rpc_manager() config = self.config = station_configuration() #self.enable_txfreq_adjust("txfreq") if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() self.dst = (self.rxpath,0) self.dst2 = (self.rxpath,1) if options.force_rx_filter: print "Forcing rx filter usage" self.connect( self.rx_filter, self.dst ) self.connect( self.rx_filter2, self.dst2 ) self.dst = self.rx_filter self.dst2 = self.rx_filter2 if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.m2 = throughput_measure(gr.sizeof_gr_complex) self.connect( self.m, self.dst ) self.connect( self.m2, self.dst2 ) self.dst = self.m self.dst2 = self.m2 if options.snr is not None: if options.berm is not None: noise_sigma = 380/32767.0 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py print " Noise St. Dev. %f" % (noise_sigma)#check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( config.rms_amplitude**2 / snr ) print " Noise St. Dev. %f" % (noise_sigma) awgn_chan = blocks.add_cc() awgn_chan2 = blocks.add_cc() awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192) awgn_noise_src2 = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma*2, 0, 2192) self.connect( awgn_chan, self.dst ) self.connect( awgn_chan2, self.dst2 ) self.connect( awgn_noise_src, (awgn_chan,1) ) self.connect( awgn_noise_src2, (awgn_chan2,1) ) self.dst = awgn_chan self.dst2 = awgn_chan2 if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff ) freq_off2 = self.freq_off2 = channel.freq_offset(options.freqoff ) dst = self.dst dst2 = self.dst2 self.connect( freq_off, dst ) self.connect( freq_off2, dst2 ) self.dst = freq_off self.dst2 = freq_off2 self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff) self.rpc_mgr_tx.add_interface("set_freq_offset2",self.freq_off2.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) self.fad_chan2 = channel.itpp_channel(options.bandwidth) self.fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) self.fad_chan.set_norm_doppler( 1e-8 ) self.fad_chan2.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) self.fad_chan2.set_norm_doppler( 1e-8 ) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan2.set_channel_profile) else: fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) fad_chan2 = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect( self.fad_chan, self.dst ) self.connect( self.fad_chan2, self.dst2 ) self.dst = self.fad_chan self.dst2 = self.fad_chan2 if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000*(1.0+soff),1000000) interp2 = moms(1000000*(1.0+soff),1000000) self.connect( interp, self.dst ) self.connect( interp2, self.dst2 ) self.dst = interp self.dst2 = interp2 if options.record: log_to_file( self, interp, "data/interp_out.compl" ) log_to_file( self, interp2, "data/interp2_out.compl" ) tmm =blocks.throttle(gr.sizeof_gr_complex, 1e6) #tmm2 =blocks.throttle(gr.sizeof_gr_complex, 1e6) #self.connect( tmm, self.dst ) #self.connect( tmm2, self.dst2 ) #self.dst = tmm #self.dst2 = tmm2 #inter = blocks.interleave(gr.sizeof_gr_complex) #deinter = blocks.deinterleave(gr.sizeof_gr_complex) # Interleaving input/output streams ##self.connect(inter, deinter) #self.connect((deinter,0),self.dst) #self.connect((deinter,1),self.dst2) #self.dst = inter #self.dst2 = (inter,1) if options.force_tx_filter: print "Forcing tx filter usage" self.connect( self.tx_filter, self.dst ) self.connect( self.tx_filter2, self.dst2 ) self.dst = self.tx_filter self.dst2 = self.tx_filter2 if options.record: log_to_file( self, self.txpath, "data/txpath_out.compl" ) log_to_file( self, self.txpath2, "data/txpath2_out.compl" ) if options.nullsink: self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst) self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2) self.dst = gr.null_sink(gr.sizeof_gr_complex) self.dst2 = gr.null_sink(gr.sizeof_gr_complex) self.connect( self.txpath,tmm,self.dst ) self.connect( tmm,self.dst2 ) #self.connect( self.txpath,self.dst2 ) print "Hit Strg^C to terminate" if self._verbose: self._print_verbage()
def __init__(self, gui, options): gr.hier_block2.__init__(self, "bpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = options.sps self.amplitude = options.amplitude self.verbose = options.verbose self._excess_bw = _def_excess_bw self._gray_code = _def_gray_code if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: raise TypeError, ("sample per symbol must be an integer >= 2, is %d" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) # turn bytes into k-bit vectors self.packed_to_unpacked_bb = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diff_encoder_bb = gr.diff_encoder_bb(arity) #This bloc allow to decode the stream #self.scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) #Transform symbols to chips self.symbols_to_chips = ieee.symbols_to_chips_bs() #self.chunks2symbols = gr.chunks_to_symbols_ic(psk.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_sc([-1+0j, 1+0j]) self.chunks2symbols_b = gr.chunks_to_symbols_bc([-1+0j, 1+0j]) # transform chips to symbols print "bits_per_symbol", self.bits_per_symbol() self.packed_to_unpacked_ss = \ gr.packed_to_unpacked_ss(self.bits_per_symbol(), gr.GR_MSB_FIRST) ntaps = 11 * self._samples_per_symbol # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol * self.amplitude, # gain (samples_per_symbol since we're # interpolating by samples_per_symbol) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) # Connect #self.connect(self, self.bytes2chunks, self.symbol_mapper,self.scrambler, self.chunks2symbols, self.rrc_filter, self) # self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c( # gui.GetWin(), # title="Constellation Plot", # sample_rate=self._samples_per_symbol, # frame_rate=5, # const_size=2048, # M=2, # theta=0, # alpha=0.005, # fmax=0.06, # mu=0.5, # gain_mu=0.005, # symbol_rate=self._samples_per_symbol/2, # omega_limit=0.005, # ) # gui.Add(self.wxgui_constellationsink2_0.win) #Modefied for IEEE 802.15.4 #self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.diff_encoder_bb, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self._scrambler, self.chunks2symbols_b, self.rrc_filter, self) #self.connect(self.rrc_filter, self.wxgui_constellationsink2_0) if self.verbose: self._print_verbage()
def __init__(self, options): gr.top_block.__init__(self) use_sink = None if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) use_sink = self.sink elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) self.throttle = gr.throttle(gr.sizeof_gr_complex*1, options.file_samp_rate) self.connect(self.throttle, self.sink) use_sink = self.throttle else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = [ ] self.txpath.append(transmit_path(options)) self.txpath.append(transmit_path(options)) samp_rate = 0 if(options.tx_freq is not None): samp_rate = self.sink.get_sample_rate() else: samp_rate = options.file_samp_rate print "SAMP RATE " + str(samp_rate) volume = options.split_amplitude band_transition = options.band_trans_width low_transition = options.low_trans_width guard_width = options.guard_width self.low_pass_filter_qv0 = gr.interp_fir_filter_ccf(2, firdes.low_pass( 1, samp_rate, samp_rate/4-guard_width/2, low_transition, firdes.WIN_HAMMING, 6.76)) self.freq_translate_qv0 = filter.freq_xlating_fir_filter_ccc(1, (options.num_taps, ), samp_rate/4, samp_rate) self.band_pass_filter_qv0 = gr.fir_filter_ccc(1, firdes.complex_band_pass( 1, samp_rate, -samp_rate/2+guard_width, 0-guard_width, band_transition, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_qv1 = gr.interp_fir_filter_ccf(2, firdes.low_pass( 1, samp_rate, samp_rate/4-guard_width/2, low_transition, firdes.WIN_HAMMING, 6.76)) self.freq_translate_qv1 = filter.freq_xlating_fir_filter_ccc(1, (options.num_taps, ), -samp_rate/4, samp_rate) self.band_pass_filter_qv1 = gr.fir_filter_ccc(1, firdes.complex_band_pass( 1, samp_rate, 0+guard_width, samp_rate/2-guard_width, band_transition, firdes.WIN_HAMMING, 6.76)) self.combiner = gr.add_vcc(1) self.volume_multiply = blocks.multiply_const_vcc((volume, )) self.connect((self.txpath[0], 0), (self.low_pass_filter_qv0, 0)) self.connect((self.txpath[1], 0), (self.low_pass_filter_qv1, 0)) self.connect((self.low_pass_filter_qv0, 0), (self.freq_translate_qv0, 0)) self.connect((self.freq_translate_qv0, 0), (self.band_pass_filter_qv0, 0)) self.connect((self.low_pass_filter_qv1, 0), (self.freq_translate_qv1, 0)) self.connect((self.freq_translate_qv1, 0), (self.band_pass_filter_qv1, 0)) self.connect((self.band_pass_filter_qv0, 0), (self.combiner, 0)) self.connect((self.band_pass_filter_qv1, 0), (self.combiner, 1)) self.connect((self.combiner, 0), (self.volume_multiply, 0)) self.connect(self.volume_multiply, use_sink)
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered QPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__(self, "qam8_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._gray_code = gray_code if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % samples_per_symbol) ntaps = 11 * samples_per_symbol arity = pow(2, self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(qam.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(qam.binary_to_ungray[arity]) self.diffenc = gr.diff_encoder_bb(arity) rot = 1.0 print "constellation with %d arity" % arity rotated_const = map(lambda pt: pt * rot, qam.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_bc(rotated_const) # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol, # gain (sps since we're interpolating by sps) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) if verbose: self._print_verbage() if log: self._setup_logging() # Connect self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter, self)
def __init__ (self, options): gr.top_block.__init__(self, "ofdm_benchmark") ##self._tx_freq = options.tx_freq # tranmitter's center frequency ##self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use ##self._fusb_block_size = options.fusb_block_size # usb info for USRP ##self._fusb_nblocks = options.fusb_nblocks # usb info for USRP ##self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose ##self._interface = options.interface ##self._mac_addr = options.mac_addr self._options = copy.copy( options ) self._interpolation = 1 f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953, 0,-24706,0,82359,262144/2,82359,0,-24706,0, 11953,0,-6107,0,2959,0,-1271,0,445,0,-107], numpy.float64)/262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0/self._interpolation tb = bw/5 if self._interpolation > 1: self.tx_filter = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter2 = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter ) self.tx_filter2.connect( self.tx_filter2, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter2 ) print "New" else: self.tx_filter = None self.tx_filter2 = None self.decimation = 1 if self.decimation > 1: bw = 0.5/self.decimation * 1 tb = bw/5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff) self.rx_filter2 = gr.fir_filter_ccf(self.decimation,filt_coeff) else: self.rx_filter = None self.rx_filter2 = None ## if not options.from_file is None: ## # sent captured file to usrp ## self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file) ## self._setup_usrp_sink() ## if hasattr(self, "filter"): ## self.connect(self.src,self.filter,self.u) #,self.filter ## else: ## self.connect(self.src,self.u) ## ## return self._setup_tx_path(options) self._setup_rx_path(options) config = station_configuration() self.enable_info_tx("info_tx", "pa_user") # if not options.no_cheat: # self.txpath.enable_channel_cheating("channelcheat") self.txpath.enable_txpower_adjust("txpower") self.txpath.publish_txpower("txpower_info") if options.disable_equalization or options.ideal: #print "CHANGE set_k" self.rxpath.enable_estim_power_adjust("estim_power") #self.rxpath.publish_estim_power("txpower_info") #self.enable_txfreq_adjust("txfreq") if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() self.dst = (self.rxpath,0) self.dst2 = (self.rxpath,1) if options.force_rx_filter: print "Forcing rx filter usage" self.connect( self.rx_filter, self.dst ) self.connect( self.rx_filter2, self.dst2 ) self.dst = self.rx_filter self.dst2 = self.rx_filter2 if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.m2 = throughput_measure(gr.sizeof_gr_complex) self.connect( self.m, self.dst ) self.connect( self.m2, self.dst2 ) self.dst = self.m self.dst2 = self.m2 if options.snr is not None: if options.berm is not False: noise_sigma = 380 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py #check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( config.rms_amplitude**2 / snr ) print " Noise St. Dev. %d" % (noise_sigma) awgn_chan = blocks.add_cc() awgn_chan2 = blocks.add_cc() awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma ) awgn_noise_src2 = ofdm.complex_white_noise( 0.0, noise_sigma ) self.connect( awgn_chan, self.dst ) self.connect( awgn_chan2, self.dst2 ) self.connect( awgn_noise_src, (awgn_chan,1) ) self.connect( awgn_noise_src2, (awgn_chan2,1) ) self.dst = awgn_chan self.dst2 = awgn_chan2 if options.freqoff is not None: freq_shift = blocks.multiply_cc() freq_shift2 = blocks.multiply_cc() norm_freq = options.freqoff / config.fft_length freq_off_src = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0 ) freq_off_src2 = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0 ) self.connect( freq_off_src, ( freq_shift, 1 ) ) self.connect( freq_off_src2, ( freq_shift2, 1 ) ) dst = self.dst dst2 = self.dst2 self.connect( freq_shift, dst ) self.connect( freq_shift2, dst2 ) self.dst = freq_shift self.dst2 = freq_shift2 if options.multipath: if options.itu_channel: fad_chan = itpp.tdl_channel( ) #[0, -7, -20], [0, 2, 6] #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) fad_chan2 = itpp.tdl_channel( ) fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) fad_chan.set_norm_doppler( 1e-8 ) fad_chan2.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) fad_chan2.set_norm_doppler( 1e-8 ) else: fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) fad_chan2 = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect( fad_chan, self.dst ) self.connect( fad_chan2, self.dst2 ) self.dst = fad_chan self.dst2 = fad_chan2 if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000+soff,1000000) interp2 = moms(1000000+soff,1000000) self.connect( interp, self.dst ) self.connect( interp2, self.dst2 ) self.dst = interp self.dst2 = interp2 if options.record: log_to_file( self, interp, "data/interp_out.compl" ) log_to_file( self, interp2, "data/interp2_out.compl" ) tmm =blocks.throttle(gr.sizeof_gr_complex,self._bandwidth) tmm2 =blocks.throttle(gr.sizeof_gr_complex,self._bandwidth) tmm_add = blocks.add_cc() tmm2_add = blocks.add_cc() self.connect( tmm, tmm_add ) self.connect( tmm2, (tmm_add,1) ) self.connect( tmm, tmm2_add ) self.connect( tmm2, (tmm2_add,1) ) self.connect( tmm_add, self.dst ) self.connect( tmm2_add, self.dst2 ) self.dst = tmm self.dst2 = tmm2 inter = blocks.interleave(gr.sizeof_gr_complex) deinter = blocks.deinterleave(gr.sizeof_gr_complex) self.connect(inter, deinter) self.connect((deinter,0),self.dst) self.connect((deinter,1),self.dst2) self.dst = inter self.dst2 = (inter,1) if options.force_tx_filter: print "Forcing tx filter usage" self.connect( self.tx_filter, self.dst ) self.connect( self.tx_filter2, self.dst2 ) self.dst = self.tx_filter self.dst2 = self.tx_filter2 if options.record: log_to_file( self, self.txpath, "data/txpath_out.compl" ) log_to_file( self, self.txpath2, "data/txpath2_out.compl" ) if options.nullsink: self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst) self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2) self.dst = gr.null_sink(gr.sizeof_gr_complex) self.dst2 = gr.null_sink(gr.sizeof_gr_complex) self.connect( self.txpath,self.dst ) self.connect( (self.txpath,1),self.dst2 ) if options.cheat: self.txpath.enable_channel_cheating("channelcheat") print "Hit Strg^C to terminate" if options.event_rxbaseband: self.publish_rx_baseband_measure() if options.with_old_gui: self.publish_spectrum(256) self.rxpath.publish_ctf("ctf_display") self.rxpath.publish_ber_measurement(["ber"]) self.rxpath.publish_average_snr(["totalsnr"]) if options.sinr_est: self.rxpath.publish_sinrsc("sinrsc_display") print "Hit Strg^C to terminate" # Display some information about the setup if self._verbose: self._print_verbage()
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, costas_alpha=_def_costas_alpha, gain_mu=_def_gain_mu, mu=_def_mu, omega_relative_limit=_def_omega_relative_limit, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered CQPSK demodulation The input is the complex modulated signal at baseband. The output is a stream of floats in [ -3 / -1 / +1 / +3 ] @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: float @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param costas_alpha: loop filter gain @type costas_alphas: float @param gain_mu: for M&M block @type gain_mu: float @param mu: for M&M block @type mu: float @param omega_relative_limit: for M&M block @type omega_relative_limit: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__( self, "cqpsk_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._costas_alpha = costas_alpha self._mm_gain_mu = gain_mu self._mm_mu = mu self._mm_omega_relative_limit = omega_relative_limit self._gray_code = gray_code if samples_per_symbol < 2: raise TypeError, "sbp must be >= 2, is %d" % samples_per_symbol arity = pow(2, self.bits_per_symbol()) # Automatic gain control scale = (1.0 / 16384.0) self.pre_scaler = gr.multiply_const_cc( scale) # scale the signal from full-range to +-1 #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100) self.agc = gr.feedforward_agc_cc(16, 2.0) # RRC data filter ntaps = 11 * samples_per_symbol self.rrc_taps = gr.firdes.root_raised_cosine( 1.0, # gain self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(1, self.rrc_taps) if not self._mm_gain_mu: sbs_to_mm = { 2: 0.050, 3: 0.075, 4: 0.11, 5: 0.125, 6: 0.15, 7: 0.15 } self._mm_gain_mu = sbs_to_mm[samples_per_symbol] self._mm_omega = self._samples_per_symbol self._mm_gain_omega = .25 * self._mm_gain_mu * self._mm_gain_mu self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha fmin = -0.025 fmax = 0.025 self.receiver = gr.mpsk_receiver_cc( arity, pi / 4.0, self._costas_alpha, self._costas_beta, fmin, fmax, self._mm_mu, self._mm_gain_mu, self._mm_omega, self._mm_gain_omega, self._mm_omega_relative_limit) # Perform Differential decoding on the constellation self.diffdec = gr.diff_phasor_cc() # take angle of the difference (in radians) self.to_float = gr.complex_to_arg() # convert from radians such that signal is in -3/-1/+1/+3 self.rescale = gr.multiply_const_ff(1 / (pi / 4)) if verbose: self._print_verbage() if log: self._setup_logging() # Connect & Initialize base class self.connect(self, self.pre_scaler, self.agc, self.rrc_filter, self.receiver, self.diffdec, self.to_float, self.rescale, self)
def __init__ (self, options): gr.top_block.__init__(self, "fbmc_benchmark") self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose self._options = copy.copy( options ) self.ideal = options.ideal self.ideal2 = options.ideal2 rms_amp = options.rms_amplitude #Disable OFDM channel estimation preamble -> Still experimental options.est_preamble = 0 self._interpolation = 1 f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953, 0,-24706,0,82359,262144/2,82359,0,-24706,0, 11953,0,-6107,0,2959,0,-1271,0,445,0,-107], numpy.float64)/262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0/self._interpolation tb = bw/5 if self._interpolation > 1: self.tx_filter = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter ) print "New" else: self.tx_filter = None self.decimation = 1 if self.decimation > 1: bw = 0.5/self.decimation * 1 tb = bw/5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff) else: self.rx_filter = None self._setup_tx_path(options) self._setup_rx_path(options) self._setup_rpc_manager() config = self.config = station_configuration() if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() # capture transmitter's stream to disk #self.dst = gr.file_sink(gr.sizeof_gr_complex,options.to_file) self.dst= self.rxpath if options.force_rx_filter: print "Forcing rx filter usage" self.connect( self.rx_filter, self.dst ) self.dst = self.rx_filter if options.ideal or self.ideal2: self._amplifier = ofdm.multiply_const_ccf( 1.0 ) self.connect( self._amplifier, self.dst ) self.dst = self._amplifier self.set_rms_amplitude(rms_amp) if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.connect( self.m, self.dst ) self.dst = self.m if options.snr is not None: if options.berm is not None: #noise_sigma = 0.0001/32767.0 noise_sigma = 380/32767.0#250/32767.0 #380/32767.0 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py #check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( config.rms_amplitude**2 / snr ) print " Noise St. Dev. %d" % (noise_sigma) awgn_chan = blocks.add_cc() #awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma ) #noise_sigma = 0.000000000001 awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192) self.connect( awgn_noise_src, (awgn_chan,1) ) self.connect( awgn_chan,self.dst ) #self.connect( awgn_chan, blocks.skiphead( gr.sizeof_gr_complex, 3* config.fft_length ),self.dst ) self.dst = awgn_chan if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff ) dst = self.dst self.connect(freq_off, dst) self.dst = freq_off self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff) #log_to_file( self, self.freq_off, "data/TRANSMITTER_OUT.compl" ) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile) else: #self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) # filter coefficients for the lab exercise self.fad_chan = filter.fir_filter_ccc(1,[0,0,0.3267,0.8868,0.3267]) self.connect(self.fad_chan, self.dst) self.dst = self.fad_chan if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000*(1.0+soff),1000000) self.connect( interp, self.dst ) self.dst = interp if options.record: log_to_file( self, interp, "data/interp_out.compl" ) tmm =blocks.throttle(gr.sizeof_gr_complex,1e6) self.connect( tmm, self.dst ) self.dst = tmm if options.force_tx_filter: print "Forcing tx filter usage" self.connect( self.tx_filter, self.dst ) self.dst = self.tx_filter if options.record: log_to_file( self, self.txpath, "data/txpath_out.compl" ) if options.scatterplot: print "Scatterplot enabled" self.connect( self.txpath,self.dst ) #log_to_file( self, self.txpath, "data/fbmc_rx_input.compl" ) print "Hit Strg^C to terminate" print "Hit Strg^C to terminate" # Display some information about the setup if self._verbose: self._print_verbage()
def __init__(self, modulator, options): gr.top_block.__init__(self) self.txpath = [] use_sink = None if options.tx_freq is not None: # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter( options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose, ) sample_rate = self.sink.get_sample_rate() options.samples_per_symbol = self.sink._sps use_sink = self.sink elif options.to_file is not None: sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) self.throttle = gr.throttle(gr.sizeof_gr_complex * 1, options.file_samp_rate) self.connect(self.throttle, self.sink) use_sink = self.throttle else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath.append(transmit_path(modulator, options)) self.txpath.append(transmit_path(modulator, options)) samp_rate = 0 if options.tx_freq is not None: samp_rate = self.sink.get_sample_rate() else: samp_rate = options.file_samp_rate volume = options.split_amplitude band_transition = options.band_trans_width low_transition = options.low_trans_width guard_width = options.guard_width self.low_pass_filter_qv0 = gr.interp_fir_filter_ccf( 2, firdes.low_pass(1, samp_rate, samp_rate / 4 - guard_width / 2, low_transition, firdes.WIN_HAMMING, 6.76) ) self.freq_translate_qv0 = filter.freq_xlating_fir_filter_ccc(1, (options.num_taps,), samp_rate / 4, samp_rate) self.band_pass_filter_qv0 = gr.fir_filter_ccc( 1, firdes.complex_band_pass( 1, samp_rate, -samp_rate / 2 + guard_width, 0 - guard_width, band_transition, firdes.WIN_HAMMING, 6.76 ), ) self.low_pass_filter_qv1 = gr.interp_fir_filter_ccf( 2, firdes.low_pass(1, samp_rate, samp_rate / 4 - guard_width / 2, low_transition, firdes.WIN_HAMMING, 6.76) ) self.freq_translate_qv1 = filter.freq_xlating_fir_filter_ccc(1, (options.num_taps,), -samp_rate / 4, samp_rate) self.band_pass_filter_qv1 = gr.fir_filter_ccc( 1, firdes.complex_band_pass( 1, samp_rate, 0 + guard_width, samp_rate / 2 - guard_width, band_transition, firdes.WIN_HAMMING, 6.76 ), ) self.combiner = gr.add_vcc(1) self.volume_multiply = blocks.multiply_const_vcc((volume,)) self.connect((self.txpath[0], 0), (self.low_pass_filter_qv0, 0)) self.connect((self.txpath[1], 0), (self.low_pass_filter_qv1, 0)) self.connect((self.low_pass_filter_qv0, 0), (self.freq_translate_qv0, 0)) self.connect((self.freq_translate_qv0, 0), (self.band_pass_filter_qv0, 0)) self.connect((self.low_pass_filter_qv1, 0), (self.freq_translate_qv1, 0)) self.connect((self.freq_translate_qv1, 0), (self.band_pass_filter_qv1, 0)) self.connect((self.band_pass_filter_qv0, 0), (self.combiner, 0)) self.connect((self.band_pass_filter_qv1, 0), (self.combiner, 1)) self.connect((self.combiner, 0), (self.volume_multiply, 0)) self.connect(self.volume_multiply, use_sink)
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered QPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__( self, "cqpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % samples_per_symbol) ntaps = 11 * samples_per_symbol arity = 8 # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) # 0 +45 1 [+1] # 1 +135 3 [+3] # 2 -45 7 [-1] # 3 -135 5 [-3] self.pi4map = [1, 3, 7, 5] self.symbol_mapper = gr.map_bb(self.pi4map) self.diffenc = gr.diff_encoder_bb(arity) self.chunks2symbols = gr.chunks_to_symbols_bc(psk.constellation[arity]) # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self. _samples_per_symbol, # gain (sps since we're interpolating by sps) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) if verbose: self._print_verbage() if log: self._setup_logging() # Connect & Initialize base class self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter, self)