SP API
Sweep Mode

Sweep mode represents the common spectrum analyzer measurement of plotting amplitude over frequency. The API provides a simple interface through spGetSweep for acquiring single sweeps.

Example

For a list of all examples, please see the examples/ folder in the SDK.

#include <cstdio>
#include <cstdlib>
#include <vector>
#include "sp_api.h"
// Configure the device for sweeps and perform a single sweep.
void sp_example_sweep()
{
int handle = -1;
SpStatus status = spNoError;
status = spOpenDevice(&handle);
// Check open status
if (status != spNoError) {
printf("Unable to open device\n");
exit(-1);
}
// Configure the sweep
spSetRefLevel(handle, -20.0); // -20dBm reference level
spSetSweepCenterSpan(handle, 2.45e9, 100.0e6); // ISM band
spSetSweepCoupling(handle, 10.0e3, 10.0e3, 0.001); // 10kHz rbw/vbw, 1ms acquisition
spSetSweepDetector(handle, spDetectorAverage, spVideoPower); // average power detector
spSetSweepScale(handle, spScaleLog); // return sweep in dBm
// Initialize the device for sweep measurement mode
status = spConfigure(handle, spModeSweeping);
if (status != spNoError) {
printf("Unable to configure device\n");
printf("%s\n", spGetErrorString(status));
spCloseDevice(handle);
exit(-1);
}
// Get the configured sweep parameters as reported by the receiver
double actualRBW, actualVBW, actualStartFreq, binSize;
int sweepSize;
spGetSweepParameters(handle, &actualRBW, &actualVBW, &actualStartFreq, &binSize, &sweepSize);
// Create memory for our sweep
std::vector<float> sweep(sweepSize);
// Get sweep, ignore the min sweep and the sweep time
status = spGetSweep(handle, nullptr, sweep.data(), nullptr);
if (status != spNoError) {
printf("Sweep status: %s\n", spGetErrorString(status));
}
// Done with the device
spCloseDevice(handle);
}
API functions for the SP145 spectrum analyzer.
SpStatus
Definition: sp_api.h:104
@ spNoError
Definition: sp_api.h:156
SP_API SpStatus spCloseDevice(int device)
@ spModeSweeping
Definition: sp_api.h:209
SP_API SpStatus spSetSweepWindow(int device, SpWindowType window)
SP_API SpStatus spSetSweepScale(int device, SpScale scale)
SP_API const char * spGetErrorString(SpStatus status)
SP_API SpStatus spOpenDevice(int *device)
SP_API SpStatus spSetRefLevel(int device, double refLevel)
SP_API SpStatus spSetSweepCenterSpan(int device, double centerFreqHz, double spanHz)
@ spWindowFlatTop
Definition: sp_api.h:261
SP_API SpStatus spSetSweepDetector(int device, SpDetector detector, SpVideoUnits videoUnits)
@ spDetectorAverage
Definition: sp_api.h:225
SP_API SpStatus spGetSweep(int device, float *sweepMin, float *sweepMax, int64_t *nsSinceEpoch)
SP_API SpStatus spConfigure(int device, SpMode mode)
@ spScaleLog
Definition: sp_api.h:235
SP_API SpStatus spGetSweepParameters(int device, double *actualRBW, double *actualVBW, double *actualStartFreq, double *binSize, int *sweepSize)
@ spVideoPower
Definition: sp_api.h:251
SP_API SpStatus spSetSweepCoupling(int device, double rbw, double vbw, double sweepTime)

Basics

Only 1 sweep configuration can be active at a time.

Changing a sweep setting requires reconfiguring the device with a new sweep configuration.

All sweeps must be finished to change sweep configuration.

The maximum sweep speed that can be achieved is ~200GHz/s. This can only be achieved with wide spans and large RBWs.

Only linear spaced sweeps can be performed.

Sweep Format

A sweep is returned from the API as a 1-dimensional array of measurement values. Each element in the array corresponds to a specific frequency. The frequency of any given element can be calculated as

Frequency of N'th element in sweep = StartFreq + N * BinSize

where StartFreq and BinSize are reported in the spGetSweepParameters function.

The measurement values can be returned in dBm or mV units.

Min and Max Sweep Arrays

All sweep functions in the API return 2 separate sweep arrays. The parameters are typically named sweepMin and sweepMax. To understand the purpose of these arrays, it is important to understand their relation to the analyzer’s detector setting. Traditionally, spectrum analyzers offer several detector settings, the most common being peak-, peak+, and average. The API reduces this to either minmax or average. When the detector is set to minmax, the sweepMin array will contain the sweep as if a peak- detector is running, and the sweepMax array will contain the sweep of a peak+ detector. When average detector is enabled, sweepMin and sweepMax will be identical arrays and will be the result of an average detector.

If you are not interested in one of the sweeps, you can pass a NULL pointer for this parameter and it will be ignored.

Most users will be interested in the sweepMax array as it will provide you either the peak+ and average detector results depending on detector setting. In this case, pass NULL for the sweepMin parameter.