def test_004(self):
        ''' Test the floating point AGC loop (attack and decay rate inputs) '''
        fg = self.fg

        expected_result = \
            (7.2191943445432116e-07,
             58.837181091308594,
             40.194305419921875,
             2.9183335304260254,
             0.67606079578399658,
             8.6260438791896377e-09,
             -1.4542514085769653,
             -1.9210131168365479,
             -1.0450780391693115,
             -0.61939650774002075,
             -1.2590258613442984e-08,
             1.4308931827545166,
             1.9054338932037354,
             1.0443156957626343,
             0.61937344074249268,
             2.0983527804219193e-08,
             -1.4308838844299316,
             -1.9054274559020996,
             -1.0443152189254761,
             -0.61937344074249268,
             -2.5180233009791664e-08,
             1.4308837652206421,
             1.9054274559020996,
             1.0443154573440552,
             0.61937344074249268,
             3.3573645197293445e-08,
             -1.4308838844299316,
             -1.9054274559020996,
             -1.0443152189254761,
             -0.61937350034713745,
             -3.7770352179222755e-08,
             1.4308837652206421,
             1.9054274559020996,
             1.0443154573440552,
             0.61937350034713745,
             4.6163762590367696e-08,
             -1.4308838844299316,
             -1.9054274559020996,
             -1.0443153381347656,
             -0.61937344074249268,
             -5.0360466019583328e-08,
             1.4308837652206421,
             1.9054274559020996,
             1.0443155765533447,
             0.61937344074249268,
             5.8753879983441948e-08,
             -1.4308837652206421,
             -1.9054274559020996,
             -1.0443153381347656,
             -0.61937344074249268)

        sampling_freq = 100
        src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE,
                                sampling_freq * 0.10, 100)
        dst1 = gr.vector_sink_f ()
        head = gr.head (gr.sizeof_float, int (5*sampling_freq * 0.10))

        agc = gr.agc2_ff(1e-2, 1e-3, 1, 1, 1000)
        
        fg.connect (src1, head)
        fg.connect (head, agc)
        fg.connect (agc, dst1)

        if test_output == True:
            fg.connect (agc, gr.file_sink(gr.sizeof_float, "test_agc2_ff.dat"))

        fg.run ()
        dst_data = dst1.data ()
        self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4)
Example #2
0
    def __init__(self):
        gr.top_block.__init__(self)
           
        amplitude = 30000

        filt_out = gr.file_sink(gr.sizeof_gr_complex, "./filt.out")
        filt2_out = gr.file_sink(gr.sizeof_gr_complex, "./filt2.out")
        ffilt_out = gr.file_sink(gr.sizeof_float, "./ffilt.out")
        ffilt2_out = gr.file_sink(gr.sizeof_float, "./ffilt2.out")

        interp_rate = 128
        dec_rate = 8
        sw_dec = 4

        num_taps = int(64000 / ( (dec_rate * 4) * 256 )) #Filter matched to 1/4 of the 256 kHz tag cycle
        taps = [complex(1,1)] * num_taps
        
        matched_filt = gr.fir_filter_ccc(sw_dec, taps);  
          
        agc = gr.agc2_cc(0.3, 1e-3, 1, 1, 100) 
     
        to_mag = gr.complex_to_mag()

        center = rfid.center_ff(4)

        omega = 2
        mu = 0.25
        gain_mu = 0.25
        gain_omega = .25 * gain_mu * gain_mu
        omega_relative_limit = .05

        mm = gr.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_relative_limit)


        self.reader = rfid.reader_f(int(128e6/interp_rate)); 
        
        tag_decoder = rfid.tag_decoder_f()
        
        command_gate = rfid.command_gate_cc(12, 60, 64000000 / dec_rate / sw_dec)
        

       
       
        to_complex = gr.float_to_complex()
        amp = gr.multiply_const_ff(amplitude)
        
        f_sink = gr.file_sink(gr.sizeof_gr_complex, 'f_sink.out');
        f_sink2 = gr.file_sink(gr.sizeof_gr_complex, 'f_sink2.out');


            #TX
      


        freq = 915e6
        rx_gain = 20  
    
        tx = usrp.sink_c(fusb_block_size = 1024, fusb_nblocks=8)
        tx.set_interp_rate(interp_rate)
        tx_subdev = (0,0)
        tx.set_mux(usrp.determine_tx_mux_value(tx, tx_subdev))
        subdev = usrp.selected_subdev(tx, tx_subdev)
        subdev.set_enable(True)
        subdev.set_gain(subdev.gain_range()[2])
        t = tx.tune(subdev.which(), subdev, freq)
        if not t:
            print "Couldn't set tx freq"
#End TX
             
#RX
        rx = usrp.source_c(0, dec_rate, fusb_block_size = 512 * 4, fusb_nblocks = 16)
        rx_subdev_spec = (1,0)
        rx.set_mux(usrp.determine_rx_mux_value(rx, rx_subdev_spec))
        rx_subdev = usrp.selected_subdev(rx, rx_subdev_spec)
        rx_subdev.set_gain(rx_gain)
        rx_subdev.set_auto_tr(False)
        rx_subdev.set_enable(True)
        
        r = usrp.tune(rx, 0, rx_subdev, freq)

        self.rx = rx
        if not r:
            print "Couldn't set rx freq"

#End RX

        command_gate.set_ctrl_out(self.reader.ctrl_q())
        tag_decoder.set_ctrl_out(self.reader.ctrl_q())
        agc2 = gr.agc2_ff(0.3, 1e-3, 1, 1, 100) 


#########Build Graph
        self.connect(rx, matched_filt)
        self.connect(matched_filt, command_gate)
        self.connect(command_gate, agc)
        self.connect(agc, to_mag) 
        self.connect(to_mag, center, agc2, mm, tag_decoder)
        self.connect(tag_decoder, self.reader, amp, to_complex, tx);
#################

        
        self.connect(matched_filt, filt_out)
Example #3
0
    def test_004(self):
        ''' Test the floating point AGC loop (attack and decay rate inputs) '''
        tb = self.tb

        expected_result = \
            (7.2191943445432116e-07,
             58.837181091308594,
             40.194305419921875,
             2.9183335304260254,
             0.67606079578399658,
             8.6260438791896377e-09,
             -1.4542514085769653,
             -1.9210131168365479,
             -1.0450780391693115,
             -0.61939650774002075,
             -1.2590258613442984e-08,
             1.4308931827545166,
             1.9054338932037354,
             1.0443156957626343,
             0.61937344074249268,
             2.0983527804219193e-08,
             -1.4308838844299316,
             -1.9054274559020996,
             -1.0443152189254761,
             -0.61937344074249268,
             -2.5180233009791664e-08,
             1.4308837652206421,
             1.9054274559020996,
             1.0443154573440552,
             0.61937344074249268,
             3.3573645197293445e-08,
             -1.4308838844299316,
             -1.9054274559020996,
             -1.0443152189254761,
             -0.61937350034713745,
             -3.7770352179222755e-08,
             1.4308837652206421,
             1.9054274559020996,
             1.0443154573440552,
             0.61937350034713745,
             4.6163762590367696e-08,
             -1.4308838844299316,
             -1.9054274559020996,
             -1.0443153381347656,
             -0.61937344074249268,
             -5.0360466019583328e-08,
             1.4308837652206421,
             1.9054274559020996,
             1.0443155765533447,
             0.61937344074249268,
             5.8753879983441948e-08,
             -1.4308837652206421,
             -1.9054274559020996,
             -1.0443153381347656,
             -0.61937344074249268)

        sampling_freq = 100
        src1 = gr.sig_source_f(sampling_freq, gr.GR_SIN_WAVE,
                               sampling_freq * 0.10, 100)
        dst1 = gr.vector_sink_f()
        head = gr.head(gr.sizeof_float, int(5 * sampling_freq * 0.10))

        agc = gr.agc2_ff(1e-2, 1e-3, 1, 1, 1000)

        tb.connect(src1, head)
        tb.connect(head, agc)
        tb.connect(agc, dst1)

        if test_output == True:
            tb.connect(agc, gr.file_sink(gr.sizeof_float, "test_agc2_ff.dat"))

        tb.run()
        dst_data = dst1.data()
        self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 4)