def acquire_single_power_spectrum(self): STAIRS_MODE = False self._capture_count += 1 if STAIRS_MODE: STAIR_WIDTH = 50 stair_start = self._capture_count % self._numpts stair_start = np.floor(stair_start / STAIR_WIDTH) * STAIR_WIDTH stair_stop = stair_start + STAIR_WIDTH ps_dBm = np.zeros(self._numpts) - 80 ps_dBm[stair_start:stair_stop] = -20 timestamp_s = self._capture_count else: drv = self._driver vrt_data, context = read_data_and_context(drv, self._numpts) assert isinstance(vrt_data, pyrf.vrt.DataPacket) ps_dBm = compute_fft(drv, vrt_data, context, convert_to_dbm=True) #Accumulate history... timestamp_s = calc_vrt_sample_time_s(vrt_data) self.capture_history.add_row(ps_dBm, timestamp_s=timestamp_s) self._last_power_spectrum_dBm = ps_dBm return ps_dBm
def acquire_single_power_spectrum(self): STAIRS_MODE = False self._capture_count += 1 if STAIRS_MODE: STAIR_WIDTH = 50 stair_start = self._capture_count % self._numpts stair_start = np.floor(stair_start / STAIR_WIDTH) * STAIR_WIDTH stair_stop = stair_start + STAIR_WIDTH ps_dBm = np.zeros(self._numpts) - 80 ps_dBm[stair_start:stair_stop] = -20 timestamp_s = self._capture_count else: drv = self._driver vrt_data, context = read_data_and_context(drv, self._numpts) assert isinstance(vrt_data, pyrf.vrt.DataPacket) ps_dBm = compute_fft(drv, vrt_data, context, convert_to_dbm=True) #Accumulate history... timestamp_s = calc_vrt_sample_time_s(vrt_data) self.capture_history.add_row(ps_dBm, timestamp_s = timestamp_s) self._last_power_spectrum_dBm = ps_dBm return ps_dBm
def update(): # update the plot to show new data global p3, z, colors # read data data, context = read_data_and_context(dut, powerSize) # ignore the reference level so plot doesn't change positions context['reflevel'] = STATIC_REFLEVEL # compute the fft of the complex data powData = compute_fft(dut, data, context) # compress the FFT into a 128 array zData = represent_fft_to_plot(powData) # move the data stream as well as colours back to show new data for i in range (ySize): if i == 0: continue else: colors[:,ySize - i,:] = colors[:, ySize - i - 1,:] z[:,ySize - i] = z[:, ySize - i - 1] z[:,0] = zData[:,0] # grab new color colors[:,0,:] = create_color_heatmap(powData) colors[:,1,:] = create_color_heatmap(powData) # update the plot p3.setData(z = z, colors = colors.reshape(xSize*ySize,4))
def update_screen(self): data, context = read_data_and_context( self.dut, self.points) self.screen.update_data( compute_fft(self.dut, data, context), self.center_freq, self.decimation_factor)
def initDUT(self): self.center_freq = self.dut.freq() self.decimation_factor = self.dut.decimation() data, context = read_data_and_context(self.dut) self.screen.update_data( compute_fft(self.dut, data, context), self.center_freq, self.decimation_factor)
def read_data(self, spp): """ Check if we have permission to read data. :param spp: the number of samples in a packet :returns: data class, context dictionary, and fft array """ data, context = read_data_and_context(self, spp) pow_data = compute_fft(self, data, context) return data, context, pow_data
def update(): global dut, curve, fft_plot, freq_range, max_location # read data data, context = read_data_and_context(dut, SAMPLE_SIZE) center_freq = context['rffreq'] bandwidth = context['bandwidth'] # compute the fft and plot the data pow_data = compute_fft(dut, data, context) if self.marker_freq == None: self.marker_freq = self.center_freq # update axes limits plot_xmin = (center_freq) - (bandwidth / 2) plot_xmax = (center_freq) + (bandwidth / 2) # update the frequency range (Hz) freq_range = np.linspace(plot_xmin , plot_xmax, SAMPLE_SIZE) # initialize the x-axis of the plot fft_plot.setXRange(plot_xmin,plot_xmax) fft_plot.setLabel('bottom', text= 'Frequency', units = 'Hz', unitPrefix=None) # grab new cursor region cursor_region = region_selection_lines.getRegion() index_region = np.zeros(2) # index_region[0] = int((cursor_region[0] - plot_xmin) * SAMPLE_SIZE/bandwidth) if index_region[0] < 0: index_region[0] = 0 index_region[1] = int((cursor_region[1] - plot_xmin) * SAMPLE_SIZE/bandwidth) if index_region[1] > SAMPLE_SIZE: index_region[1] = SAMPLE_SIZE max_index = find_max_index(pow_data[np.amin(index_region):np.amax(index_region)]) if max_index < np.amin(index_region): max_index = max_index + np.amin(index_region) max_freq = freq_range[max_index] max_pow = pow_data[max_index] label.setText("<span style='color: green'>Max Frequency Location=%0.1f MHz, Power=%0.1f dBm</span>" % (max_freq/1e6, max_pow)) # TODO: use better method than bellow # hold maximum positions pos = np.random.normal(size=(2,1), scale=1e-9) max_location.setData(x =pos[0] + max_freq , y = pos[0] + max_pow, size = 20, symbol = 't') curve.setData(freq_range,pow_data, pen = 'g')
def read_data(self, spp): """ Read and return a data packet, as well as computed power spectral density data, of *spp* (samples per packet) size, the associated context info and the computed power spetral data. If a block of data is requested (such as *ppb* is more than 1), loop through this function to retreive all data. See also data other capture functions: :meth:`pyrf.util.capture_spectrum`, :meth:`pyrf.capture_device.capture_time_domain` :param int spp: the number of samples in a VRT packet (256 to 65504) in a multiple of 32 :returns: data, context dictionary, and power spectral data array """ data, context = read_data_and_context(self, spp) pow_data = compute_fft(self, data, context) return data, context, pow_data
def update(): global dut, i_curve, q_curve # read data data, context = read_data_and_context(dut, SAMPLE_SIZE) iq_data = data.data.numpy_array() # extract i and q data and normalize i_data = (np.array(iq_data[:,0], dtype=float)) / 8192 q_data = (np.array(iq_data[:,1], dtype=float)) / 8192 # update curves i_curve.setData(freq_range, i_data, pen = 'g') q_curve.setData(freq_range, q_data, pen = 'r')
def update(): global dut, fft_curve, max_curve, freq_range # read data data, context = read_data_and_context(dut, SAMPLE_SIZE) # compute the fft and plot the data pow_data = compute_fft(dut, data, context) for i in range(len(pow_data)): if pow_data[i] > max_hold[i]: max_hold[i] = pow_data[i] fft_curve.setData(freq_range,pow_data,pen = 'g') max_curve.setData(freq_range,max_hold,pen = 'y')
def update(): global dut, curve, fft_plot, plot_xmin, plot_xmax # read data data, context = read_data_and_context(dut, SAMPLE_SIZE) # compute the fft and plot the data pow_data = compute_fft(dut, data, context) # update the frequency range (Hz) freq_range = np.linspace(plot_xmin, plot_xmax, len(pow_data)) # initialize the x-axis of the plot fft_plot.setXRange(plot_xmin, plot_xmax) fft_plot.setLabel('bottom', text='Frequency', units='Hz', unitPrefix=None) curve.setData(freq_range, pow_data, pen='g')
def update(): global dut, curve, fft_plot, plot_xmin, plot_xmax # read data data, context = read_data_and_context(dut, SAMPLE_SIZE) # compute the fft and plot the data pow_data = compute_fft(dut, data, context) # update the frequency range (Hz) freq_range = np.linspace(plot_xmin , plot_xmax, len(pow_data)) # initialize the x-axis of the plot fft_plot.setXRange(plot_xmin,plot_xmax) fft_plot.setLabel('bottom', text= 'Frequency', units = 'Hz', unitPrefix=None) curve.setData(freq_range,pow_data, pen = 'g')
def update(): global dut, curve, fft_plot, freq_range, center_freq, bandwidth, cont_pow_data, fade_curve # read data data, context = read_data_and_context(dut, SAMPLE_SIZE) center_freq = context['rffreq'] bandwidth = context['bandwidth'] # update axes limits plot_xmin = (center_freq) - (bandwidth / 2) plot_xmax = (center_freq) + (bandwidth / 2) # update the frequency range (Hz) freq_range = np.linspace(plot_xmin , plot_xmax, SAMPLE_SIZE) # initialize the x-axis of the plot fft_plot.setXRange(plot_xmin,plot_xmax) fft_plot.setLabel('bottom', text= 'Frequency', units = 'Hz', unitPrefix=None) # compute the fft and plot the data powData = compute_fft(dut, data, context) for i in range(number_of_fade_curves): #fade_curve[i].setData(freq_range,cont_pow_data[i,:],pen = (255,0,255,i * (255 / number_of_fade_curves)) ) if i == number_of_fade_curves - 1: cont_pow_data[i,:] = powData else: cont_pow_data[i,:] = cont_pow_data[i + 1,:] variance = np.zeros(number_of_curves) for i in range(number_of_curves): variance[i] = np.std(cont_pow_data[:,i]) if variance[i] < 10: color = 'r' else: color = 'b' x = np.array(freq_range[i * 8:(i * 8) + 7]) y = np.array(powData[i * 8:(i * 8) + 7]) if i == 57: color = 'g' curve[i].setData(x,y,pen = color)
def update(): global dut, curve, fft_plot, freq_range, max_location # read data data, context = read_data_and_context(dut, SAMPLE_SIZE) # retrieve freq and bandwidth to update axis center_freq = context['rffreq'] bandwidth = context['bandwidth'] # update axes limits plot_xmin = (center_freq) - (bandwidth / 2) plot_xmax = (center_freq) + (bandwidth / 2) # update the frequency range (Hz) freq_range = np.linspace(plot_xmin , plot_xmax, SAMPLE_SIZE) # update the x-axis of the plot fft_plot.setXRange(plot_xmin,plot_xmax) fft_plot.setLabel('bottom', text= 'Frequency', units = 'Hz', unitPrefix=None) # compute the fft and plot the data pow_data = compute_fft(dut, data, context) # determine the index of the maximum point max_index = np.argmax(pow_data) # retrieve maximum power and freq of max power max_freq = freq_range[max_index] max_pow = pow_data[max_index] # update label label.setText("<span style='color: green'>Max Frequency Location=%0.1f MHz, Power=%0.1f dBm</span>" % (max_freq/1e6, max_pow)) # TODO: Find a better way then using an array with small random values # create array of small numbers pos = np.random.normal(size=(2,1), scale=1e-9) # update scatter plot max_location.setData(x =pos[0] + max_freq , y = pos[0] + max_pow, size = 20, symbol = 't') # update fft curve curve.setData(freq_range,pow_data, pen = 'g')
def update(): global dut, curve, fft_plot, freq_range, center_freq, bandwidth # read data data, context = read_data_and_context(dut, SAMPLE_SIZE) center_freq = context['rffreq'] bandwidth = context['bandwidth'] # update axes limits plot_xmin = (center_freq) - (bandwidth / 2) plot_xmax = (center_freq) + (bandwidth / 2) # update the frequency range (Hz) freq_range = np.linspace(plot_xmin , plot_xmax, SAMPLE_SIZE) # initialize the x-axis of the plot fft_plot.setXRange(plot_xmin,plot_xmax) fft_plot.setLabel('bottom', text= 'Frequency', units = 'Hz', unitPrefix=None) # compute the fft and plot the data powData = compute_fft(dut, data, context) curve.setData(freq_range,powData, pen = 'g')
dut.reset() dut.request_read_perm() dut.ifgain(0) dut.freq(2450e6) dut.gain('high') dut.fshift(0) dut.decimation(0) trigger = TriggerSettings( trigtype="LEVEL", fstart=2400e6, fstop=2480e6, amplitude=-70) dut.trigger(trigger) # capture 1 packet data, context = read_data_and_context(dut, 1024) # compute the fft of the complex data powdata = compute_fft(dut, data, context) # setup my graph fig = figure(1) axis([0, 1024, -120, 20]) xlabel("Sample Index") ylabel("Amplitude") # plot something plot(powdata, color='blue') # show graph
# setup test conditions dut.reset() dut.request_read_perm() dut.ifgain(0) dut.freq(2450e6) dut.gain('high') dut.fshift(0) dut.decimation(0) trigger = TriggerSettings(trigtype="LEVEL", fstart=2400e6, fstop=2480e6, amplitude=-70) dut.trigger(trigger) # capture 1 packet data, context = read_data_and_context(dut, 1024) # compute the fft of the complex data powdata = compute_fft(dut, data, context) # setup my graph fig = figure(1) axis([0, 1024, -120, 20]) xlabel("Sample Index") ylabel("Amplitude") # plot something plot(powdata, color='blue') # show graph