graph LR A["๐งฎ r\n(autocorrelation)"] --> B["๐ spectral_fact"] B --> C["๐ h\n(impulse response)"] C --> D["๐งฎ CSD quantize"] D --> E["๐๏ธ Verilog module"] style A fill:#2196f3,color:#fff style B fill:#ff9800,color:#fff style C fill:#4caf50,color:#fff style D fill:#9c27b0,color:#fff style E fill:#f44336,color:#fff
graph LR A["r[k]\n(N samples)"] --> B["๐ก Oversample\nm = 100รN"] B --> C["๐ข R(ฯ) = ฮฃ rยทcos\n(freq response)"] C --> D["๐ log |R(ฯ)|"] D --> N(( )) style A fill:#2196f3,color:#fff style C fill:#ff9800,color:#fff
graph LR N(( )) --> E["๐ Hilbert transform\nvia FFT"] E --> F["๐ ฯ(ฯ)\n(phase)"] F --> G["โฌ Decimate\nback to N"] G --> H["๐ IFFT\nโ h[n]"] style E fill:#9c27b0,color:#fff style H fill:#4caf50,color:#fff
graph LR A["r[k]\n(N samples)"] --> B["๐ณ Build P(z)\n2N-1 coefficients"] B --> C["๐ฏ Initial guesses\ninitial_aberth_autocorr"] C --> D["๐ Aberth iteration\naberth_autocorr"] D --> N(( )) style A fill:#2196f3,color:#fff style D fill:#ff9800,color:#fff
graph LR N(( )) --> E E{"|z| < 1?"} -->|"Yes โ "| F["๐ฅ Keep root"] E -->|"No โ"| G["๐ช Take 1/z"] F --> H["๐ poly_from_roots"] G --> H H --> I["โ๏ธ Normalize\nโ h[n]"] style E fill:#9c27b0,color:#fff style I fill:#4caf50,color:#fff
graph LR subgraph "FFT ๐ ฐ๏ธ" FA["100รN oversampling"] FB["FFT (O(N log N))"] FC["Hilbert + IFFT"] FD["~0.1 ms ร 1482 = 148 ms"] end subgraph "Root ๐ ฑ๏ธ" RA["N coefficients"] RB["Aberth (O(Nยฒ/4))"] RC["poly_from_roots"] RD["~0.05 ms ร 333 = 17 ms"] end style FD fill:#f44336,color:#fff style RD fill:#4caf50,color:#fff
graph TD subgraph "API" SF["spectral_fact(r)\n(default: fft, more stable)"] end subgraph "Methods" SFR["spectral_fact_root(r, tol)\nโ ginger::aberth_autocorr\nโ poly_from_roots"] SFF["spectral_fact_fft(r)\nโ FFTW / Hilbert\nโ IFFT"] ISF["inverse_spectral_fact(h)\nโ convolution O(nยฒ)"] end SF --> SFR SF --> SFF style SF fill:#ff9800,color:#fff style SFR fill:#4caf50,color:#fff style SFF fill:#2196f3,color:#fff style ISF fill:#9c27b0,color:#fff
graph TD Q["Need spectral factor?"] --> A{"Production\nstability?"} A -->|"Yes โ "| B["๐ ฐ๏ธ FFT\nStable ยท Exact ยท Default"] A -->|"No"| C{"Want faster\niterations?"} C -->|"Yes"| D["๐ ฑ๏ธ Root-finding\nFast ยท Tunable"] C -->|"No"| E{"Large N\n> 64?"} E -->|"Yes"| B E -->|"No"| D style B fill:#2196f3,color:#fff style D fill:#4caf50,color:#fff