Skip to content

File measure_core.h

FileList > doppler > measure > measure_core.h

Go to the source code of this file

Measure module — shared result structs and module-level helpers. More...

  • #include "doppler/clib_common.h"

Classes

Type Name
struct imd_meas_t
Two-tone intermodulation result (IMD2/IMD3/TOI).
struct npr_meas_t
Noise Power Ratio (notched-noise loading) result.
struct time_stats_t
Time-domain capture statistics (AC-coupled crest/PAPR).
struct tone_meas_t
Single-tone dynamic-measurement bag.

Public Functions

Type Name
double dp_coherent_freq (double fs, double f_target, size_t N)
Nearest leakage-free coherent test frequency.
size_t dp_measure_min_samples (double fs, double target_rbw, size_t bits, double dynamic_range_db, int complex_input)
Samples needed to reach a target resolution bandwidth.
double dp_measure_proc_gain (size_t nfft)
FFT processing gain in dB: 10*log10(nfft / 2).
size_t dp_measure_rec_nfft (size_t n, size_t pad)
Recommended zero-padded transform length: next_pow_two(n * max(pad, 1)).

Public Static Functions

Type Name
double measure_dr_from_bits (size_t bits)
Default dynamic-range target (dB) implied by an ADC bit depth.
double measure_resolve_dr (double dynamic_range_db, size_t bits)
Resolve the dynamic-range target from the override/bits/default chain.

Macros

Type Name
define MEASURE_DR_DEFAULT_DB 120.0
Dynamic-range target (dB) when neither bits nor an explicit override is given (general DUT): deep enough for ~19-bit measurements. The fallback of measure_resolve_dr().
define MEASURE_DR_MARGIN_DB 12.0
Sidelobe headroom (dB) below the ideal converter SNR.
define MEASURE_PAD 2u
Zero-pad factor every measurement object hands its PSD core: nfft = next_pow_two(n * MEASURE_PAD), so a capture of n samples is transformed at no less than twice its own length.
define MEASURE_SPUR_SIDELOBES 1.0
Extra main-lobe widths excluded past the first null when searching for spurs (or, in IMDMeasure, for the second tone), so a component's near-in sidelobes are never mistaken for a spur.

Detailed Description

The doppler.measure objects (ToneMeasure, …) each own a window + FFT and analyse a time-domain capture, returning one of these plain-C result bags by value. Every spectral metric integrates a component's power over its window MAIN LOBE (IEEE Std 1241) rather than reading a single peak bin, so the reading is independent of where the tone falls between FFT bins.

Public Functions Documentation

function dp_coherent_freq

Nearest leakage-free coherent test frequency.

double dp_coherent_freq (
    double fs,
    double f_target,
    size_t N
) 

Snaps f_target to J * fs / N where J is the nearest integer cycle count that is coprime with N — an integer number of cycles in the capture (no leakage) with J coprime to N (so quantisation-noise correlation is minimised).

J starts at round(f_target * N / fs), is clamped to [1, N-1], then moved by the smallest distance that makes it coprime with N; on a tie the higher J wins.

Parameters:

  • fs Sample rate (Hz, > 0).
  • f_target Desired test frequency (Hz).
  • N Capture length (samples, >= 2).

Returns:

The coherent frequency J * fs / N (Hz), or 0 if N < 2 or fs <= 0.


function dp_measure_min_samples

Samples needed to reach a target resolution bandwidth.

size_t dp_measure_min_samples (
    double fs,
    double target_rbw,
    size_t bits,
    double dynamic_range_db,
    int complex_input
) 

Plans a capture for the same auto-Kaiser window the measurement objects use: the dynamic-range target (from dynamic_range_db, else bits) selects the Kaiser beta, whose ENBW (read from a PSD kernel at a reference length, so it is the analysers' own periodic window, #2053) sets the bins-per-RBW. RBW = ENBW * fs / n, so n = ceil(ENBW * fs / target_rbw).

Parameters:

  • fs Sample rate (Hz, > 0).
  • target_rbw Desired resolution bandwidth (Hz). When <= 0 it defaults to span/1000, where span = fs/2 for real captures and fs for complex (complex_input).
  • bits ADC depth: sets the dynamic-range target when no explicit override is given.
  • dynamic_range_db Explicit dynamic-range target (dB); used when > 0.
  • complex_input Non-zero if the capture is complex (span = fs).

Returns:

Required capture length, or 0 on bad args.


function dp_measure_proc_gain

FFT processing gain in dB: 10*log10(nfft / 2).

double dp_measure_proc_gain (
    size_t nfft
) 

How far a single bin's noise sits below the total noise power for an nfft-point transform of a real capture. A transform shorter than two bins has no gain to report (nfft = 1 would read -3 dB and nfft = 0 -inf), so it is refused with NaN, which no caller can mistake for a gain.

Parameters:

  • nfft Transform length (bins), at least 2.

Returns:

Processing gain (dB), or NaN when nfft < 2.


function dp_measure_rec_nfft

Recommended zero-padded transform length: next_pow_two(n * max(pad, 1)).

size_t dp_measure_rec_nfft (
    size_t n,
    size_t pad
) 

The same rule the measurement objects apply (with pad = MEASURE_PAD), exposed so a caller can plan an FFT size before building an analyser.

Parameters:

  • n Capture length (samples).
  • pad Zero-pad factor; 0 is treated as 1.

Returns:

The smallest power of two >= n * pad (1 when n is 0).


Public Static Functions Documentation

function measure_dr_from_bits

Default dynamic-range target (dB) implied by an ADC bit depth.

static inline double measure_dr_from_bits (
    size_t bits
) 

Ideal quantisation SNR is 6.02*bits + 1.76 dB; add MEASURE_DR_MARGIN_DB of headroom so the window's first sidelobe sits below the converter's own floor.

Parameters:

  • bits ADC depth in bits (> 0).

Returns:

Dynamic-range / sidelobe-attenuation target in dB.


function measure_resolve_dr

Resolve the dynamic-range target from the override/bits/default chain.

static inline double measure_resolve_dr (
    double dynamic_range_db,
    size_t bits
) 

Parameters:

  • dynamic_range_db Explicit target (dB); used when > 0.
  • bits ADC depth; used (via measure_dr_from_bits) when the override is unset and bits > 0.

Returns:

Dynamic-range / sidelobe-attenuation target in dB.


Macro Definition Documentation

define MEASURE_DR_DEFAULT_DB

Dynamic-range target (dB) when neither bits nor an explicit override is given (general DUT): deep enough for ~19-bit measurements. The fallback of measure_resolve_dr().

#define MEASURE_DR_DEFAULT_DB `120.0`


define MEASURE_DR_MARGIN_DB

Sidelobe headroom (dB) below the ideal converter SNR.

#define MEASURE_DR_MARGIN_DB `12.0`

A B-bit ADC's spur/noise floor sits at -(6.02*B+1.76) dBc, so measure_dr_from_bits() targets sidelobes this much deeper to be sure window leakage stays under the floor being measured.


define MEASURE_PAD

Zero-pad factor every measurement object hands its PSD core: nfft = next_pow_two(n * MEASURE_PAD), so a capture of n samples is transformed at no less than twice its own length.

#define MEASURE_PAD `2u`


define MEASURE_SPUR_SIDELOBES

Extra main-lobe widths excluded past the first null when searching for spurs (or, in IMDMeasure, for the second tone), so a component's near-in sidelobes are never mistaken for a spur.

#define MEASURE_SPUR_SIDELOBES `1.0`



The documentation for this class was generated from the following file native/inc/doppler/measure/measure_core.h