Drone Detector

Idle
Frequency Energy
Signal Level
RMS
Calibration
Threshold ON 0.0080
Raise if false alarms; lower if misses real drones.
Threshold OFF 0.0040
Hysteresis floor — alarm clears when all frequencies drop below this.
Frequencies Needed 1 / 6
How many of the 6 bands must exceed threshold to trigger. Raise to reduce false alarms; lower to catch quieter drones.
EMA Smoothing (α) 0.25
How quickly the smoothed energy tracks new frames. High = fast/reactive but noisy. Low = stable but slow to respond.
Sustain ON (frames) 2
Consecutive frames above threshold required before alarm triggers. Raise to debounce brief spikes.
Sustain OFF (frames) 8
Consecutive frames below threshold required before alarm clears. Raise to keep the alarm latched longer after a drone passes.
Noise Floor (RMS min) 0.00030
Frames quieter than this are treated as silence and skipped — prevents spurious ratios from near-zero audio.
How It Works
Goertzel Filter

A Goertzel filter computes the energy at one specific frequency using a two-sample IIR recurrence — essentially a single DFT bin without the full FFT. It runs once per target frequency per frame, making it far cheaper than an FFT when you only care about a handful of frequencies.

Each 512-sample frame is first multiplied by a Hanning window to taper the edges to zero. This reduces spectral leakage — without it, energy from one frequency bleeds into adjacent bins and raises false readings.

s[n] = x[n] + 2·cos(ω)·s[n-1] − s[n-2]
power = (s[N-1] − s[N-2]·cos(ω))² + (s[N-2]·sin(ω))²

Six filters run in parallel, one per target frequency (200, 400, 800, 1200, 2400, 4000 Hz). These are chosen to cover common drone rotor harmonics — a quadcopter at 80 Hz blade-pass produces harmonics at 160, 240, 320 Hz and above.

Energy Ratio

Raw Goertzel power scales with the microphone's gain and the drone's distance. To remove that dependency, each bin's power is divided by the total frame energy (sum-of-squares × N). This gives a tonal-to-broadband ratio that stays roughly constant regardless of volume.

ratio[f] = goertzel_power[f] / (sumSq × N)

The bars on screen show this ratio. A steady tone like a drone rotor produces a ratio well above the background. Wind, voices, and traffic produce relatively flat spectra, so no single bin dominates.

EMA Smoothing

Raw per-frame ratios are noisy. An exponential moving average smooths them across time:

ema[f] = α · ratio[f] + (1 − α) · ema[f]

α (alpha) controls the trade-off. At α = 0.25, the EMA has a time constant of roughly 3–4 frames ≈ 100 ms. A drone that appears suddenly reaches threshold in a few frames; a brief spike decays just as quickly.

Hysteresis & Sustain

Two separate thresholds prevent chattering around the detection boundary:

  • Threshold ON — EMA must exceed this to count a frequency as "active".
  • Threshold OFF — once alarming, all active frequencies must drop below this to begin clearing.

Sustain counters add debouncing in both directions. The alarm only fires after N consecutive triggering frames (Sustain ON), and only clears after M consecutive quiet frames (Sustain OFF). This prevents a single noisy frame from either triggering or cancelling an alarm.