Hubbry Logo
Goertzel algorithmGoertzel algorithmMain
Open search
Goertzel algorithm
Community hub
Goertzel algorithm
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Goertzel algorithm
Goertzel algorithm
from Wikipedia

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]

The algorithm

[edit]

The main calculation in the Goertzel algorithm has the form of a digital filter, and for this reason the algorithm is often called a Goertzel filter. The filter operates on an input sequence in a cascade of two stages with a parameter , giving the frequency to be analysed, normalised to radians per sample.

The first stage calculates an intermediate sequence, :

The second stage applies the following filter to , producing output sequence :

The first filter stage can be observed to be a second-order IIR filter 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 for are presumed all equal to 0. To establish the initial filter state so that evaluation can begin at sample , the filter states are assigned initial values . To avoid aliasing hazards, frequency is often restricted to the range 0 to π (see Nyquist–Shannon sampling theorem); 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 .

The second-stage filter can be observed to be a FIR filter, since its calculations do not use any of its past outputs.

Z-transform 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 :[citation needed]

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]

DFT computations

[edit]

For the important case of computing a DFT term, the following special restrictions are applied.

  • The filtering terminates at index , where 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 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 , 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:

  • terminate the IIR filter after processing input term ,
  • apply equation (10) to construct from the prior outputs and ,
  • apply equation (2) with the calculated value and with 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 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 pseudocode below, the complex-valued input data is stored in the array x and the variables sprev and sprev2 temporarily store output history from the IIR filter. Nterms is the number of samples in the array, and Kterm corresponds to the frequency of interest, multiplied by the sampling period.

Nterms defined here
Kterm selected here
ω = 2 × π × Kterm / Nterms;
coeff := 2 × cos(ω)

sprev := 0
sprev2 := 0
for each index n in range 0 to Nterms-1 do
    s := x[n] + coeff × sprev - sprev2
    sprev2 := sprev
    sprev := s
end

power := sprev2 + sprev22 - (coeff × sprev × sprev2)

It is possible[10] 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

[edit]

The case of real-valued input data arises frequently, especially in embedded systems where the input streams result from direct measurements of physical processes. 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 , 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

[edit]

This application requires the same evaluation of DFT term , 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

[edit]

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 , and over the sequence of imaginary parts, yielding . After that, the two complex-valued partial results can be recombined:

Computational complexity

[edit]
  • According to computational complexity theory, computing a set of DFT terms using applications of the Goertzel algorithm on a data set with values with a "cost per operation" of has complexity .
To compute a single DFT bin for a complex input sequence of length , the Goertzel algorithm requires multiplications and additions/subtractions within the loop, as well as 4 multiplications and 4 final additions/subtractions, for a total of multiplications and additions/subtractions. This is repeated for each of the frequencies.
  • In contrast, using an FFT on a data set with values has complexity .
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 multiplications and additions/subtractions per DFT bin, for each of the bins.

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 [which?] specialised for transforming real-valued data.

See also

[edit]

References

[edit]

Further reading

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
The Goertzel algorithm is a (DSP) technique for efficiently evaluating individual terms of the (DFT), enabling the detection of specific frequencies within a sampled signal using fewer computational resources than a full DFT or (FFT) when only a single or few frequency bins are needed. Originally proposed by Gerald Goertzel in 1958 as a method for computing finite trigonometric series, it implements a second-order (IIR) filter that recursively processes input samples to yield the magnitude and phase of a targeted DFT . At its core, the algorithm operates by applying a linear time-invariant (LTI) filter with an impulse response tailored to the desired frequency kk, where the DFT output XX is obtained as the filter's response at the end of the input sequence of length NN. This requires approximately N real multiplications and 2N additions in total, plus a few operations for the final complex multiplication, making it computationally superior to the FFT's O(NlogN)O(N \log N) operations for isolated frequency analysis. Unlike the FFT, it does not require the block size NN to be a power of two, offering flexibility in resolution (e.g., 80 Hz at 8 kHz sampling with N=100N = 100). The algorithm's efficiency has made it a staple in real-time applications such as dual-tone multi-frequency (DTMF) signaling for touch-tone telephones, call progress tone detection (e.g., dial or busy signals), and frequency response testing in telecommunications. Optimized variants further reduce complexity by directly computing the squared magnitude, avoiding unnecessary phase calculations for tone presence detection. Its low CPU demands suit embedded systems, where it outperforms FFT-based methods for sparse frequency monitoring.

Introduction

Overview and Purpose

The Goertzel algorithm is a computational technique in that enables the efficient evaluation of individual coefficients in the (DFT) of a discrete-time signal. It operates as a second-order (IIR) filter tuned to a specific , allowing the isolation of a single frequency bin from the input sequence without performing a full spectral analysis. Originally formulated for the evaluation of finite trigonometric series, the algorithm has become a standard method for targeted detection in contexts. The primary purpose of the Goertzel algorithm is to compute one or a small number of DFT coefficients selectively, avoiding the overhead of transforming the entire signal spectrum. This makes it particularly valuable in resource-constrained or real-time environments where only specific frequency components, such as tones in audio signals, need to be analyzed. By leveraging a recursive structure, the algorithm minimizes redundant calculations inherent in broader transforms like the DFT. In operation, the algorithm takes as input a finite-length time-domain sequence xx for n=0,1,,N1n = 0, 1, \dots, N-1, along with a target index kk, and outputs the corresponding complex DFT coefficient X(k)X(k), which represents the signal's and phase at the normalized 2πk/N2\pi k / N. A key benefit is its linear of O(NO(N operations per bin, significantly lower than the O(NlogN)O(N \log N) required by (FFT) algorithms for complete spectra, thus offering substantial savings when full computation is unnecessary.

Historical Background

The Goertzel algorithm was invented by Gerald Goertzel, an American theoretical physicist, in 1958 while affiliated with the . Originally developed in the context of computations, the algorithm provided an efficient method for evaluating finite trigonometric series, which are fundamental in analyzing periodic phenomena. Goertzel detailed the algorithm in his seminal paper, "An Algorithm for the Evaluation of Finite Trigonometric Series," published in . This two-page article outlined a recursive technique requiring approximately N multiplications and 2N additions for an N-term series, offering significant computational savings over direct summation methods prevalent at the time. The work built on the mathematical framework of the (DFT) but optimized it for single-frequency evaluation, reflecting the practical needs of mid-20th-century scientific computing in physics. During the 1970s and 1980s, as (DSP) emerged with the advent of affordable digital hardware, the Goertzel algorithm saw widespread adoption in and audio applications. Its for detecting specific frequencies made it ideal for dual-tone multi-frequency (DTMF) signaling in touch-tone telephones, where it enabled robust tone detection under noisy conditions. Key milestones included its integration into implementations compliant with (ITU) recommendations, such as ITU-T Q.24 for multifrequency signaling systems, which specified performance criteria for DTMF detection that the algorithm effectively met. As of 2025, the Goertzel algorithm remains relevant in resource-constrained environments like embedded systems and (IoT) devices, valued for its minimal and low computational overhead compared to full DFT computations. Its core continues to support targeted in applications ranging from to real-time audio monitoring.

Mathematical Foundation

Relation to Discrete Fourier Transform

The Discrete Fourier Transform (DFT) of a finite-length sequence xx, where n=0,1,,N1n = 0, 1, \dots, N-1, is defined as X(k)=n=0N1xexp(j2πknN)X(k) = \sum_{n=0}^{N-1} x \exp\left(-j \frac{2\pi k n}{N}\right) for frequency indices k=0,1,,N1k = 0, 1, \dots, N-1. This formulation requires N2N^2 complex multiplications to compute all NN coefficients, representing a significant computational burden when only a subset of the is needed. The Goertzel algorithm computes an individual X(k)X(k) by recasting the DFT summation as the response of a tuned to the input sequence, leveraging the periodic nature of the complex exponential exp(j2πkN)\exp\left(-j \frac{2\pi k}{N}\right). This approach exploits the trigonometric identity underlying the DFT, where X(k)X(k) can be separated into real cosine and imaginary sine components, avoiding the full matrix-vector multiplication of the standard DFT. It is particularly suited for partial spectrum analysis, such as isolating a single bin without evaluating the entire transform. The equivalence between the Goertzel algorithm and the DFT bin X(k)X(k) is established by deriving a recursive form of the summation that preserves the exact value for finite NN. Specifically, the algorithm evaluates the polynomial P(z)=n=0N1xznP(z) = \sum_{n=0}^{N-1} x z^{-n} at z=exp(j2πkN)z = \exp\left(j \frac{2\pi k}{N}\right) using nested multiplication (Horner's method), which unfolds to match the DFT sum precisely. This holds under the assumption of basic complex exponential properties and finite summation, ensuring the output aligns with the standard DFT for the selected kk.

Derivation of the Recurrence Relation

The derivation of the recurrence relation for the Goertzel algorithm begins with the expression for a single bin of the discrete Fourier transform (DFT), given by X(k)=n=0N1xej2πkn/N,X(k) = \sum_{n=0}^{N-1} x \, e^{-j 2\pi k n / N}, where xx is the input sequence of length NN, and kk is the frequency index of interest. Using , ejθn=cos(θn)jsin(θn)e^{-j\theta n} = \cos(\theta n) - j \sin(\theta n) with θ=2πk/N\theta = 2\pi k / N, the DFT bin can be separated into its real and imaginary parts: X(k)=n=0N1xcos(θn)jn=0N1xsin(θn).X(k) = \sum_{n=0}^{N-1} x \cos(\theta n) - j \sum_{n=0}^{N-1} x \sin(\theta n). This form highlights the trigonometric series that the algorithm efficiently evaluates. The original algorithm by Goertzel targeted such finite trigonometric sums, and its adaptation to the complex DFT follows similarly by deriving a recursive structure. To obtain the recurrence, consider the DFT as the output of a linear time-invariant filter whose is the complex exponential geometric series h=ejθnh = e^{-j \theta n} for 0n<N0 \leq n < N. The z-transform of this finite is H(z)=n=0N1ejθnzn=1ejθNzN1ejθz1H(z) = \sum_{n=0}^{N-1} e^{-j \theta n} z^{-n} = \frac{1 - e^{-j \theta N} z^{-N}}{1 - e^{-j \theta} z^{-1}}. Since ejθN=1e^{-j \theta N} = 1, this simplifies, but for efficient computation, the Goertzel approach uses an infinite impulse response (IIR) approximation matched to the finite case via boundary adjustments. The denominator 1ejθz11 - e^{-j \theta} z^{-1} corresponds to a first-order recurrence, but to enable real-valued arithmetic, the poles at e±jθe^{\pm j \theta} (conjugates on the unit circle) lead to a second-order characteristic equation z22cos(θ)z+1=0z^2 - 2 \cos(\theta) z + 1 = 0. The corresponding second-order linear difference equation for an auxiliary sequence sns_n is thus sn=x+2cos(θ)sn1sn2,n=0,1,,N1,s_n = x + 2 \cos(\theta) \, s_{n-1} - s_{n-2}, \quad n = 0, 1, \dots, N-1, which arises directly from the real coefficient filter H(z)=1ejθz112cos(θ)z1+z2H(z) = \frac{1 - e^{-j \theta} z^{-1}}{1 - 2 \cos(\theta) z^{-1} + z^{-2}}, where the numerator ensures the finite-length response matches the sum. This equation is obtained by multiplying the first-order complex recurrence sn=x+ejθsn1s_n = x + e^{-j \theta} s_{n-1} by the conjugate factor and combining, leveraging the identity ejθ+ejθ=2cos(θ)e^{-j \theta} + e^{j \theta} = 2 \cos(\theta). The trigonometric recurrence for the cosine and sine components follows from this structure, reducing complex multiplications. The initial conditions are set as s2=0s_{-2} = 0 and s1=0s_{-1} = 0, ensuring the recursion starts with s_0 = x{{grok:render&&&type=render_inline_citation&&&citation_id=0&&&citation_type=wikipedia}}. These zero-state initial conditions align the IIR filter response with the finite DFT sum via the numerator and final adjustment, accounting for the boundary effects in the finite series. After computing the sequence up to n=N1n = N-1, the DFT bin is obtained via the adjustment X(k)=sN1ejθsN2,X(k) = s_{N-1} - e^{-j \theta} s_{N-2}, which incorporates the remaining phase correction from the filter's numerator to yield the exact DFT value. This step resolves the IIR approximation into the precise finite sum, confirming the recurrence's validity for single-bin computation.

Algorithm Implementation

Step-by-Step Procedure

To implement the for computing a single bin of the (), begin with precomputation of the frequency-specific parameters based on the DFT length NN and the target bin index kk. Calculate the angular frequency θ=2πk/N\theta = 2\pi k / N and the recurrence coefficient c=2cos(θ)c = 2 \cos(\theta). Initialize the state variables to zero: set s2=0s_{-2} = 0 and s1=0s_{-1} = 0. This ensures the recursion starts from a neutral state. Process the input sequence xx iteratively for n=0n = 0 to N1N-1. For each sample, compute the next state using the recurrence relation sn=csn1sn2+xs_n = c \cdot s_{n-1} - s_{n-2} + x, then update the previous states by shifting: sn2=sn1s_{n-2} = s_{n-1} and sn1=sns_{n-1} = s_n. This loop requires careful indexing to avoid off-by-one errors, typically implemented with temporary variables for the current and prior states. After the loop, compute the final state sN=csN1sN2s_N = c \cdot s_{N-1} - s_{N-2}. After computing sNs_N, extract the complex DFT coefficient XX from the final states sNs_N and sN1s_{N-1}. The real part is given by Re{X}=sNsN1cos(θ)\operatorname{Re}\{X\} = s_N - s_{N-1} \cos(\theta), and the imaginary part by Im{X}=sN1sin(θ)\operatorname{Im}\{X\} = s_{N-1} \sin(\theta). An alternative non-complex form computes the magnitude squared directly as X2=(sNsN1cos(θ))2+(sN1sin(θ))2|X|^2 = (s_N - s_{N-1} \cos(\theta))^2 + (s_{N-1} \sin(\theta))^2 for applications like tone detection. The following pseudocode illustrates a simple iterative implementation in a code-like structure:

precompute θ = 2 * π * k / N precompute c = 2 * cos(θ) precompute cos_θ = cos(θ) precompute sin_θ = sin(θ) initialize s_prev2 = 0 initialize s_prev1 = 0 for n = 0 to N-1: s_current = c * s_prev1 - s_prev2 + x[n] s_prev2 = s_prev1 s_prev1 = s_current s_N = c * s_prev1 - s_prev2 real_part = s_N - s_prev1 * cos_θ imag_part = s_prev1 * sin_θ

precompute θ = 2 * π * k / N precompute c = 2 * cos(θ) precompute cos_θ = cos(θ) precompute sin_θ = sin(θ) initialize s_prev2 = 0 initialize s_prev1 = 0 for n = 0 to N-1: s_current = c * s_prev1 - s_prev2 + x[n] s_prev2 = s_prev1 s_prev1 = s_current s_N = c * s_prev1 - s_prev2 real_part = s_N - s_prev1 * cos_θ imag_part = s_prev1 * sin_θ

This procedure assumes real-valued input xx and ideal arithmetic; the resulting XX matches the corresponding bin up to scaling conventions in some contexts.

Numerical Stability and Mitigation

The recursive nature of the Goertzel algorithm corresponds to a second-order IIR filter with poles on the unit circle in the z-domain, rendering it marginally stable and susceptible to error accumulation from rounding in finite-precision arithmetic. In fixed-point or low-precision floating-point implementations, these rounding errors propagate through the recurrence relation, causing deviations that grow quadratically with the sequence length N. For long input sequences (N > 1000), the accumulation of such errors can result in significant deviation from the true DFT bin value, potentially exceeding several percent of the correct magnitude in unmitigated 16-bit implementations. Error bounds indicate that relative errors scale approximately as O(N² ε), where ε is the machine precision, leading to practical limitations in high-precision applications. To address these issues, fixed-point implementations commonly employ Q15 or Q31 formats with dynamic scaling to prevent overflow and maintain headroom for intermediate values, ensuring the recursive states remain within the representable range. Alternative formulations, such as the magnitude-squared variant, compute the squared magnitude |X(k)|² directly using real-valued operations on the final states (s[N] and s[N-1]), thereby avoiding complex arithmetic and reducing sensitivity to phase-related rounding errors—particularly useful in applications like DTMF tone detection. For streaming or very long sequences, periodic resetting of the filter states after each block of N samples prevents unbounded error growth, while employing double-precision floating-point arithmetic provides near-full accuracy for critical scenarios. Empirical analyses demonstrate that, with proper scaling in 16-bit fixed-point arithmetic, the algorithm achieves less than 1% deviation from reference DFT values for sequences up to N < 1024, balancing computational efficiency and accuracy in embedded systems.

Efficiency and Comparison

Computational Complexity

The Goertzel algorithm, in its standard second-order form, achieves a time complexity of O(N) for evaluating a single DFT bin from an input sequence of length N, requiring N+2 real multiplications and 2N+1 real additions across the recursive filtering and final complex value computation stages. This linear scaling arises from performing one iteration of the recurrence relation per input sample, followed by a constant-time post-processing step to extract the real and imaginary components of the bin value. In contrast, a full radix-2 FFT demands approximately 2N \log_2 N real multiplications for all N bins, highlighting the Goertzel's efficiency for isolated frequency analysis. The is O(1), independent of N, as the algorithm maintains only two scalar state variables—corresponding to the previous two outputs of the recurrence, s_{n-1} and s_{n-2}—along with a few precomputed constants like the cosine . This minimal makes it particularly suitable for resource-constrained environments, such as embedded systems, where storing intermediate results for an entire FFT (O(N)) would be prohibitive. When extended to M distinct frequencies, the becomes O(M N), as each bin requires a separate pass through the input with its unique , though shared input buffering can mitigate some overhead; this remains advantageous if M \ll N, such as in tone detection applications needing only a handful of bins. On embedded hardware like microcontrollers, benchmarks demonstrate the Goertzel can outperform a full FFT by factors of 10–100 in execution time, depending on N and optimization.

Advantages Over FFT for Single Bins

The Fast Fourier Transform (FFT) computes all N frequency bins of the discrete Fourier transform (DFT), incurring a computational complexity of O(N log N) even when only a single bin is required, which represents an inefficiency for applications needing selective frequency analysis. In contrast, the Goertzel algorithm achieves O(N) complexity for evaluating a single DFT bin, performing N+2 real multiplications and 2N+1 real additions, thereby avoiding unnecessary computations for unused bins. This linear scaling makes Goertzel particularly advantageous in scenarios where computational resources are limited, such as embedded systems. Beyond asymptotic efficiency, the Goertzel algorithm offers practical implementation benefits over the FFT. It eliminates the need for bit-reversal reordering and precomputed twiddle factors, simplifying the and reducing memory overhead, as only a single real-valued is required per . Additionally, Goertzel supports real-time streaming processing without buffering an entire block of N samples, enabling immediate computation upon receipt of each input value, which is ideal for continuous signal monitoring. Unlike the FFT, which typically requires N to be a power of 2 for optimal , Goertzel operates effectively with arbitrary N and allows precise targeting of any between 0 and the sampling rate, enhancing flexibility in non-standard sampling scenarios. These attributes position the Goertzel algorithm favorably for use cases involving fixed or known frequencies on resource-constrained platforms, such as detecting standard tones in telecommunications (e.g., DTMF signaling) or monitoring specific harmonics in low-power sensors. However, its advantages diminish when multiple bins (M) are needed; Goertzel scales as O(MN), becoming less efficient than FFT when M exceeds roughly log₂ N, as the latter leverages parallelism and shared computations across all bins.

Applications

Power Spectrum Estimation

The Goertzel algorithm is particularly suited for power spectrum estimation in real-valued signals, where only the magnitude-squared of specific (DFT) bins is required, such as for detecting energy at targeted without needing phase information. This approach leverages the recursive computation to evaluate the power spectral density at a single bin k, defined by the angle θ = 2πk/N, where N is the number of samples. After executing the core s_n = 2 cos(θ) s_{n-1} - s_{n-2} + x_n for n = 0 to N-1 (with s_{-2} = s_{-1} = 0), the magnitude-squared |X(k)|^2 is obtained directly as (s_N)^2 + (s_{N-1})^2 - 2 s_N s_{N-1} cos(θ). This formula derives from expanding the full complex DFT bin expression while eliminating the imaginary component, as |X(k)|^2 = Re{X(k)}^2 + Im{X(k)}^2, where Re{X(k)} = s_N - s_{N-1} cos(θ) and Im{X(k)} = s_{N-1} sin(θ), simplifying to the real-only form shown. The process avoids explicit computation of the sine term and complex multiplications, making it ideal for applications focused on energy detection, such as identifying signal power levels in noisy environments. By forgoing the square root operation (which would yield the magnitude |X(k)|), further computational savings are achieved when only relative power comparisons are needed. Compared to computing the full complex DFT bin, this power-only variant reduces operations by avoiding the sine precomputation and imaginary part evaluation, resulting in a simpler and faster implementation. This efficiency is pronounced for real-time systems processing sparse spectra, where full FFT computation would be overkill. For instance, in detecting a 941 Hz tone within an 8 kHz sampled signal of N=205 amid additive , the algorithm yields a magnitude-squared value peaking at around 100 million, enabling clear discrimination of the signal from background levels through threshold comparison.

Single DFT Bin Computation

The Goertzel algorithm computes a single complex DFT X(k)X(k), providing both magnitude and phase information essential for phase-sensitive applications in analysis, such as signal filtering or where the full bin value is required. Following the recursive computation of the state variables sns_n for n=0n = 0 to NN, the complex output is derived using only real arithmetic: Re{X(k)}=sNsN1cosθ,Im{X(k)}=sN1sinθ,\text{Re}\{X(k)\} = s_{N} - s_{N-1} \cos \theta, \quad \text{Im}\{X(k)\} = s_{N-1} \sin \theta, where θ=2πk/N\theta = 2\pi k / N. This formulation, rooted in the original recursive evaluation of trigonometric series, ensures the DFT bin matches the direct summation result while avoiding complex operations in the loop. The algorithm operates entirely in real arithmetic during recursion by multiplying inputs and states by the real coefficient 2cosθ2 \cos \theta, with cosθ\cos \theta and sinθ\sin \theta precomputed outside the loop for efficiency. This approach minimizes computational overhead, making it suitable for resource-constrained environments needing the complete complex bin. In spectrum analysis, the full complex X(k)X(k) facilitates tasks like coherent or phase-based feature extraction, extending beyond magnitude-only computations.

Phase Detection in Signals

The Goertzel algorithm computes a complex-valued DFT bin X(k)X(k) consisting of real and imaginary parts, from which the phase angle ϕ\phi of the signal component at frequency kk can be extracted as ϕ=\atan2(\imag(X(k)),(X(k)))\phi = \atan2(\imag(X(k)), \real(X(k))). This phase value represents the angular shift of the sinusoidal component relative to a reference, enabling precise timing analysis in periodic signals. In communications systems, the extracted phase facilitates detecting the onset and offset of tones, such as in dual-tone multi-frequency (DTMF) signaling, where timing ensures accurate decoding. It also measures delays in echoes, as the phase difference between transmitted and received signals at a known directly corresponds to the time shift τ=ϕ/(2πf)\tau = \phi / (2\pi f), aiding in applications like acoustic ranging or network latency assessment. To enhance phase accuracy, windowing functions such as the Hamming window are applied to the input signal prior to Goertzel processing, minimizing that can distort phase estimates in non-stationary or finite-length signals. For noisy environments, averaging phase results across multiple overlapping signal blocks improves robustness, reducing variance in the estimate while preserving computational efficiency. In audio processing, the phase from Goertzel computation supports by quantifying inter-channel phase differences at dominant frequencies, which informs spatial rendering algorithms. Similarly, it aids beat detection by tracking phase evolution over time, allowing to rhythmic components in music signals.

Processing Complex-Valued Signals

The Goertzel algorithm can be extended to complex-valued input sequences, such as those arising in IQ-modulated or signals, by applying the recursive procedure independently to the real and imaginary parts of the input. This leverages the real-valued of the feedback coefficients in the standard , enabling two parallel real-valued Goertzel filters—one for the real component and one for the imaginary component—to compute the corresponding parts of the output. The for each component follows the form sn=2cosθsn1sn2+cn,s_n = 2 \cos \theta \cdot s_{n-1} - s_{n-2} + c_n, where cnc_n is either the real or imaginary part of the complex input xx, θ=2πk/N\theta = 2\pi k / N, and initial conditions s2=s1=0s_{-2} = s_{-1} = 0. After processing all NN samples, the complex DFT bin value is obtained as X(k)=sNejθsN1X(k) = s_N - e^{-j\theta} s_{N-1}, where sNs_N and sN1s_{N-1} are the complex combinations of the parallel filter outputs. An alternative formulation employs complex coefficients directly in the recursion: sn=(2cosθejθ)sn1sn2+x,s_n = \left(2 \cos \theta - e^{j \theta}\right) s_{n-1} - s_{n-2} + x, which computes the full complex state but is often simplified to the parallel real recursions to minimize complex multiplications during the iterative steps. In practice, the parallel approach is preferred for hardware implementations, as it avoids complex arithmetic in the loop while preserving the exact DFT computation. This adaptation is particularly useful in radar systems for processing complex baseband signals from FMCW radars to extract frequency components related to target vital signs or positions, and in wireless communications for efficient demodulation of analytic signals in frequency-hopping schemes. For instance, in multi-person vital sign estimation using radar, the generalized Goertzel processes complex IQ data to isolate narrowband components without full FFT computation. The computational cost approximately doubles compared to the real-valued case due to the two parallel recursions, requiring about 2N real multiplications overall, yet retains O(N complexity per bin. Numerical stability mirrors the real-valued version, with potential accumulation of rounding errors in both components necessitating fixed-point scaling or periodic resets in long sequences.

References

Add your contribution
Related Hubs
User Avatar
No comments yet.