Ejemplo n.º 1
0
Archivo: thinkrf.py Proyecto: pyrf/pyrf
    def peakfind(self, n=1, rbw=None, average=1):
        """
        Returns frequency and the power level of the maximum spectral point
        computed using the current settings, Note this function disables

        :param int n: determine the number of peaks to return
        :param int rbw: rbw of spectral capture (Hz) (will round to nearest native RBW) or None
        :param int average: number of capture iterations
        :returns: [(peak_freq1, peak_power1),
                   (peak_freq2, peak_power2)
                   , ...,
                   (peak_freqn, peak_powern)]
        """
        iq_path = self.iq_output_path()
        capture_mode = self.capture_mode()

        if not iq_path == 'DIGITIZER' or not capture_mode == 'BLOCK':
            raise StandardError("Can't perform peak find while RTSA is sweeping or IQ path is not on the DIGITIZER path")
        # get read access
        self.request_read_perm()

        fstart, fstop, pow_data = capture_spectrum(self, rbw, average)
        frequencies = np.linspace(fstart, fstop, len(pow_data))
        peak_points = []
        for p in sorted(pow_data, reverse=True)[0:n]:
            peak_points.append((frequencies[np.where(pow_data == p)][0], p))
        return peak_points
Ejemplo n.º 2
0
    def peakfind(self, n=1, rbw=None, average=1):
        """
        Returns frequency and the power level of the maximum spectral point
        computed using the current settings, Note this function disables

        :param int n: determine the number of peaks to return
        :param int rbw: rbw of spectral capture (Hz) (will round to nearest native RBW) or None
        :param int average: number of capture iterations
        :returns: [(peak_freq1, peak_power1),
                   (peak_freq2, peak_power2)
                   , ...,
                   (peak_freqn, peak_powern)]
        """
        iq_path = self.iq_output_path()
        capture_mode = self.capture_mode()

        if not iq_path == 'DIGITIZER' or not capture_mode == 'BLOCK':
            raise StandardError(
                "Can't perform peak find while RTSA is sweeping or IQ path is not on the DIGITIZER path"
            )
        # get read access
        self.request_read_perm()

        fstart, fstop, pow_data = capture_spectrum(self, rbw, average)
        frequencies = np.linspace(fstart, fstop, len(pow_data))
        peak_points = []
        for p in sorted(pow_data, reverse=True)[0:n]:
            peak_points.append((frequencies[np.where(pow_data == p)][0], p))
        return peak_points
Ejemplo n.º 3
0
def update():
    global dut, curve, fft_plot, fstart, fstop, print_once

    # get spectral data with a given RBW and plot
    fstart, fstop, pow_data = capture_spectrum(dut, RBW, AVERAGE, DECIMATION)
    freq_range = np.linspace(fstart, fstop, len(pow_data))
    curve.setData(freq_range, pow_data, pen='g')
    fft_plot.enableAutoRange('xy', False)
Ejemplo n.º 4
0
def update():
    global dut, curve, fft_plot, fstart, fstop, print_once

    # get spectral data with a given RBW and plot
    fstart, fstop, pow_data = capture_spectrum(dut, RBW, AVERAGE, DECIMATION)
    freq_range = np.linspace(fstart , fstop, len(pow_data))
    curve.setData(freq_range, pow_data, pen='g')
    fft_plot.enableAutoRange('xy', False)
Ejemplo n.º 5
0
Archivo: thinkrf.py Proyecto: pyrf/pyrf
    def measure_noisefloor(self, rbw=None, average=1):
        """
        Returns a power level that represents the top edge of the noisefloor

        :param int rbw: rbw of spectral capture (Hz) (will round to nearest native RBW) or None
        :param int average: number of capture iterations
        :return: noise_power
        """
        iq_path = self.iq_output_path()
        capture_mode = self.capture_mode()

        if not iq_path == 'DIGITIZER' or not capture_mode == 'BLOCK':
            raise StandardError("Can't measure noisefloor while RTSA is sweeping or IQ path is not on the DIGITIZER path")
        # get read access
        self.request_read_perm()
        fstart, fstop, pow_data = capture_spectrum(self, rbw, average)
        noisefloor = np.mean(sorted(pow_data)[int(len(pow_data) * 0.2):])
        return noisefloor
Ejemplo n.º 6
0
    def measure_noisefloor(self, rbw=None, average=1):
        """
        Returns a power level that represents the top edge of the noisefloor

        :param int rbw: rbw of spectral capture (Hz) (will round to nearest native RBW) or None
        :param int average: number of capture iterations
        :return: noise_power
        """
        iq_path = self.iq_output_path()
        capture_mode = self.capture_mode()

        if not iq_path == 'DIGITIZER' or not capture_mode == 'BLOCK':
            raise StandardError(
                "Can't measure noisefloor while RTSA is sweeping or IQ path is not on the DIGITIZER path"
            )
        # get read access
        self.request_read_perm()
        fstart, fstop, pow_data = capture_spectrum(self, rbw, average)
        noisefloor = np.mean(sorted(pow_data)[int(len(pow_data) * 0.2):])
        return noisefloor
Ejemplo n.º 7
0
    def get_npoints(self):
        '''
        get the number of points by calling capture function and filtering 
        to start/stop frequencies, if required
        '''

        if (self._capture_mode == 'BLOCK'):
            fstart, fstop, spectra = capture_spectrum(self.dut, self.rbw(),
                                                      self.average())

            flist = np.linspace(fstart, fstop, len(spectra))

            filteredFreq, filteredSpectra = self.filter_span(flist, spectra)

            return len(filteredSpectra)

        if (self._capture_mode == 'SWEEP'):

            #TODO : calling center frequency function (or any function that returns numeric data) after sweepdev creation gives error, find a workaround
            scan_startf = self.f_start()
            scan_stopf = self.f_stop()
            atten = self.attenuation()
            rbw = self.rbw()
            mode = self.rfe_mode()
            avg = self._average()

            sweepdev = SweepDevice(self.dut)

            fstart, fstop, spectra = sweepdev.capture_power_spectrum(
                scan_startf,
                scan_stopf,
                rbw, {'attenuator': atten},
                mode=mode,
                niter=1,
                average=avg)

            self._freqlist = np.linspace(fstart, fstop, len(spectra))
            self._spectra = spectra

            return (len(spectra))
# initialize an RTSA (aka WSA) device handle
dut = WSA()

dut.connect('169.254.16.253')

#%% initialize RTSA configurations
dut.reset()
dut.request_read_perm()
dut.rfe_mode(RFE_MODE)
dut.freq(CENTER_FREQ)
dut.attenuator(ATTENUATION)
dut.psfm_gain(GAIN)
dut.trigger(TRIGGER_SETTING)

startT = time.time()
fstart, fstop, pow_data = capture_spectrum(dut, RBW, AVERAGE, DECIMATION)
freq_range = np.linspace(fstart, fstop, len(pow_data))
stopT = time.time()

print(
    f"Averages = {AVERAGE}, time = {stopT-startT:2.2f} sec, len = {len(pow_data)}"
)

plt.plot(freq_range, pow_data)
#%%
span = 40e6
fbegin = CENTER_FREQ - span / 2
fend = CENTER_FREQ + span / 2
keep = (fbegin < freq_range) & (freq_range < fend)
#plt.plot( freq_range[keep], pow_data[keep] )
plt.plot(np.linspace(fbegin, fend, len(pow_data[keep])), pow_data[keep])
Ejemplo n.º 9
0
startT = time()
avglist = [1, 5, 10, 50, 100, 500, 1000, 5000, 10000]
timelist = []

spectrum = []
freqlist = []

stopf = 0

for avg in avglist:
    startT = time()
    while (stopf <
           fstop):  # keep taking data until we have reached the stop frequency

        if (dut.freq() == CENTER_FREQ):
            startf_, stopf_, pow_data = capture_spectrum(
                dut, RBW, avg, DECIMATION)
            usableBW = stopf_ - startf_
            nextfc = (fstart + (fstart + (usableBW))
                      ) / 2.  # update center frequency for next iteration
            dut.freq(nextfc)

            continue

        dut.freq(nextfc)

        startf, stopf, pow_data = capture_spectrum(dut, RBW, avg, DECIMATION)
        # print(startf/1e9, stopf/1e9, (stopf-startf)/1e9 )
        # print(len(pow_data))

        freqlist = np.concatenate((np.linspace(startf, stopf,
                                               len(pow_data)), freqlist))
Ejemplo n.º 10
0
F_CENTER = 5.12e9
SPAN = 5e6

TRIGGER_SETTING = {
    'type': 'NONE',
    'fstart': F_CENTER - SPAN / 2,  # some value
    'fstop': F_CENTER + SPAN / 2,  # some value
    'amplitude': -100
}

dut.freq(F_CENTER)
dut.trigger(TRIGGER_SETTING)
dut.scpiset(':SOUR:REF:PLL EXT')

# setup graph
fstart, fstop, spectra_data = capture_spectrum(dut, RBW, average=100)

fig = figure(1)
xvalues = np.linspace(fstart, fstop, len(spectra_data))

xlabel("Frequency")
ylabel("Amplitude")

# plot something
plot(xvalues, spectra_data, color='blue')

# show graph
show()

# %%