viewof fftc_sampleRate = Inputs.range([100, 5000], {value: 1000, step: 100, label: "Sample Rate (Hz)"})
viewof fftc_windowSec = Inputs.range([0.5, 10], {value: 1.0, step: 0.5, label: "Window Duration (sec)"})
viewof fftc_topN = Inputs.range([1, 50], {value: 10, step: 1, label: "Top-N Frequency Components Kept"})
viewof fftc_bytesPerSample = Inputs.select([2, 4], {value: 4, label: "Bytes per Raw Sample"})
viewof fftc_signalType = Inputs.select(
["Simple (2 freqs)", "Complex (5 freqs)", "Broadband (20 freqs)"],
{value: "Simple (2 freqs)", label: "Signal Complexity"}
)Try It: FFT Compression Explorer
Try It: FFT Compression Explorer
animation
analytics-ml
edge-acquisition
Try Change Top-N Frequency Components Kept from 10 to 1.
Observe Watch FFT Output, Compression, and Reconstruction Quality with 1 component kept.
Explain Explain why keeping 1 component changes compression and reconstruction quality.
Technical boundaries. FFT Output uses 12 bytes per retained component plus 20 bytes of metadata. Reconstruction Quality uses the retained component count relative to 2, 5, or 20 signal frequencies.
NoteTry It: FFT Compression Explorer
Explore how FFT-based compression trades off between keeping more frequency components (higher fidelity) and achieving higher compression. Adjust the signal parameters and number of retained components.
fftc_numSamples = Math.round(fftc_sampleRate * fftc_windowSec)
fftc_rawBytes = fftc_numSamples * fftc_bytesPerSample
fftc_compBytes = fftc_topN * 12 + 20 // 3 floats (freq/mag/phase) x 4 bytes + metadata
fftc_ratio = fftc_rawBytes / fftc_compBytes
fftc_freqRes = fftc_sampleRate / fftc_numSamples
fftc_maxFreq = fftc_sampleRate / 2
fftc_numSignalFreqs = fftc_signalType === "Simple (2 freqs)" ? 2 : fftc_signalType === "Complex (5 freqs)" ? 5 : 20
fftc_captureRatio = Math.min(100, (fftc_topN / fftc_numSignalFreqs) * 100)
fftc_qualityLabel = fftc_captureRatio >= 100 ? "Lossless (all components captured)" : fftc_captureRatio >= 80 ? "High fidelity (most components captured)" : fftc_captureRatio >= 50 ? "Moderate fidelity (key patterns preserved)" : "Low fidelity (significant detail lost)"
fftc_qualityColor = fftc_captureRatio >= 100 ? "#0f6b5c" : fftc_captureRatio >= 80 ? "#0d47a1" : fftc_captureRatio >= 50 ? "#8a4a00" : "#9f1d1d"html`<div style="background: var(--bs-light, #f8f9fa); border: 1px solid var(--bs-border-color, #dee2e6); border-radius: 8px; padding: 1.2rem; color: var(--bs-body-color);">
<h4 style="margin-top:0; color: #2C3E50;">FFT Compression Analysis</h4>
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.8rem; margin-bottom: 1rem;">
<div style="text-align: center; padding: 0.6rem; background: rgba(231,76,60,0.08); border-radius: 6px;">
<div style="font-size: 0.8rem; color: #374151;">Raw Window</div>
<div style="font-size: 1.3rem; font-weight: bold; color: #9f1d1d;">${(fftc_rawBytes/1024).toFixed(1)} KB</div>
<div style="font-size: 0.8rem; color: #374151;">${fftc_numSamples.toLocaleString()} samples</div>
</div>
<div style="text-align: center; padding: 0.6rem; background: rgba(22,160,133,0.08); border-radius: 6px;">
<div style="font-size: 0.8rem; color: #374151;">FFT Output</div>
<div style="font-size: 1.3rem; font-weight: bold; color: #0f6b5c;">${fftc_compBytes} B</div>
<div style="font-size: 0.8rem; color: #374151;">${fftc_topN} components</div>
</div>
<div style="text-align: center; padding: 0.6rem; background: rgba(230,126,34,0.08); border-radius: 6px;">
<div style="font-size: 0.8rem; color: #374151;">Compression</div>
<div style="font-size: 1.3rem; font-weight: bold; color: #8a4a00;">${fftc_ratio.toFixed(0)}:1</div>
<div style="font-size: 0.8rem; color: #374151;">${(100 - 100/fftc_ratio).toFixed(1)}% reduction</div>
</div>
</div>
<table style="width:100%; border-collapse: collapse; font-size: 0.9rem;">
<tr style="border-bottom: 1px solid var(--bs-border-color, #dee2e6);">
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>Frequency Resolution</strong></th>
<td style="padding: 5px 8px; text-align: right;">${fftc_freqRes.toFixed(2)} Hz/bin</td>
</tr>
<tr style="border-bottom: 1px solid var(--bs-border-color, #dee2e6);">
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>Max Detectable Frequency</strong></th>
<td style="padding: 5px 8px; text-align: right;">${fftc_maxFreq.toLocaleString()} Hz</td>
</tr>
<tr style="border-bottom: 1px solid var(--bs-border-color, #dee2e6);">
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>Signal Frequencies</strong></th>
<td style="padding: 5px 8px; text-align: right;">${fftc_numSignalFreqs} components (${fftc_signalType})</td>
</tr>
<tr>
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>Reconstruction Quality</strong></th>
<td style="padding: 5px 8px; text-align: right; color: ${fftc_qualityColor}; font-weight: bold;">${fftc_qualityLabel}</td>
</tr>
</table>
<div style="margin-top: 0.8rem; background: rgba(52,152,219,0.06); border-radius: 4px; padding: 0.5rem; overflow: hidden;">
<div style="font-size: 0.8rem; color: #374151; margin-bottom: 4px;">Frequency components captured: ${Math.min(fftc_topN, fftc_numSignalFreqs)} / ${fftc_numSignalFreqs}</div>
<div style="height: 12px; background: rgba(44,62,80,0.1); border-radius: 6px; overflow: hidden;">
<div style="height: 100%; width: ${Math.min(100, fftc_captureRatio)}%; background: ${fftc_qualityColor}; border-radius: 6px; transition: width 0.3s;"></div>
</div>
</div>
</div>`