def __init__(self): gr.top_block.__init__(self) parser = ArgumentParser() parser.add_argument("-O", "--audio-output", default="", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-i", "--input-rate", type=eng_float, default=8000, help="set input sample rate to RATE %(default)r") parser.add_argument("-o", "--output-rate", type=eng_float, default=48000, help="set output sample rate to RATE %(default)r") args = parser.parse_args() input_rate = int(args.input_rate) output_rate = int(args.output_rate) interp = gru.lcm(input_rate / output_rate, input_rate) decim = gru.lcm(input_rate / output_rate, output_rate) print("interp =", interp) print("decim =", decim) ampl = 0.1 src0 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 650, ampl) rr = filter.rational_resampler_fff(interp, decim) dst = audio.sink(output_rate, args.audio_output) self.connect(src0, rr, (dst, 0))
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-O", "--audio-output", type="string", default="", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-i", "--input-rate", type="eng_float", default=8000, help="set input sample rate to RATE (%default)") parser.add_option("-o", "--output-rate", type="eng_float", default=48000, help="set output sample rate to RATE (%default)") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 input_rate = int(options.input_rate) output_rate = int(options.output_rate) interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate print "interp =", interp print "decim =", decim ampl = 0.1 src0 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 650, ampl) rr = filter.rational_resampler_fff(interp, decim) dst = audio.sink(output_rate, options.audio_output) self.connect(src0, rr, (dst, 0))
def __init__(self): gr.top_block.__init__(self) parser = ArgumentParser() parser.add_argument( "-O", "--audio-output", default="", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-i", "--input-rate", type=eng_float, default=8000, help="set input sample rate to RATE %(default)r") parser.add_argument("-o", "--output-rate", type=eng_float, default=48000, help="set output sample rate to RATE %(default)r") args = parser.parse_args() input_rate = int(args.input_rate) output_rate = int(args.output_rate) interp = gru.lcm(input_rate / output_rate, input_rate) decim = gru.lcm(input_rate / output_rate, output_rate) print("interp =", interp) print("decim =", decim) ampl = 0.1 src0 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 650, ampl) rr = filter.rational_resampler_fff(interp, decim) dst = audio.sink(output_rate, args.audio_output) self.connect(src0, rr, (dst, 0))
def __init__(self, channel_rate, threshold): gr.hier_block2.__init__(self, "ppm_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, 512)) chan_rate = 8000000 # Minimum sample rate if channel_rate < chan_rate: raise ValueError, "Invalid channel rate %d. Must be 8000000 sps or higher" % (channel_rate) if channel_rate >= 10000000: chan_rate = 10000000 # Higher Performance Receiver # if rate is not supported then resample if channel_rate != chan_rate: interp = gru.lcm(channel_rate, chan_rate)/channel_rate decim = gru.lcm(channel_rate, chan_rate)/chan_rate self.RESAMP = rational_resampler_ccf(self, interp, decim) # Calculate the leading edge threshold per sample time leading_edge = risetime_threshold_db/(chan_rate/data_rate) # Calculate the number of following samples above threshold needed to make a sample a valid pulse position valid_pulse_position = 2 if chan_rate == 10000000: valid_pulse_position = 3 # Demodulate AM with classic sqrt (I*I + Q*Q) self.MAG = gr.complex_to_mag() self.DETECT = air.ms_pulse_detect(leading_edge, threshold, valid_pulse_position) # Attack, Threshold, Pulsewidth self.SYNC = air.ms_preamble(chan_rate) self.FRAME = air.ms_framer(chan_rate) self.BIT = air.ms_ppm_decode(chan_rate) self.PARITY = air.ms_parity() self.EC = air.ms_ec_brute() if channel_rate != chan_rate: # Resample the stream first self.connect(self, self.RESAMP, self.MAG, self.DETECT) else: self.connect(self, self.MAG, self.DETECT) self.connect((self.DETECT, 0), (self.SYNC, 0)) self.connect((self.DETECT, 1), (self.SYNC, 1)) self.connect((self.SYNC, 0), (self.FRAME, 0)) self.connect((self.SYNC, 1), (self.FRAME, 1)) self.connect((self.FRAME, 0), (self.BIT, 0)) self.connect((self.FRAME, 1), (self.BIT, 1)) self.connect(self.BIT, self.PARITY, self.EC, self)
def __init__(self): gr.top_block.__init__(self) input_sample_rate = 1e6 symbol_rate = 152.34e3 output_samples_per_symbol = 5 output_sample_rate = output_samples_per_symbol * symbol_rate # least common multiple lcm = gru.lcm(input_sample_rate, output_sample_rate) intrp = int(lcm // input_sample_rate) decim = int(lcm // output_sample_rate) print intrp print decim resampler = blks2.rational_resampler_ccc(intrp, decim, None, None) src = gr.file_source(gr.sizeof_gr_complex, "infile") sink = gr.file_sink(gr.sizeof_float, "outfile") f2c = gr.float_to_complex() c2r = gr.complex_to_real() #ddc_coeffs = \ #gr.firdes.low_pass (1.0, # gain #input_sample_rate, # sampling rate #2e3, # low pass cutoff freq #6e3, # width of trans. band #gr.firdes.WIN_HANN) # just grab the lower sideband: #ddc = gr.freq_xlating_fir_filter_ccf(1,ddc_coeffs,-111.5e3,input_sample_rate) qdemod = gr.quadrature_demod_cf(1.0) lp_coeffs = \ gr.firdes.low_pass (1.0, # gain output_sample_rate, # sampling rate symbol_rate, # low pass cutoff freq symbol_rate, # width of trans. band gr.firdes.WIN_HANN) lp = gr.fir_filter_fff (1,lp_coeffs) self.connect(src,resampler,qdemod,lp,sink)
def __init__(self, output_rate): gr.hier_block2.__init__(self, "p25_c4fm_mod_bf", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature symbol_rate = 4800 # P25 baseband symbol rate lcm = gru.lcm(symbol_rate, output_rate) self._interp_factor = int(lcm // symbol_rate) self._decimation = int(lcm // output_rate) self._excess_bw =0.2 mod_map = [1.0/3.0, 1.0, -(1.0/3.0), -1.0] self.C2S = gr.chunks_to_symbols_bf(mod_map) ntaps = 11 * self._interp_factor rrc_taps = gr.firdes.root_raised_cosine( self._interp_factor, # gain (since we're interpolating by sps) lcm, # sampling rate symbol_rate, self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_fff(self._interp_factor, rrc_taps) # 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] self.shaping_filter = gr.fir_filter_fff(1, shaping_coeffs) # generate output at appropriate rate self.decimator = blks2.rational_resampler_fff(1, self._decimation) self.connect(self, self.C2S, self.rrc_filter, self.shaping_filter, self.decimator, self)
def __init__(self): gr.top_block.__init__(self) input_sample_rate = 1e6 symbol_rate = 152.34e3 output_samples_per_symbol = 5 output_sample_rate = output_samples_per_symbol * symbol_rate # least common multiple lcm = gru.lcm(input_sample_rate, output_sample_rate) intrp = int(lcm // input_sample_rate) decim = int(lcm // output_sample_rate) print intrp print decim resampler = blks2.rational_resampler_ccc(intrp, decim, None, None) src = gr.file_source(gr.sizeof_gr_complex, "infile") sink = gr.file_sink(gr.sizeof_float, "outfile") f2c = gr.float_to_complex() c2r = gr.complex_to_real() #ddc_coeffs = \ #gr.firdes.low_pass (1.0, # gain #input_sample_rate, # sampling rate #2e3, # low pass cutoff freq #6e3, # width of trans. band #gr.firdes.WIN_HANN) # just grab the lower sideband: #ddc = gr.freq_xlating_fir_filter_ccf(1,ddc_coeffs,-111.5e3,input_sample_rate) qdemod = gr.quadrature_demod_cf(1.0) lp_coeffs = \ gr.firdes.low_pass (1.0, # gain output_sample_rate, # sampling rate symbol_rate, # low pass cutoff freq symbol_rate, # width of trans. band gr.firdes.WIN_HANN) lp = gr.fir_filter_fff(1, lp_coeffs) self.connect(src, resampler, qdemod, lp, sink)
def __init__(self, output_sample_rate=_def_output_sample_rate, reverse=_def_reverse, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered P25 FM modulation. The input is a dibit (P25 symbol) stream (char, not packed) and the output is the float "C4FM" signal at baseband, suitable for application to an FM modulator stage Input is at the base symbol rate (4800), output sample rate is typically either 32000 (USRP TX chain) or 48000 (sound card) @param output_sample_rate: output sample rate @type output_sample_rate: integer @param reverse: reverse polarity flag @type reverse: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modulation data to files? @type debug: bool """ gr.hier_block2.__init__(self, "p25_c4fm_mod_bf", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature input_sample_rate = 4800 # P25 baseband symbol rate lcm = gru.lcm(input_sample_rate, output_sample_rate) self._interp_factor = int(lcm // input_sample_rate) self._decimation = int(lcm // output_sample_rate) mod_map = [1.0/3.0, 1.0, -(1.0/3.0), -1.0] self.C2S = digital.chunks_to_symbols_bf(mod_map) if reverse: self.polarity = blocks.multiply_const_ff(-1) else: self.polarity = blocks.multiply_const_ff( 1) self.filter = filter.interp_fir_filter_fff(self._interp_factor, c4fm_taps(sample_rate=output_sample_rate).generate()) if verbose: self._print_verbage() if log: self._setup_logging() self.connect(self, self.C2S, self.polarity, self.filter) if (self._decimation > 1): self.decimator = filter.rational_resampler_fff(1, self._decimation) self.connect(self.filter, self.decimator, self) else: self.connect(self.filter, self)
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-i", "--input-rate", type="eng_float", default=8000, help="set input sample rate to RATE (%default)") parser.add_option("-o", "--output-rate", type="eng_float", default=48000, help="set output sample rate to RATE (%default)") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 input_rate = int(options.input_rate) output_rate = int(options.output_rate) interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate print "interp =", interp print "decim =", decim ampl = 0.1 src0 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 650, ampl) rr = filter.rational_resampler_fff(interp, decim) dst = audio.sink(output_rate, options.audio_output) self.connect(src0, rr, (dst, 0))
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-I", "--filename", type="string", help="read input from wav FILE") parser.add_option("-s", "--input-rate", type="eng_float", default="500k", help="set sample rate to RATE (500k)") parser.add_option("-O", "--outname", type="string", help="output to wav file FILE") parser.add_option("-r", "--output-rate", type="eng_float", default="192k", help="set output sample rate to RATE (192k)") parser.add_option("-F", "--filter", action="store_true", default=False, help="filter out audible sounds, retain ultrasonic") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 src = gr.wavfile_source (options.filename) input_rate = int(options.input_rate) output_rate = int(options.output_rate) interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate dst = gr.wavfile_sink (options.outname, 1, output_rate) rr = blks2.rational_resampler_fff(int(interp), int(decim)) if options.filter: highpass = gr.firdes.high_pass (1, # gain output_rate, # sampling rate 15000, # cutoff freq 2000, # width of trans. band gr.firdes.WIN_HANN) # filter type filt = gr.fir_filter_fff(1,highpass) self.connect (src, rr, filt, dst) else: self.connect (src, rr, dst)
def __init__(self): """ Con gr.top_block.__init__(self) se llama a la funcion inicial del modulo top_block del paquete gr y se pasa como argumento el objeto creado. A continuación, podemos agregar diferentes PARAMETROS que el usuario puede especificar en la línea de comando La siguiente línea: (options, args) = parser.parse_args(), se utiliza para analizar la entrada del usuario y proporcionarla en un formato fácil de usar """ gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-O", "--audio-output", type="string", default="", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-i", "--input-rate", type="eng_float", default=8000, help="set input sample rate to RATE (%default)") parser.add_option("-o", "--output-rate", type="eng_float", default=48000, help="set output sample rate to RATE (%default)") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 input_rate = int(options.input_rate) output_rate = int(options.output_rate) interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate print "interp =", interp print "decim =", decim ampl = 0.1 src0 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 650, ampl) rr = filter.rational_resampler_fff(interp, decim) dst = audio.sink(output_rate, options.audio_output) self.connect(src0, rr, (dst, 0))
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, output_rate): gr.hier_block2.__init__( self, "p25_c4fm_mod_bf", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature symbol_rate = 4800 # P25 baseband symbol rate lcm = gru.lcm(symbol_rate, output_rate) self._interp_factor = int(lcm // symbol_rate) self._decimation = int(lcm // output_rate) self._excess_bw = 0.2 mod_map = [1.0 / 3.0, 1.0, -(1.0 / 3.0), -1.0] self.C2S = gr.chunks_to_symbols_bf(mod_map) ntaps = 11 * self._interp_factor rrc_taps = gr.firdes.root_raised_cosine( self._interp_factor, # gain (since we're interpolating by sps) lcm, # sampling rate symbol_rate, self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_fff(self._interp_factor, rrc_taps) # 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 ] self.shaping_filter = gr.fir_filter_fff(1, shaping_coeffs) # generate output at appropriate rate self.decimator = blks2.rational_resampler_fff(1, self._decimation) self.connect(self, self.C2S, self.rrc_filter, self.shaping_filter, self.decimator, self)
def _npadding_bytes(pkt_byte_len, spb): """ Generate sufficient padding such that each packet ultimately ends up being a multiple of 512 bytes when sent across the USB. We send 4-byte samples across the USB (16-bit I and 16-bit Q), thus we want to pad so that after modulation the resulting packet is a multiple of 128 samples. @param ptk_byte_len: len in bytes of packet, not including padding. @param spb: samples per baud == samples per bit (1 bit / baud with GMSK) @type spb: int @returns number of bytes of padding to append. """ modulus = 128 byte_modulus = gru.lcm(modulus / 8, spb) / spb r = pkt_byte_len % byte_modulus if r == 0: return 0 return byte_modulus - r
def _npadding_bytes(pkt_byte_len, samples_per_symbol, bits_per_symbol): """ Generate sufficient padding such that each packet ultimately ends up being a multiple of 512 bytes when sent across the USB. We send 4-byte samples across the USB (16-bit I and 16-bit Q), thus we want to pad so that after modulation the resulting packet is a multiple of 128 samples. Args: ptk_byte_len: len in bytes of packet, not including padding. samples_per_symbol: samples per bit (1 bit / symbolwidth GMSK) (int) bits_per_symbol: bits per symbol (log2(modulation order)) (int) Returns: number of bytes of padding to append. """ modulus = 128 byte_modulus = gru.lcm(modulus/8, samples_per_symbol) * bits_per_symbol / samples_per_symbol r = pkt_byte_len % byte_modulus if r == 0: return 0 return byte_modulus - r
def __init__(self, filter_gain=1.0, sample_rate=_def_sample_rate, symbol_rate=_def_symbol_rate, span=_def_span, verbose=_def_verbose, log=_def_log): self.filter_gain = filter_gain self.sample_rate = sample_rate self.symbol_rate = symbol_rate self.span = span self.verbose = verbose self.log = log gr.hier_block2.__init__( self, "tx_nyquist_filter_ff", gr.io_signature(1, 1, gr.sizeof_float), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature # Determine Interpolation factors. lcm = gru.lcm(self.symbol_rate, self.sample_rate) self.interpolation = int(lcm // self.symbol_rate) # Create Nyquist Raised Cosine filter. self.nyquist_filter = filter.interp_fir_filter_fff( self.interpolation, generate_taps(filter_gain=self.filter_gain * self.interpolation, sample_rate=self.sample_rate, symbol_rate=self.symbol_rate, span=self.span, generator=nyquist_filter_gen).generate()) # Define blocks and connect them self.connect(self, self.nyquist_filter, self)
def __init__(self, filter_gain=1.0, sample_rate=_def_sample_rate, symbol_rate=_def_symbol_rate, span=_def_span, verbose=_def_verbose, log=_def_log): self.filter_gain = filter_gain self.sample_rate = sample_rate self.symbol_rate = symbol_rate self.span = span self.verbose = verbose self.log = log gr.hier_block2.__init__( self, "tx_shaping_filter_ff", gr.io_signature(1, 1, gr.sizeof_float), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature # Determine decimation factor. lcm = gru.lcm(self.symbol_rate, self.sample_rate) self.decimation = int(lcm // self.sample_rate) # Create the TX Shaping Filter. self.tx_shaping_filter = filter.fir_filter_fff( self.decimation, generate_taps(filter_gain=self.filter_gain, sample_rate=self.sample_rate, symbol_rate=self.symbol_rate, span=self.span, generator=tx_shaping_filter_gen).generate()) # Define blocks and connect them self.connect(self, self.tx_shaping_filter, self)
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, output_sample_rate=_def_output_sample_rate, excess_bw=_def_excess_bw, reverse=_def_reverse, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered P25 FM modulation. The input is a dibit (P25 symbol) stream (char, not packed) and the output is the float "C4FM" signal at baseband, suitable for application to an FM modulator stage Input is at the base symbol rate (4800), output sample rate is typically either 32000 (USRP TX chain) or 48000 (sound card) @param output_sample_rate: output sample rate @type output_sample_rate: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param reverse: reverse polarity flag @type reverse: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modulation data to files? @type debug: bool """ gr.hier_block2.__init__( self, "p25_c4fm_mod_bf", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature input_sample_rate = 4800 # P25 baseband symbol rate lcm = gru.lcm(input_sample_rate, output_sample_rate) self._interp_factor = int(lcm // input_sample_rate) self._decimation = int(lcm // output_sample_rate) self._excess_bw = excess_bw mod_map = [1.0 / 3.0, 1.0, -(1.0 / 3.0), -1.0] self.C2S = gr.chunks_to_symbols_bf(mod_map) if reverse: self.polarity = gr.multiply_const_ff(-1) else: self.polarity = gr.multiply_const_ff(1) ntaps = 11 * self._interp_factor rrc_taps = gr.firdes.root_raised_cosine( self._interp_factor, # gain (since we're interpolating by sps) lcm, # sampling rate input_sample_rate, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) # rrc_coeffs work slightly differently: each input sample # (from mod_map above) at 4800 rate, then 9 zeros are inserted # to bring to 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 ? # 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] self.rrc_filter = gr.interp_fir_filter_fff(self._interp_factor, rrc_taps) # 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 ] self.shaping_filter = gr.fir_filter_fff(1, shaping_coeffs) if verbose: self._print_verbage() if log: self._setup_logging() self.connect(self, self.C2S, self.polarity, self.rrc_filter, self.shaping_filter) if (self._decimation > 1): self.decimator = blks2.rational_resampler_fff(1, self._decimation) self.connect(self.shaping_filter, self.decimator, self) else: self.connect(self.shaping_filter, self)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Rx side A or B (default=A)") parser.add_option( "-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-Q", "--observing", type="eng_float", default=0.0, help="set observing frequency to FREQ") parser.add_option("-a", "--avg", type="eng_float", default=1.0, help="set spectral averaging alpha") parser.add_option("-V", "--favg", type="eng_float", default=2.0, help="set folder averaging alpha") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-l", "--reflevel", type="eng_float", default=30.0, help="Set pulse display reference level") parser.add_option("-L", "--lowest", type="eng_float", default=1.5, help="Lowest valid frequency bin") parser.add_option("-e", "--longitude", type="eng_float", default=-76.02, help="Set Observer Longitude") parser.add_option("-c", "--latitude", type="eng_float", default=44.85, help="Set Observer Latitude") parser.add_option("-F", "--fft_size", type="eng_float", default=1024, help="Size of FFT") parser.add_option("-t", "--threshold", type="eng_float", default=2.5, help="pulsar threshold") parser.add_option("-p", "--lowpass", type="eng_float", default=100, help="Pulse spectra cutoff freq") parser.add_option("-P", "--prefix", default="./", help="File prefix") parser.add_option("-u", "--pulsefreq", type="eng_float", default=0.748, help="Observation pulse rate") parser.add_option("-D", "--dm", type="eng_float", default=1.0e-5, help="Dispersion Measure") parser.add_option("-O", "--doppler", type="eng_float", default=1.0, help="Doppler ratio") parser.add_option("-B", "--divbase", type="eng_float", default=20, help="Y/Div menu base") parser.add_option("-I", "--division", type="eng_float", default=100, help="Y/Div") parser.add_option("-A", "--audio_source", default="plughw:0,0", help="Audio input device spec") parser.add_option("-N", "--num_pulses", default=1, type="eng_float", help="Number of display pulses") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.show_debug_info = True self.reflevel = options.reflevel self.divbase = options.divbase self.division = options.division self.audiodev = options.audio_source self.mult = int(options.num_pulses) # Low-pass cutoff for post-detector filter # Set to 100Hz usually, since lots of pulsars fit in this # range self.lowpass = options.lowpass # What is lowest valid frequency bin in post-detector FFT? # There's some pollution very close to DC self.lowest_freq = options.lowest # What (dB) threshold to use in determining spectral candidates self.threshold = options.threshold # Filename prefix for recording file self.prefix = options.prefix # Dispersion Measure (DM) self.dm = options.dm # Doppler shift, as a ratio # 1.0 == no doppler shift # 1.005 == a little negative shift # 0.995 == a little positive shift self.doppler = options.doppler # # Input frequency and observing frequency--not necessarily the # same thing, if we're looking at the IF of some downconverter # that's ahead of the USRP and daughtercard. This distinction # is important in computing the correct de-dispersion filter. # self.frequency = options.freq if options.observing <= 0: self.observing_freq = options.freq else: self.observing_freq = options.observing # build the graph self.u = usrp.source_c(decim_rate=options.decim) self.u.set_mux( usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) # # Recording file, in case we ever need to record baseband data # self.recording = gr.file_sink(gr.sizeof_char, "/dev/null") self.recording_state = False self.pulse_recording = gr.file_sink(gr.sizeof_short, "/dev/null") self.pulse_recording_state = False # # We come up with recording turned off, but the user may # request recording later on self.recording.close() self.pulse_recording.close() # # Need these two for converting 12-bit baseband signals to 8-bit # self.tofloat = gr.complex_to_float() self.tochar = gr.float_to_char() # Need this for recording pulses (post-detector) self.toshort = gr.float_to_short() # # The spectral measurer sets this when it has a valid # average spectral peak-to-peak distance # We can then use this to program the parameters for the epoch folder # # We set a sentimental value here self.pulse_freq = options.pulsefreq # Folder runs at this raw sample rate self.folder_input_rate = 20000 # Each pulse in the epoch folder is sampled at 128 times the nominal # pulse rate self.folding = 128 # # Try to find candidate parameters for rational resampler # save_i = 0 candidates = [] for i in range(20, 300): input_rate = self.folder_input_rate output_rate = int(self.pulse_freq * i) interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate if (interp < 500 and decim < 250000): candidates.append(i) # We didn't find anything, bail! if (len(candidates) < 1): print "Couldn't converge on resampler parameters" sys.exit(1) # # Now try to find candidate with the least sampling error # mindiff = 999.999 for i in candidates: diff = self.pulse_freq * i diff = diff - int(diff) if (diff < mindiff): mindiff = diff save_i = i # Recompute rates input_rate = self.folder_input_rate output_rate = int(self.pulse_freq * save_i) # Compute new interp and decim, based on best candidate interp = gru.lcm(input_rate, output_rate) / input_rate decim = gru.lcm(input_rate, output_rate) / output_rate # Save optimized folding parameters, used later self.folding = save_i self.interp = int(interp) self.decim = int(decim) # So that we can view N pulses in the pulse viewer window FOLD_MULT = self.mult # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) self.cardtype = self.u.daughterboard_id(0) # Compute raw input rate input_rate = self.u.adc_freq() / self.u.decim_rate() # BW==input_rate for complex data self.bw = input_rate # # Set baseband filter bandwidth if DBS_RX: # if self.cardtype == usrp_dbid.DBS_RX: lbw = input_rate / 2 if lbw < 1.0e6: lbw = 1.0e6 self.subdev.set_bw(lbw) # # We use this as a crude volume control for the audio output # #self.volume = gr.multiply_const_ff(10**(-1)) # # Create location data for ephem package # self.locality = ephem.Observer() self.locality.long = str(options.longitude) self.locality.lat = str(options.latitude) # # What is the post-detector LPF cutoff for the FFT? # PULSAR_MAX_FREQ = int(options.lowpass) # First low-pass filters down to input_rate/FIRST_FACTOR # and decimates appropriately FIRST_FACTOR = int(input_rate / (self.folder_input_rate / 2)) first_filter = gr.firdes.low_pass(1.0, input_rate, input_rate / FIRST_FACTOR, input_rate / (FIRST_FACTOR * 20), gr.firdes.WIN_HAMMING) # Second filter runs at the output rate of the first filter, # And low-pass filters down to PULSAR_MAX_FREQ*10 # second_input_rate = int(input_rate / (FIRST_FACTOR / 2)) second_filter = gr.firdes.band_pass(1.0, second_input_rate, 0.10, PULSAR_MAX_FREQ * 10, PULSAR_MAX_FREQ * 1.5, gr.firdes.WIN_HAMMING) # Third filter runs at PULSAR_MAX_FREQ*20 # and filters down to PULSAR_MAX_FREQ # third_input_rate = PULSAR_MAX_FREQ * 20 third_filter = gr.firdes_band_pass(1.0, third_input_rate, 0.10, PULSAR_MAX_FREQ, PULSAR_MAX_FREQ / 10.0, gr.firdes.WIN_HAMMING) # # Create the appropriate FFT scope # self.scope = ra_fftsink.ra_fft_sink_f(panel, fft_size=int(options.fft_size), sample_rate=PULSAR_MAX_FREQ * 2, title="Post-detector spectrum", ofunc=self.pulsarfunc, xydfunc=self.xydfunc, fft_rate=200) # # Tell scope we're looking from DC to PULSAR_MAX_FREQ # self.scope.set_baseband_freq(0.0) # # Setup stripchart for showing pulse profiles # hz = "%5.3fHz " % self.pulse_freq per = "(%5.3f sec)" % (1.0 / self.pulse_freq) sr = "%d sps" % (int(self.pulse_freq * self.folding)) times = " %d Pulse Intervals" % self.mult self.chart = ra_stripchartsink.stripchart_sink_f( panel, sample_rate=1, stripsize=self.folding * FOLD_MULT, parallel=True, title="Pulse Profiles: " + hz + per + times, xlabel="Seconds @ " + sr, ylabel="Level", autoscale=True, divbase=self.divbase, scaling=1.0 / (self.folding * self.pulse_freq)) self.chart.set_ref_level(self.reflevel) self.chart.set_y_per_div(self.division) # De-dispersion filter setup # # Do this here, just before creating the filter # that will use the taps. # ntaps = self.compute_disp_ntaps(self.dm, self.bw, self.observing_freq) # Taps for the de-dispersion filter self.disp_taps = Numeric.zeros(ntaps, Numeric.Complex64) # Compute the de-dispersion filter now self.compute_dispfilter(self.dm, self.doppler, self.bw, self.observing_freq) # # Call constructors for receive chains # # # Now create the FFT filter using the computed taps self.dispfilt = gr.fft_filter_ccc(1, self.disp_taps) # # Audio sink # #print "input_rate ", second_input_rate, "audiodev ", self.audiodev #self.audio = audio.sink(second_input_rate, self.audiodev) # # The three post-detector filters # Done this way to allow an audio path (up to 10Khz) # ...and also because going from xMhz down to ~100Hz # In a single filter doesn't seem to work. # self.first = gr.fir_filter_fff(FIRST_FACTOR / 2, first_filter) p = second_input_rate / (PULSAR_MAX_FREQ * 20) self.second = gr.fir_filter_fff(int(p), second_filter) self.third = gr.fir_filter_fff(10, third_filter) # Detector self.detector = gr.complex_to_mag_squared() self.enable_comb_filter = False # Epoch folder comb filter if self.enable_comb_filter == True: bogtaps = Numeric.zeros(512, Numeric.Float64) self.folder_comb = gr.fft_filter_ccc(1, bogtaps) # Rational resampler self.folder_rr = blks2.rational_resampler_fff(self.interp, self.decim) # Epoch folder bandpass bogtaps = Numeric.zeros(1, Numeric.Float64) self.folder_bandpass = gr.fir_filter_fff(1, bogtaps) # Epoch folder F2C/C2F self.folder_f2c = gr.float_to_complex() self.folder_c2f = gr.complex_to_float() # Epoch folder S2P self.folder_s2p = gr.serial_to_parallel(gr.sizeof_float, self.folding * FOLD_MULT) # Epoch folder IIR Filter (produces average pulse profiles) self.folder_iir = gr.single_pole_iir_filter_ff( 1.0 / options.favg, self.folding * FOLD_MULT) # # Set all the epoch-folder goop up # self.set_folding_params() # # Start connecting configured modules in the receive chain # # Connect raw USRP to de-dispersion filter, detector self.connect(self.u, self.dispfilt, self.detector) # Connect detector output to FIR LPF # in two stages, followed by the FFT scope self.connect(self.detector, self.first, self.second, self.third, self.scope) # Connect audio output #self.connect(self.first, self.volume) #self.connect(self.volume, (self.audio, 0)) #self.connect(self.volume, (self.audio, 1)) # Connect epoch folder if self.enable_comb_filter == True: self.connect(self.first, self.folder_bandpass, self.folder_rr, self.folder_f2c, self.folder_comb, self.folder_c2f, self.folder_s2p, self.folder_iir, self.chart) else: self.connect(self.first, self.folder_bandpass, self.folder_rr, self.folder_s2p, self.folder_iir, self.chart) # Connect baseband recording file (initially /dev/null) self.connect(self.u, self.tofloat, self.tochar, self.recording) # Connect pulse recording file (initially /dev/null) self.connect(self.first, self.toshort, self.pulse_recording) # # Build the GUI elements # self._build_gui(vbox) # Make GUI agree with command-line self.myform['average'].set_value(int(options.avg)) self.myform['foldavg'].set_value(int(options.favg)) # Make spectral averager agree with command line if options.avg != 1.0: self.scope.set_avg_alpha(float(1.0 / options.avg)) self.scope.set_average(True) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.freq is None: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0] + r[1]) / 2 self.set_gain(options.gain) #self.set_volume(-10.0) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency") self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name()) self.myform['DM'].set_value(self.dm) self.myform['Doppler'].set_value(self.doppler) # # Start the timer that shows current LMST on the GUI # self.lmst_timer.Start(1000)
def __init__(self, options): gr.top_block.__init__(self) self.options = options (dev_rate, channel_rate, audio_rate, channel_pass, channel_stop, demod) = demod_params[options.modulation] DEV = uhd_src( options.args, # UHD device address options.spec, # device subdev spec options.antenna, # device antenna dev_rate, # device sample rate options.gain, # Receiver gain options.calibration) # Frequency offset DEV.tune(options.frequency) if_rate = DEV.rate() channel_decim = int(if_rate // channel_rate) audio_decim = int(channel_rate // audio_rate) CHAN_taps = optfir.low_pass( 1.0, # Filter gain if_rate, # Sample rate channel_pass, # One sided modulation bandwidth channel_stop, # One sided channel bandwidth 0.1, # Passband ripple 60) # Stopband attenuation CHAN = gr.freq_xlating_fir_filter_ccf( channel_decim, # Decimation rate CHAN_taps, # Filter taps 0.0, # Offset frequency if_rate) # Sample rate RFSQL = gr.pwr_squelch_cc( options.rf_squelch, # Power threshold 125.0 / channel_rate, # Time constant int(channel_rate / 20), # 50ms rise/fall False) # Zero, not gate output AGC = gr.agc_cc( 1.0 / channel_rate, # Time constant 1.0, # Reference power 1.0, # Initial gain 1.0) # Maximum gain DEMOD = demod(channel_rate, audio_decim) # From RF to audio #self.connect(DEV, CHAN, RFSQL, AGC, DEMOD) self.connect(DEV, CHAN, DEMOD) # Optionally add CTCSS and RSAMP if needed tail = DEMOD if options.ctcss != None and options.ctcss > 60.0: CTCSS = gr.ctcss_squelch_ff( audio_rate, # Sample rate options.ctcss) # Squelch tone self.connect(DEMOD, CTCSS) tail = CTCSS if options.output_rate != audio_rate: out_lcm = gru.lcm(audio_rate, options.output_rate) out_interp = int(out_lcm // audio_rate) out_decim = int(out_lcm // options.output_rate) RSAMP = blks2.rational_resampler_fff(out_interp, out_decim) self.connect(tail, RSAMP) tail = RSAMP # Send to audio output device AUDIO = audio.sink(int(options.output_rate), options.audio_output) self.connect(tail, AUDIO)
def __init__(self, output_sample_rate=_def_output_sample_rate, reverse=_def_reverse, verbose=_def_verbose, generator=transfer_function_tx, dstar=False, bt=_def_bt, rc=None, log=_def_log): """ Hierarchical block for RRC-filtered P25 FM modulation. The input is a dibit (P25 symbol) stream (char, not packed) and the output is the float "C4FM" signal at baseband, suitable for application to an FM modulator stage Input is at the base symbol rate (4800), output sample rate is typically either 32000 (USRP TX chain) or 48000 (sound card) @param output_sample_rate: output sample rate @type output_sample_rate: integer @param reverse: reverse polarity flag @type reverse: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modulation data to files? @type debug: bool """ gr.hier_block2.__init__( self, "p25_c4fm_mod_bf", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature input_sample_rate = 4800 # P25 baseband symbol rate lcm = gru.lcm(input_sample_rate, output_sample_rate) self._interp_factor = int(lcm // input_sample_rate) self._decimation = int(lcm // output_sample_rate) self.dstar = dstar self.bt = bt if self.dstar: self.C2S = digital.chunks_to_symbols_bf([-1, 1], 1) else: mod_map = [1.0 / 3.0, 1.0, -(1.0 / 3.0), -1.0] self.C2S = digital.chunks_to_symbols_bf(mod_map) if reverse: self.polarity = blocks.multiply_const_ff(-1) else: self.polarity = blocks.multiply_const_ff(1) self.generator = generator assert rc is None or rc == 'rc' or rc == 'rrc' if rc: coeffs = filter.firdes.root_raised_cosine(1.0, output_sample_rate, input_sample_rate, 0.2, 91) if rc == 'rc': coeffs = np.convolve(coeffs, coeffs) elif self.dstar: coeffs = gmsk_taps(sample_rate=output_sample_rate, bt=self.bt).generate() elif not rc: coeffs = c4fm_taps(sample_rate=output_sample_rate, generator=self.generator).generate() self.filter = filter.interp_fir_filter_fff(self._interp_factor, coeffs) if verbose: self._print_verbage() if log: self._setup_logging() self.connect(self, self.C2S, self.polarity, self.filter) if (self._decimation > 1): self.decimator = filter.rational_resampler_fff(1, self._decimation) self.connect(self.filter, self.decimator, self) else: self.connect(self.filter, self)