def build_graph(): sample_rate = 8000 scale_factor = 32000 tb = gr.top_block() src = audio.source(sample_rate, "plughw:0,0") src_scale = gr.multiply_const_ff(scale_factor) interp = blks2.rational_resampler_fff(8, 1) f2s = gr.float_to_short () enc = vocoder.cvsd_encode_sb() dec = vocoder.cvsd_decode_bs() s2f = gr.short_to_float () decim = blks2.rational_resampler_fff(1, 8) sink_scale = gr.multiply_const_ff(1.0/scale_factor) sink = audio.sink(sample_rate, "plughw:0,0") tb.connect(src, src_scale, interp, f2s, enc) tb.connect(enc, dec, s2f, decim, sink_scale, sink) if 0: # debug tb.conect(src, gr.file_sink(gr.sizeof_float, "source.dat")) tb.conect(src_scale, gr.file_sink(gr.sizeof_float, "src_scale.dat")) tb.conect(interp, gr.file_sink(gr.sizeof_float, "interp.dat")) tb.conect(f2s, gr.file_sink(gr.sizeof_short, "f2s.dat")) tb.conect(enc, gr.file_sink(gr.sizeof_char, "enc.dat")) tb.conect(dec, gr.file_sink(gr.sizeof_short, "dec.dat")) tb.conect(s2f, gr.file_sink(gr.sizeof_float, "s2f.dat")) tb.conect(decim, gr.file_sink(gr.sizeof_float, "decim.dat")) tb.conect(sink_scale, gr.file_sink(gr.sizeof_float, "sink_scale.dat")) return tb
def build_graph(): sample_rate = 8000 scale_factor = 32000 tb = gr.top_block() src = audio.source(sample_rate, "plughw:0,0") src_scale = gr.multiply_const_ff(scale_factor) interp = blks2.rational_resampler_fff(8, 1) f2s = gr.float_to_short() enc = cvsd_vocoder.encode_sb() dec = cvsd_vocoder.decode_bs() s2f = gr.short_to_float() decim = blks2.rational_resampler_fff(1, 8) sink_scale = gr.multiply_const_ff(1.0 / scale_factor) sink = audio.sink(sample_rate, "plughw:0,0") tb.connect(src, src_scale, interp, f2s, enc) tb.connect(enc, dec, s2f, decim, sink_scale, sink) if 0: # debug tb.conect(src, gr.file_sink(gr.sizeof_float, "source.dat")) tb.conect(src_scale, gr.file_sink(gr.sizeof_float, "src_scale.dat")) tb.conect(interp, gr.file_sink(gr.sizeof_float, "interp.dat")) tb.conect(f2s, gr.file_sink(gr.sizeof_short, "f2s.dat")) tb.conect(enc, gr.file_sink(gr.sizeof_char, "enc.dat")) tb.conect(dec, gr.file_sink(gr.sizeof_short, "dec.dat")) tb.conect(s2f, gr.file_sink(gr.sizeof_float, "s2f.dat")) tb.conect(decim, gr.file_sink(gr.sizeof_float, "decim.dat")) tb.conect(sink_scale, gr.file_sink(gr.sizeof_float, "sink_scale.dat")) return tb
def xInit(self, signals, noises, sinks): # ------------------------------------------------------------------------ self.sources = {} self.mutes = {} self.amps = {} #sources for signal in signals: self.sources[signal] = gr.sig_source_f( self.samprate, gr.GR_SIN_WAVE, 440, 0.25, 0) self.mutes[signal] = gr.mute_ff(True) self.amps[signal] = gr.multiply_const_ff(0.25) for noise in noises: self.sources[noise] = analog.noise_source_f( analog.GR_LAPLACIAN, 1, 0) self.mutes[noise] = gr.mute_ff(True) self.amps[noise] = gr.multiply_const_ff(0.25) #mixer if len(self.sources) > 1: self.adder = self.add = gr.add_vff(1) else: self.adder = gr.multiply_const_vff((1, )) self.level = gr.multiply_const_ff(1) #sinks self.sinks = sinks self.audiomute = gr.mute_ff(True) self.audio = audio.sink(self.samprate, "", True) self.udp = gr.null_sink(gr.sizeof_float) self.rawfile = gr.null_sink(gr.sizeof_float) self.wavefile = gr.null_sink(gr.sizeof_float)
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--audio-input", type="string", default="") parser.add_option("-A", "--audio-output", type="string", default="") parser.add_option("-f", "--factor", type="eng_float", default=1) parser.add_option("-i", "--do-interp", action="store_true", default=False, help="enable output interpolator") parser.add_option("-s", "--sample-rate", type="int", default=48000, help="input sample rate") parser.add_option("-S", "--stretch", type="int", default=0, help="flex amt") parser.add_option("-y", "--symbol-rate", type="int", default=4800, help="input symbol 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 = options.symbol_rate IN = audio.source(sample_rate, options.audio_input) audio_output_rate = 8000 if options.do_interp: audio_output_rate = 48000 OUT = audio.sink(audio_output_rate, options.audio_output) symbol_decim = 1 symbol_coeffs = gr.firdes.root_raised_cosine(1.0, # gain sample_rate , # sampling rate symbol_rate, # symbol rate 0.2, # width of trans. band 500) # filter type SYMBOL_FILTER = gr.fir_filter_fff (symbol_decim, symbol_coeffs) AMP = gr.multiply_const_ff(options.factor) msgq = gr.msg_queue(2) FSK4 = op25.fsk4_demod_ff(msgq, sample_rate, symbol_rate) levels = levels = [-2.0, 0.0, 2.0, 4.0] SLICER = repeater.fsk4_slicer_fb(levels) framer_msgq = gr.msg_queue(2) DECODE = repeater.p25_frame_assembler('', # udp hostname 0, # udp port no. options.verbose, #debug True, # do_imbe True, # do_output False, # do_msgq framer_msgq) IMBE = repeater.vocoder(False, # 0=Decode,True=Encode options.verbose, # Verbose flag options.stretch, # flex amount "", # udp ip address 0, # udp port False) # dump raw u vectors CVT = gr.short_to_float() if options.do_interp: interp_taps = gr.firdes.low_pass(1.0, 48000, 4000, 4000 * 0.1, gr.firdes.WIN_HANN) INTERP = gr.interp_fir_filter_fff(48000 // 8000, interp_taps) AMP2 = gr.multiply_const_ff(1.0 / 32767.0) self.connect(IN, AMP, SYMBOL_FILTER, FSK4, SLICER, DECODE, IMBE, CVT, AMP2) if options.do_interp: self.connect(AMP2, INTERP, OUT) else: self.connect(AMP2, OUT)
def build_graph(): tb = gr.top_block() src = audio.source(8000) src_scale = gr.multiply_const_ff(32767) f2s = gr.float_to_short () enc = vocoder.g723_40_encode_sb() dec = vocoder.g723_40_decode_bs() s2f = gr.short_to_float () sink_scale = gr.multiply_const_ff(1.0/32767.) sink = audio.sink(8000) tb.connect(src, src_scale, f2s, enc, dec, s2f, sink_scale, sink) return tb
def build_graph(): fg = gr.flow_graph() src = audio.source(8000) src_scale = gr.multiply_const_ff(32767) f2s = gr.float_to_short () enc = gsm_full_rate.encode_sp() dec = gsm_full_rate.decode_ps() s2f = gr.short_to_float () sink_scale = gr.multiply_const_ff(1.0/32767.) sink = audio.sink(8000) fg.connect(src, src_scale, f2s, enc, dec, s2f, sink_scale, sink) return fg
def build_graph(): tb = gr.top_block() src = audio.source(8000) src_scale = gr.multiply_const_ff(32767) f2s = gr.float_to_short () enc = vocoder.ulaw_encode_sb() dec = vocoder.ulaw_decode_bs() s2f = gr.short_to_float () sink_scale = gr.multiply_const_ff(1.0/32767.) sink = audio.sink(8000) tb.connect(src, src_scale, f2s, enc, dec, s2f, sink_scale, sink) return tb
def setup_radiometer_common(self,n): # The IIR integration filter for post-detection self.integrator = gr.single_pole_iir_filter_ff(1.0) self.integrator.set_taps (1.0/self.bw) if (self.use_notches == True): self.compute_notch_taps(self.notches) if (n == 2): self.notch_filt1 = gr.fft_filter_ccc(1, self.notch_taps) self.notch_filt2 = gr.fft_filter_ccc(1, self.notch_taps) else: self.notch_filt = gr.fft_filter_ccc(1, self.notch_taps) # Signal probe self.probe = gr.probe_signal_f() # # Continuum calibration stuff # x = self.calib_coeff/100.0 self.cal_mult = gr.multiply_const_ff(self.calib_coeff/100.0) self.cal_offs = gr.add_const_ff(self.calib_offset*(x*8000)) # # Mega decimator after IIR filter # if (self.switch_mode == False): self.keepn = gr.keep_one_in_n(gr.sizeof_float, self.bw) else: self.keepn = gr.keep_one_in_n(gr.sizeof_float, int(self.bw/2)) # # For the Dicke-switching scheme # #self.switch = gr.multiply_const_ff(1.0) # if (self.switch_mode == True): self.vector = gr.vector_sink_f() self.swkeep = gr.keep_one_in_n(gr.sizeof_float, int(self.bw/3)) self.mute = gr.keep_one_in_n(gr.sizeof_float, 1) self.cmute = gr.keep_one_in_n(gr.sizeof_float, int(1.0e9)) self.cintegrator = gr.single_pole_iir_filter_ff(1.0/(self.bw/2)) self.cprobe = gr.probe_signal_f() else: self.mute = gr.multiply_const_ff(1.0) self.avg_reference_value = 0.0 self.reference_level = gr.add_const_ff(0.0)
def ms_to_file(hb,block,filename,N=4096,delay=0,fft=False,scale=1): streamsize = determine_streamsize(block) vlen = streamsize/gr.sizeof_gr_complex blks = [block] if fft and vlen > 1: gr_fft = fft_blocks.fft_vcc(vlen,True,[],True) blks.append(gr_fft) mag_sqrd = gr.complex_to_mag_squared(vlen) blks.append(mag_sqrd) if vlen > 1: v2s = blocks.vector_to_stream(gr.sizeof_float,vlen) blks.append(v2s) if delay != 0: delayline = delayline_ff(delay) blks.append(delayline) gr_scale = gr.multiply_const_ff(scale) blks.append(gr_scale) filter = gr.fir_filter_fff(1,[1.0/N]*N) blks.append(filter) for i in range(len(blks)-1): hb.connect(blks[i],blks[i+1]) log_to_file(hb,filter,filename)
def ms_to_file(hb, block, filename, N=4096, delay=0, fft=False, scale=1): streamsize = determine_streamsize(block) vlen = streamsize / gr.sizeof_gr_complex blks = [block] if fft and vlen > 1: gr_fft = fft_blocks.fft_vcc(vlen, True, [], True) blks.append(gr_fft) mag_sqrd = gr.complex_to_mag_squared(vlen) blks.append(mag_sqrd) if vlen > 1: v2s = blocks.vector_to_stream(gr.sizeof_float, vlen) blks.append(v2s) if delay != 0: delayline = delayline_ff(delay) blks.append(delayline) gr_scale = gr.multiply_const_ff(scale) blks.append(gr_scale) filter = gr.fir_filter_fff(1, [1.0 / N] * N) blks.append(filter) for i in range(len(blks) - 1): hb.connect(blks[i], blks[i + 1]) log_to_file(hb, filter, filename)
def __init__(self, sps, channel_decim, channel_taps, options, usrp_rate, channel_rate, lo_freq): gr.hier_block2.__init__(self, "rx_channel_cqpsk", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float)) chan = gr.freq_xlating_fir_filter_ccf(int(channel_decim), channel_taps, lo_freq, usrp_rate) agc = gr.feedforward_agc_cc(16, 1.0) gain_omega = 0.125 * options.gain_mu * options.gain_mu alpha = options.costas_alpha beta = 0.125 * alpha * alpha fmin = -0.025 fmax = 0.025 clock = repeater.gardner_costas_cc(sps, options.gain_mu, gain_omega, alpha, beta, fmax, fmin) # Perform Differential decoding on the constellation diffdec = gr.diff_phasor_cc() # take angle of the difference (in radians) to_float = gr.complex_to_arg() # convert from radians such that signal is in -3/-1/+1/+3 rescale = gr.multiply_const_ff((1 / (pi / 4))) self.connect(self, chan, agc, clock, diffdec, to_float, rescale, self)
def __init__(self, fs, svn, alpha, fd_range, dump_bins=False): gr.hier_block2.__init__(self, "acquisition", gr.io_signature(1,1, gr.sizeof_gr_complex), gr.io_signature(3,3, gr.sizeof_float)) fft_size = int( 1e-3*fs) doppler_range = self.get_doppler_range(fd_range) agc = gr.agc_cc( 1.0/fs, 1.0, 1.0, 1.0) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fft = gr.fft_vcc(fft_size, True, []) argmax = gr.argmax_fs(fft_size) max = gr.max_ff(fft_size) self.connect( self, s2v, fft) self.connect( (argmax, 0), gr.short_to_float(), (self, 0)) self.connect( (argmax,1), gr.short_to_float(), gr.add_const_ff(-fd_range), gr.multiply_const_ff(1e3), (self,1)) self.connect( max, (self, 2)) # Connect the individual channels to the input and the output. self.correlators = [ single_channel_correlator( fs, fd, svn, alpha, dump_bins) for fd in doppler_range ] for (correlator, i) in zip( self.correlators, range(len(self.correlators))): self.connect( fft, correlator ) self.connect( correlator, (argmax, i) ) self.connect( correlator, (max, i) )
def __init__(self, length, debug=False): """ Hierarchical block to detect Null symbols @param length length of the Null symbol (in samples) @param debug whether to write signals out to files """ gr.hier_block2.__init__(self, "detect_null", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_char)) # output signature # get the magnitude squared self.ns_c2magsquared = gr.complex_to_mag_squared() self.ns_moving_sum = dabp.moving_sum_ff(length) self.ns_invert = gr.multiply_const_ff(-1) # peak detector on the inverted, summed up signal -> we get the nulls (i.e. the position of the start of a frame) self.ns_peak_detect = gr.peak_detector_fb(0.6,0.7,10,0.0001) # mostly found by try and error -> remember that the values are negative! # connect it all self.connect(self, self.ns_c2magsquared, self.ns_moving_sum, self.ns_invert, self.ns_peak_detect, self) if debug: self.connect(self.ns_invert, gr.file_sink(gr.sizeof_float, "debug/ofdm_sync_dabp_ns_filter_inv_f.dat")) self.connect(self.ns_peak_detect,gr.file_sink(gr.sizeof_char, "debug/ofdm_sync_dabp_peak_detect_b.dat"))
def test_031_multiple_internal_inputs(self): tb = gr.top_block() src = gr.vector_source_f([1.0]) hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) m1 = gr.multiply_const_ff(1.0) m2 = gr.multiply_const_ff(2.0) add = gr.add_ff() hb.connect(hb, m1) # m1 is connected to hb external input #0 hb.connect(hb, m2) # m2 is also connected to hb external input #0 hb.connect(m1, (add, 0)) hb.connect(m2, (add, 1)) hb.connect(add, hb) # add is connected to hb external output #0 dst = gr.vector_sink_f() tb.connect(src, hb, dst) tb.run() self.assertEquals(dst.data(), (3.0,))
def test_001_enc(self): length = 2048 # DANGER: this fails for > 2048 for some reason data = [random.randint(0, 255) for i in range(length)] # last K-1 bits are padding, meaning last byte is lost data[-1] = 0 data = tuple(data) src = gr.vector_source_b(data) enc = raw.conv_enc() tofloat = gr.uchar_to_float() offset = gr.multiply_const_ff(255.0) touchar = gr.float_to_uchar() dec = raw.conv_dec(length * 8) dst = gr.vector_sink_b() self.tb.connect(src, enc, tofloat, offset, touchar, dec, dst) self.tb.run() # self.assertEqual (data, dst.data()) nerrors = 0 i = 0 for (a, b) in itertools.izip(data, dst.data()): nerr = bitCount(a ^ b) if nerr: print "%g " % (i / 2048.0), nerr nerrors += nerr i += 1 print "Number or Errors %d BER %g" % (nerrors, (nerrors * 1.0 / (length * 8))) self.assertEqual(nerrors, 0)
def __init__(self, options, queue): gr.top_block.__init__(self, "mhp") self.audio_amps = [] self.converters = [] self.vocoders = [] self.output_files = [] input_audio_rate = 8000 self.audio_input = audio.source(input_audio_rate, options.audio_input) for i in range(options.nchannels): udp_port = options.udp_port + i if options.output_files: t = gr.file_sink(gr.sizeof_char, "baseband-%d.dat" % i) self.output_files.append(t) udp_port = 0 t = gr.multiply_const_ff(32767 * options.audio_gain) self.audio_amps.append(t) t = gr.float_to_short() self.converters.append(t) t = repeater.vocoder( True, # 0=Decode,True=Encode options.verbose, # Verbose flag options.stretch, # flex amount options.udp_addr, # udp ip address udp_port, # udp port or zero False) # dump raw u vectors self.vocoders.append(t) for i in range(options.nchannels): self.connect((self.audio_input, i), self.audio_amps[i], self.converters[i], self.vocoders[i]) if options.output_files: self.connect(self.vocoders[i], self.output_files[i])
def __init__(self, uhd_address, options): gr.top_block.__init__(self) self.uhd_addr = uhd_address self.freq = options.freq self.samp_rate = options.samp_rate self.gain = options.gain self.threshold = options.threshold self.trigger = options.trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1, ) self.uhd_src.set_samp_rate(self.samp_rate) self.uhd_src.set_center_freq(self.freq, 0) self.uhd_src.set_gain(self.gain, 0) taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = gr.fir_filter_ccc(10, taps) self.tagger = gr.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods data = 1000*[0,] + 1000*[1,] self.signal = gr.vector_source_s(data, True) # Energy detector to get signal burst ## use squelch to detect energy self.det = gr.simple_squelch_cc(self.threshold, 0.01) ## convert to mag squared (float) self.c2m = gr.complex_to_mag_squared() ## average to debounce self.avg = gr.single_pole_iir_filter_ff(0.01) ## rescale signal for conversion to short self.scale = gr.multiply_const_ff(2**16) ## signal input uses shorts self.f2s = gr.float_to_short() # Use file sink burst tagger to capture bursts self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## # Connections ################################################## self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) else: # Connect an energy detector signaler to the burst tagger self.connect(self.uhd_src, self.det) self.connect(self.det, self.c2m, self.avg, self.scale, self.f2s) self.connect(self.f2s, (self.tagger, 1))
def __init__(self, fft_length): gr.hier_block2.__init__(self, "foe", gr.io_signature2(2,2,gr.sizeof_gr_complex,gr.sizeof_char), gr.io_signature(1,1,gr.sizeof_float)) self.input = (self,0) self.time_sync = (self,1) # P(d) self.nominator = schmidl_nominator(fft_length) # sample nominator sampler = vector_sampler(gr.sizeof_gr_complex,1) self.connect(self.input, self.nominator, (sampler,0)) self.connect(self.time_sync, (sampler,1)) # calculate epsilon from P(d), epsilon is normalized fractional frequency offset angle = complex_to_arg() self.epsilon = gr.multiply_const_ff(1.0/math.pi) self.connect(sampler, angle, self.epsilon, self) try: gr.hier_block.update_var_names(self, "foe", vars()) gr.hier_block.update_var_names(self, "foe", vars(self)) except: pass
def __init__(self, vlen): gr.hier_block2.__init__(self, "coarse_frequency_offset_estimation", gr.io_signature2(2,2,gr.sizeof_gr_complex,gr.sizeof_char), gr.io_signature (1,1,gr.sizeof_float)) ## Preamble Extraction sampler = vector_sampler(gr.sizeof_gr_complex,vlen) self.connect(self,sampler) self.connect((self,1),(sampler,1)) ## Split block into two parts splitter = gr.vector_to_streams(gr.sizeof_gr_complex*vlen/2,2) self.connect(sampler,splitter) ## Multiply 2nd sub-part with conjugate of 1st sub-part conj_mult = gr.multiply_conjugate_cc(vlen/2) self.connect((splitter,1),(conj_mult,0)) self.connect((splitter,0),(conj_mult,1)) ## Sum of Products psum = vector_sum_vcc(vlen/2) self.connect((conj_mult,0),psum) ## Complex to Angle angle = complex_to_arg() self.connect(psum,angle) ## Normalize norm = gr.multiply_const_ff(1.0/math.pi) self.connect(angle,norm) ## Setup Output Connections self.connect(norm,self)
def __init__(self, length, debug=False): """ Hierarchical block to detect Null symbols @param length length of the Null symbol (in samples) @param debug whether to write signals out to files """ gr.hier_block2.__init__(self,"detect_null", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_char)) # output signature # get the magnitude squared self.ns_c2magsquared = gr.complex_to_mag_squared() # this wastes cpu cycles: # ns_detect_taps = [1]*length # self.ns_moving_sum = gr.fir_filter_fff(1,ns_detect_taps) # this isn't better: #self.ns_filter = gr.iir_filter_ffd([1]+[0]*(length-1)+[-1],[0,1]) # this does the same again, but is actually faster (outsourced to an independent block ..): self.ns_moving_sum = dab_swig.moving_sum_ff(length) self.ns_invert = gr.multiply_const_ff(-1) # peak detector on the inverted, summed up signal -> we get the nulls (i.e. the position of the start of a frame) self.ns_peak_detect = gr.peak_detector_fb(0.6,0.7,10,0.0001) # mostly found by try and error -> remember that the values are negative! # connect it all self.connect(self, self.ns_c2magsquared, self.ns_moving_sum, self.ns_invert, self.ns_peak_detect, self) if debug: self.connect(self.ns_invert, gr.file_sink(gr.sizeof_float, "debug/ofdm_sync_dab_ns_filter_inv_f.dat")) self.connect(self.ns_peak_detect,gr.file_sink(gr.sizeof_char, "debug/ofdm_sync_dab_peak_detect_b.dat"))
def __init__(self, fft_length): gr.hier_block2.__init__( self, "foe", gr.io_signature2(2, 2, gr.sizeof_gr_complex, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_float)) self.input = (self, 0) self.time_sync = (self, 1) # P(d) self.nominator = schmidl_nominator(fft_length) # sample nominator sampler = vector_sampler(gr.sizeof_gr_complex, 1) self.connect(self.input, self.nominator, (sampler, 0)) self.connect(self.time_sync, (sampler, 1)) # calculate epsilon from P(d), epsilon is normalized fractional frequency offset angle = complex_to_arg() self.epsilon = gr.multiply_const_ff(1.0 / math.pi) self.connect(sampler, angle, self.epsilon, self) try: gr.hier_block.update_var_names(self, "foe", vars()) gr.hier_block.update_var_names(self, "foe", vars(self)) except: pass
def punctest(self, nc, np): length = 2046 # should be divisible by nc data = [random.randint(0, 255) for i in range(length)] # last K-1 bits are padding, meaning last byte is lost data[-1] = 0 data = tuple(data) src = gr.vector_source_b(data) enc = raw.conv_enc() dec = raw.conv_dec(length * 8) punc = raw.conv_punc(nc, np) depunc = raw.conv_punc(np, nc, 128) tofloat = gr.uchar_to_float() offset = gr.multiply_const_ff(255.0) touchar = gr.float_to_uchar() dst = gr.vector_sink_b() rx = gr.vector_sink_b() self.tb.connect(src, enc, punc, tofloat, offset, touchar, depunc, dec, dst) self.tb.connect(punc, rx) self.tb.run() rxlen = len(rx.data()) self.assertEqual(rxlen, (length * 8 * 2 * np) / nc) self.assertEqual(data, dst.data())
def __init__(self, vlen): gr.hier_block2.__init__( self, "coarse_frequency_offset_estimation", gr.io_signature2(2, 2, gr.sizeof_gr_complex, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_float)) ## Preamble Extraction sampler = vector_sampler(gr.sizeof_gr_complex, vlen) self.connect(self, sampler) self.connect((self, 1), (sampler, 1)) ## Split block into two parts splitter = gr.vector_to_streams(gr.sizeof_gr_complex * vlen / 2, 2) self.connect(sampler, splitter) ## Multiply 2nd sub-part with conjugate of 1st sub-part conj_mult = gr.multiply_conjugate_cc(vlen / 2) self.connect((splitter, 1), (conj_mult, 0)) self.connect((splitter, 0), (conj_mult, 1)) ## Sum of Products psum = vector_sum_vcc(vlen / 2) self.connect((conj_mult, 0), psum) ## Complex to Angle angle = complex_to_arg() self.connect(psum, angle) ## Normalize norm = gr.multiply_const_ff(1.0 / math.pi) self.connect(angle, norm) ## Setup Output Connections self.connect(norm, self)
def __init__(self, sps, channel_decim, channel_taps, options, usrp_rate, channel_rate, lo_freq): gr.hier_block2.__init__(self, "rx_channel_cqpsk", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float)) chan = gr.freq_xlating_fir_filter_ccf(int(channel_decim), channel_taps, lo_freq, usrp_rate) agc = gr.feedforward_agc_cc(16, 1.0) gain_omega = 0.125 * options.gain_mu * options.gain_mu alpha = options.costas_alpha beta = 0.125 * alpha * alpha fmin = -0.025 fmax = 0.025 clock = repeater.gardner_costas_cc(sps, options.gain_mu, gain_omega, alpha, beta, fmax, fmin) # Perform Differential decoding on the constellation diffdec = gr.diff_phasor_cc() # take angle of the difference (in radians) to_float = gr.complex_to_arg() # convert from radians such that signal is in -3/-1/+1/+3 rescale = gr.multiply_const_ff( (1 / (pi / 4)) ) self.connect (self, chan, agc, clock, diffdec, to_float, rescale, self)
def test_00(self): expected_result = ( 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff) # Filter taps to expand the data to oversample by 8 # Just using a RRC for some basic filter shape taps = gr.firdes.root_raised_cosine(8, 8, 1.0, 0.5, 21) src = gr.vector_source_b(expected_result) frame = digital.simple_framer(4) unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) expand = gr.interp_fir_filter_fff(8, taps) b2f = gr.char_to_float() mult2 = gr.multiply_const_ff(2) sub1 = gr.add_const_ff(-1) op = digital.simple_correlator(4) dst = gr.vector_sink_b() self.tb.connect(src, frame, unpack, b2f, mult2, sub1, expand) self.tb.connect(expand, op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_001_enc(self): length = 2048 # DANGER: this fails for > 2048 for some reason data = [random.randint(0, 255) for i in range(length)] # last K-1 bits are padding, meaning last byte is lost data[-1] = 0 data = tuple(data) src = gr.vector_source_b(data) enc = raw.conv_enc() tofloat = gr.uchar_to_float() offset = gr.multiply_const_ff(255.0) touchar = gr.float_to_uchar() dec = raw.conv_dec(length * 8) dst = gr.vector_sink_b() self.tb.connect(src, enc, tofloat, offset, touchar, dec, dst) self.tb.run() #self.assertEqual (data, dst.data()) nerrors = 0 i = 0 for (a, b) in itertools.izip(data, dst.data()): nerr = bitCount(a ^ b) if nerr: print "%g " % (i / 2048.), nerr nerrors += nerr i += 1 print "Number or Errors %d BER %g" % (nerrors, (nerrors * 1.0 / (length * 8))) self.assertEqual(nerrors, 0)
def __init__(self, uhd_address, options): gr.top_block.__init__(self) self.uhd_addr = uhd_address self.freq = options.freq self.samp_rate = options.samp_rate self.gain = options.gain self.threshold = options.threshold self.trigger = options.trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, stream_args=uhd.stream_args('fc32')) self.uhd_src.set_samp_rate(self.samp_rate) self.uhd_src.set_center_freq(self.freq, 0) self.uhd_src.set_gain(self.gain, 0) taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = gr.fir_filter_ccc(10, taps) self.tagger = gr.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods data = 1000 * [ 0, ] + 1000 * [ 1, ] self.signal = gr.vector_source_s(data, True) # Energy detector to get signal burst ## use squelch to detect energy self.det = gr.simple_squelch_cc(self.threshold, 0.01) ## convert to mag squared (float) self.c2m = gr.complex_to_mag_squared() ## average to debounce self.avg = gr.single_pole_iir_filter_ff(0.01) ## rescale signal for conversion to short self.scale = gr.multiply_const_ff(2**16) ## signal input uses shorts self.f2s = gr.float_to_short() # Use file sink burst tagger to capture bursts self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## # Connections ################################################## self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) else: # Connect an energy detector signaler to the burst tagger self.connect(self.uhd_src, self.det) self.connect(self.det, self.c2m, self.avg, self.scale, self.f2s) self.connect(self.f2s, (self.tagger, 1))
def __init__(self, options, queue): gr.top_block.__init__(self, "mhp") self.audio_amps = [] self.converters = [] self.vocoders = [] self.output_files = [] input_audio_rate = 8000 self.audio_input = audio.source(input_audio_rate, options.audio_input) for i in range (options.nchannels): udp_port = options.udp_port + i if options.output_files: t = gr.file_sink(gr.sizeof_char, "baseband-%d.dat" % i) self.output_files.append(t) udp_port = 0 t = gr.multiply_const_ff(32767 * options.audio_gain) self.audio_amps.append(t) t = gr.float_to_short() self.converters.append(t) t = repeater.vocoder(True, # 0=Decode,True=Encode options.verbose, # Verbose flag options.stretch, # flex amount options.udp_addr, # udp ip address udp_port, # udp port or zero False) # dump raw u vectors self.vocoders.append(t) for i in range (options.nchannels): self.connect((self.audio_input, i), self.audio_amps[i], self.converters[i], self.vocoders[i]) if options.output_files: self.connect(self.vocoders[i], self.output_files[i])
def __init__(self, fs, svn, alpha, fd_range, dump_bins=False): gr.hier_block2.__init__(self, "acquisition", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(3, 3, gr.sizeof_float)) fft_size = int(1e-3 * fs) doppler_range = self.get_doppler_range(fd_range) agc = gr.agc_cc(1.0 / fs, 1.0, 1.0, 1.0) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) fft = gr.fft_vcc(fft_size, True, []) argmax = gr.argmax_fs(fft_size) max = gr.max_ff(fft_size) self.connect(self, s2v, fft) self.connect((argmax, 0), gr.short_to_float(), (self, 0)) self.connect((argmax, 1), gr.short_to_float(), gr.add_const_ff(-fd_range), gr.multiply_const_ff(1e3), (self, 1)) self.connect(max, (self, 2)) # Connect the individual channels to the input and the output. self.correlators = [ single_channel_correlator(fs, fd, svn, alpha, dump_bins) for fd in doppler_range ] for (correlator, i) in zip(self.correlators, range(len(self.correlators))): self.connect(fft, correlator) self.connect(correlator, (argmax, i)) self.connect(correlator, (max, i))
def __init__( self, if_rate, af_rate ): gr.hier_block2.__init__(self, "ssb_demod", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_float)) self.if_rate = int(if_rate) self.af_rate = int(af_rate) self.if_decim = int(if_rate / af_rate) self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = gr.firdes.low_pass( 1.0, self.af_rate, 3e3, 600, gr.firdes.WIN_HAMMING ) self.xlate = gr.freq_xlating_fir_filter_ccc( self.if_decim, self.xlate_taps, 0, self.if_rate ) self.split = gr.complex_to_float() self.lpf = gr.fir_filter_fff( 1, self.audio_taps ) self.sum = gr.add_ff( ) self.am_sel = gr.multiply_const_ff( 0 ) self.sb_sel = gr.multiply_const_ff( 1 ) self.mixer = gr.add_ff() self.am_det = gr.complex_to_mag() self.connect(self, self.xlate) self.connect(self.xlate, self.split) self.connect((self.split, 0), (self.sum, 0)) self.connect((self.split, 1), (self.sum, 1)) self.connect(self.sum, self.sb_sel) self.connect(self.xlate, self.am_det) self.connect(self.sb_sel, (self.mixer, 0)) self.connect(self.am_det, self.am_sel) self.connect(self.am_sel, (self.mixer, 1)) self.connect(self.mixer, self.lpf) self.connect(self.lpf, self)
def __init__(self, options, queue): gr.top_block.__init__(self, "mhp") sample_rate = options.sample_rate arity = 2 IN = gr.file_source(gr.sizeof_char, options.input_file, options.repeat) B2C = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST) mod_map = [1.0, 3.0, -1.0, -3.0] C2S = gr.chunks_to_symbols_bf(mod_map) if options.reverse: polarity = gr.multiply_const_ff(-1) else: polarity = gr.multiply_const_ff( 1) symbol_rate = 4800 samples_per_symbol = sample_rate // symbol_rate excess_bw = 0.1 ntaps = 11 * samples_per_symbol rrc_taps = gr.firdes.root_raised_cosine( samples_per_symbol, # gain (sps since we're interpolating by sps samples_per_symbol, # sampling rate 1.0, # symbol rate excess_bw, # excess bandwidth (roll-off factor) ntaps) rrc_filter = gr.interp_fir_filter_fff(samples_per_symbol, rrc_taps) rrc_coeffs = [0, -0.003, -0.006, -0.009, -0.012, -0.014, -0.014, -0.013, -0.01, -0.006, 0, 0.007, 0.014, 0.02, 0.026, 0.029, 0.029, 0.027, 0.021, 0.012, 0, -0.013, -0.027, -0.039, -0.049, -0.054, -0.055, -0.049, -0.038, -0.021, 0, 0.024, 0.048, 0.071, 0.088, 0.098, 0.099, 0.09, 0.07, 0.039, 0, -0.045, -0.091, -0.134, -0.17, -0.193, -0.199, -0.184, -0.147, -0.085, 0, 0.105, 0.227, 0.36, 0.496, 0.629, 0.751, 0.854, 0.933, 0.983, 1, 0.983, 0.933, 0.854, 0.751, 0.629, 0.496, 0.36, 0.227, 0.105, 0, -0.085, -0.147, -0.184, -0.199, -0.193, -0.17, -0.134, -0.091, -0.045, 0, 0.039, 0.07, 0.09, 0.099, 0.098, 0.088, 0.071, 0.048, 0.024, 0, -0.021, -0.038, -0.049, -0.055, -0.054, -0.049, -0.039, -0.027, -0.013, 0, 0.012, 0.021, 0.027, 0.029, 0.029, 0.026, 0.02, 0.014, 0.007, 0, -0.006, -0.01, -0.013, -0.014, -0.014, -0.012, -0.009, -0.006, -0.003, 0] # rrc_coeffs work slightly differently: each input sample # (from mod_map above) at 4800 rate, then 9 zeros are inserted # to bring to a 48000 rate, then this filter is applied: # rrc_filter = gr.fir_filter_fff(1, rrc_coeffs) # FIXME: how to insert the 9 zero samples using gr ? # FM pre-emphasis filter shaping_coeffs = [-0.018, 0.0347, 0.0164, -0.0064, -0.0344, -0.0522, -0.0398, 0.0099, 0.0798, 0.1311, 0.121, 0.0322, -0.113, -0.2499, -0.3007, -0.2137, -0.0043, 0.2825, 0.514, 0.604, 0.514, 0.2825, -0.0043, -0.2137, -0.3007, -0.2499, -0.113, 0.0322, 0.121, 0.1311, 0.0798, 0.0099, -0.0398, -0.0522, -0.0344, -0.0064, 0.0164, 0.0347, -0.018] shaping_filter = gr.fir_filter_fff(1, shaping_coeffs) OUT = audio.sink(sample_rate, options.audio_output) amp = gr.multiply_const_ff(options.factor) self.connect(IN, B2C, C2S, polarity, rrc_filter, shaping_filter, amp) # output to both L and R channels self.connect(amp, (OUT,0) ) self.connect(amp, (OUT,1) )
def __init__(self,k): gr.hier_block2.__init__(self,"BER Estimator", gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,1,gr.sizeof_float)) self.add = gr.add_const_vff((-1, )) self.mult= gr.multiply_const_ff(-1/k) self.connect(self,self.add, self.mult,self)
def __build_graph(self, source, capture_rate): # tell the scope the source rate self.spectrum.set_sample_rate(capture_rate) # channel filter self.channel_offset = 0.0 channel_decim = capture_rate // self.channel_rate channel_rate = capture_rate // channel_decim trans_width = 12.5e3 / 2 trans_centre = trans_width + (trans_width / 2) # discriminator tap doesn't do freq. xlation, FM demodulation, etc. if not self.baseband_input: coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN) self.channel_filter = gr.freq_xlating_fir_filter_ccf( channel_decim, coeffs, 0.0, capture_rate) self.set_channel_offset(0.0, 0, self.spectrum.win._units) # power squelch squelch_db = 0 self.squelch = gr.pwr_squelch_cc(squelch_db, 1e-3, 0, True) self.set_squelch_threshold(squelch_db) # FM demodulator fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation) fm_demod = gr.quadrature_demod_cf(fm_demod_gain) # symbol filter symbol_decim = 1 #symbol_coeffs = gr.firdes.root_raised_cosine(1.0, channel_rate, self.symbol_rate, 0.2, 500) # boxcar coefficients for "integrate and dump" filter samples_per_symbol = channel_rate // self.symbol_rate symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs) # C4FM demodulator autotuneq = gr.msg_queue(2) demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, self.symbol_rate) # for now no audio output sink = gr.null_sink(gr.sizeof_float) # connect it all up if self.baseband_input: self.rescaler = gr.multiply_const_ff(1) sinkx = gr.file_sink(gr.sizeof_float, "rx.dat") self.__connect([[ source, self.rescaler, self.symbol_filter, demod_fsk4, self.slicer, self.p25_decoder, sink ], [self.symbol_filter, self.signal_scope], [demod_fsk4, sinkx], [demod_fsk4, self.symbol_scope]]) self.connect_data_scope(not self.datascope_raw_input) else: self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset) self.__connect([[ source, self.channel_filter, self.squelch, fm_demod, self.symbol_filter, demod_fsk4, self.slicer, self.p25_decoder, sink ], [source, self.spectrum], [self.symbol_filter, self.signal_scope], [demod_fsk4, self.symbol_scope]])
def __init__(self, rate, device): gr.hier_block2.__init__(self, "output", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0, 0, 0)) self.vol = gr.multiply_const_ff(0.1) self.out = audio.sink(int(rate), device) self.connect(self, self.vol, self.out)
def __init__( self, rate, device ): gr.hier_block2.__init__(self, "output", gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(0,0,0)) self.vol = gr.multiply_const_ff( 0.1 ) self.out = audio.sink( int(rate), device ) self.connect( self, self.vol, self.out )
def __init__(self, k): gr.hier_block2.__init__(self, "BER Estimator", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) self.add = gr.add_const_vff((-1, )) self.mult = gr.multiply_const_ff(-1 / k) self.connect(self, self.add, self.mult, self)
def __init__(self, subdev_spec, audio_input): gr.hier_block2.__init__( self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self.if_rate = 320e3 # 320 kS/s self.usrp_interp = int(dac_rate // self.if_rate) self.u.set_interp_rate(self.usrp_interp) self.sw_interp = 10 self.audio_rate = self.if_rate // self.sw_interp # 32 kS/s self.audio_gain = 10 self.normal_gain = 32000 self.audio = audio.source(int(self.audio_rate), audio_input) self.audio_amp = gr.multiply_const_ff(self.audio_gain) lpf = gr.firdes.low_pass( 1, # gain self.audio_rate, # sampling rate 3800, # low pass cutoff freq 300, # width of trans. band gr.firdes.WIN_HANN) # filter type hpf = gr.firdes.high_pass( 1, # gain self.audio_rate, # sampling rate 325, # low pass cutoff freq 50, # width of trans. band gr.firdes.WIN_HANN) # filter type audio_taps = convolve(array(lpf), array(hpf)) self.audio_filt = gr.fir_filter_fff(1, audio_taps) self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0) self.add_pl = gr.add_ff() self.connect(self.pl, (self.add_pl, 1)) self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate) self.amp = gr.multiply_const_cc(self.normal_gain) # determine the daughterboard subdevice we're using if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec)) self.subdev = usrp.selected_subdev(self.u, subdev_spec) print "TX using", self.subdev.name() self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain
def __init__( self, fg, if_rate, af_rate ): self.if_rate = if_rate self.af_rate = af_rate self.if_decim = if_rate / af_rate self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = gr.firdes.low_pass( 1.0, self.af_rate, 3e3, 600, gr.firdes.WIN_HAMMING ) self.xlate = gr.freq_xlating_fir_filter_ccc( self.if_decim, self.xlate_taps, 0, self.if_rate ) self.split = gr.complex_to_float() self.lpf = gr.fir_filter_fff( 1, self.audio_taps ) self.sum = gr.add_ff( ) self.am_sel = gr.multiply_const_ff( 0 ) self.sb_sel = gr.multiply_const_ff( 1 ) self.mixer = gr.add_ff() self.am_det = gr.complex_to_mag() fg.connect( self.xlate, self.split ) fg.connect( ( self.split,0 ), ( self.sum,0 ) ) fg.connect( ( self.split,1 ), ( self.sum,1 ) ) fg.connect( self.sum, self.sb_sel ) fg.connect( self.xlate, self.am_det ) fg.connect( self.sb_sel, ( self.mixer, 0 ) ) fg.connect( self.am_det, self.am_sel ) fg.connect( self.am_sel, ( self.mixer, 1 ) ) fg.connect( self.mixer, self.lpf ) gr.hier_block.__init__( self, fg, self.xlate, self.lpf )
def __init__(self, subdev_spec, audio_input): gr.hier_block2.__init__( self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0) # Input signature ) # Output signature self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self.if_rate = 320e3 # 320 kS/s self.usrp_interp = int(dac_rate // self.if_rate) self.u.set_interp_rate(self.usrp_interp) self.sw_interp = 10 self.audio_rate = self.if_rate // self.sw_interp # 32 kS/s self.audio_gain = 10 self.normal_gain = 32000 self.audio = audio.source(int(self.audio_rate), audio_input) self.audio_amp = gr.multiply_const_ff(self.audio_gain) lpf = gr.firdes.low_pass( 1, # gain self.audio_rate, # sampling rate 3800, # low pass cutoff freq 300, # width of trans. band gr.firdes.WIN_HANN, ) # filter type hpf = gr.firdes.high_pass( 1, # gain self.audio_rate, # sampling rate 325, # low pass cutoff freq 50, # width of trans. band gr.firdes.WIN_HANN, ) # filter type audio_taps = convolve(array(lpf), array(hpf)) self.audio_filt = gr.fir_filter_fff(1, audio_taps) self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0) self.add_pl = gr.add_ff() self.connect(self.pl, (self.add_pl, 1)) self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate) self.amp = gr.multiply_const_cc(self.normal_gain) # determine the daughterboard subdevice we're using if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec)) self.subdev = usrp.selected_subdev(self.u, subdev_spec) print "TX using", self.subdev.name() self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain
def __init__(self): gr.flow_graph.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option( "-T", "--tx-subdev-spec", type="subdev", default=None, help= "select USRP Tx side A or B (default=first one with a daughterboard)" ) parser.add_option("-c", "--cordic-freq", type="eng_float", default=434845200, help="set Tx cordic frequency to FREQ", metavar="FREQ") (options, args) = parser.parse_args() print "cordic_freq = %s" % (eng_notation.num_to_str( options.cordic_freq)) self.normal_gain = 8000 self.u = usrp.sink_s() dac_rate = self.u.dac_rate() self._freq = 1000 self._spb = 256 self._interp = int(128e6 / self._spb / self._freq) self.fs = 128e6 / self._interp print "Interpolation:", self._interp self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if options.tx_subdev_spec is None: options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux( usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec) print "Using TX d'board %s" % (self.subdev.side_and_name(), ) self.u.tune(self.subdev._which, self.subdev, options.cordic_freq) self.sin = gr.sig_source_f(self.fs, gr.GR_SIN_WAVE, self._freq, 1, 0) self.gain = gr.multiply_const_ff(self.normal_gain) self.ftos = gr.float_to_short() self.filesink = gr.file_sink(gr.sizeof_float, 'sin.dat') self.connect(self.sin, self.gain) self.connect(self.gain, self.ftos, self.u) #self.connect(self.gain, self.filesink) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def __init__(self): gr.hier_block2.__init__(self,"BER Estimator", gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,1,gr.sizeof_float)) #TODO Implement a polynomial block in C++ and approximate with polynomials #of arbitrary order self.add = gr.add_const_vff((-1, )) self.square = gr.multiply_ff() self.mult_lin = gr.multiply_const_ff(-0.20473967) self.mult_sq = gr.multiply_const_ff(1.5228658) self.sum = gr.add_ff() self.connect(self,self.add) self.connect(self.add,(self.square,0)) self.connect(self.add,(self.square,1)) self.connect(self.square,self.mult_sq,(self.sum,0)) self.connect(self.add,self.mult_lin,(self.sum,1)) self.connect(self.sum,self)
def __init__(self, fg): self.split = gr.multiply_const_ff(1) self.sqr = gr.multiply_ff() self.int0 = gr.iir_filter_ffd([.004, 0], [0, .999]) self.offs = gr.add_const_ff(-30) self.gain = gr.multiply_const_ff(70) self.log = gr.nlog10_ff(10, 1) self.agc = gr.divide_ff() fg.connect(self.split, (self.agc, 0)) fg.connect(self.split, (self.sqr, 0)) fg.connect(self.split, (self.sqr, 1)) fg.connect(self.sqr, self.int0) fg.connect(self.int0, self.log) fg.connect(self.log, self.offs) fg.connect(self.offs, self.gain) fg.connect(self.gain, (self.agc, 1)) gr.hier_block.__init__(self, fg, self.split, self.agc)
def __init__(self): gr.hier_block2.__init__(self, "BER Estimator", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) #TODO Implement a polynomial block in C++ and approximate with polynomials #of arbitrary order self.add = gr.add_const_vff((-1, )) self.square = gr.multiply_ff() self.mult_lin = gr.multiply_const_ff(-0.20473967) self.mult_sq = gr.multiply_const_ff(1.5228658) self.sum = gr.add_ff() self.connect(self, self.add) self.connect(self.add, (self.square, 0)) self.connect(self.add, (self.square, 1)) self.connect(self.square, self.mult_sq, (self.sum, 0)) self.connect(self.add, self.mult_lin, (self.sum, 1)) self.connect(self.sum, self)
def test_031_multiple_internal_inputs(self): tb = gr.top_block() src = gr.vector_source_f([ 1.0, ]) hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) m1 = gr.multiply_const_ff(1.0) m2 = gr.multiply_const_ff(2.0) add = gr.add_ff() hb.connect(hb, m1) # m1 is connected to hb external input #0 hb.connect(hb, m2) # m2 is also connected to hb external input #0 hb.connect(m1, (add, 0)) hb.connect(m2, (add, 1)) hb.connect(add, hb) # add is connected to hb external output #0 dst = gr.vector_sink_f() tb.connect(src, hb, dst) tb.run() self.assertEquals(dst.data(), (3.0, ))
def __init__(self, fg): self.split = gr.multiply_const_ff(1) self.sqr = gr.multiply_ff() self.int0 = gr.iir_filter_ffd([0.004, 0], [0, 0.999]) self.offs = gr.add_const_ff(-30) self.gain = gr.multiply_const_ff(70) self.log = gr.nlog10_ff(10, 1) self.agc = gr.divide_ff() fg.connect(self.split, (self.agc, 0)) fg.connect(self.split, (self.sqr, 0)) fg.connect(self.split, (self.sqr, 1)) fg.connect(self.sqr, self.int0) fg.connect(self.int0, self.log) fg.connect(self.log, self.offs) fg.connect(self.offs, self.gain) fg.connect(self.gain, (self.agc, 1)) gr.hier_block.__init__(self, fg, self.split, self.agc)
def __init__(self, options, args): gr.top_block.__init__(self) self.options = options self.args = args frekvens = options.freq # u = usrp.source_c(0) # u.set_decim_rate(256) # subdev_spec = (1,0) # u.set_mux(usrp.determine_rx_mux_value(u,subdev_spec)) # subdev = usrp.selected_subdev(u,subdev_spec) # subdev.set_auto_tr(True) # subdev.set_gain(57) # usrp.tune(u,0,subdev,frekvens)#106.3e6) # samplerate = 64000000/256 # 250000 self.u = uhd.usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32, 1) self.u.set_subdev_spec("") # default should be good? self.u.set_samp_rate(250e3) samplerate = self.u.get_samp_rate() # Retrieve what it actually does self.u.set_antenna("RX2", 0) if options.gain is None: # set to halfway g = self.u.get_gain_range() options.gain = (g.start() + g.stop()) / 2.0 if not (self.u.set_center_freq(frekvens, 0)): print "Failed to set frequency" sys.exit(1) print "Setting gain to %i" % options.gain self.u.set_gain(options.gain) coeffs = gr.firdes.low_pass(1, samplerate, 10000, 10000) filter = gr.fir_filter_ccf(5, coeffs) gang = gr.multiply_const_ff(10) lpcoeffs = gr.firdes.low_pass(1, samplerate, 8000, 3000) lpfilter = gr.fir_filter_fff(1, lpcoeffs) demod = gr.quadrature_demod_cf(0.5) clockrec = gr.clock_recovery_mm_ff( float(samplerate) / 5 / 9600, 0.25 * 0.175 * 0.175, 0.5, 0.175, 0.005) #datadec = ais.ais_decoder_mysql("localhost","diverse","aisblock","elgelg") self.datadec = ais.ais_decoder_gearth(30003) slicer = gr.binary_slicer_fb() diff = gr.diff_decoder_bb(2) invert = ais.invert10_bb() # print subdev.name() self.connect(self.u, filter, demod, lpfilter, gang, clockrec, slicer, diff, invert, self.datadec)
def __init__(self, audio_output_dev): gr.hier_block2.__init__(self, "audio_tx", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.packet_src = gr.message_source(33) voice_decoder = gsm_full_rate.decode_ps() s2f = gr.short_to_float () sink_scale = gr.multiply_const_ff(1.0/32767.) audio_sink = audio.sink(8000, audio_output_dev) self.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink)
def __init__(self, audio_input_dev): gr.hier_block2.__init__(self, "audio_rx", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature sample_rate = 44100 src = audio.source(sample_rate, audio_input_dev) src_scale = gr.multiply_const_ff(32767) f2s = gr.float_to_short() voice_coder = gsm_full_rate.encode_sp() self.packets_from_encoder = gr.msg_queue() packet_sink = gr.message_sink(33, self.packets_from_encoder, False) self.connect(src, src_scale, f2s, voice_coder, packet_sink)
def __init__(self, audio_input_dev): gr.hier_block2.__init__(self, "audio_rx", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature sample_rate = 8000 src = audio.source(sample_rate, audio_input_dev) src_scale = gr.multiply_const_ff(32767) f2s = gr.float_to_short() voice_coder = gsm_full_rate.encode_sp() self.packets_from_encoder = gr.msg_queue() packet_sink = gr.message_sink(33, self.packets_from_encoder, False) self.connect(src, src_scale, f2s, voice_coder, packet_sink)
def __init__(self, if_rate, af_rate): gr.hier_block2.__init__(self, "ssb_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float)) self.if_rate = int(if_rate) self.af_rate = int(af_rate) self.if_decim = int(if_rate / af_rate) self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = gr.firdes.low_pass(1.0, self.af_rate, 3e3, 600, gr.firdes.WIN_HAMMING) self.xlate = gr.freq_xlating_fir_filter_ccc(self.if_decim, self.xlate_taps, 0, self.if_rate) self.split = gr.complex_to_float() self.lpf = gr.fir_filter_fff(1, self.audio_taps) self.sum = gr.add_ff() self.am_sel = gr.multiply_const_ff(0) self.sb_sel = gr.multiply_const_ff(1) self.mixer = gr.add_ff() self.am_det = gr.complex_to_mag() self.connect(self, self.xlate) self.connect(self.xlate, self.split) self.connect((self.split, 0), (self.sum, 0)) self.connect((self.split, 1), (self.sum, 1)) self.connect(self.sum, self.sb_sel) self.connect(self.xlate, self.am_det) self.connect(self.sb_sel, (self.mixer, 0)) self.connect(self.am_det, self.am_sel) self.connect(self.am_sel, (self.mixer, 1)) self.connect(self.mixer, self.lpf) self.connect(self.lpf, self)
def __init__(self, options, args): gr.top_block.__init__(self) self.options = options self.args = args frekvens = options.freq # u = usrp.source_c(0) # u.set_decim_rate(256) # subdev_spec = (1,0) # u.set_mux(usrp.determine_rx_mux_value(u,subdev_spec)) # subdev = usrp.selected_subdev(u,subdev_spec) # subdev.set_auto_tr(True) # subdev.set_gain(57) # usrp.tune(u,0,subdev,frekvens)#106.3e6) # samplerate = 64000000/256 # 250000 self.u = uhd.usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32,1) self.u.set_subdev_spec(""); # default should be good? self.u.set_samp_rate(250e3); samplerate = self.u.get_samp_rate() # Retrieve what it actually does self.u.set_antenna("RX2",0) if options.gain is None: # set to halfway g = self.u.get_gain_range() options.gain = (g.start()+g.stop()) / 2.0 if not(self.u.set_center_freq(frekvens, 0)): print "Failed to set frequency" sys.exit(1) print "Setting gain to %i" % options.gain self.u.set_gain(options.gain) coeffs = gr.firdes.low_pass(1,samplerate,10000,10000) filter = gr.fir_filter_ccf(5,coeffs) gang = gr.multiply_const_ff(10) lpcoeffs = gr.firdes.low_pass(1,samplerate,8000,3000) lpfilter = gr.fir_filter_fff(1,lpcoeffs) demod = gr.quadrature_demod_cf(0.5) clockrec = gr.clock_recovery_mm_ff(float(samplerate)/5/9600,0.25*0.175*0.175,0.5,0.175,0.005) #datadec = ais.ais_decoder_mysql("localhost","diverse","aisblock","elgelg") self.datadec = ais.ais_decoder_gearth(30003) slicer = gr.binary_slicer_fb() diff = gr.diff_decoder_bb(2) invert = ais.invert10_bb() # print subdev.name() self.connect(self.u,filter,demod,lpfilter,gang,clockrec, slicer,diff,invert,self.datadec)
def __init__( self, parent, unit='%', minval=0, maxval=100, decimal_places=5, sample_rate=1, number_rate=DEFAULT_NUMBER_RATE, label='Bit Error Rate', size=DEFAULT_WIN_SIZE, show_gauge=True, **kwargs #catchall for backwards compatibility ): gr.hier_block2.__init__( self, "number_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) #blocks sd = blks2.stream_to_vector_decimator( item_size=self._item_size, sample_rate=sample_rate, vec_rate=number_rate, vec_len=1, ) mult = gr.multiply_const_ff(100) add = gr.add_const_ff(1e-10) msgq = gr.msg_queue(2) sink = gr.message_sink(self._item_size, msgq, True) #connect self.connect(self, sd, mult, add, sink) #controller self.controller = pubsub() #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = number_window(parent=parent, controller=self.controller, size=size, title=label, units=unit, real=self._real, minval=minval, maxval=maxval, decimal_places=decimal_places, show_gauge=show_gauge, msg_key=MSG_KEY, sample_rate_key=SAMPLE_RATE_KEY)
def __init__(self): gr.hier_block2.__init__(self, "agc", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) self.split = gr.multiply_const_ff(1) self.sqr = gr.multiply_ff() self.int0 = gr.iir_filter_ffd([.004, 0], [0, .999]) self.offs = gr.add_const_ff(-30) self.gain = gr.multiply_const_ff(70) self.log = gr.nlog10_ff(10, 1) self.agc = gr.divide_ff() self.connect(self, self.split) self.connect(self.split, (self.agc, 0)) self.connect(self.split, (self.sqr, 0)) self.connect(self.split, (self.sqr, 1)) self.connect(self.sqr, self.int0) self.connect(self.int0, self.log) self.connect(self.log, self.offs) self.connect(self.offs, self.gain) self.connect(self.gain, (self.agc, 1)) self.connect(self.agc, self)
def __init__(self, bits_per_byte): gr.hier_block2.__init__(self, "BitErrors", gr.io_signature(2, 2, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_int)) # Bit comparison comp = gr.xor_bb() intdump_decim = 100000 if N_BITS < intdump_decim: intdump_decim = int(N_BITS) self.connect(self, comp, gr.unpack_k_bits_bb(bits_per_byte), gr.uchar_to_float(), gr.integrate_ff(intdump_decim), gr.multiply_const_ff(1.0 / N_BITS), self) self.connect((self, 1), (comp, 1))
def xtest_ccsds_27(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) expected = (0, 0, 0, 0, 1, 2, 3, 4, 5, 6) src = gr.vector_source_b(src_data) enc = gr.encode_ccsds_27_bb() b2f = gr.char_to_float() add = gr.add_const_ff(-0.5) mul = gr.multiply_const_ff(2.0) dec = gr.decode_ccsds_27_fb() dst = gr.vector_sink_b() self.tb.connect(src, enc, b2f, add, mul, dec, dst) self.tb.run() dst_data = dst.data() self.assertEqual(expected, dst_data)
def __init__(self, audio_output_dev): gr.hier_block2.__init__( self, "audio_tx", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.packet_src = gr.message_source(33) voice_decoder = gsm_full_rate.decode_ps() s2f = gr.short_to_float() sink_scale = gr.multiply_const_ff(1.0 / 32767.) audio_sink = audio.sink(8000, audio_output_dev) self.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink)
def __init__(self, fg, if_rate, af_rate): self.if_rate = if_rate self.af_rate = af_rate self.if_decim = if_rate / af_rate self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = gr.firdes.low_pass(1.0, self.af_rate, 3e3, 600, gr.firdes.WIN_HAMMING) self.xlate = gr.freq_xlating_fir_filter_ccc(self.if_decim, self.xlate_taps, 0, self.if_rate) self.split = gr.complex_to_float() self.lpf = gr.fir_filter_fff(1, self.audio_taps) self.sum = gr.add_ff() self.am_sel = gr.multiply_const_ff(0) self.sb_sel = gr.multiply_const_ff(1) self.mixer = gr.add_ff() self.am_det = gr.complex_to_mag() fg.connect(self.xlate, self.split) fg.connect((self.split, 0), (self.sum, 0)) fg.connect((self.split, 1), (self.sum, 1)) fg.connect(self.sum, self.sb_sel) fg.connect(self.xlate, self.am_det) fg.connect(self.sb_sel, (self.mixer, 0)) fg.connect(self.am_det, self.am_sel) fg.connect(self.am_sel, (self.mixer, 1)) fg.connect(self.mixer, self.lpf) gr.hier_block.__init__(self, fg, self.xlate, self.lpf)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, constellation, Es, N0, IT, seed): tb = gr.top_block() # TX src = gr.lfsr_32k_source_s() src_head = gr.head(gr.sizeof_short, Kb / 16) # packet size in shorts s2fsmi = gr.packed_to_unpacked_ss( bitspersymbol, gr.GR_MSB_FIRST ) # unpack shorts to symbols compatible with the outer FSM input cardinality #src = gr.vector_source_s([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],False) enc = trellis.pccc_encoder_ss(fo, 0, fi, 0, interleaver, K) code = gr.vector_sink_s() mod = gr.chunks_to_symbols_sf(constellation, dimensionality) # CHANNEL add = gr.add_ff() noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX metrics_in = trellis.metrics_f( fi.O() * fo.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN ) # data preprocessing to generate metrics for innner SISO scale = gr.multiply_const_ff(1.0 / N0) dec = trellis.pccc_decoder_s(fo, 0, -1, fi, 0, -1, interleaver, K, IT, trellis.TRELLIS_MIN_SUM) fsmi2s = gr.unpacked_to_packed_ss( bitspersymbol, gr.GR_MSB_FIRST) # pack FSM input symbols to shorts dst = gr.check_lfsr_32k_s() tb.connect(src, src_head, s2fsmi, enc, mod) #tb.connect (src,enc,mod) #tb.connect(enc,code) tb.connect(mod, (add, 0)) tb.connect(noise, (add, 1)) tb.connect(add, metrics_in, scale, dec, fsmi2s, dst) tb.run() #print code.data() ntotal = dst.ntotal() nright = dst.nright() runlength = dst.runlength() return (ntotal, ntotal - nright)