File imdmeas_core.h¶
FileList > doppler > imdmeas > imdmeas_core.h
Go to the source code of this file
IMDMeasure — two-tone intermodulation (IMD2/IMD3) and intercept. More...
#include "doppler/clib_common.h"#include "doppler/jm_perf.h"#include "doppler/measure/measure_core.h"#include "doppler/psd/psd_core.h"#include "doppler/dp_complex.h"
Classes¶
| Type | Name |
|---|---|
| struct | dp_imdmeas_state_t IMDMeasure state: owned window, FFT plan and one-sided power scratch. |
Public Functions¶
| Type | Name |
|---|---|
| imd_meas_t | dp_imdmeas_analyze (dp_imdmeas_state_t * state, const float * x, size_t n_in) Two-tone IMD/TOI of a real capture (finds the two strongest tones). |
| dp_imdmeas_state_t * | dp_imdmeas_create (size_t n, double fs, double full_scale, size_t bits, double dynamic_range_db) Create an IMDMeasure analyser (auto Kaiser window). |
| void | dp_imdmeas_destroy (dp_imdmeas_state_t * state) Destroy an IMDMeasure analyser. |
| void | dp_imdmeas_reset (dp_imdmeas_state_t * state) Reset the analyser (a no-op: each analyze() call is independent). |
| size_t | dp_imdmeas_spectrum_dbfs (dp_imdmeas_state_t * state, const float * x, size_t x_len, float * out, size_t max_out) DC-centred dBFS magnitude spectrum of a capture (length nfft). |
| size_t | dp_imdmeas_spectrum_dbfs_max_out (dp_imdmeas_state_t * state) Capacity (== nfft) of the spectrum_dbfs output buffer. |
Detailed Description¶
Drive two equal-amplitude tones f1<f2; the analyser finds them as the two strongest lobes, integrates each fundamental and the intermodulation products (2f1-f2, 2f2-f1 for IMD3; f2-f1 for IMD2) over their window main lobes (folded into the analysed band), and reports the third/second-order intercepts.
Lifecycle: create -> [analyze]* -> destroy
Public Functions Documentation¶
function dp_imdmeas_analyze¶
Two-tone IMD/TOI of a real capture (finds the two strongest tones).
Averages the Kaiser-windowed power spectrum over floor(n_in / n) whole frames (a trailing partial frame is dropped), takes the two strongest bins more than spur_guard_bins from DC and from each other as f1 < f2, and integrates each tone and the IM products 2f1-f2, 2f2-f1 and f2-f1 (folded into [0, fs/2]) over +/- lobe_bins. imd3_dbc is the worse of the two third-order products; both IMD ratios are relative to the mean tone power. TOI = P_tone + |IMD3|/2 and SOI = P_tone + |IMD2| (dBFS).
Parameters:
stateThe analyser.xReal capture (float32), lengthn_in.n_inNumber of samples inx; at least n for a result.
Returns:
the IMD metric record (by value; zeroed if no two tones are found or n_in < n).
>>> from doppler.measure import IMDMeasure
>>> import numpy as np
>>> t = np.arange(4096)
>>> # two equal tones at 200 & 250 cycles, plus 3rd-order
>>> # products 40 dB down
>>> x = (np.cos(2*np.pi*200*t/4096) + np.cos(2*np.pi*250*t/4096)
... + 0.01*np.cos(2*np.pi*150*t/4096)
... + 0.01*np.cos(2*np.pi*300*t/4096)).astype(np.float32)
>>> r = IMDMeasure(n=4096, fs=1.0).analyze(x)
>>> round(r.f1, 4), round(r.f2, 4), round(r.imd3_dbc, 0)
(0.0488, 0.061, -40.0)
function dp_imdmeas_create¶
Create an IMDMeasure analyser (auto Kaiser window).
dp_imdmeas_state_t * dp_imdmeas_create (
size_t n,
double fs,
double full_scale,
size_t bits,
double dynamic_range_db
)
The window is always Kaiser; its shape is auto-selected so the sidelobes sit below the requested dynamic range (see measure_resolve_dr()), keeping the resolution bandwidth as fine as n allows.
Parameters:
nCapture/frame length (>= 2).fsSample rate (Hz, > 0).full_scaleAmplitude that equals 0 dBFS (> 0). Ignored if bits > 0.bitsADC depth: bits>0 sets the 0-dBFS reference to 2^(bits-1) and, unless overridden, the dynamic-range target.dynamic_range_dbExplicit sidelobe/dynamic-range target (dB); used when > 0, else derived frombits.
Returns:
Heap state, or NULL on bad args / allocation failure.
function dp_imdmeas_destroy¶
Destroy an IMDMeasure analyser.
Parameters:
stateMay be NULL.
function dp_imdmeas_reset¶
Reset the analyser (a no-op: each analyze() call is independent).
Every analyze() / spectrum_dbfs() call re-windows and re-transforms its own capture from scratch, so nothing is carried between calls to clear. The method exists only so IMDMeasure honours the same reset() contract as every other doppler object, letting a generic pipeline reset each stage uniformly.
Parameters:
stateThe analyser (left unchanged).
>>> from doppler.measure import IMDMeasure
>>> m = IMDMeasure(n=4096, fs=1.0)
>>> m.reset() # stateless: provided only for API uniformity
>>> m.reset() is None # returns nothing; safe to call anytime
True
function dp_imdmeas_spectrum_dbfs¶
DC-centred dBFS magnitude spectrum of a capture (length nfft).
size_t dp_imdmeas_spectrum_dbfs (
dp_imdmeas_state_t * state,
const float * x,
size_t x_len,
float * out,
size_t max_out
)
The same windowed, zero-padded PSD the IMD metrics are read off, laid out DC-centred (fftshifted) and normalised to dBFS for an analyzer-display backdrop. Use it to see the two fundamentals and the intermodulation products that analyze() integrates.
Parameters:
stateThe analyser.xReal time-domain capture (lengthx_len); averaged over its whole n-sample frames like analyze().x_lenNumber of input samples.outDestination buffer (length >=max_out).max_outCapacity ofout(== nfft).
Returns:
Number of bins written to out: min(nfft, max_out), or 0 when x_len < n (no whole frame to transform).
>>> from doppler.measure import IMDMeasure
>>> import numpy as np
>>> t = np.arange(4096)
>>> x = (0.5*np.cos(2*np.pi*200*t/4096)
... + 0.5*np.cos(2*np.pi*250*t/4096)).astype(np.float32)
>>> s = IMDMeasure(n=4096, fs=1.0).spectrum_dbfs(x) # DC-centred dBFS
>>> s.shape
(8192,)
>>> round(float(s.max()), 1) # each tone splits into two images
-12.0
function dp_imdmeas_spectrum_dbfs_max_out¶
Capacity (== nfft) of the spectrum_dbfs output buffer.
Parameters:
stateThe analyser.
Returns:
nfft, the zero-padded transform length (bins).
The documentation for this class was generated from the following file native/inc/doppler/imdmeas/imdmeas_core.h