Goertzel Algorithm Simulator Back
Signal Processing Simulator

Goertzel Algorithm Simulator — DTMF Single Frequency Detection

Detect the 16 DTMF keys with the Goertzel method. See how 8 DFT bins are computed in O(N) using a second-order IIR filter and how the pressed key is identified from the strongest row and column frequencies.

Parameters
DTMF Key Index
Noise Level
Sampling F_s
Hz
Frame Length N

Key map — 0:'1' 1:'2' 2:'3' 3:'A' / 4:'4' 5:'5' 6:'6' 7:'B' / 8:'7' 9:'8' 10:'9' 11:'C' / 12:'*' 13:'0' 14:'#' 15:'D'

Results
Detected Key
Strongest Row Freq.
Strongest Col Freq.
Goertzel Ops N·M
Input Signal & Goertzel Detection Strength

Top = input signal x[n] (blue) / Bottom = |X_k| for 8 frequencies (red = row, blue = column, yellow = strongest)

Theory & Key Formulas

The Goertzel algorithm directly computes the squared amplitude using a second-order IIR recurrence for the bin k = round(f·N/F_s) closest to target frequency f.

Angular frequency ω and coefficient c:

$$\omega = \frac{2\pi k}{N},\qquad c = 2\cos\omega$$

Second-order IIR recurrence (s_{-1} = s_{-2} = 0):

$$s_n = x_n + c\,s_{n-1} - s_{n-2}$$

Squared amplitude (bin power) after N samples:

$$|X_k|^2 = s_{N-1}^2 + s_{N-2}^2 - c\,s_{N-1}\,s_{N-2}$$

The cost for 1 bin is O(N); for M frequencies it is O(N·M). Compared to FFT's overall O(N log N), Goertzel wins as the number of target bins shrinks.

What is the Goertzel Algorithm Simulator

🙋
If we already have FFT, why do we need a separate algorithm called Goertzel?
🎓
In short, Goertzel is the specialist when you only want "one frequency bin." FFT computes all N bins, but for DTMF detection you only need 8 frequencies. Goertzel costs O(N) per bin and uses a second-order IIR filter with just three variables, which fits embedded MCUs perfectly. As you change keys in the simulator, you'll see that only 2 frequencies — one row, one column — are actually needed.
🙋
What's a "second-order IIR"? The word "filter" sounds intimidating…
🎓
It's not hard. Just advance the recurrence $s_n = x_n + c\,s_{n-1} - s_{n-2}$ one sample at a time. The coefficient $c = 2\cos(2\pi k/N)$ is computed once. You only carry two state variables $s_{n-1}$ and $s_{n-2}$, so 3 words of memory suffice. At the end, $|X_k|^2 = s_{N-1}^2 + s_{N-2}^2 - c\,s_{N-1}s_{N-2}$ gives the squared amplitude. It pairs beautifully with a DSP's multiply-accumulate instruction.
🙋
When I raise "Noise Level" in the simulator, the bars dance around. How does real hardware decide?
🎓
Good question. Real systems AND together several conditions: the strongest bin level exceeds a threshold, the row-to-column level ratio is within ±6 dB, the second-strongest ratio (twist) is within range, the tone lasts at least 40 ms — and only then call it valid. Even if noise flips the strongest bin momentarily, the duration test suppresses the false trigger. ITU-T Q.24 documents this clearly.
🙋
What changes when I increase "Frame Length N"?
🎓
A larger N gives finer frequency resolution $\Delta f = F_s/N$, so neighboring frequencies separate better — but cost scales linearly too. F_s=8 kHz, N=205 gives $\Delta f \approx 39$ Hz, the standard DTMF choice. If N is too small, bins drift away from the DTMF frequencies and detection strength drops. Slide N from 128 to 1024 in the simulator and you'll see selectivity change.

Frequently Asked Questions

It is widely used wherever only specific frequencies must be detected: power grid frequency monitoring (50/60 Hz harmonic analysis), carrier detection for industrial sensors, ultrasonic echo ranging, CTCSS/DCS tone squelch in radios, and pulse detection in medical equipment. The common thread is "we don't need all N bins, just a few bins quickly."
The basic form assumes integer k, but the Generalized Goertzel extension supports any real k. This allows precise amplitude estimation while suppressing spectral leakage even when the target frequency is not on the DFT grid — important for applications like power-system frequency estimation where the frequency does not fall on an integer bin.
The second-order IIR state can grow rapidly, and large frame length N causes the dynamic range of s_n to explode. Either pre-scale the input (e.g., by 1/N) to prevent overflow, or apply saturating arithmetic with guard bits at each sample. In Q1.15 or Q1.31 fixed-point, it is common to round coefficient c to Q14 to control error.
Yes. By computing the complex DFT value X_k = s_{N-1} − e^{-jω} s_{N-2} at the final stage, you obtain real and imaginary parts, and atan2 gives the phase. This simulator only performs amplitude detection, but AM/FM demodulation and synchronous detection require phase, so the complex-output version is used. Skipping phase saves one multiplication — one of the elegant simplicities of Goertzel.

Real-World Applications

DTMF decoding in telephony: The Goertzel method is the standard real-time key detector on landlines, IP phones, and IVR systems. Analog lines carry DTMF tones superimposed on the voice; receivers run 8 Goertzel filters in parallel and extract the valid key using level ratio, duration, and twist tests. Even in VoIP, where RFC 2833 provides digital DTMF transport, Goertzel decoders remain in active use for interoperability.

Power-system harmonic analysis: Power quality monitors continuously track 50 Hz / 60 Hz and their harmonics (150/180, 250/300, 350/420 Hz, etc.). Instead of running a full FFT, only the few harmonics of interest are continuously computed with Goertzel, keeping CPU load low while delivering responsive alarms. Combined with Generalized Goertzel, even small drifts from 50 Hz produce accurate amplitude estimates.

CTCSS/DCS tone detection in radios: In commercial and amateur radio, CTCSS encodes group IDs as sub-audible tones (about 50 tones in the 67–250 Hz range). Receivers continuously monitor the Goertzel output for the assigned tone and unmute the speaker only when the threshold is exceeded. Detecting a small number of low-frequency tones is Goertzel's sweet spot.

Carrier detection on embedded devices: FSK modem preamble detection, ultrasonic sensor echo amplitude, and pulse oximeter heartbeat sync are commonly implemented on ARM Cortex-M MCUs where "we want only a few frequencies with FFT-grade accuracy." The CMSIS-DSP library provides Goertzel implementations leveraging arm_biquad_cascade_df1_q15, processing one frame in microseconds with hardware multipliers.

Common Misconceptions & Caveats

The most common misconception is assuming "Goertzel is always faster than FFT." In fact there is a break-even point: once the number of target frequencies M exceeds about log₂N, FFT becomes more economical. For N=1024, log₂N = 10, so if you need 10 or more bins, a single FFT computes them all faster. The simulator's "ops" card shows Goertzel's N·M; train yourself to mentally compare it against FFT's N·log₂N. Goertzel wins only when "few frequencies" AND "bins known in advance" are both true.

The next pitfall is underestimating the importance of placing the target frequency exactly on the DFT grid. Standard Goertzel uses k = round(f·N/F_s), so any offset from bin center causes "scalloping loss" — up to 3.9 dB (ΔdB ≈ 20log₁₀(sinc(0.5))) reduction in amplitude estimate. DTMF classically recommends F_s=8000, N=205 precisely because all 8 DTMF frequencies sit close to the DFT grid at those values. The bar height fluctuation as you change N in the simulator is exactly this scalloping effect.

Finally, beware of jumping to "large Goertzel output = successful detection." Picking the strongest bar in the chart alone produces frequent false detections under noise or speech harmonics. Real systems AND together multiple conditions: each row/column's strongest level is above an absolute threshold, their ratio is within ±6 dB, the twist is within the specified range, tone duration is ≥ 40 ms, and silence between tones is ≥ 40 ms — only then is the key declared valid. Raise noise to 1.0 in the simulator and watch the strongest bin flip frequently to feel why a simple max-only judgement is dangerous.