Example #1
0
    def test_001_t(self):
        # compare signal in time domain
        # set up fg
        test_len = 1000

        samp_rate = 4000
        samp_per_freq = 2
        blocks_per_tag = 100
        freq_low = 0
        freq_high = 200
        amplitude = 1

        src = radar.signal_generator_fsk_c(samp_rate, samp_per_freq,
                                           blocks_per_tag, freq_low, freq_high,
                                           amplitude)
        head = blocks.head(8, test_len)
        snk = blocks.vector_sink_c()

        self.tb.connect(src, head, snk)
        self.tb.run()

        # get ref data
        ref_data = [0] * test_len
        phase_low = 0
        phase_high = 0
        counter = 0
        state = 0
        for k in range(len(ref_data)):
            if counter == samp_per_freq:
                if state:
                    state = 0
                else:
                    state = 1
                counter = 0

            if state:
                ref_data[k] = amplitude * np.exp(1j * phase_high)
            else:
                ref_data[k] = amplitude * np.exp(
                    1j * phase_low)  # first is low

            phase_low = phase_low + 2 * np.pi * freq_low / samp_rate
            phase_high = phase_high + 2 * np.pi * freq_high / samp_rate
            counter = counter + 1

        # check data
        data = snk.data()
        self.assertComplexTuplesAlmostEqual(data, ref_data, 4)
    def test_001_t (self):
        # set up fg
		test_len = 1200
		
		samp_rate = 4000
		samp_per_freq = 2
		blocks_per_tag = 100
		freq_low = 0
		freq_high = 200
		amplitude = 1
		
		samp_discard = 1
		
		src = radar.signal_generator_fsk_c(samp_rate, samp_per_freq, blocks_per_tag, freq_low, freq_high, amplitude)
		head = blocks.head(8,test_len)
		split = radar.split_fsk_cc(samp_per_freq,samp_discard)
		snk0 = blocks.vector_sink_c()
		snk1 = blocks.vector_sink_c()
		snk = blocks.vector_sink_c()
		
		self.tb.connect(src,head,split)
		self.tb.connect((split,0),snk0)
		self.tb.connect((split,1),snk1)
		self.tb.connect(head,snk)
		self.tb.run ()
		
		# check correct length of data
		nblock = test_len/2/samp_per_freq
		self.assertEqual(len(snk0.data()),nblock*(samp_per_freq-samp_discard))
		self.assertEqual(len(snk1.data()),nblock*(samp_per_freq-samp_discard))
		
		# split data self
		data = snk.data()
		data0 = []
		data1 = []
		k=0
		while k<len(data):
			k = k+samp_discard
			data0.append(data[k])
			k = k+1
			k = k+samp_discard
			data1.append(data[k])
			k = k+1
		
		# check if data0/1 is same as split from block
		self.assertComplexTuplesAlmostEqual(data0,snk0.data(),10)
		self.assertComplexTuplesAlmostEqual(data1,snk1.data(),10)
    def test_001_t (self):
        # set up fg
        test_len = 1200
        samp_rate = 4000
        samp_per_freq = 2
        blocks_per_tag = 100
        freq_low = 0
        freq_high = 200
        amplitude = 1

        samp_discard = 1

        src = radar.signal_generator_fsk_c(samp_rate, samp_per_freq, blocks_per_tag, freq_low, freq_high, amplitude)
        head = blocks.head(8,test_len)
        split = radar.split_fsk_cc(samp_per_freq,samp_discard)
        snk0 = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()
        snk = blocks.vector_sink_c()

        self.tb.connect(src,head,split)
        self.tb.connect((split,0),snk0)
        self.tb.connect((split,1),snk1)
        self.tb.connect(head,snk)
        self.tb.run ()

        # check correct length of data
        nblock = test_len/2/samp_per_freq
        self.assertEqual(len(snk0.data()),nblock*(samp_per_freq-samp_discard))
        self.assertEqual(len(snk1.data()),nblock*(samp_per_freq-samp_discard))

        # split data self
        data = snk.data()
        data0 = []
        data1 = []
        k=0
        while k<len(data):
            k = k+samp_discard
            data0.append(data[k])
            k = k+1
            k = k+samp_discard
            data1.append(data[k])
            k = k+1

        # check if data0/1 is same as split from block
        self.assertComplexTuplesAlmostEqual(data0,snk0.data(),10)
        self.assertComplexTuplesAlmostEqual(data1,snk1.data(),10)
	def test_001_t (self):
		# compare signal in time domain
		# set up fg
		test_len = 1000
		
		samp_rate = 4000
		samp_per_freq = 2
		blocks_per_tag = 100
		freq_low = 0
		freq_high = 200
		amplitude = 1
		
		src = radar.signal_generator_fsk_c(samp_rate, samp_per_freq, blocks_per_tag, freq_low, freq_high, amplitude)
		head = blocks.head(8,test_len)
		snk = blocks.vector_sink_c()
		
		self.tb.connect(src,head,snk)
		self.tb.run ()
		
		# get ref data
		ref_data = [0]*test_len
		phase_low = 0
		phase_high = 0
		counter = 0
		state = 0
		for k in range(len(ref_data)):
			if counter==samp_per_freq:
				if state:
					state = 0
				else:
					state = 1
				counter = 0
			
			if state:
				ref_data[k] = amplitude*np.exp(1j*phase_high)
			else:
				ref_data[k] = amplitude*np.exp(1j*phase_low) # first is low
				
			phase_low = phase_low+2*np.pi*freq_low/samp_rate
			phase_high = phase_high+2*np.pi*freq_high/samp_rate
			counter = counter+1
		
		# check data
		data = snk.data()
		self.assertComplexTuplesAlmostEqual(data,ref_data,4)
Example #5
0
    def test_002_t(self):
        # compare signal in frequency domain
        # set up fg
        test_len = 1000

        samp_rate = 4000
        samp_per_freq = 1
        blocks_per_tag = 100
        freq_low = 0
        freq_high = 200
        amplitude = 1

        src = radar.signal_generator_fsk_c(samp_rate, samp_per_freq,
                                           blocks_per_tag, freq_low, freq_high,
                                           amplitude)
        head = blocks.head(8, test_len)
        snk = blocks.vector_sink_c()

        self.tb.connect(src, head, snk)
        self.tb.run()

        # split data
        data = snk.data()
        data0 = [0] * (test_len // 2)
        data1 = [0] * (test_len // 2)

        for k in range(test_len // 2):
            data0[k] = data[2 * k]
            data1[k] = data[2 * k + 1]

        # check data with fft
        fft0 = numpy.fft.fft(data0)  # get fft
        fft1 = numpy.fft.fft(data1)  # get fft
        num0 = np.argmax(abs(fft0))  # index of max sample
        fft_freq0 = samp_rate / 2 * num0 / len(
            fft0
        )  # calc freq out of max sample index, works only for frequencies < samp_rate/2!, samp rate is halfed
        num1 = np.argmax(abs(fft1))  # index of max sample
        fft_freq1 = samp_rate / 2 * num1 / len(
            fft1
        )  # calc freq out of max sample index, works only for frequencies < samp_rate/2!, samp rate is halfed

        self.assertEqual(freq_low, fft_freq0)  # check if freq is correct
        self.assertEqual(freq_high, fft_freq1)
	def test_002_t (self):
		# compare signal in frequency domain
		# set up fg
		test_len = 1000
		
		samp_rate = 4000
		samp_per_freq = 1
		blocks_per_tag = 100
		freq_low = 0
		freq_high = 200
		amplitude = 1
		
		src = radar.signal_generator_fsk_c(samp_rate, samp_per_freq, blocks_per_tag, freq_low, freq_high, amplitude)
		head = blocks.head(8,test_len)
		snk = blocks.vector_sink_c()
		
		self.tb.connect(src,head,snk)
		self.tb.run ()
		
		# split data
		data = snk.data()
		data0 = [0]*(test_len/2)
		data1 = [0]*(test_len/2)
		
		for k in range(test_len/2):
			data0[k] = data[2*k]
			data1[k] = data[2*k+1]
		
		# check data with fft
		fft0 = numpy.fft.fft(data0) # get fft
		fft1 = numpy.fft.fft(data1) # get fft
		num0 = np.argmax(abs(fft0)) # index of max sample
		fft_freq0 = samp_rate/2*num0/len(fft0) # calc freq out of max sample index, works only for frequencies < samp_rate/2!, samp rate is halfed
		num1 = np.argmax(abs(fft1)) # index of max sample
		fft_freq1 = samp_rate/2*num1/len(fft1) # calc freq out of max sample index, works only for frequencies < samp_rate/2!, samp rate is halfed
		
		self.assertEqual(freq_low,fft_freq0) # check if freq is correct
		self.assertEqual(freq_high,fft_freq1)
	def test_001_t (self):
		# run full fsk setup on high sample rates
		test_len = 2**19

		packet_len = 2**19
		min_output_buffer = packet_len*2
		samp_rate = 5000000
		
		center_freq = 2.45e9
		
		Range = 50
		velocity = 5
				
		samp_per_freq = 1
		blocks_per_tag = packet_len/2
		freq_low = 0
		freq_high = 1250000
		amplitude = 1
		samp_discard = 0

		src = radar.signal_generator_fsk_c(samp_rate, samp_per_freq, blocks_per_tag, freq_low, freq_high, amplitude)
		src.set_min_output_buffer(min_output_buffer)
		
		head = blocks.head(8,test_len)
		head.set_min_output_buffer(min_output_buffer)
		
		sim = radar.static_target_simulator_cc((Range,),(velocity,),(1e20,),(0,),(0,),samp_rate,center_freq,1,False,False)
		sim.set_min_output_buffer(min_output_buffer)
		
		mult = blocks.multiply_conjugate_cc()
		mult.set_min_output_buffer(min_output_buffer)
		
		fft1 = radar.ts_fft_cc(packet_len/2)
		fft1.set_min_output_buffer(min_output_buffer)
		fft2 = radar.ts_fft_cc(packet_len/2)
		fft2.set_min_output_buffer(min_output_buffer)
		
		split = radar.split_fsk_cc(samp_per_freq,samp_discard)
		split.set_min_output_buffer(min_output_buffer)
		
		mult_conj = blocks.multiply_conjugate_cc()
		mult_conj.set_min_output_buffer(min_output_buffer)
		
		cfar = radar.find_max_peak_c(samp_rate/2,-120,0,(),False)
		cfar.set_min_output_buffer(min_output_buffer)
		
		est = radar.estimator_fsk(center_freq,freq_high-freq_low)
		res = radar.print_results()
		debug = blocks.message_debug()

		self.tb.connect(src,head,(mult,1))
		self.tb.connect(head,sim,(mult,0))
		self.tb.connect(mult,split)
		self.tb.connect((split,0),fft1)
		self.tb.connect((split,1),fft2)
		self.tb.connect(fft1,(mult_conj,0))
		self.tb.connect(fft2,(mult_conj,1))
		self.tb.connect(mult_conj,cfar)
		self.tb.msg_connect(cfar,'Msg out',est,'Msg in')
		self.tb.msg_connect(est,'Msg out',res,'Msg in')
		self.tb.msg_connect(est,'Msg out',debug,'store')

		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
		
		# check data
		msg = debug.get_message(0)
		#print "VELOCITY:", pmt.f32vector_ref(pmt.nth(1,(pmt.nth(1,msg))),0), velocity
		#print "RANGE:", pmt.f32vector_ref(pmt.nth(1,(pmt.nth(2,msg))),0), Range
		self.assertAlmostEqual( 1, velocity/pmt.f32vector_ref(pmt.nth(1,(pmt.nth(1,msg))),0), 1 ) # check velocity value
		self.assertAlmostEqual( 1, Range/pmt.f32vector_ref(pmt.nth(1,(pmt.nth(2,msg))),0), 1 ) # check range value