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
| Metric | Function | Description |
|---|---|---|
| Normalized RMS Error | normalized_rms_error_db | Overall signal difference (lower is better) |
| Peak Error | peak_error_db | Maximum sample-level difference |
| THD | thd_db | Total Harmonic Distortion |
| THD Error | thd_error_db | THD difference between two signals |
| Even/Odd Ratio | even_odd_ratio_db | Even vs odd harmonic balance |
| Spectral Error | spectral_error_db | Frequency domain difference |
| DC Drift | dc_drift_mv | Low-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§
Structs§
- Comparison
Result - 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.