def spectrum_scanner(self, samples): #measure power for each channel power_level_ch = src_power(samples, self.fft_len, self.Fr, self.sample_rate, self.bb_freqs, self.srch_bins) #trunc channels outside useful band (filter curve) --> trunc band < sample_rate if self.trunc > 0: power_level_ch = power_level_ch[self.trunc_ch:-self.trunc_ch] #log maximum powers - cumulative self.logger.set_cumulative_max_power(np.maximum(power_level_ch, self.logger.cumulative_max_power)) #log maximum powers - periodic self.logger.set_periodic_max_power(np.maximum(power_level_ch, self.logger.periodic_max_power)) #compute noise estimate (averaged) min_power = np.amin (power_level_ch) self.noise_estimate = (1-self.alpha_avg) * self.noise_estimate + self.alpha_avg * min_power thr = self.noise_estimate * self.thr_leveler if self.verbose: print 'noise_estimate dB (channel)', 10*np.log10(self.noise_estimate+1e-20) #compare channel power with detection threshold spectrum_constraint_hz = [] i = 0 for item in power_level_ch: if item>thr: spectrum_constraint_hz.append(self.ax_ch[i]) i += 1 return spectrum_constraint_hz
def spectrum_scanner(self, samples): #measure power for each channel power_level_ch = src_power(samples, self.fft_len, self.Fr, self.sample_rate, self.bb_freqs, self.srch_bins) #trunc channels outside useful band (filter curve) --> trunc band < sample_rate if self.trunc > 0: power_level_ch = power_level_ch[self.trunc_ch:-self.trunc_ch] #share data among threads self.plc = self.plc * 0.6 + np.array(power_level_ch) * 0.4 self.data_queue.put(self.plc) #log maximum powers - cumulative self.logger.set_cumulative_max_power(np.maximum(power_level_ch, self.logger.cumulative_max_power)) #log maximum powers - periodic self.logger.set_periodic_max_power(np.maximum(power_level_ch, self.logger.periodic_max_power)) #compute noise estimate (averaged) min_power = np.amin (power_level_ch) self.noise_estimate = (1-self.alpha_avg) * self.noise_estimate + self.alpha_avg * min_power thr = self.noise_estimate * self.thr_leveler if self.verbose: print 'noise_estimate dB (channel)', 10*np.log10(self.noise_estimate+1e-20) #compare channel power with detection threshold spectrum_constraint_hz = [] i = 0 for item in power_level_ch: if item>thr: spectrum_constraint_hz.append(self.ax_ch[i]) i += 1 return spectrum_constraint_hz
def flank_detector(self, samples): #measure power for each channel power_level_ch = src_power(samples, self.fft_len, self.Fr, self.sample_rate, self.bb_freqs, self.srch_bins) #trunc channels outside useful band (filter curve) --> trunc band < sample_rate if self.trunc > 0: power_level_ch = power_level_ch[self.trunc_ch:-self.trunc_ch] #compute noise estimate (averaged) min_power = np.amin (power_level_ch) self.noise_estimate = (1-self.alpha_avg) * self.noise_estimate + self.alpha_avg * min_power thr = self.noise_estimate * self.thr_leveler thr2 = thr*20 #2nd thrshold to limit fast growing if self.verbose: print 'noise_estimate dB (channel)', 10*np.log10(self.noise_estimate+1e-20) self.prev_power[:] = self.curr_power[:] k = 0 for channel in self.idx_subject_channels: self.curr_power[k] = (1-self.peak_alpha[k]) * np.clip(power_level_ch[channel], 0, thr2) + (self.peak_alpha[k]) * self.prev_power[k] if self.curr_power[k] < thr2 and self.curr_power[k] > thr: # kind of an AGC for weaker channels self.curr_power[k] = thr2 #if power_level_ch[channel] > thr: print 'instant power > thr' if self.curr_power[k] > self.prev_power[k] and self.curr_power[k] > thr and self.flag[k] == False: #print 'detected flanck!', self.ax_ch[channel]/1e6, 'MHz', self.subject_channels[k]/1e6, 'MHz' self.flag[k] = True self.peak_alpha[k] = 0 #count occurrences -> cumulative if self.ax_ch[channel] in self.logger.cumulative_statistics: self.logger.cumulative_statistics[self.ax_ch[channel]] += 1 else: self.logger.cumulative_statistics[self.ax_ch[channel]] = 1 #count occurrences -> periodic if self.ax_ch[channel] in self.logger.periodic_statistic: self.logger.periodic_statistic[self.ax_ch[channel]] += 1 else: self.logger.periodic_statistic[self.ax_ch[channel]] = 1 elif self.flag[k] == True and self.curr_power[k] < thr: #print 'detected negative flanck!' , self.ax_ch[channel]/1e6, 'MHz', self.subject_channels[k]/1e6, 'MHz' self.flag[k] = False self.peak_alpha[k] = self.peak_alpha_original k += 1 #update thread that logs data self.logger.set_settings(self.logger.settings) self.logger.set_n_measurements_period(self.logger.n_measurements_period) self.logger.set_cumulative_statistics(self.logger.cumulative_statistics) self.logger.set_periodic_statistic(self.logger.periodic_statistic)
def spectrum_scanner(self, samples): #measure power for each channel power_level_ch = src_power(samples, self.fft_len, self.Fr, self.sample_rate, self.bb_freqs, self.srch_bins) #trunc channels outside useful band (filter curve) --> trunc band < sample_rate if self.trunc > 0: power_level_ch = power_level_ch[self.trunc_ch:-self.trunc_ch] #share data among threads self.plc = self.plc * 0.6 + np.array(power_level_ch) * 0.4 self.data_queue.put(self.plc)
def spectrum_scanner(self, samples): #measure power for each channel power_level_ch = src_power(samples, self.fft_len, self.Fr, self.sample_rate, self.bb_freqs, self.srch_bins) #trunc channels outside useful band (filter curve) --> trunc band < sample_rate if self.trunc > 0: power_level_ch = power_level_ch[self.trunc_ch:-self.trunc_ch] #share data among threads self.plc = self.plc * 0.6 + np.array(power_level_ch) * 0.4
def flank_detector(self, samples): #measure power for each channel power_level_ch = src_power(samples, self.fft_len, self.Fr, self.sample_rate, self.bb_freqs, self.srch_bins) #trunc channels outside useful band (filter curve) --> trunc band < sample_rate if self.trunc > 0: power_level_ch = power_level_ch[self.trunc_ch:-self.trunc_ch] #compute noise estimate (averaged) min_power = np.amin(power_level_ch) self.noise_estimate = ( 1 - self.alpha_avg) * self.noise_estimate + self.alpha_avg * min_power thr = self.noise_estimate * self.thr_leveler thr2 = thr * 20 #2nd thrshold to limit fast growing if self.verbose: print 'noise_estimate dB (channel)', 10 * np.log10( self.noise_estimate + 1e-20) self.prev_power[:] = self.curr_power[:] k = 0 for channel in self.idx_subject_channels: self.curr_power[k] = (1 - self.peak_alpha[k]) * np.clip( power_level_ch[channel], 0, thr2) + (self.peak_alpha[k]) * self.prev_power[k] if self.curr_power[k] < thr2 and self.curr_power[ k] > thr: # kind of an AGC for weaker channels self.curr_power[k] = thr2 #if power_level_ch[channel] > thr: print 'instant power > thr' if self.curr_power[k] > self.prev_power[k] and self.curr_power[ k] > thr and self.flag[k] == False: #print 'detected flanck!', self.ax_ch[channel]/1e6, 'MHz', self.subject_channels[k]/1e6, 'MHz' self.flag[k] = True self.peak_alpha[k] = 0 #count occurrences -> cumulative if self.ax_ch[channel] in self.logger.cumulative_statistics: self.logger.cumulative_statistics[self.ax_ch[channel]] += 1 else: self.logger.cumulative_statistics[self.ax_ch[channel]] = 1 #count occurrences -> periodic if self.ax_ch[channel] in self.logger.periodic_statistic: self.logger.periodic_statistic[self.ax_ch[channel]] += 1 else: self.logger.periodic_statistic[self.ax_ch[channel]] = 1 elif self.flag[k] == True and self.curr_power[k] < thr: #print 'detected negative flanck!' , self.ax_ch[channel]/1e6, 'MHz', self.subject_channels[k]/1e6, 'MHz' self.flag[k] = False self.peak_alpha[k] = self.peak_alpha_original k += 1 #update thread that logs data self.logger.set_settings(self.logger.settings) self.logger.set_n_measurements_period( self.logger.n_measurements_period) self.logger.set_cumulative_statistics( self.logger.cumulative_statistics) self.logger.set_periodic_statistic(self.logger.periodic_statistic)