Exemple #1
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Wav To Raw Iq")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Blocks
        ##################################################
        self.test_wav = blocks.wavfile_source("original.wav", False)
        self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
                interpolation=2000000,
                decimation=44100,
                taps=None,
                fractional_bw=None,
        )
        self.blocks_streams_to_stream_0 = blocks.streams_to_stream(gr.sizeof_float*1, 2)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 127)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "sample.raw", False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.test_wav, 1), (self.blocks_streams_to_stream_0, 1))
        self.connect((self.blocks_streams_to_stream_0, 0), (self.rational_resampler_xxx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.test_wav, 0), (self.blocks_streams_to_stream_0, 0))
    def __init__(self):
        gr.hier_block2.__init__(self,
                                "bch_viterbi_vfvb",
                                gr.io_signature(1, 1, gr.sizeof_float * 120), # Input signature
                                gr.io_signature(1, 1, gr.sizeof_char * 40)) # Output signature

        # Define blocks and connect them
        # Repeat input vector one time to get viterbi decoder state right (tail-biting stuff)
        #self.rpt = blocks.repeat(gr.sizeof_float * 120, 2)
        # viterbi decoder requires stream as input
        #self.vtos = blocks.vector_to_stream(1 * gr.sizeof_float, 120)

        # self.vtss = blocks.vector_to_streams(1* gr.sizeof_float, 120, "bch_viterbi_vector_to_streams_0")
        self.vtss = blocks.vector_to_streams(1* gr.sizeof_float, 120)
        #self.app = blocks.streams_to_stream(1* gr.sizeof_float, 138, "bch_viterbi_streams_to_stream_0")
        self.app = blocks.streams_to_stream(1* gr.sizeof_float, 138)
        self.connect(self, self.vtss)
        for i in range(18):
            self.connect( (self.vtss, 120-18+i), (self.app, i) )
        for i in range(120):
            self.connect( (self.vtss, i), (self.app, i+18) )



        # Correct FSM instantiation: k=num_input_bits, n=num_output_bits, Tuple[dim(k*n)] (decimal notation)
        self.fsm = trellis.fsm(1, 3, [91, 121, 117])

        # Values for viterbi decoder        
        K = 46  # steps for one coding block
        SO = 0  # initial state
        SK = -1 # final state (in this case unknown, therefore -1)
        D = 3   # dimensionality
        # D = 3 follows from the fact that 1 {0,1} input symbol of the encoder produces 3 {0,1} output symbols.
        # (packed into one byte {0,1,...,7} )
        # with NRZ coding follows: 
        # 0 -->  1
        # 1 --> -1
        # This leads to the following constellation input
        #               |  0  |  1   | 2    | 3     |  4   |  5    |  6    |  7     |
        constellation = [1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1]
        # print "len(constellation)/D = " + str(len(constellation)/D) + "\tfsm.O = " + str(self.fsm.O())
        # Viterbi_combined input: FSM, K, SO, SK, D, TABLE, TYPE
        # FSM    = Finite State Machine
        # K      = number of output symbols produced by the FSM
        # SO     = initial state of the FSM
        # SK     = final state of the FSM (unknown in this example)
        # D      = dimensionality
        # TABLE  = constellation of the input symbols
        # self.vit = trellis.viterbi_combined_fb(self.fsm, K, SO, SK, D, constellation, 200, "bch_viterbi_combined_fb_0")
        self.vit = trellis.viterbi_combined_fb(self.fsm, K, SO, SK, D, constellation, 200)
        self.connect(self.app, self.vit)
        # connect all streams which are crated yet        
        #self.connect(self,self.rpt,self.vtos,self.vit)
        # self.keep = blocks.keep_m_in_n(gr.sizeof_char, 40, 46, 6, "bch_viterbi_keep_m_in_n_0")
        self.keep = blocks.keep_m_in_n(gr.sizeof_char, 40, 46, 6)
        # self.tovec = blocks.stream_to_vector(1, 40, "bch_viterbi_stream_to_vector_0")
        self.tovec = blocks.stream_to_vector(1, 40)
        self.connect(self.vit, self.keep, self.tovec, self)
Exemple #3
0
    def __init__(self):
        gr.hier_block2.__init__(
            self,
            "bch_viterbi_vfvb",
            gr.io_signature(1, 1, gr.sizeof_float * 120),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char * 40))  # Output signature

        # Define blocks and connect them
        # Repeat input vector one time to get viterbi decoder state right (tail-biting stuff)
        #self.rpt = blocks.repeat(gr.sizeof_float * 120, 2)
        # viterbi decoder requires stream as input
        #self.vtos = blocks.vector_to_stream(1 * gr.sizeof_float, 120)

        self.vtss = blocks.vector_to_streams(1 * gr.sizeof_float, 120)
        self.app = blocks.streams_to_stream(1 * gr.sizeof_float, 138)
        self.connect(self, self.vtss)
        for i in range(18):
            self.connect((self.vtss, 120 - 18 + i), (self.app, i))
        for i in range(120):
            self.connect((self.vtss, i), (self.app, i + 18))

        # Correct FSM instantiation: k=num_input_bits, n=num_output_bits, Tuple[dim(k*n)] (decimal notation)
        self.fsm = trellis.fsm(1, 3, [91, 121, 117])

        # Values for viterbi decoder
        K = 46  # steps for one coding block
        SO = 0  # initial state
        SK = -1  # final state (in this case unknown, therefore -1)
        D = 3  # dimensionality
        # D = 3 follows from the fact that 1 {0,1} input symbol of the encoder produces 3 {0,1} output symbols.
        # (packed into one byte {0,1,...,7} )
        # with NRZ coding follows:
        # 0 -->  1
        # 1 --> -1
        # This leads to the following constellation input
        #               |  0  |  1   | 2    | 3     |  4   |  5    |  6    |  7     |
        constellation = [
            1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1,
            -1, 1, -1, -1, -1
        ]
        # print "len(constellation)/D = " + str(len(constellation)/D) + "\tfsm.O = " + str(self.fsm.O())
        # Viterbi_combined input: FSM, K, SO, SK, D, TABLE, TYPE
        # FSM    = Finite State Machine
        # K      = number of output symbols produced by the FSM
        # SO     = initial state of the FSM
        # SK     = final state of the FSM (unknown in this example)
        # D      = dimensionality
        # TABLE  = constellation of the input symbols
        self.vit = trellis.viterbi_combined_fb(self.fsm, K, SO, SK, D,
                                               constellation, 200)
        self.connect(self.app, self.vit)
        # connect all streams which are crated yet
        #self.connect(self,self.rpt,self.vtos,self.vit)
        self.keep = blocks.keep_m_in_n(gr.sizeof_char, 40, 46, 6)
        self.tovec = blocks.stream_to_vector(1, 40)
        self.connect(self.vit, self.keep, self.tovec, self)
	def __init__(self):
		gr.hier_block2.__init__(self, "interleaver",
				gr.io_signature(1, 1, gr.sizeof_char),	# Input signature
				gr.io_signature(1, 1, gr.sizeof_char))	# Output signature

		self.demux = blocks.stream_to_streams(gr.sizeof_char, INTERLEAVER_I)
		self.shift_registers = [dvb.fifo_shift_register_bb(INTERLEAVER_M * j)
				for j in range(INTERLEAVER_I)]
		self.mux = blocks.streams_to_stream(gr.sizeof_char, INTERLEAVER_I)

		self.connect(self, self.demux)
		for j in range(INTERLEAVER_I):
			self.connect((self.demux, j), self.shift_registers[j], (self.mux, j))
		self.connect(self.mux, self)
Exemple #5
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16*P) # packet size in shorts
    s2fsmi=blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    s2p = blocks.stream_to_streams(gr.sizeof_short,P) # serial to parallel
    enc = trellis.encoder_ss(f,0) # initiali state = 0
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add=[]
    noise=[]
    for i in range(P):
        add.append(blocks.add_ff())
        noise.append(analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed))

    # RX
    metrics = trellis.metrics_f(f.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
    p2s = blocks.streams_to_stream(gr.sizeof_short,P) # parallel to serial
    fsmi2s=blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect (src,src_head,s2fsmi,s2p)
    for i in range(P):
        tb.connect ((s2p,i),(enc,i),(mod,i))
        tb.connect ((mod,i),(add[i],0))
        tb.connect (noise[i],(add[i],1))
        tb.connect (add[i],(metrics,i))
        tb.connect ((metrics,i),(va,i),(p2s,i))
    tb.connect (p2s,fsmi2s,dst)


    tb.run()

    # A bit of cheating: run the program once and print the
    # final encoder state.
    # Then put it as the last argument in the viterbi block
    #print "final state = " , enc.ST()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()

    return (ntotal,ntotal-nright)
	def __init__(self):
		gr.hier_block2.__init__(self, "deinterleaver",
				gr.io_signature(1, 1, gr.sizeof_char),	# Input signature
				gr.io_signature(1, 1, gr.sizeof_char))	# Output signature

		self.demux = blocks.stream_to_streams(gr.sizeof_char, INTERLEAVER_I)
		self.shift_registers = [dvb.fifo_shift_register_bb(INTERLEAVER_M * j)
				for j in range(INTERLEAVER_I)]
		# Deinterleaver shift registers are reversed compared to interleaver
		self.shift_registers.reverse()
		self.mux = blocks.streams_to_stream(gr.sizeof_char, INTERLEAVER_I)
		# Remove the uninitialised zeros that come out of the deinterleaver
		self.skip = blocks.skiphead(gr.sizeof_char, DELAY)

		self.connect(self, self.demux)
		for j in range(INTERLEAVER_I):
			self.connect((self.demux, j), self.shift_registers[j], (self.mux, j))
		self.connect(self.mux, self.skip, self)
Exemple #7
0
    def __init__(self, sequence1, sequence2, samp_rate, center_freq):
        """
	Description:
	This block is functionally equivalent to a conventional frequency xlating FIR filter, with filter taps given by the kronecker product of sequence1 with sequence2.
	This block consists of two filtering steps. First, the received samples are filtered using a frequency xlating filter with frequency offset equal to center_freq and taps equal to sequence2.  Second, the output is fed into a S/P converter to generate len(sequence2) parallel substreams, and each substream is filtered with identical filter with taps equal to sequence1. Then all substreams are connected to a P/S converter to generate the output sequence. 

	Complexity discussion:
	Originally the filter taps have length len(sequence1)*len(sequence2).
	For the kronecker we have one filter of len(sequence2), followed by a bank of len(sequence2) filters, each of length len(sequence1) operating at a rate 1/len(sequence2), for a total complexity of roughly len(sequence2)+len(sequence1), thus resulting in considerable complexity reduction.

	Args:
	     sequence1: the identical taps of each parallel filter in the filter bank.
	     sequence2: the taps of the first filter.
	     samp_rate: the samp_rate of the first freq_xlating_fir filter.
	     center_freq: the center frequency of the freq_xlating_fir filter.
        """

        gr.hier_block2.__init__(
            self,
            "kronecker_filter",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex))  # Output signature

        self.n = n = len(sequence2)

        # Build  filterbank
        self._s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, n)
        self._ss2s = blocks.streams_to_stream(gr.sizeof_gr_complex, n)
        self._filter2 = filter.freq_xlating_fir_filter_ccc(
            1, sequence2, center_freq, samp_rate)
        self._filter = [0] * n
        for i in range(n):
            self._filter[i] = filter.interp_fir_filter_ccc(1, sequence1)

        # Connect blocks
        self.connect(self, self._filter2)
        self.connect(self._filter2, self._s2ss)
        for i in range(n):
            self.connect((self._s2ss, i), self._filter[i])
            self.connect(self._filter[i], (self._ss2s, i))

        self.connect(self._ss2s, self)
Exemple #8
0
    def test_002(self):

        # Test streams_to_stream (using stream_to_streams).

        n = 8
        src_len = n * 8
        src_data = tuple(range(src_len))
        expected_results = src_data

        src = blocks.vector_source_i(src_data)
        op1 = blocks.stream_to_streams(gr.sizeof_int, n)
        op2 = blocks.streams_to_stream(gr.sizeof_int, n)
        dst = blocks.vector_sink_i()

        self.tb.connect(src, op1)
        for i in range(n):
            self.tb.connect((op1, i), (op2, i))
        self.tb.connect(op2, dst)

        self.tb.run()
        self.assertEqual(expected_results, dst.data())
Exemple #9
0
    def test_002(self):

        # Test streams_to_stream (using stream_to_streams).

        n = 8
        src_len = n * 8
        src_data = tuple(range(src_len))
        expected_results = src_data

        src = blocks.vector_source_i(src_data)
        op1 = blocks.stream_to_streams(gr.sizeof_int, n)
        op2 = blocks.streams_to_stream(gr.sizeof_int, n)
        dst = blocks.vector_sink_i()

        self.tb.connect(src, op1)
        for i in range(n):
            self.tb.connect((op1, i), (op2, i))
        self.tb.connect(op2, dst)

        self.tb.run()
        self.assertEqual(expected_results, dst.data())
    def __init__(self, sequence1, sequence2, samp_rate, center_freq):
        """
	Description:
	This block is functionally equivalent to a conventional frequency xlating FIR filter, with filter taps given by the kronecker product of sequence1 with sequence2.
	This block consists of two filtering steps. First, the received samples are filtered using a frequency xlating filter with frequency offset equal to center_freq and taps equal to sequence2.  Second, the output is fed into a S/P converter to generate len(sequence2) parallel substreams, and each substream is filtered with identical filter with taps equal to sequence1. Then all substreams are connected to a P/S converter to generate the output sequence. 

	Complexity discussion:
	Originally the filter taps have length len(sequence1)*len(sequence2).
	For the kronecker we have one filter of len(sequence2), followed by a bank of len(sequence2) filters, each of length len(sequence1) operating at a rate 1/len(sequence2), for a total complexity of roughly len(sequence2)+len(sequence1), thus resulting in considerable complexity reduction.

	Args:
	     sequence1: the identical taps of each parallel filter in the filter bank.
	     sequence2: the taps of the first filter.
	     samp_rate: the samp_rate of the first freq_xlating_fir filter.
	     center_freq: the center frequency of the freq_xlating_fir filter.
        """

        gr.hier_block2.__init__(self,
            "kronecker_filter",
            gr.io_signature(1,1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(1,1, gr.sizeof_gr_complex)) # Output signature

        self.n = n = len(sequence2)

        # Build  filterbank
        self._s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex,n)
        self._ss2s = blocks.streams_to_stream(gr.sizeof_gr_complex,n)
        self._filter2=filter.freq_xlating_fir_filter_ccc(1,sequence2,center_freq,samp_rate)
        self._filter=[0]*n
        for i in range(n):
          self._filter[i]=filter.interp_fir_filter_ccc(1,sequence1)

        # Connect blocks             
        self.connect(self, self._filter2)
        self.connect(self._filter2, self._s2ss)
        for i in range(n):
          self.connect((self._s2ss, i),self._filter[i])
          self.connect(self._filter[i],(self._ss2s, i))

        self.connect(self._ss2s,self)
Exemple #11
0
    def __init__(self, mpoints, taps=None):
        """
        Takes M complex streams in, produces single complex stream out
        that runs at M times the input sample rate

        Args:
            mpoints: number of freq bins/interpolation factor/subbands
            taps: filter taps for subband filter

        The channel spacing is equal to the input sample rate.
        The total bandwidth and output sample rate are equal the input
        sample rate * nchannels.

        Output stream to frequency mapping:

          channel zero is at zero frequency.

          if mpoints is odd:

            Channels with increasing positive frequencies come from
            channels 1 through (N-1)/2.

            Channel (N+1)/2 is the maximum negative frequency, and
            frequency increases through N-1 which is one channel lower
            than the zero frequency.

          if mpoints is even:

            Channels with increasing positive frequencies come from
            channels 1 through (N/2)-1.

            Channel (N/2) is evenly split between the max positive and
            negative bins.

            Channel (N/2)+1 is the maximum negative frequency, and
            frequency increases through N-1 which is one channel lower
            than the zero frequency.

            Channels near the frequency extremes end up getting cut
            off by subsequent filters and therefore have diminished
            utility.
        """
        item_size = gr.sizeof_gr_complex
        gr.hier_block2.__init__(self, "synthesis_filterbank",
                                gr.io_signature(mpoints, mpoints, item_size), # Input signature
                                gr.io_signature(1, 1, item_size))             # Output signature


        if taps is None:
            taps = _generate_synthesis_taps(mpoints)

        # pad taps to multiple of mpoints
        r = len(taps) % mpoints
        if r != 0:
            taps = taps + (mpoints - r) * (0,)

        # split in mpoints separate set of taps
        sub_taps = _split_taps(taps, mpoints)

        self.ss2v = blocks.streams_to_vector(item_size, mpoints)
        self.ifft = fft.fft_vcc(mpoints, False, [])
        self.v2ss = blocks.vector_to_streams(item_size, mpoints)
        # mpoints filters go in here...
        self.ss2s = blocks.streams_to_stream(item_size, mpoints)

        for i in range(mpoints):
            self.connect((self, i), (self.ss2v, i))

        self.connect(self.ss2v, self.ifft, self.v2ss)

        # build mpoints fir filters...
        for i in range(mpoints):
            f = fft_filter_ccc(1, sub_taps[i])
            self.connect((self.v2ss, i), f)
            self.connect(f, (self.ss2s, i))

	self.connect(self.ss2s, self)
Exemple #12
0
def run_test(seed,blocksize):
        tb = gr.top_block()

	##################################################
	# Variables
	##################################################
	M = 2
	K = 1
	P = 2
	h = (1.0*K)/P
	L = 3
	Q = 4
        frac = 0.99
        f = trellis.fsm(P,M,L)

        # CPFSK signals
        #p = numpy.ones(Q)/(2.0)
        #q = numpy.cumsum(p)/(1.0*Q)

        # GMSK signals
        BT=0.3;
        tt=numpy.arange(0,L*Q)/(1.0*Q)-L/2.0;
        #print tt
        p=(0.5*scipy.special.erfc(2*math.pi*BT*(tt-0.5)/math.sqrt(math.log(2.0))/math.sqrt(2.0))-0.5*scipy.special.erfc(2*math.pi*BT*(tt+0.5)/math.sqrt(math.log(2.0))/math.sqrt(2.0)))/2.0;
        p=p/sum(p)*Q/2.0;
        #print p
        q=numpy.cumsum(p)/Q;
        q=q/q[-1]/2.0;
        #print q

        (f0T,SS,S,F,Sf,Ff,N) = fsm_utils.make_cpm_signals(K,P,M,L,q,frac)
        #print N
        #print Ff
        Ffa = numpy.insert(Ff,Q,numpy.zeros(N),axis=0)
        #print Ffa
        MF = numpy.fliplr(numpy.transpose(Ffa))
        #print MF
        E = numpy.sum(numpy.abs(Sf)**2,axis=0)
        Es = numpy.sum(E)/f.O()
        #print Es

        constellation = numpy.reshape(numpy.transpose(Sf),N*f.O())
        #print Ff
        #print Sf
        #print constellation
        #print numpy.max(numpy.abs(SS - numpy.dot(Ff , Sf)))

	EsN0_db = 10.0
        N0 =  Es * 10.0**(-(1.0*EsN0_db)/10.0)
        #N0 = 0.0
        #print N0
        head = 4
        tail = 4
        numpy.random.seed(seed*666)
        data = numpy.random.randint(0, M, head+blocksize+tail+1)
        #data = numpy.zeros(blocksize+1+head+tail,'int')
        for i in range(head):
            data[i]=0
        for i in range(tail+1):
            data[-i]=0



	##################################################
	# Blocks
	##################################################
	random_source_x_0 = blocks.vector_source_b(data.tolist(), False)
	digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf((-1, 1), 1)
	filter_interp_fir_filter_xxx_0 = filter.interp_fir_filter_fff(Q, p)
	analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(2*math.pi*h*(1.0/Q))

	blocks_add_vxx_0 = blocks.add_vcc(1)
	analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, (N0/2.0)**0.5, -long(seed))

	blocks_multiply_vxx_0 = blocks.multiply_vcc(1)
	analog_sig_source_x_0 = analog.sig_source_c(Q, analog.GR_COS_WAVE, -f0T, 1, 0)
        # only works for N=2, do it manually for N>2...
	filter_fir_filter_xxx_0_0 = filter.fir_filter_ccc(Q, MF[0].conjugate())
	filter_fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(Q, MF[1].conjugate())
	blocks_streams_to_stream_0 = blocks.streams_to_stream(gr.sizeof_gr_complex*1, int(N))
	blocks_skiphead_0 = blocks.skiphead(gr.sizeof_gr_complex*1, int(N*(1+0)))
	viterbi = trellis.viterbi_combined_cb(f, head+blocksize+tail, 0, -1, int(N),
					      constellation, digital.TRELLIS_EUCLIDEAN)

        blocks_vector_sink_x_0 = blocks.vector_sink_b()

	##################################################
	# Connections
	##################################################
	tb.connect((random_source_x_0, 0), (digital_chunks_to_symbols_xx_0, 0))
	tb.connect((digital_chunks_to_symbols_xx_0, 0), (filter_interp_fir_filter_xxx_0, 0))
	tb.connect((filter_interp_fir_filter_xxx_0, 0), (analog_frequency_modulator_fc_0, 0))
	tb.connect((analog_frequency_modulator_fc_0, 0), (blocks_add_vxx_0, 0))
	tb.connect((analog_noise_source_x_0, 0), (blocks_add_vxx_0, 1))
	tb.connect((blocks_add_vxx_0, 0), (blocks_multiply_vxx_0, 0))
	tb.connect((analog_sig_source_x_0, 0), (blocks_multiply_vxx_0, 1))
	tb.connect((blocks_multiply_vxx_0, 0), (filter_fir_filter_xxx_0_0, 0))
	tb.connect((blocks_multiply_vxx_0, 0), (filter_fir_filter_xxx_0_0_0, 0))
	tb.connect((filter_fir_filter_xxx_0_0, 0), (blocks_streams_to_stream_0, 0))
	tb.connect((filter_fir_filter_xxx_0_0_0, 0), (blocks_streams_to_stream_0, 1))
	tb.connect((blocks_streams_to_stream_0, 0), (blocks_skiphead_0, 0))
	tb.connect((blocks_skiphead_0, 0), (viterbi, 0))
	tb.connect((viterbi, 0), (blocks_vector_sink_x_0, 0))


        tb.run()
        dataest = blocks_vector_sink_x_0.data()
        #print data
        #print numpy.array(dataest)
        perr = 0
        err = 0
        for i in range(blocksize):
          if data[head+i] != dataest[head+i]:
            #print i
            err += 1
        if err != 0 :
          perr = 1
        return (err,perr)
Exemple #13
0
    def __init__(self, baud=20000, deviation=25000, frequency_shift=0, read_file='', write_file='', interpolate=1):
        gr.top_block.__init__(self, "Tpms Fsk")

        ##################################################
        # Parameters
        ##################################################
        self.baud = baud
        self.deviation = deviation
        self.frequency_shift = frequency_shift
        self.read_file = read_file
        self.write_file = write_file
        self.interpolate = interpolate

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2.5e5
        self.sensivity = sensivity = deviation/(samp_rate*0.16)
        self.samp_per_symbol = samp_per_symbol = samp_rate/baud

        ##################################################
        # Blocks
        ##################################################
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
                interpolation=interpolate,
                decimation=1,
                taps=None,
                fractional_bw=None,
        )
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(1, (1, ), frequency_shift, samp_rate)
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_streams_to_stream_0 = blocks.streams_to_stream(gr.sizeof_char*1, 2)
        self.blocks_repeat_0 = blocks.repeat(gr.sizeof_float*1, int(samp_per_symbol))
        self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_vff((127, ))
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((127, ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((1.0/127, ))
        self.blocks_float_to_uchar_0_0 = blocks.float_to_uchar()
        self.blocks_float_to_uchar_0 = blocks.float_to_uchar()
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, read_file, False)
        self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL)
        self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, write_file, False)
        self.blocks_file_sink_0_0.set_unbuffered(False)
        self.blocks_complex_to_float_0 = blocks.complex_to_float(1)
        self.blocks_add_const_vxx_1_0 = blocks.add_const_vff((1, ))
        self.blocks_add_const_vxx_1 = blocks.add_const_vff((1, ))
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, ))
        self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(sensivity)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_frequency_modulator_fc_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_repeat_0, 0))
        self.connect((self.blocks_add_const_vxx_1, 0), (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_add_const_vxx_1_0, 0), (self.blocks_multiply_const_vxx_1_0, 0))
        self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_add_const_vxx_1, 0))
        self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_add_const_vxx_1_0, 0))
        self.connect((self.blocks_file_source_0, 0), (self.blocks_uchar_to_float_0, 0))
        self.connect((self.blocks_float_to_uchar_0, 0), (self.blocks_streams_to_stream_0, 0))
        self.connect((self.blocks_float_to_uchar_0_0, 0), (self.blocks_streams_to_stream_0, 1))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_float_to_uchar_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.blocks_float_to_uchar_0_0, 0))
        self.connect((self.blocks_repeat_0, 0), (self.analog_frequency_modulator_fc_0, 0))
        self.connect((self.blocks_streams_to_stream_0, 0), (self.blocks_file_sink_0_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.rational_resampler_xxx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_complex_to_float_0, 0))
Exemple #14
0
    def __init__(self, mpoints, taps=None):
        """
        Takes M complex streams in, produces single complex stream out
        that runs at M times the input sample rate

        Args:
            mpoints: number of freq bins/interpolation factor/subbands
            taps: filter taps for subband filter

        The channel spacing is equal to the input sample rate.
        The total bandwidth and output sample rate are equal the input
        sample rate * nchannels.

        Output stream to frequency mapping:

          channel zero is at zero frequency.

          if mpoints is odd:

            Channels with increasing positive frequencies come from
            channels 1 through (N-1)/2.

            Channel (N+1)/2 is the maximum negative frequency, and
            frequency increases through N-1 which is one channel lower
            than the zero frequency.

          if mpoints is even:

            Channels with increasing positive frequencies come from
            channels 1 through (N/2)-1.

            Channel (N/2) is evenly split between the max positive and
            negative bins.

            Channel (N/2)+1 is the maximum negative frequency, and
            frequency increases through N-1 which is one channel lower
            than the zero frequency.

            Channels near the frequency extremes end up getting cut
            off by subsequent filters and therefore have diminished
            utility.
        """
        item_size = gr.sizeof_gr_complex
        gr.hier_block2.__init__(self, "synthesis_filterbank",
                                gr.io_signature(mpoints, mpoints, item_size), # Input signature
                                gr.io_signature(1, 1, item_size))             # Output signature


        if taps is None:
            taps = _generate_synthesis_taps(mpoints)

        # pad taps to multiple of mpoints
        r = len(taps) % mpoints
        if r != 0:
            taps = taps + (mpoints - r) * (0,)

        # split in mpoints separate set of taps
        sub_taps = _split_taps(taps, mpoints)

        self.ss2v = blocks.streams_to_vector(item_size, mpoints)
        self.ifft = fft.fft_vcc(mpoints, False, [])
        self.v2ss = blocks.vector_to_streams(item_size, mpoints)
        # mpoints filters go in here...
        self.ss2s = blocks.streams_to_stream(item_size, mpoints)

        for i in range(mpoints):
            self.connect((self, i), (self.ss2v, i))

        self.connect(self.ss2v, self.ifft, self.v2ss)

        # build mpoints fir filters...
        for i in range(mpoints):
            f = fft_filter_ccc(1, sub_taps[i])
            self.connect((self.v2ss, i), f)
            self.connect(f, (self.ss2s, i))

            self.connect(self.ss2s, self)
Exemple #15
0
    def __init__(self,options):
        '''
            Constructor for top block of Power Estimator
            Creates the graph for calculating mean and variance
        '''
        gr.hier_block2.__init__(self, "periodogram", \
                                    gr.io_signature(1,1,gr.sizeof_gr_complex), \
                                    gr.io_signature(0,0,0) )

        scalarx=blocks.multiply_const_cc(1)

        ########## Node 1 - streams2vector block (input from usrp & output to fft block) ##########
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, options.fft_size)

        #Node 3 - fft block
        mywindow = filter.window.blackmanharris(options.fft_size)
        ffter = fft.fft_vcc(options.fft_size, True, mywindow)

        #Node 4 - magnitude-squared block
        c2mag = blocks.complex_to_mag_squared(options.fft_size)

        #Node 5 - vector2stream block
        vector2stream = blocks.vector_to_stream(gr.sizeof_float,options.fft_size)

        #Node 6 - stream2streams block
        stream2streams = blocks.stream_to_streams(gr.sizeof_float, options.fft_size)

        #Node 7 - adder block
        self.sumofNstreams = blocks.add_ff()

        #Node 8 - multiplier block (used to divide the output of adder block)
        self.avgofNstreams = blocks.multiply_const_ff(1.0/options.noofbins) # TODO: will depend on the number of bins

        #Node 9 - sinks (vector and null)
        to_nullsink = blocks.streams_to_stream(gr.sizeof_float,10)
        #self.vsink = gr.vector_sink_f()
        self.fsink = blocks.file_sink(gr.sizeof_float,"fsink.dat")
        if options.fft_size != options.noofbins:
            streams2stream = blocks.streams_to_stream(gr.sizeof_float, options.fft_size-options.noofbins)
        nullsink = blocks.null_sink(gr.sizeof_float)

        #Connect Phase 1 - From USRP source to stream2streams
        self.connect(self, scalarx, s2v, ffter, c2mag, vector2stream,stream2streams)
        for index in range(options.noofbins):
            self.connect((stream2streams,index), (self.sumofNstreams, index))
        i=10
        #Connect Phase 2 - From stream2streams to adder(few) and streams2stream(remaining)
        '''for index in range(5):
            self.connect((stream2streams,index), (to_nullsink,index))
        for index in range(5,options.noofbins-5):
            self.connect((stream2streams,index), (sumofNstreams, index-5))
        for index in range(options.fft_size-5,options.fft_size):
            self.connect((stream2streams,index), (to_nullsink,i))
            i=i+1
        else:
            for index in range(5,options.noofbins+5):
                self.connect((stream2streams,index), (sumofNstreams, index-5))
            for index in range(options.noofbins+5,options.fft_size):
                self.connect((stream2streams,index), (streams2stream,index-options.noofbins))'''

        #Connect Phase 3 - (few) from adder to vector sink, (remaining) to null sink
        #self.connect(streams2stream, nullsink)
        self.connect(self.sumofNstreams,self.avgofNstreams,self.fsink)

        #self.connect(to_nullsink,nullsink)

        print "FFT size                 %d" % (options.fft_size)
        print "Nblocks considered       %d" % (options.nblocks)
        print "No.of bins considered    %d" % (options.noofbins)