Goertzel algorithm
   HOME

TheInfoList



OR:

The Goertzel algorithm is a technique in
digital signal processing Digital signal processing (DSP) is the use of digital processing, such as by computers or more specialized digital signal processors, to perform a wide variety of signal processing operations. The digital signals processed in this manner are ...
(DSP) for efficient evaluation of the individual terms of the
discrete Fourier transform In mathematics, the discrete Fourier transform (DFT) converts a finite sequence of equally-spaced samples of a function into a same-length sequence of equally-spaced samples of the discrete-time Fourier transform (DTFT), which is a complex- ...
(DFT). It is useful in certain practical applications, such as recognition of
dual-tone multi-frequency signaling Dual-tone multi-frequency signaling (DTMF) is a telecommunication signaling system using the voice-frequency band over telephone lines between telephone equipment and other communications devices and switching centers. DTMF was first developed ...
(DTMF) tones produced by the push buttons of the keypad of a traditional analog
telephone A telephone is a telecommunications device that permits two or more users to conduct a conversation when they are too far apart to be easily heard directly. A telephone converts sound, typically and most efficiently the human voice, into e ...
. The algorithm was first described by Gerald Goertzel in 1958. Like the DFT, the Goertzel algorithm analyses one selectable frequency component from a
discrete signal In Dynamical system, mathematical dynamics, discrete time and continuous time are two alternative frameworks within which Variable (mathematics), variables that evolve over time are modeled. Discrete time Discrete time views values of variable ...
. 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, the Goertzel algorithm has a higher order of complexity than
fast Fourier transform A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its original domain (often time or space) to a representation in th ...
(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.


The algorithm

The main calculation in the Goertzel algorithm has the form of a
digital filter In signal processing, a digital filter is a system that performs mathematical operations on a sampled, discrete-time signal to reduce or enhance certain aspects of that signal. This is in contrast to the other major type of electronic filter, t ...
, and for this reason the algorithm is often called a ''Goertzel filter''. The filter operates on an input sequence x /math> in a cascade of two stages with a parameter \omega_0, giving the frequency to be analysed, normalised to
radian The radian, denoted by the symbol rad, is the unit of angle in the International System of Units (SI) and is the standard unit of angular measure used in many areas of mathematics. The unit was formerly an SI supplementary unit (before that c ...
s per sample. The first stage calculates an intermediate sequence, s /math>: The second stage applies the following filter to s /math>, producing output sequence y /math>: The first filter stage can be observed to be a second-order
IIR filter Infinite impulse response (IIR) is a property applying to many linear time-invariant systems that are distinguished by having an impulse response h(t) which does not become exactly zero past a certain point, but continues indefinitely. This is in ...
with a direct-form structure. This particular structure has the property that its internal state variables equal the past output values from that stage. Input values x /math> for n < 0 are presumed all equal to 0. To establish the initial filter state so that evaluation can begin at sample x /math>, the filter states are assigned initial values s 2= s 1= 0. To avoid
aliasing In signal processing and related disciplines, aliasing is an effect that causes different signals to become indistinguishable (or ''aliases'' of one another) when sampled. It also often refers to the distortion or artifact that results when a ...
hazards, frequency \omega_0 is often restricted to the range 0 to π (see
Nyquist–Shannon sampling theorem The Nyquist–Shannon sampling theorem is a theorem in the field of signal processing which serves as a fundamental bridge between continuous-time signals and discrete-time signals. It establishes a sufficient condition for a sample rate that pe ...
); using a value outside this range is not meaningless, but is equivalent to using an aliased frequency inside this range, since the exponential function is periodic with a period of 2π in \omega_0. The second-stage filter can be observed to be a
FIR filter In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of ''finite'' duration, because it settles to zero in finite time. This is in contrast to infinite impulse ...
, since its calculations do not use any of its past outputs.
Z-transform In mathematics and signal processing, the Z-transform converts a discrete-time signal, which is a sequence of real or complex numbers, into a complex frequency-domain (z-domain or z-plane) representation. It can be considered as a discrete-tim ...
methods can be applied to study the properties of the filter cascade. The Z transform of the first filter stage given in equation (1) is The Z transform of the second filter stage given in equation (2) is The combined transfer function of the cascade of the two filter stages is then This can be transformed back to an equivalent time-domain sequence, and the terms unrolled back to the first input term at index n = 0:


Numerical stability

It can be observed that the
poles Poles,, ; singular masculine: ''Polak'', singular feminine: ''Polka'' or Polish people, are a West Slavic nation and ethnic group, who share a common history, culture, the Polish language and are identified with the country of Poland in Ce ...
of the filter's
Z transform In mathematics and signal processing, the Z-transform converts a discrete-time signal, which is a sequence of real or complex numbers, into a complex frequency-domain (z-domain or z-plane) representation. It can be considered as a discrete-tim ...
are located at e^ and e^, 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. A numerically stable version was proposed by Christian Reinsch.


DFT computations

For the important case of computing a DFT term, the following special restrictions are applied. * The filtering terminates at index n = N, where N is the number of terms in the input sequence of the DFT. * The frequencies chosen for the Goertzel analysis are restricted to the special form * The index number k indicating the "frequency bin" of the DFT is selected from the set of index numbers Making these substitutions into equation (6) and observing that the term e^ = 1, 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 X /math>, the DFT term for index number k, but not exactly the same. The summation shown in equation (9) requires N+1 input terms, but only N input terms are available when evaluating a DFT. A simple but inelegant expedient is to extend the input sequence x /math> with one more artificial value x = 0. We can see from equation (9) that the mathematical effect on the final result is the same as removing term x /math> 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 x = 0 is used in the final step, Thus, the algorithm can be completed as follows: * terminate the IIR filter after processing input term x -1/math>, * apply equation (10) to construct s /math> from the prior outputs s -1/math> and s -2/math>, * apply equation (2) with the calculated s /math> value and with s -1/math> produced by the final direct calculation of the filter. The last two mathematical operations are simplified by combining them algebraically: Note that stopping the filter updates at term N-1 and immediately applying equation (2) rather than equation (11) misses the final filter state updates, yielding a result with incorrect phase. 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 y /math> 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 s s /math>, 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


Power-spectrum terms

Examining equation (6), a final IIR filter pass to calculate term y /math> using a supplemental input value x 0 applies a complex multiplier of magnitude 1 to the previous term y -1/math>. Consequently, y /math> and y -1/math> represent equivalent signal power. It is equally valid to apply equation (11) and calculate the signal power from term y /math> or to apply equation (2) and calculate the signal power from term y -1/math>. Both cases lead to the following expression for the signal power represented by DFT term X /math>: In the
pseudocode In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
below, the variables sprev and sprev2 temporarily store output history from the IIR filter, while x /code> is an indexed element of the
array An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
x, which stores the input. Nterms defined here Kterm selected here ω = 2 × π × Kterm / Nterms; cr := cos(ω) ci := sin(ω) coeff := 2 × cr sprev := 0 sprev2 := 0 for each index ''n'' in range 0 to Nterms-1 do s := x + coeff × sprev - sprev2 sprev2 := sprev sprev := s end power := sprev2 × sprev2 + sprev × sprev - coeff × sprev × sprev2 It is possible to organise the computations so that incoming samples are delivered singly to a software object that maintains the filter state between updates, with the final power result accessed after the other processing is done.


Single DFT term with real-valued arithmetic

The case of real-valued input data arises frequently, especially in embedded systems where the input streams result from direct measurements of physical processes. Comparing to the illustration in the previous section, when the input data are real-valued, the filter internal state variables sprev and sprev2 can be observed also to be real-valued, consequently, no complex arithmetic is required in the first IIR stage. Optimizing for real-valued arithmetic typically is as simple as applying appropriate real-valued data types for the variables. After the calculations using input term x -1/math>, and filter iterations are terminated, equation (11) must be applied to evaluate the DFT term. The final calculation uses complex-valued arithmetic, but this can be converted into real-valued arithmetic by separating real and imaginary terms: Comparing to the power-spectrum application, the only difference are the calculation used to finish:
(Same IIR filter calculations as in the signal power implementation)
XKreal = sprev * cr - sprev2;
XKimag = sprev * ci;


Phase detection

This application requires the same evaluation of DFT term X /math>, as discussed in the previous section, using a real-valued or complex-valued input stream. Then the signal phase can be evaluated as taking appropriate precautions for singularities, quadrant, and so forth when computing the inverse tangent function.


Complex signals in real arithmetic

Since complex signals decompose linearly into real and imaginary parts, the Goertzel algorithm can be computed in real arithmetic separately over the sequence of real parts, yielding y_\text /math>, and over the sequence of imaginary parts, yielding y_\text /math>. After that, the two complex-valued partial results can be recombined:


Computational complexity

* According to
computational complexity theory In theoretical computer science and mathematics, computational complexity theory focuses on classifying computational problems according to their resource usage, and relating these classes to each other. A computational problem is a task solved by ...
, computing a set of M DFT terms using M applications of the Goertzel algorithm on a data set with N values with a "cost per operation" of K has
complexity Complexity characterises the behaviour of a system or model whose components interaction, interact in multiple ways and follow local rules, leading to nonlinearity, randomness, collective dynamics, hierarchy, and emergence. The term is generall ...
O(KNM). : To compute a single DFT bin X(f) for a complex input sequence of length N, the Goertzel algorithm requires 2 N multiplications and 4\ N additions/subtractions within the loop, as well as 4 multiplications and 4 final additions/subtractions, for a total of 2 N + 4 multiplications and 4 N + 4 additions/subtractions. This is repeated for each of the M frequencies. * In contrast, using an
FFT A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its original domain (often time or space) to a representation in the ...
on a data set with N values has complexity O(KN\log N). : This is harder to apply directly because it depends on the FFT algorithm used, but a typical example is a radix-2 FFT, which requires 2 \log_2(N) multiplications and 3 \log_2(N) additions/subtractions per DFT bin, for each of the N bins. In the complexity order expressions, when the number of calculated terms M is smaller than \log N, the advantage of the Goertzel algorithm is clear. But because FFT code is comparatively complex, the "cost per unit of work" factor K is often larger for an FFT, and the practical advantage favours the Goertzel algorithm even for M several times larger than \log_2(N). As a rule-of-thumb for determining whether a radix-2 FFT or a Goertzel algorithm is more efficient, adjust the number of terms N in the data set upward to the nearest exact power of 2, calling this N_2, and the Goertzel algorithm is likely to be faster if :M \le \frac \log_2(N_2) FFT implementations and processing platforms have a significant impact on the relative performance. Some FFT implementations 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.


See also

*
Bluestein's FFT algorithm The chirp Z-transform (CZT) is a generalization of the discrete Fourier transform (DFT). While the DFT samples the Z plane at uniformly-spaced points along the unit circle, the chirp Z-transform samples along spiral arcs in the Z-plane, correspon ...
(chirp-Z) *
Frequency-shift keying Frequency-shift keying (FSK) is a frequency modulation scheme in which digital information is transmitted through discrete frequency changes of a carrier signal. The technology is used for communication systems such as telemetry, weather ball ...
(FSK) *
Phase-shift keying Phase-shift keying (PSK) is a digital modulation process which conveys data by changing (modulating) the phase of a constant frequency reference signal (the carrier wave). The modulation is accomplished by varying the sine and cosine inputs at a ...
(PSK)


References


Further reading

*


External links

* {{webarchive , url=https://web.archive.org/web/20180628024641/http://en.dsplib.org/content/goertzel/goertzel.html , title=Goertzel Algorithm
A DSP algorithm for frequency analysis

The Goertzel Algorithm by Kevin Banks
FFT algorithms Digital signal processing