Goertzel algorithm
The Goertzel algorithm is a technique in digital signal processing (DSP) for efficient evaluation of the individual terms of the discrete Fourier transform (DFT). It is useful in certain practical applications, such as recognition of dual-tone multi-frequency signaling (DTMF) tones produced by the push buttons of the keypad of a traditional analog telephone. The algorithm was first described by Gerald Goertzel in 1958.[1]
Like the DFT, the Goertzel algorithm analyses one selectable frequency component from a discrete signal.[2][3][4] Unlike direct DFT calculations, the Goertzel algorithm applies a single real-valued coefficient at each iteration, using real-valued arithmetic for real-valued input sequences. For covering a full spectrum (except when using for continuous stream of data where coefficients are reused for subsequent calculations, which has computational complexity equivalent of sliding DFT), the Goertzel algorithm has a higher order of complexity than fast Fourier transform (FFT) algorithms, but for computing a small number of selected frequency components, it is more numerically efficient. The simple structure of the Goertzel algorithm makes it well suited to small processors and embedded applications.
The Goertzel algorithm can also be used "in reverse" as a sinusoid synthesis function, which requires only 1 multiplication and 1 subtraction per generated sample.[5]
Numerical stability[edit]
It can be observed that the poles of the filter's Z transform are located at and , on a circle of unit radius centered on the origin of the complex Z-transform plane. This property indicates that the filter process is marginally stable and vulnerable to numerical-error accumulation when computed using low-precision arithmetic and long input sequences.[6] A numerically stable version was proposed by Christian Reinsch.[7]
For the important case of computing a DFT term, the following special restrictions are applied.
Making these substitutions into equation (6) and observing that the term , equation (6) then takes the following form:
We can observe that the right side of equation (9) is extremely similar to the defining formula for DFT term , the DFT term for index number , but not exactly the same. The summation shown in equation (9) requires input terms, but only input terms are available when evaluating a DFT. A simple but inelegant expedient is to extend the input sequence with one more artificial value .[8] We can see from equation (9) that the mathematical effect on the final result is the same as removing term from the summation, thus delivering the intended DFT value.
However, there is a more elegant approach that avoids the extra filter pass. From equation (1), we can note that when the extended input term is used in the final step,
Thus, the algorithm can be completed as follows:
The last two mathematical operations are simplified by combining them algebraically:
Note that stopping the filter updates at term and immediately applying equation (2) rather than equation (11) misses the final filter state updates, yielding a result with incorrect phase.[9]
The particular filtering structure chosen for the Goertzel algorithm is the key to its efficient DFT calculations. We can observe that only one output value is used for calculating the DFT, so calculations for all the other output terms are omitted. Since the FIR filter is not calculated, the IIR stage calculations , etc. can be discarded immediately after updating the first stage's internal state.
This seems to leave a paradox: to complete the algorithm, the FIR filter stage must be evaluated once using the final two outputs from the IIR filter stage, while for computational efficiency the IIR filter iteration discards its output values. This is where the properties of the direct-form filter structure are applied. The two internal state variables of the IIR filter provide the last two values of the IIR filter output, which are the terms required to evaluate the FIR filter stage.
Applications[edit]
Power-spectrum terms[edit]
Examining equation (6), a final IIR filter pass to calculate term using a supplemental input value applies a complex multiplier of magnitude 1 to the previous term . Consequently, and represent equivalent signal power. It is equally valid to apply equation (11) and calculate the signal power from term or to apply equation (2) and calculate the signal power from term . Both cases lead to the following expression for the signal power represented by DFT term :
In the complexity order expressions, when the number of calculated terms is smaller than , the advantage of the Goertzel algorithm is clear. But because FFT code is comparatively complex,
the "cost per unit of work" factor is often larger for an FFT, and the practical advantage favours the Goertzel algorithm even for several times larger than .
As a rule-of-thumb for determining whether a radix-2 FFT or a Goertzel algorithm is more efficient, adjust the number of terms in the data set upward to the nearest exact power of 2, calling this , and the Goertzel algorithm is likely to be faster if
FFT implementations and processing platforms have a significant impact on the relative performance. Some FFT implementations[11] perform internal complex-number calculations to generate coefficients on-the-fly, significantly increasing their "cost K per unit of work." FFT and DFT algorithms can use tables of pre-computed coefficient values for better numerical efficiency, but this requires more accesses to coefficient values buffered in external memory, which can lead to increased cache contention that counters some of the numerical advantage.
Both algorithms gain approximately a factor of 2 efficiency when using real-valued rather than complex-valued input data. However, these gains are natural for the Goertzel algorithm but will not be achieved for the FFT without using certain algorithm variants specialised for transforming real-valued data.