diff options
| author | skal <pascal.massimino@gmail.com> | 2026-03-23 23:12:40 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-03-23 23:12:40 +0100 |
| commit | 8a3da8213cd8ef58b04a2147f51d849b5a22e795 (patch) | |
| tree | 30a4ab0f6bffea25c3b00fbe21dfba70cebf2061 /TODO.md | |
| parent | 7f38486df37997ccbf02fe5f29eeefe1664040ad (diff) | |
test(fft): re-enable DCT tests, document twiddle accumulation bug
- Remove unused variable `bits` in bit_reverse_permute
- Re-enable previously skipped DCT correctness tests (impulse at N/2,
sinusoidal, complex inputs) with tolerance bumped to 2e-2
- Close TODO for FFT-DCT discrepancy investigation
- Add detailed TODO for fixing twiddle factor accumulation bug in
fft_radix2 (root cause of sign errors at large N), with step-by-step
test plan (components A–E)
handoff(Gemini): FFT twiddle bug plan in TODO.md §"Fix FFT twiddle factor
accumulation bug". Tests currently pass at 2e-2; target <1e-5 after fix.
Diffstat (limited to 'TODO.md')
| -rw-r--r-- | TODO.md | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -16,9 +16,37 @@ Procedural spectrogram tool: 50-100× compression (5 KB .spec → ~100 bytes C++ **Status:** 38/38 tests passing -**Outstanding TODOs:** +### Fix FFT twiddle factor accumulation bug (`src/audio/fft.cc`) -1. **test_fft.cc:87** - Investigate FFT-DCT algorithm discrepancy +**Root cause:** `fft_radix2` updates twiddle factors iteratively over 256 iterations +in the final stage (N=512). Accumulated floating-point drift causes sign flips on +specific DCT coefficients. Round-trip (DCT+IDCT) still works because both sides +make the same errors symmetrically, masking the bug. + +**Fix:** Replace iterative twiddle update with direct `cosf/sinf` per k: +```cpp +// fft_radix2, inner loop — replace: +wr = wr_old * wr_delta - wi * wi_delta; +wi = wr_old * wi_delta + wi * wr_delta; +// with: +wr = cosf(angle * (float)k); +wi = sinf(angle * (float)k); +``` + +**Test plan (`src/tests/audio/test_fft.cc`):** add one test per component, in order: + +- [ ] **A: `bit_reverse_permute`** — for N=8 verify exact index mapping: + 0→0, 1→4, 2→1, 3→6, 4→2, 5→7, 6→3, 7→5 (must be exact) +- [ ] **B: `fft_radix2` small N** — DFT of `[1,0,0,0]` (N=4) via FFT vs direct sum; + all 4 unit impulses. Expect machine epsilon. +- [ ] **C: twiddle accumulation** — compare iterative vs `cosf/sinf` twiddle factors + at k=128..255, stage size=512. **This test must fail before the fix.** +- [ ] **D: `dct_fft` small N** — all 8 unit impulses for N=8 vs reference. + Expect machine epsilon (exact for small N). +- [ ] **E: `dct_fft` large N** — all original test cases (N=512): impulse[0], + impulse[N/2], sinusoidal, complex. Expect < 1e-5 after fix. + +Revert threshold in `arrays_match` back to `5e-3` (or tighter) once fixed. ## Priority 4: Audio System Enhancements [LOW PRIORITY] |
