Spectrum Analyzer Instrument¶
This instrument provides frequency-domain analysis of input signals. It features switchable window functions, resolution bandwidth, averaging modes and more.
Example Usage¶
For an in-depth walkthrough on using the pymoku Spectrum Analyzer Instrument, see the pymoku Spectrum Analyzer tutorial. The following example code and a wide range of other pymoku demo scripts can be found at the pymoku Github repository.
#
# pymoku example: Basic Spectrum Analyzer
#
# This example demonstrates how you can use the Spectrum Analyzer instrument to
# to retrieve a single spectrum data frame over a set frequency span.
#
# (c) 2017 Liquid Instruments Pty. Ltd.
#
from pymoku import Moku
from pymoku.instruments import SpectrumAnalyzer
# Connect to your Moku by its device name
# Alternatively, use Moku.get_by_serial('#####') or Moku('192.168.###.###')
m = Moku.get_by_name('Moku')
# Deploy the Spectrum Analyzer to your Moku
try:
i = m.deploy_or_connect(SpectrumAnalyzer)
# DC to 10MHz span
i.set_span(0, 10e6)
# Get the scan results and print them out (power vs frequency, two channels)
data = i.get_data()
print(data.ch1, data.ch2, data.frequency)
finally:
# Close the connection to the Moku.
m.close()
The SpectrumData Class¶
-
class
pymoku.instruments.
SpectrumData
(instrument, scales)¶ Object representing a frame of dual-channel frequency spectrum data (amplitude vs frequency in Hz). Amplitude is in units of either dBm power or RMS Voltage, as indicated by the dbm attribute of the frame. The amplitude scale may be selected by calling
set_dbmscale
on the relevantSpectrumAnalyzer
instrument.This is the native output format of the
SpectrumAnalyzer
instrument.This object should not be instantiated directly, but will be returned by a call to
get_data
on the associatedSpectrumAnalyzer
instrument.-
ch1
= [CH1_DATA]¶
-
ch2
= [CH2_DATA]¶
-
frequency
= [FREQ]¶
-
dbm
= bool¶
-
waveformid
= n¶
-
The SpectrumAnalyzer Class¶
-
class
pymoku.instruments.
SpectrumAnalyzer
¶ Spectrum Analyzer instrument object.
To run a new Spectrum Analyzer instrument, this should be instantiated and deployed via a connected
Moku
object usingdeploy_instrument
. Alternatively, a pre-configured instrument object can be obtained by discovering an already running Spectrum Analyzer instrument on a Moku:Lab device viadiscover_instrument
.-
__init__
()¶ Create a new Spectrum Analyzer instrument, ready to be attached to a Moku.
-
framerate
= 10¶ Frame Rate, range 10 - 30.
-
type
= "spectrumanalyzer"¶ Name of this instrument.
-
commit
()¶ Apply all modified settings.
Note
If the autocommit feature has been turned off, this function can be used to manually apply any instrument settings to the Moku device. These instrument settings are those configured by calling all set_ and gen_ type functions. Manually calling this function allows you to atomically apply many instrument settings at once.
-
gen_off
(*args, **kwargs)¶ Turn waveform generator output off.
If ch is specified, turn off only a single channel, otherwise turn off both.
Parameters: ch (int; {1,2}) – Channel number to turn off (None, or leave blank, for both)firmware_is_compatible
-
gen_sinewave
(*args, **kwargs)¶ Configure the output sinewaves on DAC channels
Parameters: - ch (int; {1,2}) – Output DAC channel to configure
- amp (float, 0.0 - 2.0 volts) – Peak-to-peak output voltage
- freq (float, 0 - 250e6 Hertz) – Frequency of output sinewave (ignored if sweep=True)
- sweep (bool) – Sweep current frequency span (ignores freq parameter if True). Defaults to False.
Raises: - ValueError – if the channel number is invalid
- ValueOutOfRangeException – if wave parameters are out of range
-
get_data
(timeout=None, wait=True)¶ Get the latest sweep results.
On SpectrumAnalyzer this is an alias for
get_realtime_data
as the output data is never downsampled from the sweep results.
-
get_frontend
(channel)¶ Get the analog frontend configuration.
Parameters: channel (int; {1,2}) – Channel for which the relay settings are being retrieved Returns: Array of bool with the front end configuration of channels - [0] 50 Ohm - [1] 10xAttenuation - [2] AC Coupling
-
get_rbw
()¶ Returns: The current resolution bandwidth (Hz)
-
get_realtime_data
(timeout=None, wait=True)¶ Get downsampled data from the instrument with low latency.
Returns a new
InstrumentData
subclass (instrument-specific), containing a version of the data that may have been downsampled from the original in order to be transferred quickly.This function always returns a new object at framerate (10Hz by default), whether or not there is new data in that object. This can be verified by checking the return object’s waveformid parameter, which increments each time a new waveform is captured internally.
The downsampled, low-latency nature of this data makes it particularly suitable for plotting in real time. If you require high-accuracy, high-resolution data for analysis, see get_data.
If the wait parameter is true (the default), this function will wait for any new settings to be applied before returning. That is, if you have set a new timebase (for example), calling this with wait=True will guarantee that the data returned has this new timebase.
Note that if instrument configuration is changed, a trigger event must occur before data captured with that configuration set can become available. This can take an arbitrary amount of time. For this reason the timeout should be set appropriately.
Parameters: - timeout (float) – Maximum time to wait for new data, or None for indefinite.
- wait (bool) – If true (default), waits for a new waveform to be captured with the most recently-applied settings, otherwise just return the most recently captured valid data.
Returns: InstrumentData
subclass, specific to the instrument.
-
set_dbmscale
(*args, **kwargs)¶ Configures the scale of the Spectrum Analyzer amplitude data. This can be either power in dBm, or RMS Voltage.
Parameters: dbm (bool) – Enable dBm scale
-
set_defaults
(*args, **kwargs)¶ Reset the Spectrum Analyzer to sane defaults.
-
set_framerate
(*args, **kwargs)¶ Set framerate
-
set_frontend
(channel, fiftyr=True, atten=False, ac=False)¶ Configures gain, coupling and termination for each channel.
Parameters: - channel (int; {1,2}) – Channel to which the settings should be applied
- fiftyr (bool) – 50Ohm termination; default is 1MOhm.
- atten (bool) – Turn on 10x attenuation. Changes the dynamic range between 1Vpp and 10Vpp.
- ac (bool) – AC-couple; default DC.
-
set_rbw
(*args, **kwargs)¶ Set desired Resolution Bandwidth
Actual resolution bandwidth will be rounded to the nearest allowable unit when settings are applied to the device.
Parameters: rbw (float) – Desired resolution bandwidth (Hz), or None
for auto-modeRaises: ValueError – if the RBW is not positive-definite or None
-
set_span
(*args, **kwargs)¶ Sets the frequency span to be analysed.
Rounding and quantization in the instrument limits the range of spans for which a full set of 1024 data points can be calculated. This means that the resultant number of data points in
SpectrumData
frames will vary with the set span. Note however that the associated frequencies are given with the frame containing the data.Parameters: - f1 (float) – Left-most frequency (Hz)
- f2 (float) – Right-most frequency (Hz)
Raises: InvalidConfigurationException – if the span is not positive-definite.
-
set_window
(*args, **kwargs)¶ Set Window function
Parameters: window (string, {'blackman-harris','flattop','hanning','none'}) – Window Function
-