Ejemplo n.º 1
0
def main():

	print os.getpid()

	tb = gr.top_block()

        u = gr.file_source(gr.sizeof_float,"/tmp/atsc_pipe_2")

        input_rate = 19.2e6
	IF_freq = 5.75e6


	# 1/2 as wide because we're designing lp filter
	symbol_rate = atsc.ATSC_SYMBOL_RATE/2.
	NTAPS = 279
	tt = gr.firdes.root_raised_cosine (1.0, input_rate, symbol_rate, .115, NTAPS)
  # heterodyne the low pass coefficients up to the specified bandpass
  # center frequency.  Note that when we do this, the filter bandwidth
  # is effectively twice the low pass (2.69 * 2 = 5.38) and hence
  # matches the diagram in the ATSC spec.
	arg = 2. * math.pi * IF_freq / input_rate
	t=[]
	for i in range(len(tt)):
	  t += [tt[i] * 2. * math.cos(arg * i)]
	rrc = gr.fir_filter_fff(1, t)

	fpll = atsc.fpll()

	pilot_freq = IF_freq - 3e6 + 0.31e6
	lower_edge = 6e6 - 0.31e6
	upper_edge = IF_freq - 3e6 + pilot_freq
	transition_width = upper_edge - lower_edge
	lp_coeffs = gr.firdes.low_pass (1.0,
			   input_rate,
			   (lower_edge + upper_edge) * 0.5,
                           transition_width,
                           gr.firdes.WIN_HAMMING);

	lp_filter = gr.fir_filter_fff (1,lp_coeffs)

	alpha = 1e-5
	iir = gr.single_pole_iir_filter_ff(alpha)
	remove_dc = gr.sub_ff()

	out = gr.file_sink(gr.sizeof_float,"/tmp/atsc_pipe_3")
	# out = gr.file_sink(gr.sizeof_float,"/mnt/sata/atsc_data_float")

        tb.connect(u, fpll, lp_filter)
	tb.connect(lp_filter, iir)
	tb.connect(lp_filter, (remove_dc,0))
	tb.connect(iir, (remove_dc,1))
	tb.connect(remove_dc, out)

	tb.run()
Ejemplo n.º 2
0
    def __init__(self, Source):
        gr.top_block.__init__(self, "Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 750e3
        self.transition = transition = 100e3
        self.cutoff = cutoff = 100000


        ##################################################
        # Blocks
        ##################################################
        self.frame_source = FrameS.FrameSource(Source)

        self.gr_short_to_float_0 = gr.short_to_float(1, 32768)
        self.gr_short_to_float_1 = gr.short_to_float(1, 32768)

        self.high_pass_filter_0 = gr.fir_filter_fff(1, firdes.high_pass(
			1, samp_rate, cutoff, transition, firdes.WIN_RECTANGULAR, 6.76))
        self.high_pass_filter_1 = gr.fir_filter_fff(1, firdes.high_pass(
			1, samp_rate, cutoff, transition, firdes.WIN_RECTANGULAR, 6.76))

        self.gr_float_to_short_0 = gr.float_to_short(1, 32768)
        self.gr_float_to_short_1 = gr.float_to_short(1, 32768)

        self.threshold = Threshold.CustomTwoChannelThreshold()

        self.gr_interleave = gr.interleave(gr.sizeof_short*1)

        self.frame_sink = FrameTFS.FrameToFileSink()


        ##################################################
        # Connections
        ##################################################
        self.connect((self.frame_source, 0), (self.gr_short_to_float_0, 0))
        self.connect((self.frame_source, 1), (self.gr_short_to_float_1, 0))

        self.connect((self.gr_short_to_float_0, 0), (self.high_pass_filter_0, 0))
        self.connect((self.gr_short_to_float_1, 0), (self.high_pass_filter_1, 0))

        self.connect((self.high_pass_filter_0, 0), (self.gr_float_to_short_0, 0))
        self.connect((self.high_pass_filter_1, 0), (self.gr_float_to_short_1, 0))

        self.connect((self.gr_float_to_short_0, 0), (self.threshold, 0))
        self.connect((self.gr_float_to_short_1, 0), (self.threshold, 1))

        self.connect((self.threshold, 0), (self.gr_interleave, 0))
        self.connect((self.threshold, 1), (self.gr_interleave, 1))

        self.connect((self.gr_interleave, 0), (self.frame_sink, 0))
Ejemplo n.º 3
0
def main():

    print os.getpid()

    tb = gr.top_block()

    u = gr.file_source(gr.sizeof_float, "/tmp/atsc_pipe_2")

    input_rate = 19.2e6
    IF_freq = 5.75e6

    # 1/2 as wide because we're designing lp filter
    symbol_rate = atsc.ATSC_SYMBOL_RATE / 2.
    NTAPS = 279
    tt = gr.firdes.root_raised_cosine(1.0, input_rate, symbol_rate, .115,
                                      NTAPS)
    # heterodyne the low pass coefficients up to the specified bandpass
    # center frequency.  Note that when we do this, the filter bandwidth
    # is effectively twice the low pass (2.69 * 2 = 5.38) and hence
    # matches the diagram in the ATSC spec.
    arg = 2. * math.pi * IF_freq / input_rate
    t = []
    for i in range(len(tt)):
        t += [tt[i] * 2. * math.cos(arg * i)]
    rrc = gr.fir_filter_fff(1, t)

    fpll = atsc.fpll()

    pilot_freq = IF_freq - 3e6 + 0.31e6
    lower_edge = 6e6 - 0.31e6
    upper_edge = IF_freq - 3e6 + pilot_freq
    transition_width = upper_edge - lower_edge
    lp_coeffs = gr.firdes.low_pass(1.0, input_rate,
                                   (lower_edge + upper_edge) * 0.5,
                                   transition_width, gr.firdes.WIN_HAMMING)

    lp_filter = gr.fir_filter_fff(1, lp_coeffs)

    alpha = 1e-5
    iir = gr.single_pole_iir_filter_ff(alpha)
    remove_dc = gr.sub_ff()

    out = gr.file_sink(gr.sizeof_float, "/tmp/atsc_pipe_3")
    # out = gr.file_sink(gr.sizeof_float,"/mnt/sata/atsc_data_float")

    tb.connect(u, fpll, lp_filter)
    tb.connect(lp_filter, iir)
    tb.connect(lp_filter, (remove_dc, 0))
    tb.connect(iir, (remove_dc, 1))
    tb.connect(remove_dc, out)

    tb.run()
Ejemplo n.º 4
0
 def __init__(self):
     gr.hier_block2.__init__(self, "dc_block",
                             gr.io_signature(1, 1, gr.sizeof_float),
                             gr.io_signature(1, 1, gr.sizeof_float))
     match0 = [1, 1]
     match1 = [1, -1]
     self.match_filt0 = gr.fir_filter_fff(1, match0)
     self.match_filt1 = gr.fir_filter_fff(1, match1)
     self.destroy0 = gr.keep_one_in_n(gr.sizeof_float, 2)
     self.destroy1 = gr.keep_one_in_n(gr.sizeof_float, 2)
     self.compare = rfidbts.compare()
     #(self.compare, 0),
     self.connect(self, self.match_filt0, self.destroy0, (self.compare, 0),
                  self)
     self.connect(self, self.match_filt1, self.destroy1, (self.compare, 1))
Ejemplo n.º 5
0
def build_pipeline(fg, quad_rate, audio_decimation):
    '''Given a flow_graph, fg, construct a pipeline
    for demodulating a broadcast FM signal.  The
    input is the downconverteed complex baseband
    signal. The output is the demodulated audio.

    build_pipeline returns a two element tuple
    containing the input and output endpoints.
    '''
    fm_demod_gain = 2200.0 / 32768.0
    audio_rate = quad_rate / audio_decimation
    volume = 1.0

    # input: complex; output: float
    fm_demod = gr.quadrature_demod_cf(volume * fm_demod_gain)

    # compute FIR filter taps for audio filter
    width_of_transition_band = audio_rate / 32
    audio_coeffs = gr.firdes.low_pass(
        1.0,  # gain
        quad_rate,  # sampling rate
        audio_rate / 2 - width_of_transition_band,
        width_of_transition_band,
        gr.firdes.WIN_HAMMING)

    # input: float; output: float
    audio_filter = gr.fir_filter_fff(audio_decimation, audio_coeffs)

    fg.connect(fm_demod, audio_filter)
    return ((fm_demod, 0), (audio_filter, 0))
Ejemplo n.º 6
0
  def reset(self):
    self.ch_est.reset()
    self.sampler_trigsrc.rewind()

    cir_len = self.cir_len
    vlen = self.vlen

    self.disconnect( self.padded_sccir, self.conv )
    self.disconnect( self.conv, self.search_window )

    self.disconnect( self.null_source, ( self.padded_sccir, 0 ) )
    self.disconnect( self.serial_ccir, ( self.padded_sccir, 1 ) )
    self.disconnect( self.null_source, ( self.padded_sccir, 2 ) )


    # rebuild
    self.padded_sccir = gr.stream_mux( gr.sizeof_float,
                                       [ cir_len-1, 2*vlen, cir_len-1 ] )

    if cir_len > 1:
      self.conv = gr.fir_filter_fff( 1, [ 1 ] * cir_len )


    self.connect( self.padded_sccir, self.conv )

    self.connect( self.null_source, ( self.padded_sccir, 0 ) )
    self.connect( self.serial_ccir, ( self.padded_sccir, 1 ) )
    self.connect( self.null_source, ( self.padded_sccir, 2 ) )

    self.connect( self.conv, self.search_window )
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    def __init__(self, sps, channel_decim, channel_taps, options, usrp_rate, channel_rate, lo_freq):
        gr.hier_block2.__init__(self, "rx_channel_fm",
                                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)

        symbol_decim = 1
        symbol_rate = 4800

        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)

        symbol_coeffs = gr.firdes_root_raised_cosine(1.0,
                                                     channel_rate,
                                                     symbol_rate, 
                                                     1.0,
                                                     51)
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        demod_fsk4 = fsk4.demod_ff(autotuneq, channel_rate, symbol_rate)
 
        self.connect (self, chan, fm_demod, symbol_filter, demod_fsk4, self)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def build_pipeline (fg, quad_rate, audio_decimation):
    '''Given a flow_graph, fg, construct a pipeline
    for demodulating a broadcast FM signal.  The
    input is the downconverteed complex baseband
    signal. The output is the demodulated audio.

    build_pipeline returns a two element tuple
    containing the input and output endpoints.
    '''
    fm_demod_gain = 2200.0/32768.0
    audio_rate = quad_rate / audio_decimation
    volume = 1.0

    # input: complex; output: float
    fm_demod = gr.quadrature_demod_cf (volume*fm_demod_gain)

    # compute FIR filter taps for audio filter
    width_of_transition_band = audio_rate / 32
    audio_coeffs = gr.firdes.low_pass (1.0,            # gain
                                       quad_rate,      # sampling rate
                                       audio_rate/2 - width_of_transition_band,
                                       width_of_transition_band,
                                       gr.firdes.WIN_HAMMING)

    # input: float; output: float
    audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs)

    fg.connect (fm_demod, audio_filter)
    return ((fm_demod, 0), (audio_filter, 0))
Ejemplo n.º 12
0
	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, fg, channel_rate, audio_decim, deviation, audio_pass, audio_stop, gain=1.0, tau=75e-6):

        """	
	# Equalizer for ~100 us delay
	delay = 100e-6
	num_taps = int(channel_rate*delay)

	mu = 1e-4/num_taps
	print "CMA: delay =", delay, "n =", num_taps, "mu =", mu
	CMA = gr.cma_equalizer_cc(num_taps, 1.0, mu)
        """
        k = channel_rate / (2 * pi * deviation)
        QUAD = gr.quadrature_demod_cf(k)

        audio_taps = optfir.low_pass(
            gain,  # Filter gain
            channel_rate,  # Sample rate
            audio_pass,  # Audio passband
            audio_stop,  # Audio stopband
            0.1,  # Passband ripple
            60,
        )  # Stopband attenuation
        LPF = gr.fir_filter_fff(audio_decim, audio_taps)

        if tau is not None:
            DEEMPH = fm_deemph(fg, channel_rate, tau)
            fg.connect(QUAD, DEEMPH, LPF)
        else:
            fg.connect(QUAD, LPF)

        gr.hier_block.__init__(self, fg, QUAD, LPF)
Ejemplo n.º 14
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 __init__(self, fg, audio_rate, quad_rate, tau=75e-6, max_dev=5e3):
        """
        Narrow Band FM Receiver.

        Takes a single complex baseband input stream and produces a single
        float output stream of audio sample in the range [-1, +1].

        @param fg: flow graph
        @param audio_rate: sample rate of audio stream, >= 16k
        @type audio_rate: integer
        @param quad_rate: sample rate of output stream
        @type quad_rate: integer
        @param tau: preemphasis time constant (default 75e-6)
        @type tau: float
        @param max_dev: maximum deviation in Hz (default 5e3)
        @type max_dev: float

        quad_rate must be an integer multiple of audio_rate.

        Exported sub-blocks (attributes):
          squelch
          quad_demod
          deemph
          audio_filter
        """

        # FIXME audio_rate and quad_rate ought to be exact rationals
        audio_rate = int(audio_rate)
        quad_rate = int(quad_rate)

        if quad_rate % audio_rate != 0:
            raise ValueError, "quad_rate is not an integer multiple of audio_rate"

        squelch_threshold = 20		# dB
        #self.squelch = gr.simple_squelch_cc(squelch_threshold, 0.001)

        # FM Demodulator  input: complex; output: float
        k = quad_rate/(2*math.pi*max_dev)
        self.quad_demod = gr.quadrature_demod_cf(k)

        # FM Deemphasis IIR filter
        self.deemph = fm_deemph (fg, quad_rate, tau=tau)

        # compute FIR taps for audio filter
        audio_decim = quad_rate // audio_rate
        audio_taps = gr.firdes.low_pass (1.0,            # gain
                                         quad_rate,      # sampling rate
                                         4.5e3,          # Audio LPF cutoff
                                         2.5e3,          # Transition band
                                         gr.firdes.WIN_HAMMING)  # filter type

        print "len(audio_taps) =", len(audio_taps)

        # Decimating audio filter
        # input: float; output: float; taps: float
        self.audio_filter = gr.fir_filter_fff(audio_decim, audio_taps)

        fg.connect(self.quad_demod, self.deemph, self.audio_filter)

        gr.hier_block.__init__(self, fg, self.quad_demod, self.audio_filter)
Ejemplo n.º 16
0
 def __init__(self):
     gr.hier_block2.__init__(
             self, 
             "dc_block",
             gr.io_signature(1, 1, gr.sizeof_float),
             gr.io_signature(1, 1, gr.sizeof_float))
     match0 = [1, 1]
     match1 = [1, -1]
     self.match_filt0 = gr.fir_filter_fff(1, match0)
     self.match_filt1 = gr.fir_filter_fff(1, match1)
     self.destroy0 = gr.keep_one_in_n(gr.sizeof_float, 2)
     self.destroy1 = gr.keep_one_in_n(gr.sizeof_float, 2)
     self.compare = rfidbts.compare()
     #(self.compare, 0),
     self.connect(self, self.match_filt0, self.destroy0, (self.compare, 0), self)
     self.connect(self, self.match_filt1, self.destroy1, (self.compare, 1))
Ejemplo n.º 17
0
    def __init__(self, sps, channel_decim, channel_taps, options, usrp_rate,
                 channel_rate, lo_freq):
        gr.hier_block2.__init__(self, "rx_channel_fm",
                                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)

        symbol_decim = 1
        symbol_rate = 4800

        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)

        symbol_coeffs = gr.firdes_root_raised_cosine(1.0, channel_rate,
                                                     symbol_rate, 1.0, 51)
        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, symbol_rate)

        self.connect(self, chan, fm_demod, symbol_filter, demod_fsk4, self)
Ejemplo n.º 18
0
    def __init__(self,
                 channel_rate,
                 audio_decim,
                 deviation,
                 audio_pass,
                 audio_stop,
                 gain=1.0,
                 tau=75e-6):
        gr.hier_block2.__init__(
            self,
            "fm_demod_cf",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_float))  # Output signature

        k = channel_rate / (2 * pi * deviation)
        QUAD = gr.quadrature_demod_cf(k)

        audio_taps = optfir.low_pass(
            gain,  # Filter gain
            channel_rate,  # Sample rate
            audio_pass,  # Audio passband
            audio_stop,  # Audio stopband
            0.1,  # Passband ripple
            60)  # Stopband attenuation
        LPF = gr.fir_filter_fff(audio_decim, audio_taps)

        if tau is not None:
            DEEMPH = fm_deemph(channel_rate, tau)
            self.connect(self, QUAD, DEEMPH, LPF, self)
        else:
            self.connect(self, QUAD, LPF, self)
Ejemplo n.º 19
0
    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)
Ejemplo n.º 20
0
	def __init__(self, samplerate, symbolrate = SYMRATE, channel_str = None,
		sendmsg = True, debug = False,
		samplepersymbol = SPS, fmdeviation = FM_DEVIATION
		):

		gr.hier_block2.__init__(self, "pocsag",
			gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, 1))

		self.samplerate = samplerate
		self.symbolrate = symbolrate
		self.sendmsg = sendmsg
		self.debug = debug
		self.samplepersymbol = samplepersymbol
		self.fmdeviation = fmdeviation

		self.fractional_interpolator = gr.fractional_interpolator_cc(0, 1.0 * samplerate / (symbolrate * samplepersymbol))
		self.quadrature_demod = gr.quadrature_demod_cf((symbolrate * samplepersymbol) / (fmdeviation * 4.0))
		self.low_pass_filter = gr.fir_filter_fff(1, gr.firdes.low_pass(1, symbolrate * samplepersymbol, symbolrate * 2, symbolrate / 2.0, gr.firdes.WIN_HAMMING, 6.76))
		self.digital_clock_recovery_mm = digital.clock_recovery_mm_ff(samplepersymbol, 0.03 * 0.03 * 0.3, 0.4, 0.03, 1e-4)
		self.digital_binary_slicer_fb = digital.binary_slicer_fb()
		self.pktdecoder = pocsag_pktdecoder(channel_str = channel_str, sendmsg = sendmsg, debug = debug)
		self.connect(self,
			self.fractional_interpolator,
			self.quadrature_demod,
			self.low_pass_filter,
			self.digital_clock_recovery_mm,
			self.digital_binary_slicer_fb,
			self.pktdecoder,
			self)
Ejemplo n.º 21
0
 def __init__(self, samprate=48000, cutoff=1000, transit=100):
 #   ------------------------------------------------------------------------
     super(LowpassAdapter, self).__init__()
     self.filter = gr.fir_filter_fff(1, firdes.low_pass(
         1, samprate, cutoff, transit, firdes.WIN_HAMMING, 6.76))
     self.samprate = samprate
     self.cutoff = cutoff
     self.transit = transit
Ejemplo n.º 22
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1000000
        self.dec_rate = dec_rate = 2

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_source_0 = uhd.usrp_source(
            device_addr="",
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_source_0.set_samp_rate(1000000)
        self.uhd_usrp_source_0.set_center_freq(2400490000, 0)
        self.uhd_usrp_source_0.set_gain(0, 0)
        self.low_pass_filter_0_0 = gr.interp_fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate, 500000, 10000, firdes.WIN_HAMMING,
                            6.76))
        self.low_pass_filter_0 = gr.fir_filter_fff(
            1,
            firdes.low_pass(1, samp_rate, 500000, 10000, firdes.WIN_HAMMING,
                            6.76))
        self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf(1)
        self.gr_pwr_squelch_xx_0 = gr.pwr_squelch_cc(-100, 0.001, 0, True)
        self.flysky_dumpsync_0 = flysky.dumpsync()
        self.digital_correlate_access_code_bb_0_1 = digital.correlate_access_code_bb(
            "010101010101010101010101010101010101010001110101", 1)
        self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(
            2, 0.0076562, 0.5, 0.175, 0.005)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()

        ##################################################
        # Connections
        ##################################################
        self.connect((self.digital_clock_recovery_mm_xx_0, 0),
                     (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.gr_quadrature_demod_cf_0, 0),
                     (self.low_pass_filter_0, 0))
        self.connect((self.low_pass_filter_0, 0),
                     (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_pwr_squelch_xx_0, 0),
                     (self.gr_quadrature_demod_cf_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.low_pass_filter_0_0, 0))
        self.connect((self.low_pass_filter_0_0, 0),
                     (self.gr_pwr_squelch_xx_0, 0))
        self.connect((self.digital_binary_slicer_fb_0, 0),
                     (self.digital_correlate_access_code_bb_0_1, 0))
        self.connect((self.digital_correlate_access_code_bb_0_1, 0),
                     (self.flysky_dumpsync_0, 0))
Ejemplo n.º 23
0
    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]])
Ejemplo n.º 24
0
    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
Ejemplo n.º 25
0
    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 reference_dec_filter(src_data, decim, taps):
    fg = gr.flow_graph()
    src = gr.vector_source_f(src_data)
    op = gr.fir_filter_fff(decim, taps)
    dst = gr.vector_sink_f()
    fg.connect(src, op, dst)
    fg.run()
    result_data = dst.data()
    fg = None
    return result_data
Ejemplo n.º 27
0
def reference_dec_filter(src_data, decim, taps):
    tb = gr.top_block()
    src = gr.vector_source_f(src_data)
    op = gr.fir_filter_fff(decim, taps)
    dst = gr.vector_sink_f()
    tb.connect(src, op, dst)
    tb.run()
    result_data = dst.data()
    tb = None
    return result_data
Ejemplo n.º 28
0
    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 reference_interp_dec_filter(src_data, interp, decim, taps):
    fg = gr.flow_graph()
    src = gr.vector_source_f(src_data)
    up = gr.interp_fir_filter_fff(interp, (1,))
    dn = gr.fir_filter_fff(decim, taps)
    dst = gr.vector_sink_f()
    fg.connect(src, up, dn, dst)
    fg.run()
    result_data = dst.data()
    fg = None
    return result_data
Ejemplo n.º 30
0
def reference_interp_dec_filter(src_data, interp, decim, taps):
    tb = gr.top_block()
    src = gr.vector_source_f(src_data)
    up = gr.interp_fir_filter_fff(interp, (1,))
    dn = gr.fir_filter_fff(decim, taps)
    dst = gr.vector_sink_f()
    tb.connect(src, up, dn, dst)
    tb.run()
    result_data = dst.data()
    tb = None
    return result_data
Ejemplo n.º 31
0
 def __init__(self, samprate=48000, cutoff_low=300, cutoff_high=3000, 
     transit=100):
 #   ------------------------------------------------------------------------
     super(BandpassAdapter, self).__init__()
     self.filter = gr.fir_filter_fff(1, firdes.band_pass(
         1, samprate, cutoff_low, cutoff_high, transit, firdes.WIN_HAMMING, 
         6.76))
     self.samprate = samprate
     self.cutoff_low = cutoff_low
     self.cutoff_high = cutoff_high
     self.transit = transit
Ejemplo n.º 32
0
def reference_filter_fff(dec, taps, input):
    """
    compute result using conventional fir filter
    """
    tb = gr.top_block()
    #src = gr.vector_source_f(((0,) * (len(taps) - 1)) + input)
    src = gr.vector_source_f(input)
    op = gr.fir_filter_fff(dec, taps)
    dst = gr.vector_sink_f()
    tb.connect(src, op, dst)
    tb.run()
    return dst.data()
Ejemplo n.º 33
0
def reference_filter_fff(dec, taps, input):
    """
    compute result using conventional fir filter
    """
    tb = gr.top_block()
    #src = gr.vector_source_f(((0,) * (len(taps) - 1)) + input)
    src = gr.vector_source_f(input)
    op = gr.fir_filter_fff(dec, taps)
    dst = gr.vector_sink_f()
    tb.connect(src, op, dst)
    tb.run()
    return dst.data()
Ejemplo n.º 34
0
def run_test(f, Kb, bitspersymbol, K, channel, modulation, dimensionality,
             tot_constellation, N0, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K + 2 * L)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1)  # random symbols
    for i in range(L):  # first/last L symbols set to 0
        packet[i] = 0
        packet[len(packet) - i - 1] = 0
    src = gr.vector_source_s(packet, False)
    mod = gr.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = gr.fir_filter_fff(1, channel)
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    skip = gr.skiphead(
        gr.sizeof_float, L
    )  # skip the first L samples since you know they are coming from the L zero symbols
    #metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    #va = trellis.viterbi_s(f,K+L,0,0) # Put -1 if the Initial/Final states are not set.
    va = trellis.viterbi_combined_s(
        f, K + L, 0, 0, dimensionality, tot_constellation,
        trellis.TRELLIS_EUCLIDEAN
    )  # using viterbi_combined_s instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
    dst = gr.vector_sink_s()

    tb.connect(src, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    #tb.connect (add,metrics)
    #tb.connect (metrics,va,dst)
    tb.connect(add, skip, va, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data) - L
    nright = 0
    for i in range(ntotal):
        if packet[i + L] == data[i]:
            nright = nright + 1
        #else:
        #print "Error in ", i

    return (ntotal, ntotal - nright)
Ejemplo n.º 35
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="RTTY decoder example")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 44100

		##################################################
		# Blocks
		##################################################
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate/40,
			v_scale=1,
			v_offset=0,
			t_scale=25e-3,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.rtty_decode_ff_0 = rtty.decode_ff(
		  samp_rate=samp_rate/40, 
		  baud_rate=45.45, 
		  polarity=True,
		)
		self.low_pass_filter_0 = gr.fir_filter_fff(40, firdes.low_pass(
			100, samp_rate, 45.45*3, 20, firdes.WIN_HANN, 6.76))
		self.gr_wavfile_source_0 = gr.wavfile_source("/home/nick/Downloads/ksm_rtty.wav", False)
		self.gr_sub_xx_0 = gr.sub_ff(1)
		self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf(1)
		self.gr_moving_average_xx_0 = gr.moving_average_ff(5000, 1.0/5000, 20000)
		self.gr_hilbert_fc_0 = gr.hilbert_fc(64)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "/home/nick/Desktop/rtty/test.dat")
		self.gr_file_sink_0.set_unbuffered(False)

		##################################################
		# Connections
		##################################################
		self.connect((self.low_pass_filter_0, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_sub_xx_0, 1))
		self.connect((self.gr_sub_xx_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.low_pass_filter_0, 0), (self.gr_sub_xx_0, 0))
		self.connect((self.rtty_decode_ff_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_sub_xx_0, 0), (self.rtty_decode_ff_0, 0))
		self.connect((self.gr_quadrature_demod_cf_0, 0), (self.low_pass_filter_0, 0))
		self.connect((self.gr_hilbert_fc_0, 0), (self.gr_quadrature_demod_cf_0, 0))
		self.connect((self.gr_wavfile_source_0, 0), (self.gr_hilbert_fc_0, 0))
Ejemplo n.º 36
0
    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)
Ejemplo n.º 37
0
    def __init__(self):
        gr.flow_graph.__init__(self)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default='B',
                          help="select USRP Rx side A or B (default=first one with a daughterboard)")
        parser.add_option ("-c", "--cordic-freq", type="eng_float", default=434845200,
                           help="set rx cordic frequency to FREQ", metavar="FREQ")
        parser.add_option ("-g", "--gain", type="eng_float", default=0,
                           help="set Rx PGA gain in dB [0,20]")
        
        (options, args) = parser.parse_args ()
        print "cordic_freq = %s" % (eng_notation.num_to_str (options.cordic_freq))
        

        # ----------------------------------------------------------------

        self.freq = 1000
        self.samples_per_symbol = 256
        self.usrp_decim = int (64e6 / self.samples_per_symbol / self.freq)
        self.fs = self.freq * self.samples_per_symbol

        print "freq = ", eng_notation.num_to_str(self.freq)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "usrp_decim = ", self.usrp_decim
        print "fs = ", eng_notation.num_to_str(self.fs)

        u = usrp.source_s (0, self.usrp_decim)
        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(u)
        u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec))

        subdev = usrp.selected_subdev(u, options.rx_subdev_spec)
        print "Using RX d'board %s" % (subdev.side_and_name(),)

        u.tune(0, subdev, options.cordic_freq)
        u.set_pga(0, options.gain)
        u.set_pga(1, options.gain)

        self.u = u

        self.filesink = gr.file_sink(gr.sizeof_float, 'rx_sin.dat')
        self.stof = gr.short_to_float()

        filter_coeffs = gr.firdes.low_pass (1.0,                # gain
                                          self.fs,                # sampling rate
                                          self.freq,              # low pass cutoff freq
                                          0.1*self.freq,                # width of trans. band
                                          gr.firdes.WIN_HANN) # filter type 
        
        self.lowpass = gr.fir_filter_fff(1, filter_coeffs)
        self.connect(self.u, self.stof, self.lowpass, self.filesink)
Ejemplo n.º 38
0
    def __init__(self):
         gr.hier_block2.__init__(self, "HierBlock_data",
                        gr.io_signature(1, 1, gr.sizeof_float),
                        gr.io_signature(1, 1, 1))
 
         fsk = gr.hilbert_fc((AUDIO_RATE/300)+1)
         bp_coeff = gr.firdes.band_pass(1,AUDIO_RATE,BP_START,BP_STOP,100)
         bpf = gr.fir_filter_fff(1,bp_coeff)
       
         quad_demod = gr.quadrature_demod_cf(1.0)
        
         hpf_coeff = gr.firdes.high_pass(10, AUDIO_RATE, 10, 5)
         dc_block = gr.fir_filter_fff (1, hpf_coeff)
       	
         mm = gr.clock_recovery_mm_ff(REPEAT_TIME,0.000625,0.5,0.01,0.05)
       
         slicer = gr.binary_slicer_fb()
       
         sync_corr = gr.correlate_access_code_bb("0100011101111000",0)
         
       
         self.connect(self,bpf,fsk,quad_demod,dc_block,mm,slicer,sync_corr,self)
    def __init__(self, fg, channel_rate, audio_decim, audio_pass, audio_stop):
	MAG = gr.complex_to_mag()
	DCR = gr.add_const_ff(-1.0)

	audio_taps = optfir.low_pass(0.5, 	   # Filter gain
	                             channel_rate, # Sample rate
				     audio_pass,   # Audio passband
				     audio_stop,   # Audio stopband
				     0.1, 	   # Passband ripple
				     60)	   # Stopband attenuation
	LPF = gr.fir_filter_fff(audio_decim, audio_taps)

	fg.connect(MAG, DCR, LPF)
	gr.hier_block.__init__(self, fg, MAG, LPF)
Ejemplo n.º 40
0
    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)
        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
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq,
                                           self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate,
                                        self.symbol_rate)
        # symbol slicer
        levels = [-2.0, 0.0, 2.0, 4.0]
        slicer = op25.fsk4_slicer_fb(levels)
        # ALSA output device (if not locked)
        try:
            sink = audio.sink(8000, "plughw:0,0",
                              True)  # ToDo: get actual device from prefs
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)

        # connect it all up
        self.__connect([[
            source, self.channel_filter, self.squelch, fm_demod, symbol_filter,
            demod_fsk4, slicer, self.p25_decoder, sink
        ], [source, self.spectrum], [symbol_filter, self.signal_scope],
                        [demod_fsk4, self.symbol_scope]])
Ejemplo n.º 41
0
    def __init__(self):
        gr.top_block.__init__(self)
        parser = OptionParser(option_class=eng_option)

        parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file")
        parser.add_option("-g", "--gain", type="eng_float", default=1.0)
        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=48000, 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
        sps = 10
        symbol_rate = 4800
        # output rate will be 48,000
        ntaps = 11 * sps

        channel_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN)

        IN = gr.file_source(gr.sizeof_short, options.input_file)
        OUT = gr.file_sink(gr.sizeof_char, options.output_file)

        CVT = gr.short_to_float()
        AMP = gr.multiply_const_ff(options.gain / 32767.0)

        symbol_decim = 1
        symbol_coeffs = gr.firdes.root_raised_cosine (1.0,        	# gain
                                          sample_rate ,  	# sampling rate
                                          symbol_rate,     # symbol rate
                                          0.20,     	# width of trans. band
                                          500) 		# filter type 
        SYMBOL_FILTER = gr.fir_filter_fff (symbol_decim, symbol_coeffs)
        self.msgq = gr.msg_queue(2)

        FSK4 = op25.fsk4_demod_ff(self.msgq, sample_rate, symbol_rate)

        levels = [ -2.0, 0.0, 2.0, 4.0 ]
        SLICER = repeater.fsk4_slicer_fb(levels)

        hostname = "127.0.0.1"
        port = 23456
        debug = 255
        do_imbe = False
        do_output = True
        do_msgq = False
        msgqd = gr.msg_queue(2)
        DECODER = repeater.p25_frame_assembler(hostname, port, debug, do_imbe, do_output, do_msgq, msgqd)

        self.connect(IN, CVT, AMP, SYMBOL_FILTER, FSK4, SLICER, DECODER, OUT)
Ejemplo n.º 42
0
    def __init__(self, nstages, ntaps=256):
        """
        Create a pipeline of nstages of gr.fir_filter_fff's connected in serial
        terminating in a gr.null_sink.
        """
        gr.hier_block2.__init__(self, "pipeline",
                                gr.io_signature(1, 1, gr.sizeof_float),
                                gr.io_signature(0, 0, 0))
        taps = ntaps*[1.0/ntaps]
        upstream = self
        for i in range(nstages):
            op = gr.fir_filter_fff(1, taps)
            self.connect(upstream, op)
            upstream = op

        self.connect(upstream, gr.null_sink(gr.sizeof_float))
def run_test (f,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,N0,seed):
    fg = gr.flow_graph ()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0]*(K+2*L)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols
    for i in range(L): # first/last L symbols set to 0
        packet[i] = 0
        packet[len(packet)-i-1] = 0
    src = gr.vector_source_s(packet,False)
    mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0])

    # CHANNEL
    isi = gr.fir_filter_fff(1,channel)
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
    
    # RX
    skip = gr.skiphead(gr.sizeof_float, L) # skip the first L samples since you know they are coming from the L zero symbols
    #metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    #va = trellis.viterbi_s(f,K+L,-1,0) # Put -1 if the Initial/Final states are not set.
    va = trellis.viterbi_combined_fs(f,K+L,0,0,dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # using viterbi_combined_fs instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
    dst = gr.vector_sink_s()

    fg.connect (src,mod)
    fg.connect (mod,isi,(add,0))
    fg.connect (noise,(add,1))
    #fg.connect (add,metrics)
    #fg.connect (metrics,va,dst)
    fg.connect (add,skip,va,dst)

    fg.run()

    data = dst.data() 
    ntotal = len(data) - L
    nright=0
    for i in range(ntotal):
        if packet[i+L]==data[i]:
            nright=nright+1
        #else:
            #print "Error in ", i
    
    return (ntotal,ntotal-nright)
Ejemplo n.º 44
0
    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)
Ejemplo n.º 45
0
    def __init__(self, channel_rate, audio_decim, audio_pass, audio_stop):
	gr.hier_block2.__init__(self, "am_demod_cf",
				gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
				gr.io_signature(1, 1, gr.sizeof_float))      # Input signature

	MAG = gr.complex_to_mag()
	DCR = gr.add_const_ff(-1.0)

	audio_taps = optfir.low_pass(0.5, 	   # Filter gain
	                             channel_rate, # Sample rate
				     audio_pass,   # Audio passband
				     audio_stop,   # Audio stopband
				     0.1, 	   # Passband ripple
				     60)	   # Stopband attenuation
	LPF = gr.fir_filter_fff(audio_decim, audio_taps)

	self.connect(self, MAG, DCR, LPF, self)
Ejemplo n.º 46
0
    def __init__(self, quad_rate, audio_decimation):
        """
        Hierarchical block for demodulating a broadcast FM signal.

        The input is the downconverted complex baseband signal (gr_complex).
        The output is the demodulated audio (float).

        @param quad_rate: input sample rate of complex baseband input.
        @type quad_rate: float
        @param audio_decimation: how much to decimate quad_rate to get to audio.
        @type audio_decimation: integer
        """
        gr.hier_block2.__init__(
            self,
            "wfm_rcv",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_float))  # Output signature

        volume = 20.

        max_dev = 75e3
        fm_demod_gain = quad_rate / (2 * math.pi * max_dev)
        audio_rate = quad_rate / audio_decimation

        # We assign to self so that outsiders can grab the demodulator
        # if they need to.  E.g., to plot its output.
        #
        # input: complex; output: float
        self.fm_demod = gr.quadrature_demod_cf(fm_demod_gain)

        # input: float; output: float
        self.deemph = fm_deemph(audio_rate)

        # compute FIR filter taps for audio filter
        width_of_transition_band = audio_rate / 32
        audio_coeffs = gr.firdes.low_pass(
            1.0,  # gain
            quad_rate,  # sampling rate
            audio_rate / 2 - width_of_transition_band,
            width_of_transition_band,
            gr.firdes.WIN_HAMMING)
        # input: float; output: float
        self.audio_filter = gr.fir_filter_fff(audio_decimation, audio_coeffs)

        self.connect(self, self.fm_demod, self.audio_filter, self.deemph, self)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, channel, modulation,
             dimensionality, tot_constellation, Es, N0, IT, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1)  # random symbols
    src = gr.vector_source_s(packet, False)
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1,
                                gr.sizeof_short)
    mod = gr.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = gr.fir_filter_fff(1, channel)
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    (head, tail) = make_rx(tb, fo, fi, dimensionality, tot_constellation, K,
                           interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM)
    dst = gr.vector_sink_s()

    tb.connect(src, enc_out, inter, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, head)
    tb.connect(tail, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data)
    nright = 0
    for i in range(ntotal):
        if packet[i] == data[i]:
            nright = nright + 1
        #else:
        #print "Error in ", i

    return (ntotal, ntotal - nright)
Ejemplo n.º 48
0
    def __init__(self, resample=8, bw=0.5):
        '''
        When using the CVSD vocoder, appropriate sampling rates are from 8k to 64k with resampling rates
        from 1 to 8. A rate of 8k with a resampling rate of 8 provides a good quality signal.
        '''
	gr.hier_block2.__init__(self, "cvsd_decode",
				gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
				gr.io_signature(1, 1, gr.sizeof_float)) # Output signature

        scale_factor = 32000.0
        self.decim = resample

        dec = vocoder_swig.cvsd_decode_bs()
        s2f = gr.short_to_float()
        taps = gr.firdes.low_pass(1, 1, bw, 2*bw)
        decim = gr.fir_filter_fff(self.decim, taps)
        sink_scale = gr.multiply_const_ff(1.0/scale_factor)

        self.connect(self, dec, s2f, decim, sink_scale, self)
Ejemplo n.º 49
0
    def __init__(self, fft_length):
        gr.hier_block2.__init__(self, "schmidl_denominator",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_float))

        # R(d) = sum(0 to L-1, |r_d|**2)
        r_mag_sqrd = gr.complex_to_mag_squared()
        r_mov_avg = gr.fir_filter_fff(1, [0.5 for i in range(fft_length)])
        #r_mov_avg_half = gr.multiply_const_ff(0.5)
        #r_mov_avg = moving_sum_cc(fft_length)

        self.connect(self, r_mag_sqrd, r_mov_avg, self)
        # r_mov_avg = R(d)

        try:
            gr.hier_block.update_var_names(self, "schmidl_denom", vars())
            gr.hier_block.update_var_names(self, "schmidl_denom", vars(self))
        except:
            pass
Ejemplo n.º 50
0
    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)
Ejemplo n.º 51
0
    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)
Ejemplo n.º 52
0
    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)
Ejemplo n.º 53
0
    def __init__(self,
                 samplerate,
                 symbolrate=SYMRATE,
                 channel_str=None,
                 sendmsg=True,
                 debug=False,
                 samplepersymbol=SPS,
                 fmdeviation=FM_DEVIATION):

        gr.hier_block2.__init__(self, "pocsag",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, 1))

        self.samplerate = samplerate
        self.symbolrate = symbolrate
        self.sendmsg = sendmsg
        self.debug = debug
        self.samplepersymbol = samplepersymbol
        self.fmdeviation = fmdeviation

        self.fractional_interpolator = gr.fractional_interpolator_cc(
            0, 1.0 * samplerate / (symbolrate * samplepersymbol))
        self.quadrature_demod = gr.quadrature_demod_cf(
            (symbolrate * samplepersymbol) / (fmdeviation * 4.0))
        self.low_pass_filter = gr.fir_filter_fff(
            1,
            gr.firdes.low_pass(1, symbolrate * samplepersymbol, symbolrate * 2,
                               symbolrate / 2.0, gr.firdes.WIN_HAMMING, 6.76))
        self.digital_clock_recovery_mm = digital.clock_recovery_mm_ff(
            samplepersymbol, 0.03 * 0.03 * 0.3, 0.4, 0.03, 1e-4)
        self.digital_binary_slicer_fb = digital.binary_slicer_fb()
        self.pktdecoder = pocsag_pktdecoder(channel_str=channel_str,
                                            sendmsg=sendmsg,
                                            debug=debug)
        self.connect(self, self.fractional_interpolator, self.quadrature_demod,
                     self.low_pass_filter, self.digital_clock_recovery_mm,
                     self.digital_binary_slicer_fb, self.pktdecoder, self)
Ejemplo n.º 54
0
    def __init__(self, args, spec, antenna, gain, 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 = uhd.usrp_sink(device_addr=args, stream_args=uhd.stream_args('fc32'))

        # Set the subdevice spec
        if(spec):
            self.u.set_subdev_spec(spec, 0)

        # Set the antenna
        if(antenna):
            self.u.set_antenna(antenna, 0)

        self.if_rate = 320e3
        self.audio_rate = 32e3

        self.u.set_samp_rate(self.if_rate)
        dev_rate = self.u.get_samp_rate()

        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)

        rrate = dev_rate / self.if_rate
        self.resamp = blks2.pfb_arb_resampler_ccf(rrate)

        self.connect(self.audio, self.audio_amp, self.audio_filt,
                     (self.add_pl,0), self.fmtx, self.amp,
                     self.resamp, self.u)

        if gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.u.get_gain_range()
            gain = float(g.start() + g.stop())/2.0

        self.set_gain(gain)

        self.set_enable(False)
Ejemplo n.º 55
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self,
                                         title="Intensity Interferometer")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 250e3
        self.magnitude = magnitude = 0.05
        self.integ = integ = 1
        self.beat = beat = 1

        ##################################################
        # Blocks
        ##################################################
        _magnitude_sizer = wx.BoxSizer(wx.VERTICAL)
        self._magnitude_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_magnitude_sizer,
            value=self.magnitude,
            callback=self.set_magnitude,
            label="Magnitude",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._magnitude_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_magnitude_sizer,
            value=self.magnitude,
            callback=self.set_magnitude,
            minimum=0.05,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_magnitude_sizer)
        _integ_sizer = wx.BoxSizer(wx.VERTICAL)
        self._integ_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_integ_sizer,
            value=self.integ,
            callback=self.set_integ,
            label="Integration Time (Sec)",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._integ_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_integ_sizer,
            value=self.integ,
            callback=self.set_integ,
            minimum=1,
            maximum=30,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_integ_sizer)
        _beat_sizer = wx.BoxSizer(wx.VERTICAL)
        self._beat_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_beat_sizer,
            value=self.beat,
            callback=self.set_beat,
            label="Beat Frequency (kHz)",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._beat_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_beat_sizer,
            value=self.beat,
            callback=self.set_beat,
            minimum=1,
            maximum=10,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_beat_sizer)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
            self.GetWin(),
            title="2nd detector power level",
            sample_rate=2,
            v_scale=0,
            v_offset=0,
            t_scale=450,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_STRIPCHART,
            y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
            self.GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate / 10,
            fft_size=1024,
            fft_rate=8,
            average=True,
            avg_alpha=0.1,
            title="First Detector Spectrum",
            peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0.win)
        self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(
            1.0 / ((samp_rate / 10) * integ), 1)
        self.low_pass_filter_0 = gr.fir_filter_fff(
            int(samp_rate / 25e3),
            firdes.low_pass(1, samp_rate, 11e3, 2.5e3, firdes.WIN_HAMMING,
                            6.76))
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1,
                                                 samp_rate)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(
            gr.sizeof_float * 1, int(samp_rate / 20))
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.band_pass_filter_0 = gr.fir_filter_fff(
            1,
            firdes.band_pass(1, samp_rate / 10, (beat * 1000) - 100,
                             (beat * 1000) + 100, 50, firdes.WIN_HAMMING,
                             6.76))
        self.analog_sig_source_x_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, 122e3, magnitude, 0)
        self.analog_sig_source_x_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, 122e3 - (beat * 1000), magnitude, 0)
        self.analog_noise_source_x_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 0.2, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 2))
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.band_pass_filter_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.band_pass_filter_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.band_pass_filter_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.low_pass_filter_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.single_pole_iir_filter_xx_0, 0))
        self.connect((self.blocks_keep_one_in_n_0, 0),
                     (self.wxgui_scopesink2_0, 0))
        self.connect((self.single_pole_iir_filter_xx_0, 0),
                     (self.blocks_keep_one_in_n_0, 0))
Ejemplo n.º 56
0
    def __init__(self, talkgroup, options):
        gr.hier_block2.__init__(
            self,
            "fsk_demod",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(0, 0, gr.sizeof_char))  # Output signature

        #print "Starting log_receiver init()"

        self.audiorate = options.audiorate
        self.rate = options.rate
        self.talkgroup = talkgroup
        self.directory = options.directory

        if options.squelch is None:
            options.squelch = 28

        if options.volume is None:
            options.volume = 3.0

        self.audiotaps = gr.firdes.low_pass(1, self.rate, 8000, 2000,
                                            gr.firdes.WIN_HANN)

        self.prefilter_decim = int(self.rate / self.audiorate)

        #the audio prefilter is a channel selection filter.
        self.audio_prefilter = gr.freq_xlating_fir_filter_ccf(
            self.prefilter_decim,  #decimation
            self.audiotaps,  #taps
            0,  #freq offset
            int(self.rate))  #sampling rate

        #on a trunked network where you know you will have good signal, a carrier power squelch works well. real FM receviers use a noise squelch, where
        #the received audio is high-passed above the cutoff and then fed to a reverse squelch. If the power is then BELOW a threshold, open the squelch.
        self.squelch = gr.pwr_squelch_cc(
            options.squelch,  #squelch point
            alpha=0.1,  #wat
            ramp=10,  #wat
            gate=True
        )  #gated so that the audio recording doesn't contain blank spaces between transmissions

        self.audiodemod = blks2.fm_demod_cf(
            self.rate / self.prefilter_decim,  #rate
            1,  #audio decimation
            4000,  #deviation
            3000,  #audio passband
            4000,  #audio stopband
            options.volume,  #gain
            75e-6)  #deemphasis constant

        #the filtering removes FSK data woobling from the subaudible channel
        self.audiofilttaps = gr.firdes.high_pass(1, self.audiorate, 300, 50,
                                                 gr.firdes.WIN_HANN)

        self.audiofilt = gr.fir_filter_fff(1, self.audiofilttaps)

        #self.audiogain = gr.multiply_const_ff(options.volume)

        #here we generate a random filename in the form /tmp/[random].wav, and then use it for the wavstamp block. this avoids collisions later on. remember to clean up these files when deallocating.

        self.tmpfilename = "/tmp/%s.wav" % (
            "".join([
                random.choice(string.letters + string.digits) for x in range(8)
            ])
        )  #if this looks glaringly different, it's because i totally cribbed it from a blog.

        self.valve = grc_blks2.valve(gr.sizeof_float, bool(1))

        #self.prefiltervalve = grc_blks2.valve(gr.sizeof_gr_complex, bool(1))

        #open the logfile for appending
        self.timestampfilename = "%s/%i.txt" % (self.directory, self.talkgroup)
        self.timestampfile = open(self.timestampfilename, 'a')

        self.filename = "%s/%i.wav" % (self.directory, self.talkgroup)
        self.audiosink = smartnet.wavsink(
            self.filename, 1, self.audiorate,
            8)  #this version allows appending to existing files.

        #		self.connect(self, self.audio_prefilter, self.squelch, self.audiodemod, self.valve, self.audiofilt, self.audiosink)
        self.connect(self, self.audio_prefilter, self.audiodemod, self.valve,
                     self.audiofilt, self.audiosink)

        self.timestamp = 0.0

        #print "Finishing logging receiver init()."

        self.mute()  #start off muted.
	def __init__(self, talkgroup, options):
		gr.hier_block2.__init__(self, "fsk_demod",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature(0, 0, gr.sizeof_char)) # Output signature

		#print "Starting log_receiver init()"
		self.samp_rate = samp_rate = int(options.rate)
		self.samp_per_sym = samp_per_sym = 5+1
		self.decim = decim = 20
		self.xlate_bandwidth = xlate_bandwidth = 24260.0
		self.xlate_offset = xlate_offset = 0
		self.channel_rate = channel_rate = op25.SYMBOL_RATE*samp_per_sym
		self.audio_mul = audio_mul = 2
		self.pre_channel_rate = pre_channel_rate = int(samp_rate/decim)


		self.auto_tune_offset = auto_tune_offset = 0	
		self.audiorate = 44100 #options.audiorate
		self.rate = options.rate
		self.talkgroup = talkgroup
		self.directory = options.directory

		if options.squelch is None:
			options.squelch = 28

		if options.volume is None:
			options.volume = 3.0


		##################################################
		# Message Queues
		##################################################
		op25_fsk4_0_msgq_out = baz_message_callback_0_msgq_in = gr.msg_queue(2)
		op25_decoder_simple_0_msgq_out = op25_traffic_pane_0_msgq_in = gr.msg_queue(2)

		##################################################
		# Blocks
		##################################################

		self.op25_fsk4_0 = op25.op25_fsk4(channel_rate=channel_rate, auto_tune_msgq=op25_fsk4_0_msgq_out,)
		self.op25_decoder_simple_0 = op25.op25_decoder_simple(key="",traffic_msgq=op25_decoder_simple_0_msgq_out,)
		self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf((channel_rate/(2.0 * math.pi * op25.SYMBOL_DEVIATION)))
		self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(decim, 
										       (firdes.low_pass(1, samp_rate, xlate_bandwidth/2, 4000)),
										       0, 
										       samp_rate)
		self.gr_fir_filter_xxx_0 = gr.fir_filter_fff(1, ((1.0/samp_per_sym,)*samp_per_sym))



		
		self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((10.**(audio_mul/10.), ))
		self.blks2_rational_resampler_xxx_1 = blks2.rational_resampler_ccc(
			interpolation=channel_rate,
			decimation=pre_channel_rate,
			taps=None,
			fractional_bw=None,
		)
		self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff(
			interpolation=self.audiorate,
			decimation=8000,
			taps=None,
			fractional_bw=None,
		)
		self.baz_message_callback_0 = message_callback.message_callback(msgq=baz_message_callback_0_msgq_in,	callback=auto_tune_offset	, msg_part="arg1", custom_parts="",	dummy=False)
			

		#here we generate a random filename in the form /tmp/[random].wav, and then use it for the wavstamp block. this avoids collisions later on. remember to clean up these files when deallocating.

		self.tmpfilename = "/tmp/%s.wav" % ("".join([random.choice(string.letters+string.digits) for x in range(8)])) #if this looks glaringly different, it's because i totally cribbed it from a blog.

		self.valve = grc_blks2.valve(gr.sizeof_float, bool(1))


		#open the logfile for appending
		self.timestampfilename = "%s/%i.txt" % (self.directory, self.talkgroup)
		self.timestampfile = open(self.timestampfilename, 'a');

		self.filename = "%s/%i.wav" % (self.directory, self.talkgroup)
		self.audiosink = smartnet.wavsink(self.filename, 1, self.audiorate, 8) #this version allows appending to existing files.

		self.audio_sink_0 = audio.sink(44100, "", True)


		self.timestamp = 0.0

		#print "Finishing logging receiver init()."

		self.mute() #start off muted.



	##################################################
	# Connections
		##################################################
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.blks2_rational_resampler_xxx_1, 0))
		self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.gr_quadrature_demod_cf_0, 0))
		self.connect((self.gr_quadrature_demod_cf_0, 0), (self.gr_fir_filter_xxx_0, 0))
		self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0))

		self.connect((self.gr_fir_filter_xxx_0, 0), (self.op25_fsk4_0, 0))
		self.connect((self.op25_fsk4_0, 0), (self.op25_decoder_simple_0, 0))
		self.connect((self.op25_decoder_simple_0, 0), (self.blks2_rational_resampler_xxx_0, 0))

		## Start
		self.connect(self, (self.gr_freq_xlating_fir_filter_xxx_0, 0))

		## End
		self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0,0))