Skip to main content

Module metrics

Module metrics 

Source
Expand description

Audio signal comparison metrics.

This module provides functions for comparing audio signals and measuring various quality metrics commonly used in audio circuit validation.

§Available Metrics

MetricFunctionDescription
Normalized RMS Errornormalized_rms_error_dbOverall signal difference (lower is better)
Peak Errorpeak_error_dbMaximum sample-level difference
THDthd_dbTotal Harmonic Distortion
THD Errorthd_error_dbTHD difference between two signals
Even/Odd Ratioeven_odd_ratio_dbEven vs odd harmonic balance
Spectral Errorspectral_error_dbFrequency domain difference
DC Driftdc_drift_mvLow-frequency offset measurement

§Example

use pedalkernel_validate::metrics;

let wdf_output: Vec<f64> = vec![0.1, 0.2, 0.3, 0.2, 0.1];
let reference: Vec<f64> = vec![0.1, 0.2, 0.3, 0.2, 0.1];
let sample_rate = 48000.0;

// Compare individual metrics
let rms_err = metrics::normalized_rms_error_db(&wdf_output, &reference);
let peak_err = metrics::peak_error_db(&wdf_output, &reference);

// Or use the combined comparison function
let result = metrics::compare(&wdf_output, &reference, sample_rate, Some(1000.0));
println!("RMS error: {:.1} dB", result.normalized_rms_error_db);
println!("Peak error: {:.1} dB", result.peak_error_db);

§Interpreting Results

  • RMS Error: -60 dB means error is 0.1% of signal. -80 dB is excellent.
  • Peak Error: Maximum instantaneous difference. Usually higher than RMS.
  • THD: Pure sine should be < -80 dB. Audible distortion starts around -40 dB.
  • Even/Odd Ratio: Push-pull amps should have < -40 dB (even harmonics suppressed)

Modules§

ac_accuracy
op_point

Structs§

ComparisonResult
Result of comparing WDF output to reference.

Functions§

ac_amplitude_drift_db
AC-amplitude drift across a signal: dB difference between the single-bin amplitude of the SECOND half vs the FIRST half of signal.
ac_gain_db
Steady-state, level-independent AC gain ratio in dB at freq_hz: 20*log10(amp_wdf / amp_ref). Positive = WDF louder than the reference.
compare
Compare WDF output to reference with all metrics.
dc_drift_mv
Measure DC drift over time.
dc_offset
Mean (DC offset) of a signal. Use as the AC-coupling / settle guard: an AC-coupled output that has reached steady state has |mean| ≈ 0.
even_odd_ratio_db
Compute even/odd harmonic ratio in dB.
even_odd_ratio_error_db
Compute even/odd harmonic ratio error between WDF and reference in dB.
harmonic_mag_error_db
Compute the maximum harmonic magnitude error between WDF and reference in dB.
normalized_rms_error_db
Compute normalized RMS error in dB.
peak_error_db
Compute peak absolute error in dB relative to reference peak.
single_bin_amplitude
Single-bin DFT amplitude (peak, in signal units) of the component at exactly freq_hz.
spectral_error_db
Compute maximum spectral magnitude error in dB.
thd_db
Compute THD (Total Harmonic Distortion) in dB.
thd_error_db
Compute THD error between WDF and reference in dB.
thd_plus_n_db
Compute THD+N (Total Harmonic Distortion plus Noise) in dB.
thd_plus_n_error_db
Compute THD+N error between WDF and reference in dB.