Debug spectrum analyzer and waterfall display issues in WaveCap-SDR...
This skill helps diagnose and fix issues with the spectrum analyzer and waterfall display in WaveCap-SDR.
Use this skill when:
Symptoms:
Diagnosis Steps:
curl http://127.0.0.1:8087/api/v1/captures | jq '.[] | {id, status, center_hz}'
Look for "status": "started". If stopped, start it:
curl -X POST http://127.0.0.1:8087/api/v1/captures/{capture_id}/start
/api/v1/stream/spectrum/...# List available captures
curl http://127.0.0.1:8087/api/v1/captures | jq
# Check spectrum snapshot (includes metadata: centerHz, sampleRate, fft_bins)
curl http://127.0.0.1:8087/api/v1/captures/{capture_id}/spectrum/snapshot | jq
Solutions:
useSpectrumData hook is properly configured in SpectrumAnalyzer.react.tsxSymptoms:
Diagnosis:
curl http://127.0.0.1:8087/api/v1/captures/{capture_id} | jq '.center_hz, .sample_rate'
(center_hz - sample_rate/2) to (center_hz + sample_rate/2)Example:
SpectrumAnalyzer.react.tsx, verify:const startFreq = centerHz - (sampleRate / 2)
const endFreq = centerHz + (sampleRate / 2)
const freqPerBin = sampleRate / fftBins
Solutions:
centerHz and sampleRate props passed to SpectrumAnalyzercenter_hz and sample_rateSymptoms:
Diagnosis:
curl http://127.0.0.1:8087/api/v1/captures/{capture_id}/spectrum/snapshot | jq '.power | length'
Typical FFT sizes: 512, 1024, 2048, 4096
Frequency resolution = sample_rate / fft_bins
Example:
Solutions:
Increase FFT size for better frequency resolution (but slower updates):
backend/wavecapsdr/capture.pyfft_size or nperseg parameter in spectrum generationTrade-offs:
Alternative: Use zoom feature (if implemented)
Symptoms:
Diagnosis:
# Capture audio and check actual signal quality
PYTHONPATH=backend backend/.venv/bin/python .claude/skills/audio-quality-checker/analyze_audio_stream.py \
--duration 3
# Should be: 20 * log10(magnitude) or 10 * log10(power)
spectrum_db = 20 * np.log10(np.abs(fft_result) + 1e-10)
Solutions:
Adjust SDR gain:
gain_db in capture configurationApply averaging:
smoothed_spectrum = alpha * new_spectrum + (1 - alpha) * smoothed_spectrum
Adjust dB floor:
spectrum_db = np.clip(spectrum_db, -100, 0) # Floor at -100 dB
Use windowing function:
scipy.signal.get_window() is used in FFT computationSymptoms:
Diagnosis:
# Monitor WebSocket data rate (requires WebSocket client like wscat)
# Install wscat: npm install -g wscat
wscat -c ws://127.0.0.1:8087/api/v1/stream/captures/{capture_id}/spectrum
# Count messages per second
SpectrumAnalyzer or WaterfallDisplay re-rendering too oftenSolutions:
Reduce FFT update rate:
capture.py to throttle spectrum generationOptimize React rendering:
React.memo() for SpectrumAnalyzer componentuseRef() for canvas elementReduce FFT size:
Use RequestAnimationFrame:
requestAnimationFrame()Implement downsampling:
Symptoms:
Solutions:
// In WaterfallDisplay.react.tsx
const minDb = -90 // Adjust to lowest dB value to show
const maxDb = -20 // Adjust to highest dB value to show
// Normalize to 0-255 range
const normalized = ((value - minDb) / (maxDb - minDb)) * 255
const gamma = 0.5 // <1 = brighter, >1 = darker
const corrected = Math.pow(normalized / 255, gamma) * 255
Symptoms:
Diagnosis:
# Run server in foreground to see errors
cd backend
PYTHONPATH=. .venv/bin/python -m wavecapsdr.app
// In browser console
window.addEventListener('beforeunload', () => {
console.log('WebSocket state:', ws.readyState)
})
Solutions:
Implement reconnection logic:
useSpectrumData hook for reconnection handlingAdd ping/pong:
Check network issues:
FFT Pipeline:
IQ samples → Windowing → FFT → Magnitude → dB conversion → Smoothing → WebSocket
Key Files:
backend/wavecapsdr/api.py (spectrum WebSocket endpoint)frontend/src/components/primitives/SpectrumAnalyzer.react.tsxfrontend/src/components/primitives/WaterfallDisplay.react.tsxfrontend/src/hooks/useSpectrumData.tsFFT Parameters:
nperseg: FFT size (512, 1024, 2048, 4096)window: Window function (Hann, Hamming, Blackman)noverlap: Overlap between segments (0 to nperseg-1)scaling: 'spectrum' or 'density'Typical Good Settings:
Monitor spectrum WebSocket:
# Using wscat
npm install -g wscat
wscat -c ws://127.0.0.1:8087/api/v1/stream/spectrum/{capture_id}
Test FFT generation:
# Quick FFT test in Python
import numpy as np
from scipy import signal
sample_rate = 2_000_000
iq_data = np.random.randn(sample_rate) + 1j * np.random.randn(sample_rate)
f, t, Sxx = signal.spectrogram(
iq_data,
fs=sample_rate,
window='hann',
nperseg=2048,
noverlap=1024,
scaling='spectrum',
mode='magnitude'
)
print(f"Freq bins: {len(f)}, Time bins: {len(t)}")
print(f"Freq resolution: {(f[1] - f[0]) / 1e3:.2f} kHz")
SKILL.md: This file - diagnostic instructions and solutions