Goertzel Algorithm Calculator

One frequency, measured the cheap way.

  • Coefficient and power
  • Bin or any frequency
  • Matches the DFT
A small rounded clay table holding a soft clay wavy ribbon, a rounded clay sieve catching one bead, and a few loose rounded beads.

The guide

One recurrence, one coefficient and one frequency: how the Goertzel filter reads a single bin of a transform

Why a two-term recurrence can pick one frequency out of a block of samples, why the final step fixes the phase, how a tone between bins leaks, and when a few bins beat a full transform.

  • 1.635859 coefficient 2 cos(2 pi 20 / 205) for bin 20
  • 8169.566 power at bin 20 for a 770 Hz plus 1336 Hz block
  • 19.7312 exact bin index of 770 Hz at 8000 Hz and N = 205
  • 38.3 times weaker present tone over the strongest absent bin
  • 16.7 percent power outside the two nearest bins for a half-bin tone
Read the full guide Fold the guide 6 min · 12 sources

Most of the time you want a whole spectrum. Sometimes you want one number: how much of a block of samples sits at 770 hertz? A full transform answers that and a thousand other questions you did not ask. The Goertzel algorithm answers only the one.

It is a technique in digital signal processing for evaluating individual terms of the discrete Fourier transform. Its best-known job is recognising the tones that a telephone keypad makes, where each key sounds one low and one high frequency and a decoder only has eight candidate frequencies to test.

A filter that runs once

Like the transform, the algorithm looks at one selectable frequency of a discrete signal. Unlike a direct sum, it needs only a single real coefficient at each step. The main calculation has the shape of a digital filter, a second-order recursive stage: s[n] = x[n] + coeff times s[n-1] minus s[n-2], with both starting values at zero.

The coefficient is 2 cos(omega), where omega is the angle that one sample advances at the target frequency. For a bin k of an N-sample block, omega is 2 pi k / N. A common slip is to write cos where 2 cos belongs. The factor of two comes from the recursion that a sine wave obeys, and dropping it changes the filter entirely.

Take 205 samples at 8000 samples per second, made from a 770 Hz tone plus a 1336 Hz tone. The bins are fs / N = 39.0244 hertz apart. The exact index of 770 Hz is 19.7312, so the nearest bin is 20, which sits at 780.4878 Hz. The coefficient for bin 20 is 1.635859.

Run the recurrence over all 205 samples and keep only the last two values, s[204] and s[203]. Nothing else is stored, which is why the method needs so little memory. The power is s[204] squared plus s[203] squared minus coeff times s[204] times s[203], and it needs no complex arithmetic. For this block it is 8169.566.

Here are the first rows, so you can follow one by hand. The first sample x[0] is 0, so s[0] is 0. Then x[1] is 1.435633 and s[1] is 1.435633, because both earlier states are still zero. At n = 2 the input is 1.799367 and s[2] = 1.799367 + 1.635859 x 1.435633 - 0 = 4.147859. At n = 3 the state grows to 6.313903, and at n = 4 it is 5.971922.

Those numbers rise and fall with a growing swing. The recurrence is a resonator, a filter tuned so that a component at the target frequency keeps adding to itself, while other components do not. After 205 samples the build-up at bin 20 is what the power reports.

Why only the last two values? A resonator carries all of its history in two numbers. Everything earlier has already been folded in. That is the reason the loop can throw each state away as soon as the next one exists, and why the page can show the whole run as a short table of the first and last rows.

The final step and the phase

The power uses only the last two states, but the complex value needs one more idea. The filter has run to the last sample and then stops. The remaining stage of the filter would apply one more update with an input of zero, and the source folds that update into a single formula: the value is e to the j omega times s[N-1] minus s[N-2].

If you stop after the last sample and apply the plain second stage instead, you miss that last state update. The result has the wrong phase, though its magnitude may look right. For bin 20 of the example the final step gives about -66.2075 minus 61.5316 j, a phase of about -137.1 degrees, and it equals the transform bin itself.

That is the check the page makes everywhere. For a bin, the Goertzel value equals the transform value. Euler’s formula is what turns the exponential into cosines and sines, so the same sums can be written with real numbers only.

A tone that is not in phase with the block start changes the complex value but not the power. Shift the 780.4878 Hz tone by 60 degrees and the power at bin 20 stays 10506.25, while the phase at the bin moves to about -30 degrees. A sine of zero phase reads as -90 degrees at its own bin, so the 60 degrees adds on to give -30. Without the final step you could not read that angle off the recurrence at all.

Bins, tones and the cheaper question

Does it matter which bin you pick? Yes, a great deal. Bin 18 for the 770 Hz tone reads a power of only 213.432, against 8169.566 at bin 20. The two present tones at bins 20 and 34 give 8169.566 and 8790.091, while absent keypad frequencies land at powers such as 54.164 at bin 31.

The weaker present tone beats the strongest absent one by a factor of 38.3. That gap is the whole basis of a tone detector: a clear margin between what is there and what is not.

When the target is not a bin, there is a second way to run it. Use omega = 2 pi f / fs for the target itself. The power then equals the squared magnitude of the direct sum over the same N samples. At exactly 770 Hz the example gives 10502.368, larger than the bin value because the bin sits 10.5 hertz off the tone.

The sampling limit also bites. A target above half the sample rate cannot be seen as itself. A tone at 4001 Hz sampled at 8000 Hz shows up as 3999 Hz, and the page refuses the target and names the alias rather than measure the wrong thing.

Leakage when a tone falls between bins

Put a tone exactly at the centre of bin 20 and a block of 205 samples shows its power in that one bin, 10506.25, and nowhere else. Move the tone halfway to bin 21 and the picture changes. The power splits between bins 20 and 21, about 4349.6 and 4169.9, and some of it spills into bins farther away.

Of the power in a window of 14 bins, 16.7 percent lands outside the two nearest bins. That spreading is spectral leakage. It happens because the block is a slice of a longer signal and the slice does not hold a whole number of cycles.

A window function tapers the block to trade leakage against sharpness of the peak. This page names windows but does not design them, so the leakage you see is that of the plain block.

When few bins are cheaper

The source counts operations. For one bin of a complex input of N samples, the loop needs 2N multiplications and 4N additions, and the final step adds 4 and 4 more. For 205 samples that is 414 multiplications and 824 additions per bin.

A fast Fourier transform spends on the order of N log2 N operations to get every bin. A radix-2 version, as the source gives it, uses 2 log2 N multiplications and 3 log2 N additions per bin for each of N bins. So when only a handful of bins are wanted, the one-frequency recurrence is the cheaper way to ask.

This page’s own loop is lighter still, because real samples need one multiplication per sample: 1640 multiplications for the eight keypad frequencies of the example. The comparison counts operations only. It says nothing about how fast either method runs on a particular machine.

What it leaves out

The page does not decode a whole keypad, track a tone as it changes, or decide among several tones. It does not capture sound, and it does not design windows. Each of those is a separate problem built on top of the single measurement shown here.

It does show every step, so you can see where a chatbot or a half-remembered formula goes wrong: the missing factor of two, the missing final step, the wrong bin, the unstated cost.

Sources

Every source consulted for this guide. Links checked November 14, 2026.

  1. Goertzel algorithm Wikipedia (CC BY-SA)
  2. Discrete Fourier transform Wikipedia (CC BY-SA)
  3. DTMF signaling Wikipedia (CC BY-SA)
  4. Spectral leakage Wikipedia (CC BY-SA)
  5. Fast Fourier transform Wikipedia (CC BY-SA)
  6. Digital filter Wikipedia (CC BY-SA)
  7. Infinite impulse response Wikipedia (CC BY-SA)
  8. Window function Wikipedia (CC BY-SA)
  9. Nyquist-Shannon sampling theorem Wikipedia (CC BY-SA)
  10. Euler's formula Wikipedia (CC BY-SA)
  11. Aliasing Wikipedia (CC BY-SA)
  12. numpy.fft.fft NumPy documentation (BSD licence)