Ejemplo n.º 1
0
	def __init__(self, fft_len, sens_per_sec, sample_rate, channel_space = 1,
	 search_bw = 1, thr_leveler = 10, tune_freq = 0, alpha_avg = 1, test_duration = 1,
	  period = 3600, trunc_band = 1, verbose = False, psd = False, waterfall = False, subject_channels = []):
		gr.hier_block2.__init__(self,
			"spectrum_sensor_v1",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),
			gr.io_signature(0, 0, 0))
		self.fft_len = fft_len #lenght of the fft for spectral analysis
		self.sens_per_sec = sens_per_sec #number of measurements per second (decimates)
		self.sample_rate = sample_rate 
		self.channel_space = channel_space #channel space for analysis
		self.search_bw = search_bw #search bandwidth within each channel
		self.thr_leveler = thr_leveler #leveler factor for noise floor / threshold comparison
		self.tune_freq = tune_freq #center frequency
		self.threshold = 0 #actual value of the threshold
		self.alpha_avg = alpha_avg #averaging factor for noise level between consecutive measurements
		self.verbose = verbose
		self.trunc_band = trunc_band
		self.psd = psd
		self.waterfall = waterfall
		self.subject_channels = subject_channels

		#gnuradio msg queues
		self.msgq0 = gr.msg_queue(2)
		self.msgq1 = gr.msg_queue(2)

		#######BLOCKS#####
		self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
		self.one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex * self.fft_len,
		 max(1, int(self.sample_rate/self.fft_len/self.sens_per_sec)))

		mywindow = window.blackmanharris(self.fft_len)
		self.fft = fft.fft_vcc(self.fft_len, True, (), True)

		self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
		self.multiply = blocks.multiply_const_vff(np.array([1.0/float(self.fft_len**2)]*fft_len))

		#MSG sinks PSD data 
		self.sink0 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq0, True)
		self.sink1 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq1, True)

		#####CONNECTIONS####
		self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2, self.multiply, self.sink0)
		self.connect(self.multiply, self.sink1)
		
		#-----waterfall-----> different decimation because operates in a slower rate
		self.msgq2 = gr.msg_queue(2)
		self.sink2 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq2, True)
		self.one_in_n_waterfall = blocks.keep_one_in_n(gr.sizeof_float * self.fft_len, self.sens_per_sec) #keep 1 per second...
		self.connect(self.multiply, self.one_in_n_waterfall, self.sink2)

		#start periodic logging
		self._logger = logger(self.fft_len, period, test_duration)

		#Watchers
		#statistics and power
		self._stats_watcher = _stats_watcher(self.msgq0, sens_per_sec, self.tune_freq, self.channel_space,
		 self.search_bw, self.fft_len, self.sample_rate, self.thr_leveler, self.alpha_avg, test_duration,
		  trunc_band, verbose, self._logger)
		#psd
		if self.psd:
			self._psd_watcher = _psd_watcher(self.msgq1, verbose, self._logger)
		#waterfall
		if self.waterfall:
			self._waterfall_watcher = _waterfall_watcher(self.msgq2, verbose, self._logger)
Ejemplo n.º 2
0
    def __init__(self,
                 fft_len,
                 sens_per_sec,
                 sample_rate,
                 channel_space=1,
                 search_bw=1,
                 thr_leveler=10,
                 tune_freq=0,
                 alpha_avg=1,
                 test_duration=1,
                 period=3600,
                 trunc_band=1,
                 verbose=False,
                 stats=False,
                 psd=False,
                 waterfall=False,
                 output=False,
                 subject_channels=[]):
        gr.hier_block2.__init__(self, "spectrum_sensor_v2",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        self.fft_len = fft_len  #lenght of the fft for spectral analysis
        self.sens_per_sec = sens_per_sec  #number of measurements per second (decimates)
        self.sample_rate = sample_rate
        self.channel_space = channel_space  #channel space for analysis
        self.search_bw = search_bw  #search bandwidth within each channel
        self.thr_leveler = thr_leveler  #leveler factor for noise floor / threshold comparison
        self.tune_freq = tune_freq  #center frequency
        self.threshold = 0  #actual value of the threshold
        self.alpha_avg = alpha_avg  #averaging factor for noise level between consecutive measurements
        self.verbose = verbose
        self.trunc_band = trunc_band
        self.stats = stats
        self.psd = psd
        self.waterfall = waterfall
        self.output = output
        self.subject_channels = subject_channels

        #data queue to share data between theads
        self.q = Queue.Queue()

        #gnuradio msg queues
        self.msgq0 = gr.msg_queue(2)
        self.msgq1 = gr.msg_queue(2)

        #output top 4 freqs
        self.top4 = [0, 0, 0, 0]

        #register message out to other blocks
        self.message_port_register_hier_out("freq_out_0")
        self.message_port_register_hier_out("freq_out_1")
        self.message_port_register_hier_out("freq_out_2")
        self.message_port_register_hier_out("freq_out_3")
        self.message_port_register_hier_out("freq_msg_PDU")

        #######BLOCKS#####
        self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
        self.one_in_n = blocks.keep_one_in_n(
            gr.sizeof_gr_complex * self.fft_len,
            max(1, int(self.sample_rate / self.fft_len / self.sens_per_sec)))

        mywindow = window.blackmanharris(self.fft_len)
        self.fft = fft.fft_vcc(self.fft_len, True, (), True)

        self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
        self.multiply = blocks.multiply_const_vff(
            np.array([1.0 / float(self.fft_len**2)] * fft_len))

        #MSG sinks PSD data
        #stats and basic
        self.sink0 = blocks.message_sink(gr.sizeof_float * self.fft_len,
                                         self.msgq0, True)
        if self.psd:
            self.sink1 = blocks.message_sink(gr.sizeof_float * self.fft_len,
                                             self.msgq1, True)

        #-----waterfall-----> different decimation because operates in a slower rate
        if self.waterfall:
            self.msgq2 = gr.msg_queue(2)
            self.sink2 = blocks.message_sink(gr.sizeof_float * self.fft_len,
                                             self.msgq2, True)
            self.one_in_n_waterfall = blocks.keep_one_in_n(
                gr.sizeof_float * self.fft_len,
                self.sens_per_sec)  #keep 1 per second...

        #MSG output blocks to other blocks
        self.message_out0 = blocks.message_strobe(
            pmt.cons(pmt.intern("freq"), pmt.to_pmt(self.top4[0])), 1000)
        self.message_out1 = blocks.message_strobe(
            pmt.cons(pmt.intern("freq"), pmt.to_pmt(self.top4[1])), 1000)
        self.message_out2 = blocks.message_strobe(
            pmt.cons(pmt.intern("freq"), pmt.to_pmt(self.top4[2])), 1000)
        self.message_out3 = blocks.message_strobe(
            pmt.cons(pmt.intern("freq"), pmt.to_pmt(self.top4[3])), 1000)
        self.PDU_messages = message_pdu.message_pdu(None)

        #####CONNECTIONS####
        #main stream
        self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2,
                     self.multiply, self.sink0)
        #psd stream
        if self.psd:
            self.connect(self.multiply, self.sink1)
        #waterfall stream
        if self.waterfall:
            self.connect(self.multiply, self.one_in_n_waterfall, self.sink2)

        #MSG output
        self.msg_connect(self.message_out0, "strobe", self, "freq_out_0")
        self.msg_connect(self.message_out1, "strobe", self, "freq_out_1")
        self.msg_connect(self.message_out2, "strobe", self, "freq_out_2")
        self.msg_connect(self.message_out3, "strobe", self, "freq_out_3")
        self.msg_connect(self.PDU_messages, 'out', self, 'freq_msg_PDU')

        #start periodic logging
        if self.stats or self.psd or self.waterfall:
            self._logger = logger(self.fft_len, period, test_duration)

        #Watchers
        #statistics and power
        if self.stats:
            self._stats_watcher = stats_watcher(
                self.msgq0, sens_per_sec, self.tune_freq, self.channel_space,
                self.search_bw, self.fft_len, self.sample_rate,
                self.thr_leveler, self.alpha_avg, test_duration, trunc_band,
                verbose, self._logger, self.q)
        #psd
        if self.psd:
            self._psd_watcher = psd_watcher(self.msgq1, verbose, self._logger)
        #waterfall
        if self.waterfall:
            self._waterfall_watcher = waterfall_watcher(
                self.msgq2, verbose, self._logger)
        #output_data - start basic watcher and output data threads
        if self.output:
            if self.stats is not True:
                self._basic_spectrum_watcher = basic_spectrum_watcher(
                    self.msgq0, sens_per_sec, self.tune_freq,
                    self.channel_space, self.search_bw, self.fft_len,
                    self.sample_rate, trunc_band, verbose, self.q)
            self._output_data = output_data(self.q, self.sample_rate,
                                            self.tune_freq, self.fft_len,
                                            self.trunc_band,
                                            self.channel_space, self.search_bw,
                                            self.output, self.subject_channels,
                                            self.top4, self.set_freqs)
            #send PDU's w/ freq data
            self._send_PDU_data = send_PDU_data(self.top4, self.PDU_messages)
Ejemplo n.º 3
0
	def __init__(self, fft_len, sens_per_sec, sample_rate, channel_space = 1,
	 search_bw = 1, thr_leveler = 10, tune_freq = 0, alpha_avg = 1, test_duration = 1,
	  period = 3600, trunc_band = 1, verbose = False, stats = False, psd = False, waterfall = False, output = False, subject_channels = []):
		gr.hier_block2.__init__(self,
			"spectrum_sensor_v2",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),
			gr.io_signature(0, 0, 0))
		self.fft_len = fft_len #lenght of the fft for spectral analysis
		self.sens_per_sec = sens_per_sec #number of measurements per second (decimates)
		self.sample_rate = sample_rate 
		self.channel_space = channel_space #channel space for analysis
		self.search_bw = search_bw #search bandwidth within each channel
		self.thr_leveler = thr_leveler #leveler factor for noise floor / threshold comparison
		self.tune_freq = tune_freq #center frequency
		self.threshold = 0 #actual value of the threshold
		self.alpha_avg = alpha_avg #averaging factor for noise level between consecutive measurements
		self.verbose = verbose
		self.trunc_band = trunc_band
		self.stats = stats
		self.psd = psd
		self.waterfall = waterfall
		self.output = output
		self.subject_channels = subject_channels

		#data queue to share data between theads
		self.q = Queue.Queue()

		#gnuradio msg queues
		self.msgq0 = gr.msg_queue(2)
		self.msgq1 = gr.msg_queue(2)
		
		#output top 4 freqs
		self.top4 = [0, 0, 0, 0]
		
		#register message out to other blocks
		self.message_port_register_hier_in("freq_out_0")
		self.message_port_register_hier_in("freq_out_1")
		self.message_port_register_hier_in("freq_out_2")
		self.message_port_register_hier_in("freq_out_3")
		self.message_port_register_hier_in("freq_msg_PDU")

		#######BLOCKS#####
		self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
		self.one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex * self.fft_len,
		 max(1, int(self.sample_rate/self.fft_len/self.sens_per_sec)))

		mywindow = window.blackmanharris(self.fft_len)
		self.fft = fft.fft_vcc(self.fft_len, True, (), True)

		self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
		self.multiply = blocks.multiply_const_vff(np.array([1.0/float(self.fft_len**2)]*fft_len))

		#MSG sinks PSD data
		#stats and basic
		self.sink0 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq0, True)
		if self.psd:
			self.sink1 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq1, True)

		#-----waterfall-----> different decimation because operates in a slower rate
		if self.waterfall:
			self.msgq2 = gr.msg_queue(2)
			self.sink2 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq2, True)
			self.one_in_n_waterfall = blocks.keep_one_in_n(gr.sizeof_float * self.fft_len, self.sens_per_sec) #keep 1 per second...

		#MSG output blocks to other blocks
		self.message_out0 = blocks.message_strobe( pmt.cons( pmt.intern("freq"), pmt.to_pmt(self.top4[0])), 1000)
		self.message_out1 = blocks.message_strobe( pmt.cons( pmt.intern("freq"), pmt.to_pmt(self.top4[1])), 1000)
		self.message_out2 = blocks.message_strobe( pmt.cons( pmt.intern("freq"), pmt.to_pmt(self.top4[2])), 1000)
		self.message_out3 = blocks.message_strobe( pmt.cons( pmt.intern("freq"), pmt.to_pmt(self.top4[3])), 1000)
		self.PDU_messages = message_pdu.message_pdu(None)

		#####CONNECTIONS####
		#main stream
		self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2, self.multiply, self.sink0)
		#psd stream
		if self.psd:
			self.connect(self.multiply, self.sink1)
		#waterfall stream
		if self.waterfall:
			self.connect(self.multiply, self.one_in_n_waterfall, self.sink2)

		#MSG output
		self.msg_connect(self.message_out0, "strobe", self, "freq_out_0")
		self.msg_connect(self.message_out1, "strobe", self, "freq_out_1")
		self.msg_connect(self.message_out2, "strobe", self, "freq_out_2")
		self.msg_connect(self.message_out3, "strobe", self, "freq_out_3")
		self.msg_connect(self.PDU_messages, 'out', self, 'freq_msg_PDU')

		#start periodic logging
		if self.stats or self.psd or self.waterfall:
			self._logger = logger(self.fft_len, period, test_duration)

		#Watchers
		#statistics and power
		if self.stats:
			self._stats_watcher = stats_watcher(self.msgq0, sens_per_sec, self.tune_freq, self.channel_space,
			 self.search_bw, self.fft_len, self.sample_rate, self.thr_leveler, self.alpha_avg, test_duration,
			  trunc_band, verbose, self._logger, self.q)
		#psd
		if self.psd:
			self._psd_watcher = psd_watcher(self.msgq1, verbose, self._logger)
		#waterfall
		if self.waterfall:
			self._waterfall_watcher = waterfall_watcher(self.msgq2, verbose, self._logger)
		#output_data - start basic watcher and output data threads
		if self.output:
			if self.stats is not True:
				self._basic_spectrum_watcher = basic_spectrum_watcher(self.msgq0, sens_per_sec, self.tune_freq, self.channel_space,
				 self.search_bw, self.fft_len, self.sample_rate, trunc_band, verbose, self.q)
			self._output_data = output_data(self.q, self.sample_rate, self.tune_freq, self.fft_len, self.trunc_band,
			 self.channel_space, self.search_bw, self.output, self.subject_channels, self.top4, self.set_freqs)
			#send PDU's w/ freq data
			self._send_PDU_data = send_PDU_data(self.top4, self.PDU_messages)
Ejemplo n.º 4
0
	def __init__(self, fft_len, sens_per_sec, sample_rate, channel_space = 1,
	 search_bw = 1, thr_leveler = 10, tune_freq = 0, alpha_avg = 1, test_duration = 1,
	  period = 3600, trunc_band = 1, verbose = False, psd = False, waterfall = False, subject_channels = []):
		gr.hier_block2.__init__(self,
			"spectrum_sensor_v1",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),
			gr.io_signature(0, 0, 0))
		self.fft_len = fft_len #lenght of the fft for spectral analysis
		self.sens_per_sec = sens_per_sec #number of measurements per second (decimates)
		self.sample_rate = sample_rate 
		self.channel_space = channel_space #channel space for analysis
		self.search_bw = search_bw #search bandwidth within each channel
		self.thr_leveler = thr_leveler #leveler factor for noise floor / threshold comparison
		self.tune_freq = tune_freq #center frequency
		self.threshold = 0 #actual value of the threshold
		self.alpha_avg = alpha_avg #averaging factor for noise level between consecutive measurements
		self.verbose = verbose
		self.trunc_band = trunc_band
		self.psd = psd
		self.waterfall = waterfall
		self.subject_channels = subject_channels

		#gnuradio msg queues
		self.msgq0 = gr.msg_queue(2)
		self.msgq1 = gr.msg_queue(2)

		#######BLOCKS#####
		self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
		self.one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex * self.fft_len,
		 max(1, int(self.sample_rate/self.fft_len/self.sens_per_sec)))

		mywindow = window.blackmanharris(self.fft_len)
		self.fft = fft.fft_vcc(self.fft_len, True, (), True)

		self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
		self.multiply = blocks.multiply_const_vff(np.array([1.0/float(self.fft_len**2)]*fft_len))

		#MSG sinks PSD data 
		self.sink0 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq0, True)
		self.sink1 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq1, True)

		#####CONNECTIONS####
		self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2, self.multiply, self.sink0)
		self.connect(self.multiply, self.sink1)
		
		#-----waterfall-----> different decimation because operates in a slower rate
		self.msgq2 = gr.msg_queue(2)
		self.sink2 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq2, True)
		self.one_in_n_waterfall = blocks.keep_one_in_n(gr.sizeof_float * self.fft_len, self.sens_per_sec) #keep 1 per second...
		self.connect(self.multiply, self.one_in_n_waterfall, self.sink2)

		#start periodic logging
		self._logger = logger(self.fft_len, period, test_duration)

		#Watchers
		#statistics and power
		self._stats_watcher = _stats_watcher(self.msgq0, sens_per_sec, self.tune_freq, self.channel_space,
		 self.search_bw, self.fft_len, self.sample_rate, self.thr_leveler, self.alpha_avg, test_duration,
		  trunc_band, verbose, self._logger)
		#psd
		if self.psd:
			self._psd_watcher = _psd_watcher(self.msgq1, verbose, self._logger)
		#waterfall
		if self.waterfall:
			self._waterfall_watcher = _waterfall_watcher(self.msgq2, verbose, self._logger)