Frequency Response Analyzer Instrument

This instrument measures the transfer function of a system by generating a swept output sinewave and measuring the system response on the input.

Example Usage

The following example code and a wide range of other pymoku demo scripts can be found at the pymoku Github repository.

frequency_response_analyzer_basic.py
#
# pymoku example: Basic Frequency Response Analyzer
#
# This example demonstrates how you can generate output sweeps using the
# Frequency Response Analyzer instrument, and view transfer function data in real-time.
#
# (c) 2019 Liquid Instruments Pty. Ltd.
#
from pymoku import Moku
from pymoku.instruments import FrequencyResponseAnalyzer
import logging

# Connect to your Moku by its device name
# Alternatively, use Moku.get_by_serial('#####') or Moku('192.168.###.###')
m = Moku.get_by_name('Moku')

try:
	# Deploy the Frequency Response Analyzer to your Moku
	i = m.deploy_or_connect(FrequencyResponseAnalyzer)

	# Configure output sweep parameters (100Hz-20MHz)
	i.set_sweep(f_start=100,f_end=20e6,sweep_points=256)

	# Configure output sweep amplitudes
	# Channel 1 - 0.1Vpp
	# Channel 1 - 0.1Vpp
	i.set_output(1, 0.1)
	i.set_output(2, 0.1)

	# Start the sweep
	i.start_sweep(single=True)

	# Get a single sweep frame. This will block until the sweep is complete, beware
	# if your range includes low frequencies!
	frame = i.get_data()

	# Print out the data for Channel 1
	print(frame.ch1.magnitude_dB, frame.ch1.phase, frame.frequency)
finally:
	m.close()

The FRAData Class

class pymoku.instruments.FRAData(instrument, scales)

Object representing a frame of dual-channel (amplitude and phase) vs frequency response data.

This is the native output format of the FrequencyResponseAnalyzer instrument.

This object should not be instantiated directly, but will be returned by a call to get_data on the associated FrequencyResponseAnalyzer instrument.

  • ch1.magnitude = [CH1_MAG_DATA]
  • ch1.magnitude_dB = [CH1_MAG_DATA_DB]
  • ch1.phase = [CH1_PHASE_DATA]
  • ch2.magnitude = [CH2_MAG_DATA]
  • ch2.magnitude_dB = [CH2_MAG_DATA_DB]
  • ch2.phase = [CH2_PHASE_DATA]
  • frequency = [FREQ]
  • waveformid = n

The FrequencyResponseAnalyzer Class

class pymoku.instruments.FrequencyResponseAnalyzer

Frequency Response Analyzer instrument object.

This should be instantiated and attached to a Moku instance.

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.

enable_amplitude(*args, **kwargs)

Enable/disable amplitude on the selected channel.

Parameters:
  • ch (int; {1, 2}) – Output channel
  • en (bool) – Enable amplitude)
enable_offset(*args, **kwargs)

Enable/disable output offset on the selected channel.

Parameters:
  • ch (int; {1, 2}) – Output channel
  • en (bool) – Enable offset
gen_off(*args, **kwargs)

Turn off the output sweep.

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)
get_data(timeout=None, wait=True)

Get current sweep data. In the FrequencyResponseAnalyzer this is an alias for get_realtime_data as the data is never downsampled.

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_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_ch_phase(*args, **kwargs)

set the phase of the measurement with respect to the output signal.

Parameters:
  • ch (int; {1, 2}) – selects the channel to apply settings.
  • phase (float [0.0, 360.0] deg) – phase difference between channel 1 and channel 2.
set_defaults(*args, **kwargs)

Reset the Frequency Response 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_harmonic_multiplier(*args, **kwargs)

set the harmonic multiplier to demodulate at integer harmonic of output.

Parameters:
  • ch (int; {1, 2}) – selects the channel to apply settings.
  • multiplier (int; [0, 15]) – multiplier applied to fundemental.
set_input_range(*args, **kwargs)

Set the input range for a channel.

Parameters:
  • ch (int; {1,2}) – channel
  • input_range ({1, 10}) – the peak to peak voltage (Vpp) range of the inputs.
set_output(*args, **kwargs)

Set the output sweep amplitude.

Note

Ensure that the output amplitude is set so as to not saturate the inputs. Inputs are limited to 1.0Vpp with attenuation turned off.

Parameters:
  • ch (int; {1, 2}) – Output channel
  • amplitude (float; [0.0, 2.0] Vpp) – Sweep amplitude
  • offset (float; [-1.0, 1.0] Volts) – Sweep offset
set_sweep(*args, **kwargs)

Set the output sweep parameters

Parameters:
  • f_start (int; 1 <= f_start <= 120e6 Hz) – Sweep start frequency
  • f_end (int; 1 <= f_end <= 120e6 Hz) – Sweep end frequency
  • sweep_points (int; 32 <= sweep_points <= 512) – Number of points in the sweep (rounded to nearest power of 2).
  • sweep_log (bool) – Enable logarithmic frequency sweep scale.
  • averaging_time (float; sec) – Minimum averaging time per sweep point.
  • settling_time (float; sec) – Minimum setting time per sweep point.
  • averaging_cycles (int; cycles) – Minimum averaging cycles per sweep point.
  • settling_cycles (int; cycles) – Minimum settling cycles per sweep point.
set_xmode(*args, **kwargs)

Set rendering mode for the horizontal axis.

Parameters:xmode (string, {'sweep','fullframe'}) – Respectively; Sweep Mode (bode function sweeping across the screen) or Full Frame (like sweep, but waits for the frame to be completed).
start_sweep(*args, **kwargs)

Start sweeping

Parameters:single (bool) – Enable single sweep (otherwise loop)
stop_sweep(*args, **kwargs)

Stop sweeping.

This will stop new data frames from being received, so ensure you implement a timeout on get_data calls.