libpg2sdr
Host library for the ProStick Gen 2 SDR
Loading...
Searching...
No Matches
Device configuration

Macros

#define PG2SDR_DECIMATION_AUTO   (-1)
 Decimation mode that auto-selects decimation to avoid bandpass filter issues.
 

Enumerations

enum  pg2sdr_conversion_mode_t { PG2SDR_MODE_LOWIF_REAL , PG2SDR_MODE_BASEBAND }
 Enum controlling how ADC data is converted. More...
 
enum  pg2sdr_sideband_mode_t { PG2SDR_SIDEBAND_LOWER , PG2SDR_SIDEBAND_UPPER }
 Enum controlling sideband tuning selection. More...
 

Functions

int pg2sdr_set_conversion_mode (pg2sdr_device *dev, pg2sdr_conversion_mode_t mode)
 Set the conversion mode for sample data received by user callbacks.
 
int pg2sdr_get_conversion_mode (pg2sdr_device *dev, pg2sdr_conversion_mode_t *mode)
 Get the current sample conversion mode.
 
int pg2sdr_set_buffer_size (pg2sdr_device *dev, size_t buffer_size)
 Set size of sample buffer passed to user callbacks.
 
int pg2sdr_get_buffer_size (pg2sdr_device *dev, size_t *buffer_size)
 Get size of sample buffer passed to user callbacks.
 
int pg2sdr_set_sample_rate (pg2sdr_device *dev, double rate)
 Set the current requested user sampling rate.
 
int pg2sdr_get_sample_rate (pg2sdr_device *dev, double *requested, double *actual)
 Get current user sampling rate.
 
int pg2sdr_set_decimation_mode (pg2sdr_device *dev, int decimation_mode)
 Set current decimation mode.
 
int pg2sdr_get_decimation_mode (pg2sdr_device *dev, int *decimation_mode, unsigned *actual_decimation)
 Get current decimation mode and/or actual number of decimation steps.
 
int pg2sdr_set_undersampling_mode (pg2sdr_device *dev, unsigned undersampling_mode)
 Set the current undersampling mode.
 
int pg2sdr_get_undersampling_mode (pg2sdr_device *dev, unsigned *undersampling_mode)
 Get current undersampling mode.
 
int pg2sdr_set_adc_limit (pg2sdr_device *dev, double adc_limit)
 Set hardware ADC sampling rate limit.
 
int pg2sdr_get_adc_limit (pg2sdr_device *dev, double *adc_limit)
 Get current hardware ADC sampling rate limit.
 
int pg2sdr_get_adc_rate (pg2sdr_device *dev, double *actual_adc_rate)
 Get current ADC sampling rate.
 
int pg2sdr_set_sideband (pg2sdr_device *dev, pg2sdr_sideband_mode_t mode)
 Set the current sideband tuning mode.
 
int pg2sdr_get_sideband (pg2sdr_device *dev, pg2sdr_sideband_mode_t *mode)
 Get current sideband mode.
 
int pg2sdr_set_frequency (pg2sdr_device *dev, double frequency)
 Set the center frequency of received data.
 
int pg2sdr_get_frequency (pg2sdr_device *dev, double *requested, double *actual)
 Get current center frequency.
 
int pg2sdr_set_bandpass (pg2sdr_device *dev, double low, double high)
 Set bandpass filter limits.
 
int pg2sdr_get_bandpass (pg2sdr_device *dev, double *req_low, double *req_high, double *actual_low, double *actual_high)
 Get requested and actual bandpass filter settings.
 
int pg2sdr_apply_changes (pg2sdr_device *dev)
 Apply pending configuration changes.
 

Detailed Description

This group of functions control the capture configuration of an opened device: tuned frequency and bandwidth, sample rate and format, gain settings, etc.

Most changes to configuration settings require a subsequent call to pg2sdr_apply_changes() before taking effect. pg2sdr_apply_changes() is implicitly called by pg2sdr_stream_data(), so for simple cases where the configuration does not change at runtime, it's sufficient to just configure the device in advance of calling pg2sdr_stream_data().

In cases where configuration settings interact, it is possible that out-of-range combinations of configuration settings are discovered only when pg2sdr_apply_changes() is called. It is also possible that, when several settings need to be changed, the intermediate configurations after each individual setting change are out-of-range, even if the final combination of all changes is valid. If you have several settings to change, call pg2sdr_apply_changes() once after all changes have been made, to avoid trying to apply an intermediate configuration that may be out-of-range.

Some configuration settings cannot be changed while streaming is active. In these cases, PG2SDR_ERROR_BAD_STATE is returned, and changes are not applied.

Macro Definition Documentation

◆ PG2SDR_DECIMATION_AUTO

#define PG2SDR_DECIMATION_AUTO   (-1)

Decimation mode that auto-selects decimation to avoid bandpass filter issues.

This decimation mode adds decimation steps, if needed, to avoid the received signal falling into the high-pass filter region of the tuner bandpass filter. This avoids problems with the effective bandwidth being limited by the available tuner bandpass settings near 0Hz, an issue that mostly affects lower sample rates. This is the default decimation mode.

See also
pg2sdr_set_decimation_mode()

Enumeration Type Documentation

◆ pg2sdr_conversion_mode_t

Enum controlling how ADC data is converted.

See also
pg2sdr_get_conversion_mode()
pg2sdr_set_conversion_mode()
Enumerator
PG2SDR_MODE_LOWIF_REAL 

Provide real-valued samples at low intermediate frequency (unconverted ADC output)

PG2SDR_MODE_BASEBAND 

Provide complex-valued samples at baseband

◆ pg2sdr_sideband_mode_t

Enum controlling sideband tuning selection.

See also
pg2sdr_get_sideband()
pg2sdr_set_sideband()
Enumerator
PG2SDR_SIDEBAND_LOWER 

Place tuner LO above target frequency, and capture lower sideband

PG2SDR_SIDEBAND_UPPER 

Place tuner LO below target frequency, and capture upper sideband

Function Documentation

◆ pg2sdr_apply_changes()

int pg2sdr_apply_changes ( pg2sdr_device dev)

Apply pending configuration changes.

Attempts to apply any outstanding configuration changes to conversion mode, sampling rate, center frequency, bandpass filter, decimation mode, undersampling mode, sideband mode, ADC rate limit.

This function should be called after all the corresponding pg2sdr_set_xxx functions for a batch of changes have been completed. These settings can interact, so it is possible that the hardware can support the final configuration successfully but not every intermediate configuration. Batching the changes together with a single "apply" call allows you to jump to the final configuration in one step.

Not all configuration changes can be applied while streaming is active. Either stop streaming before calling pg2sdr_apply_changes(), or interpret a return value of PG2SDR_ERROR_BAD_STATE as "some changes could not be applied because streaming is active". If PG2SDR_ERROR_BAD_STATE is returned, the device remains in a consistent state, and any unapplied changes remain pending and can be applied later by a further call to pg2sdr_apply_changes()

It is safe to call pg2sdr_apply_changes() if no changes are pending, doing so is a no-op.

Calls to pg2sdr_stream_data() implicitly call pg2sdr_apply_changes() before starting streaming.

Parameters
[in]devthe device to reconfigure
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_STATEstreaming is active, and some pending changes cannot be applied while streaming
PG2SDR_ERROR_ADC_RATE_RANGErequested configuration requires an out-of-range ADC sampling rate
PG2SDR_ERROR_TUNER_PLL_RANGErequested configuration requires an out-of-range tuner LO frequency
PG2SDR_ERROR_TUNER_PLL_LOCKtuner LO PLL failed to lock at requested frequency
PG2SDR_ERROR_TUNER_I2Ctuner I2C communication failed
<0negative error code on failure
See also
pg2sdr_set_conversion_mode()
pg2sdr_set_sampling_rate()
pg2sdr_set_frequency()
pg2sdr_set_bandpass()
pg2sdr_set_decimation_mode()
pg2sdr_set_undersampling_mode()
pg2sdr_set_sideband()
pg2sdr_set_adc_limit()

◆ pg2sdr_get_adc_limit()

int pg2sdr_get_adc_limit ( pg2sdr_device dev,
double *  adc_limit 
)

Get current hardware ADC sampling rate limit.

Parameters
[in]devthe device to query
[out]adc_limita non-NULL pointer where the current sampling rate limit will be stored on success
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif adc_limit is NULL
<0negative error code on failure
See also
pg2sdr_set_adc_limit()

◆ pg2sdr_get_adc_rate()

int pg2sdr_get_adc_rate ( pg2sdr_device dev,
double *  actual_adc_rate 
)

Get current ADC sampling rate.

Gets the underlying ADC rate used for the current configuration.

If there are configuration changes pending that affect the ADC rate, and pg2sdr_apply_changes() has not yet been called, then the returned rate is 0.

Parameters
[in]devthe device to query
[out]actual_adc_ratea non-NULL pointer where the ADC rate will be stored
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif actual_adc_rate is NULL
<0negative error code on failure

◆ pg2sdr_get_bandpass()

int pg2sdr_get_bandpass ( pg2sdr_device dev,
double *  req_low,
double *  req_high,
double *  actual_low,
double *  actual_high 
)

Get requested and actual bandpass filter settings.

The requested filter settings are the settings in the last call to pg2sdr_set_bandpass()

The actual filter settings are how the hardware has actually been configured, and may differ (sometimes greatly) from the requested filter settings, as the available bandpass filter choices are limited by hardware.

If the requested filter has been changed by calling pg2sdr_set_bandpass(), but pg2sdr_apply_changes() has not yet been called, then the actual limits have not yet been determined, and will return 0.

Parameters
[in]devthe device to query
[out]req_lowif not NULL, location to store the requested low-cutoff frequency, in Hz
[out]req_highif not NULL, location to store the requested high-cutoff frequency, in Hz
[out]actual_lowif not NULL, location to store the actual low-cutoff frequency, in Hz
[out]actual_highif not NULL, location to store the actual high-cutoff frequency, in Hz
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif all of req_low, req_high, actual_low, actual_high are NULL
<0negative error code on failure
See also
pg2sdr_set_bandpass()

◆ pg2sdr_get_buffer_size()

int pg2sdr_get_buffer_size ( pg2sdr_device dev,
size_t *  buffer_size 
)

Get size of sample buffer passed to user callbacks.

Parameters
[in]devthe device to query
[out]buffer_sizea non-NULL pointer where the current buffer size will be stored on success
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif buffer_size is NULL
<0negative error code on failure
See also
pg2sdr_set_buffer_size()

◆ pg2sdr_get_conversion_mode()

int pg2sdr_get_conversion_mode ( pg2sdr_device dev,
pg2sdr_conversion_mode_t mode 
)

Get the current sample conversion mode.

This returns the currently requested mode, i.e. the mode passed to the last successful call to pg2sdr_set_conversion_mode(), even if pg2sdr_apply_changes() has not yet been called.

Parameters
[in]devthe device to query
[out]modea non-NULL pointer where the current format will be stored on success
Return values
PG2SDR_SUCCESSsuccess
<0negative error code on failure
See also
pg2sdr_set_conversion_mode()
pg2sdr_apply_changes()

◆ pg2sdr_get_decimation_mode()

int pg2sdr_get_decimation_mode ( pg2sdr_device dev,
int *  decimation_mode,
unsigned *  actual_decimation 
)

Get current decimation mode and/or actual number of decimation steps.

The currently requested decimation mode is the mode given to the last call to pg2sdr_set_decimation_mode().

The actual decimation is the number of decimation stages configured after a call to pg2sdr_apply_changes(). That is, for a returned value of N, there are N decimate-by-2 stages configured, with a total decimation factor of 2^N.

If configuration settings have been changed but pg2sdr_apply_changes() has not yet been called, then the actual number of decimation steps has not yet been determined and will return 0.

Parameters
[in]devthe device to query
[out]decimation_modeif non-NULL, pointer where the currently requested decimation mode will be stored on success
[out]actual_decimationif non-NULL, pointer where the current number of decimation steps will be stored on success
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif both decimation_mode and actual_decimation are NULL
<0negative error code on failure
See also
pg2sdr_set_decimation_mode()

◆ pg2sdr_get_frequency()

int pg2sdr_get_frequency ( pg2sdr_device dev,
double *  requested,
double *  actual 
)

Get current center frequency.

Gets the currently requested center frequency, and/or the actual effective center frequency in use.

The requested center frequency is the frequency set by the last call to pg2sdr_set_frequency().

The actual effective center frequency is the effective center frequency in use by the hardware, and may vary slightly from the requested frequency due to hardware limitations (not all frequencies can be exactly tuned)

If the requested frequency has been changed by calling pg2sdr_set_frequency(), but pg2sdr_apply_changes() has not yet been called, then the actual frequency has not yet been determined, and will return 0.

Parameters
[in]devthe device to query
[out]requestedif not NULL, location to store the requested center frequency
[out]actualif not NULL, location to store the actual center frequency
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif both requested and actual are NULL
<0negative error code on failure
See also
pg2sdr_set_frequency()

◆ pg2sdr_get_sample_rate()

int pg2sdr_get_sample_rate ( pg2sdr_device dev,
double *  requested,
double *  actual 
)

Get current user sampling rate.

Gets the currently requested user sampling rate, and/or the actual effective sampling rate in use.

The requested user sampling rate is the rate set by the last call to pg2sdr_set_sample_rate().

The actual effective sampling rate is the effective sampling rate in use by the hardware, and may vary slightly from the requested rate due to hardware limitations (not all sampling rates can be exactly supported).

If the requested sampling rate has been changed by calling pg2sdr_set_sample_rate(), but pg2sdr_apply_changes() has not yet been called, then the actual sampling rate has not yet been determined, and will return 0.

Parameters
[in]devthe device to query
[out]requestedif not NULL, location to store the requested user sampling rate
[out]actualif not NULL, location to store the actual user sampling rate
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif both requested and actual are NULL
<0negative error code on failure
See also
pg2sdr_set_sample_rate()

◆ pg2sdr_get_sideband()

int pg2sdr_get_sideband ( pg2sdr_device dev,
pg2sdr_sideband_mode_t mode 
)

Get current sideband mode.

Parameters
[in]devthe device to query
[out]modea non-NULL pointer where the current sideband mode will be stored on success
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif mode is NULL
<0negative error code on failure
See also
pg2sdr_set_sideband()

◆ pg2sdr_get_undersampling_mode()

int pg2sdr_get_undersampling_mode ( pg2sdr_device dev,
unsigned *  undersampling_mode 
)

Get current undersampling mode.

Parameters
[in]devthe device to query
[out]undersampling_modea non-NULL pointer where the current undersampling mode will be stored on success
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif undersampling_mode is NULL
<0negative error code on failure
See also
pg2sdr_set_undersampling_mode()

◆ pg2sdr_set_adc_limit()

int pg2sdr_set_adc_limit ( pg2sdr_device dev,
double  adc_limit 
)

Set hardware ADC sampling rate limit.

libpg2sdr will only select ADC sampling rates that are less than the configured sampling rate limit.

Limiting the ADC sampling rate implicitly limits the available user sampling rates. In PG2SDR_MODE_LOWIF_REAL conversion mode, the user sampling rate is limited to the ADC rate. In PG2SDR_MODE_BASEBAND conversion mode, the user sampling rate is limited to one-half of the ADC rate. If additional decimation is requested (see pg2sdr_set_decimation_mode()) then this increases the required ADC sampling rate for a given user sampling rate.

The ADC limit defaults to 28MHz, which is close to the limit for what most USB 2.0 host controllers can support on a single USB 2.0 bus. Higher limits can be set, up to the ADC hardware limit of 80MHz, but anything above 28MHz is likely to start dropping data due to USB bus bandwidth limits.

Setting a lower limit can be useful to limit the USB bandwidth used by a single device, if it is sharing a USB bus with other devices. Setting a lower limit also reduces power consumption, and reduces the amount of CPU work needed to process the received samples on the host.

May be called at any time; does not affect the configuration of any currently active stream. Call pg2sdr_apply_changes() to complete the configuration change.

Parameters
[in]devthe device to configure
[in]adc_limitthe maximum ADC sampling rate to allow, in Hz
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTadc_limit is out of range
<0negative error code on failure
See also
pg2sdr_get_adc_limit()

◆ pg2sdr_set_bandpass()

int pg2sdr_set_bandpass ( pg2sdr_device dev,
double  low,
double  high 
)

Set bandpass filter limits.

This controls the cutoffs of the analog tuner bandpass filter that shapes the incoming signal before the ADC. The low and high limits are relative to the RF frequency set by pg2sdr_set_frequency(). Signals between the limits are retained, other signals are attenuated.

In PG2SDR_MODE_BASEBAND conversion mode, usually low will be negative and high will be positive, as you want to receive a signal that is on both sides of the center frequency. For a simple bandwidth setting centered around the center frequency, use low = -bandwidth/2 and high = +bandwidth/2.

In PG2SDR_MODE_LOWIF_REAL conversion mode, either both values are positive (with PG2SDR_SIDEBAND_UPPER) or both values are negative (with PG2SDR_SIDEBAND_LOWER) as all of the RF signal captured is on one side of the LO.

The actual bandpass limits used may be significantly different to what is requested, for two reasons:

  • the hardware is quite limited in terms of the available filtering options;
  • the sampling rate chosen influences the maximum cutoff on one side of the bandpass region, as we must pick a cutoff below the ADC's Nyquist frequency to avoid aliasing in the ADC.

May be called at any time; does not affect the configuration of any currently active stream. Call pg2sdr_apply_changes() to complete the configuration change.

Parameters
[in]devthe device to configure
[in]lowthe new low-cutoff frequency, in Hz
[in]highthe new low-cutoff frequency, in Hz
Return values
PG2SDR_SUCCESSsuccess
<0negative error code on failure
See also
pg2sdr_get_bandpassy()

◆ pg2sdr_set_buffer_size()

int pg2sdr_set_buffer_size ( pg2sdr_device dev,
size_t  buffer_size 
)

Set size of sample buffer passed to user callbacks.

Set the user buffer size to buffer_size user samples. The user buffer size controls the maximum number of samples contained in each pg2sdr_sample_buffer passed to the user callback while pg2sdr_stream_data is running.

This setting also influences the size of internally allocated USB buffers. Setting large values may exceed system limits on USB buffer size and return an error.

The buffer size may not be changed while streaming is active.

Parameters
[in]devthe device to configure
[in]buffer_sizethe user buffer size, in samples
Return values
PG2SDR_SUCCESSSuccess
PG2SDR_ERROR_BAD_ARGUMENTbuffer_size is out of range
PG2SDR_ERROR_BAD_STATEcannot change buffer size while streaming is active
<0negative error code on failure
See also
pg2sdr_get_buffer_size()

◆ pg2sdr_set_conversion_mode()

int pg2sdr_set_conversion_mode ( pg2sdr_device dev,
pg2sdr_conversion_mode_t  mode 
)

Set the conversion mode for sample data received by user callbacks.

Sets the current conversion mode, controlling how raw ADC data is converted into samples passed to the user callback (user samples).

If mode is PG2SDR_MODE_BASEBAND, then ADC data is converted to a complex baseband representation. A user sample is two int16_t values (I/Q, or real/imaginary). The complex baseband signal, centered around 0Hz, corresponds to the RF signal centered around the configured center frequency. This is the default mode, and the mode that most SDR clients will want to use.

If mode is PG2SDR_MODE_LOWIF_REAL, then ADC data from the hardware is scaled to 16 bits, but is otherwise unmodified. Each user sample is a single int16_t value, with the full signed 16-bit range used. These samples are a digitization of the low-IF signal produced by the tuner, corresponding to one sideband of the RF input, either above or below the configured frequency depending on the configured sideband mode. The configured RF frequency maps to an IF frequency of 0Hz (though there will not be a useful signal at 0Hz, due to both the limits of the tuner bandpass filter, and LO leakage). This mode is mostly for lower-level debugging of the PG2SDR hardware or software itself, where direct inspection of the ADC data is useful.

The conversion mode may not be changed while streaming is active.

Call pg2sdr_apply_changes() to complete a change in conversion mode.

Parameters
[in]devthe device to configure
[in]modethe new conversion mode to set
Return values
PG2SDR_SUCCESSSuccess
PG2SDR_ERROR_BAD_ARGUMENTmode is not a recognized conversion mode
PG2SDR_ERROR_BAD_STATEcannot change conversion mode while streaming is active
<0negative error code on failure
See also
pg2sdr_get_conversion_mode()
pg2sdr_apply_changes()

◆ pg2sdr_set_decimation_mode()

int pg2sdr_set_decimation_mode ( pg2sdr_device dev,
int  decimation_mode 
)

Set current decimation mode.

Configures the decimation mode, which controls additional, transparent, ADC sampling rate scaling and decimation performed in the receive path. In all cases, the user callback still receives data at the requested user sampling rate.

Extra decimation can provide lower noise or better bandpass filtering characteristics, at the cost of needing to run the ADC at a higher sample rate and transfer more data over the USB bus.

If decimation_mode is zero or positive, it is interpreted as the maximum number of decimate-by-2 stages to use, i.e. the total decimation factor is 2^decimation_node. The ADC sampling rate is scaled correspondingly. The actual number of stages used may be limited by the maximum available ADC sampling rate.

Otherwise, decimation_mode may be PG2SDR_DECIMATION_AUTO, which adds decimation stages as needed to avoid losing signal to the low end of the tuner bandpass filter. This is the default setting.

Decimation settings are ignored when the conversion mode is PG2SDR_MODE_LOWIF_REAL.

May be called at any time; does not affect the decimation of any currently active stream. Call pg2sdr_apply_changes() while not streaming data to complete the configuration change.

Parameters
[in]devthe device to configure
[in]decimation_modethe new decimation mode to set
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTdecimation_mode is not a valid decimation mode
<0negative error code on failure
See also
pg2sdr_get_decimation_mode()

◆ pg2sdr_set_frequency()

int pg2sdr_set_frequency ( pg2sdr_device dev,
double  frequency 
)

Set the center frequency of received data.

The center frequency is the RF frequency that will be downconverted to 0Hz in samples provided to user callbacks, in both PG2SDR_MODE_BASEBAND and PG2SDR_MODE_LOWIF_REAL conversion modes.

May be called at any time; does not affect the configuration of any currently active stream. Call pg2sdr_apply_changes() to complete the configuration change.

Parameters
[in]devthe device to configure
[in]frequencythe new center frequency, in Hz
Return values
PG2SDR_SUCCESSsuccess
<0negative error code on failure
See also
pg2sdr_get_frequency()

◆ pg2sdr_set_sample_rate()

int pg2sdr_set_sample_rate ( pg2sdr_device dev,
double  rate 
)

Set the current requested user sampling rate.

Change the requested user sampling rate. The user sampling rate is the effective sampling rate seen by the user-provided callback: it is the rate at which user samples are provided, rate user samples per second. The actual ADC sampling rate may be higher than the user sampling rate, with libpg2sdr providing decimation down to the user sampling rate.

As a broad sanity check, libpg2sdr will immediately reject sample rates that are <1kHz or >100MHz. Sample rate support is still limited by hardware support, and rates that are accepted by this function may later be rejected by pg2sdr_apply_changes().

May be called at any time; does not affect the sample rate of any currently active stream. Call pg2sdr_apply_changes() while not streaming data to complete the configuration change.

Parameters
[in]devthe device to configure
[in]ratethe new sampling rate, in Hz
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTrate is out of range
<0negative error code on failure
See also
pg2sdr_get_sample_rate()

◆ pg2sdr_set_sideband()

int pg2sdr_set_sideband ( pg2sdr_device dev,
pg2sdr_sideband_mode_t  mode 
)

Set the current sideband tuning mode.

The sideband tuning mode controls which of the two sidebands around the tuner LO is retained by the tuner.

When the PG2SDR_MODE_BASEBAND conversion mode is used, the choice of sideband is largely transparent to the libpg2sdr user. Both choices of sideband produce the same complex baseband signal, with the requested frequency at 0Hz and increasing RF frequencies appearing as increasing baseband frequencies. Using PG2SDR_SIDEBAND_UPPER near the top of the available tuner range, or using PG2SDR_SIDEBAND_LOWER near the bottom of the available range, will slightly extend the range of tunable frequencies.

When the PG2SDR_MODE_LOWIF_REAL conversion mode is used, the tuned frequency directly sets the tuner LO, and the choice of sideband affects the range of frequencies captured. When using PG2SDR_SIDEBAND_LOWER, then frequencies above the tuned frequency are captured and increasing RF frequencies appear as increasing frequencies in captured data. When using PG2SDR_SIDEBAND_UPPER, then frequencies below the tuned frequencies are captured, and decreasing RF frequencies appear as increasing frequencies in captured data.

May be called at any time; does not affect the configuration of any currently active stream. Call pg2sdr_apply_changes() to complete the configuration change.

Parameters
[in]devthe device to configure
[in]modethe new sideband mode to configure
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTmode is not a recognized sideband mode
<0negative error code on failure
See also
pg2sdr_get_sideband()

◆ pg2sdr_set_undersampling_mode()

int pg2sdr_set_undersampling_mode ( pg2sdr_device dev,
unsigned  undersampling_mode 
)

Set the current undersampling mode.

Experimental, use with caution.

libpg2sdr can be configured to run the ADC at a sampling rate that is less than the Nyquist rate of the IF signal, and deliberately capture parts of the signal above the Nyquist rate as aliases.

The default mode (N=1) corresponds to the normal case where the ADC sampling rate is Fs, and we arrange for the IF signal to be contained between 0 .. Fs/2

For values N>1, we arrange for the IF signal to be placed between (N-1)*Fs/2 and N*Fs/2. For example, N=2 places the IF signal between Fs/2 and Fs. This causes undersampling (a.k.a. bandpass sampling) to happen. The IF signal is above the Nyquist frequency for the ADC's sampling rate. One of the spectral replicas of the IF signal will lie between 0..Fs/2, and it is this replica/alias that is captured by the ADC.

Undersampling with N>1 can help in cases where there's no suitable tuner bandpass filter available for f < Fs/2. There are tradeoffs, notably increased noise.

May be called at any time; does not affect the configuration of any currently active stream. Call pg2sdr_apply_changes() to complete the configuration change.

Parameters
[in]devthe device to configure
[in]undersampling_modethe new undersampling mode (value of N) to set
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTundersampling_mode is out of range
<0negative error code on failure
See also
pg2sdr_get_undersampling_mode()