Compute Total Harmonic Distortion
Measure the total harmonic distortion of an amplifier output by summing the power of the harmonics relative to the fundamental.
Constraints
- Function: thd_pct = compute_thd(x, fs, f0).
- Include harmonics up to the Nyquist frequency.
- Use a window and search a small band around each harmonic.
- Return the result as a percentage.
- A pure sine must return close to zero.
- Harmonics above Nyquist must be skipped, not aliased in.
1function thd_pct = compute_thd(x, fs, f0)2% TODO3end