Goertzel Algorithm Generalized To Non-Integer Mult
Goertzel Algorithm Generalized To Non-Integer Mult
net/publication/257879807
CITATIONS READS
30 725
2 authors, including:
Pavel Rajmic
Brno University of Technology
50 PUBLICATIONS 144 CITATIONS
SEE PROFILE
All content following this page was uploaded by Pavel Rajmic on 22 May 2015.
Abstract
The article deals with the Goertzel algorithm, used to establish the modulus and phase of harmonic components
of a signal. The advantages of the Goertzel approach over the DFT and the FFT in cases of a few harmonics of
interest are highlighted, with the article providing deeper and more accurate analysis than can be found in the
literature, including the memory complexity. But the main emphasis is placed on the generalization of the Goertzel
algorithm, which allows us to use it also for frequencies which are not integer multiples of the fundamental
frequency. Such an algorithm is derived at the cost of negligibly increasing the computational and memory
complexity.
Keywords: Goertzel algorithm, generalization, spectrum, DFT, DTFT, DTMF
© 2012 Sysel and Rajmic; licensee Springer. This is an Open Access article distributed under the terms of the Creative Commons
Attribution License (http://creativecommons.org/licenses/by/2.0), which permits unrestricted use, distribution, and reproduction in
any medium, provided the original work is properly cited.
Sysel and Rajmic EURASIP Journal on Advances in Signal Processing 2012, 2012:56 Page 2 of 8
http://asp.eurasipjournals.com/content/2012/1/56
in [4,1], but just for the computation of the modulus, phase of a component at an arbitrary (even non-integer)
not the phase of a harmonic component. frequency. The number of operations and memory
requirements increases only negligibly with this
1.1 Example of utilization of Goertzel algorithm—DTMF approach.
The Goertzel algorithm is typically used for frequency
detection in the telephone tone dialing (dual-tone multi- 1.2 Notation
frequency, DTMF), where the meaning of the signaling In the following text, we assume a discrete signal x of
is determined by two out of a total of eight frequencies length N, whose samples can be complex, {x[n]} = {x[0],
being simultaneously present [5]. The frequencies of x[1],..., x[N - 1]}. Symbol k represents the number
each of the two groups of four signaling tones were cho- (index) of the harmonic component in the DFT, thus k
sen such that the frequencies of their higher harmonics Î N. However, in the later parts of the text, we will
or intermodulation products were sufficiently distant. work also with k Î ℝ. The unit step signal is denoted
The frequencies chosen for the DTFM have a big least by {u[n]}, whilst u[n] = 1 for n ≥ 0, u[n] = 0 for n < 0.
common multiple. Hence, using a digital receiver with a
sampling frequency of 8 kHz, the period of DTMF sig- 2 Standard Goertzel algorithm
nal amounts to several tens of thousands of samples. In 2.1 Derivation of standard Goertzel algorithm
practice, however, the transform length N must be The algorithm invented by Goertzel [7] serves to com-
much smaller, so naturally the effect of spectrum leak- pute the kth DFT component of the signal {x[n]} of
age will appear. For example, with N = 205, instead of length N, i.e.,
the accurate frequency 770 Hz the modulus at approxi-
mately 780.5 Hz (= 20·8000/205) is computed. This
N−1
n
X[k] = x[n]e−j2π k N , k = 0, . . . , N − 1. (1)
situation is illustrated in Figure 1, where it is evident
n=0
that the maximum occurs at the non-integer multiple of
the fundamental frequency. Multiplying the right side of this equation by
The value N = 205 is often used in practice [6], N
because one of the local minima of the sum of squared 1 = ej2π k N leads to its equivalent
relative deviations of the signaling frequencies is experi- N
N−1
n
enced precisely for this length. In this situation, the X[k] = ej2π k N x[n]e−j2π k N , (2)
deviation is approximately equal to 1.4%, while the n=0
transmitter frequency tolerance is 1.8%. Nevertheless, in
which can be rearranged into
some applications of the Goertzel algorithm the devia-
tion from the exact frequency can exceed a prescribed n−N
N−1
−j2π k
tolerance, and thus both the DFT and the Goertzel algo- X[k] = x[n]e N . (3)
rithm would be of little use. n=0
Using the approach presented in this article it is not
necessary to round the frequencies at which detection is The right side of (3) can be understood as a discrete
desired; it is possible to determine the modulus and linear convolution of signals {x[n]} and {hk[n]}, provided
frequency [Hz]
700 720 740 760 780 800 820 840 860 880
100
80
module
60
time [s] 40
0 0.005 0.01 0.015 0.02 0.025
20
1.5
0
17.5 18 18.5 19 19.5 20 20.5 21 21.5 22 22.5 23
1 harmonics
frequency [Hz]
0.5 700 720 740 760 780 800 820 840 860 880
3
0
2
í0.5
1
phase
0
í1
í1
í1.5
í2
Figure 1 The picture at the top shows the sum of two harmonic signals with frequencies 770 and 1477 Hz. It is 205 samples obtained
with fs = 8000 Hz. The bottom picture shows the spectrum of the signal: the DFT coefficients (1) are depicted with black fill, the red ones are
the values of DTFT for a non-integer mesh of frequencies (22).
Sysel and Rajmic EURASIP Journal on Advances in Signal Processing 2012, 2012:56 Page 3 of 8
http://asp.eurasipjournals.com/content/2012/1/56
that the elements of the latter signal are defined by This first order difference equation contains a com-
plex multiplication factor, which is computationally
hk [] = e j2π k N
u[]. In fact, if {yk[n]} denotes the result of
demanding. To save the computational cost, the trans-
such a convolution, then it holds for its entries:
mission function can be extended in both the numerator
∞
and the denominator by the conjugate of
yk [m] = x[n]hk [m − n], (4) 2π k
n=−∞ (1 − ej N z−1 ), which leads to
which can be viewed as a geometric series with the x[n] s[n] yk [n]
ies is convergent and its sum equals the desired transfer −e−j
2π k
N
function: 2π k
2 cos s[n − 1]
N
1
Hk (z) = 2π k
. (11) z−1
1− ej N z−1
The corresponding difference equation is s[n − 2]
−1
2π k Figure 2 Signal flow graph of second order Goertzel system
yk [n] = x[n] + ej N yk [n − 1], with yk [−1] = 0. (12)
with indicated state variables.
Sysel and Rajmic EURASIP Journal on Advances in Signal Processing 2012, 2012:56 Page 4 of 8
http://asp.eurasipjournals.com/content/2012/1/56
zero). Only in the last step is the output yk[N] calculated algorithm does not need any reordering of input or
according to (17) using only a single complex multiplica- output data in the bit-reverse order [1].
tion. As mentioned earlier, the value in y k [N] is the - Finally, as will be shown later in the article, the
desired spectral coefficient X[k]. modulus and phase can be established also for the
The Goertzel algorithm can hence be considered as an non-integral spectral indexes k, raising the computa-
IIR filtering process, while only a single output sample tional effort only negligibly. Therefore the Goertzel
is of interest. The algorithm is presented step by step in algorithm is convenient in cases when, for some rea-
Figure 3. son, it is required to detect harmonic signals of non-
integral frequencies, or, signals with a limited num-
2.2 Comparison of Goertzel algorithm and FFT ber of samples which causes a decrease of the DFT
2.2.1 Properties frequency resolution.
The Goertzel algorithm in fact performs the computa-
tion of a single DFT coefficient. Compared to the DFT, 2.2.2 Computational and memory complexities
it has several advantages, because of which it is used. In the following analysis, operations which can be per-
formed before the first data sample has been received are
- First of all, the Goertzel algorithm is advantageous not considered. Specifically, the constants A, B, C in Figure
in situations when only values of a few spectral com- 3 can be precomputed. The memory performance is
ponents are required (as in the DTMF example in handled in a minimalist scenario, i.e., such that it would
Section 1.1), not the whole spectrum. In such a case not be possible to implement the algorithm with fewer sto-
the algorithm can be significantly faster. rage locations.
- The efficiency of using the FFT algorithm for the The FFT algorithm used with N being a power of two
computation of DFT components is strongly deter- has computational demands proportional to N log2 N, the
mined by the signal length N. The most effective absolute number depends on the particular implementa-
case is when N is a power of two. On the contrary, tion. Usually the number of real-number operations found
N can be arbitrary in the case of the Goertzel algo- in the literature is approximately 6N log2 N (taking one
rithm, and the computational complexity does not complex multiplication as a combination of four multipli-
vary. cations and two summations). When working with real
- The computation can be initiated at an arbitrary signals, a number of operations can be avoided; however,
moment, even at the very time of the arrival of the it is at the cost of increased complexity of the algorithm,
very first input sample; it is not necessary to wait for and, it is not true that the demands can be reduced by
the whole data block as in the case of the FFT. Thus, half, as can be read, for example in [9]. For this reason, we
the Goertzel algorithm can be less demanding from consider the standard “complex” FFT even for real signals.
the viewpoint of the memory capacity and it can per- If we analyze the number of operations of the stan-
form at a very low latency. Also, the Goertzel dard Goertzel algorithm, we realize that for a real input
signal, N real multiplications and 2N real additions are For each considered frequency, the Goertzel algorithm
performed in the main loop. So the total number of requires: locations for saving two state variables, the real
operations is approximately 3N for a single frequency; constant B, the real and imaginary parts of the precom-
we omit the small number of operations needed for pre- puted C, and the real and imaginary parts of the final
2π k result. There is no need to implement input buffering,
computing B = 2 cos 2π N
k
, C = e−j N and the conclud- because the computation can be run as the new signal
ing complex multiplication (one for each frequency k). samples arrive. Similarly, the output signal can be over-
Thus, if N frequencies were of interest, the Goertzel algo- written after the last sample has arrived. In many cases
rithm would be of quadratic complexity as the DFT is. it will therefore not be necessary to use buffering at the
To answer the question “for how many frequencies K output side either. The total memory complexity of the
is it more advantageous to exploit the Goertzel algo- Goertzel algorithm is thus 7K positions.
rithm than the FFT” we compare Combining all the above together, the Goertzel algo-
rithm will be less memory-demanding than the FFT if
3NK < 6Nlog2 N
(18) 7K < 4N
K < 2log2 N,
4 (19)
which represents a more accurate result than for K < N.
7
example [[8], p. 635], where the sharper inequality K <
log 2 N, based solely on a comparison of the order of A comparison of (19) and (18) leads to the conclusion
magnitude, is presented. Such a result, however, holds that, if we look for a number K for which the Goertzel
only for N being a power of two; otherwise the inequal- algorithm dominates over the FFT from both the mem-
ity (18) can even be more favorable for the Goertzel ory and the computational viewpoints, then: for N ≥ 13
algorithm. formula (18) is decisive, because for these N it holds
The formula (18) says that the computation should be 7 N > 2log2 N;
4 on the other hand, for N Î {2,..., 12}
faster than the FFT as long as the number of frequen- (which is unusual in practice), the decisive formula is
cies does not exceed 2 log2 N. For example, with a sig- (19), because for these N it holds 47 N > 2log2 N; never-
nal of length N = 32 the Goertzel algorithm is
theless, as the difference of the right and the left sides
preferable if K ≤ 9. In the case of N = 128 Goertzel
does not exceed 2 in this case, we can conclude, with a
dominates over the FFT if K ≤ 13.
small loss of generality, that the comparison of the
In fact, the algorithm introduced in [3] can be even
effectiveness of the two algorithms can be based just on
more efficient than this. It combines the good properties
relation (18).
of both the FFT and the Goertzel algorithm, producing a
DFT decomposition similar to the one used in the split-
3 Generalized Goertzel algorithm
radix FFT. The dominance of the algorithm of Sorensen
Formula (2) holds for integer-valued k only. In such a
and Burrus over the FFT is guaranteed even for K <N/2.
case, the integer number of periods of the transforma-
An experimental comparison of this approach with the n
Goertzel algorithm showed that the Goertzel algorithm tion kernel, e−j2π k N , corresponds to the signal length
performs actually better than their algorithm when K ≤ 4 N. In the case of k Î ℝ, formulas (1) and (2) are gener-
or K ≤ 5 for a wide range of N. It should be noticed, how- ally no longer in agreement. (The period of the transfor-
ever, that the algorithm from [3] has to work with a whole mation kernel no longer corresponds to N, hence the
data block, and also the complexity being compared does standard approach cannot be used.)
not include rearrangement of the input data sequence. In Sections 3.1 and 3.2, we will generalize the algo-
Using the FFT algorithm requires a memory space of rithm such that it includes also the non-integral-valued
at least 2N, which contains the real and imaginary parts multiples of the fundamental frequency. The complexity
of signal samples. Also the N values of the transforma- of the novel approach is analyzed in Section 3.3. And, as
tion kernel, sin and cos (so-called twiddle factors), are shown in Section 3.4, the non-integer case can be trea-
often precomputed and stored. The FFT calculation ted by the standard algorithm using a small trick; how-
itself can be performed with no values being moved in ever, this is at the cost of increased computational
memory (i.e., in-place), however, with regard to the effort.
impossibility of starting the computation until the last
sample of a block of data is received, a buffer of at least 3.1 Generalizing to non-integer k
2N in size must be used. In the case of real signals, N In fact, when k is not integer-valued, we can no longer
memory locations are enough. Thus, the overall FFT speak of the DFT (1), rather of the discrete-time Fourier
memory demand is 4N for real signals. transform (DTFT), which is defined by
Sysel and Rajmic EURASIP Journal on Advances in Signal Processing 2012, 2012:56 Page 6 of 8
http://asp.eurasipjournals.com/content/2012/1/56
∞
the interest in the modules of the components with
X(ω) = x[n]e−jωn , ω ∈ R. (20) non-integer k can be satisfied using the standard algo-
n=−∞ rithm. Indeed, for example [4] uses it in this way. In
cases when the phase plays a role (the delay of a signal
With the notation ωk = 2π Nk we can write that
is detected, for example), however, the use of this “cor-
∞
n
rection constant” is necessary. A short remark can be
X(ωk ) = x[n]e−j2π k N (21) found in [[1], p. 531], describing the possiblility of com-
n=−∞ puting the Goertzel results also for non-integer-valued
k; however, it misleads the reader in that the phase case
N−1
n
is not distinguished at all.
= x[n]e−j2π k N , k, ωk ∈ R, (22)
n=0 3.2 Reducing number of iterations
It will be shown in this section that the last iteration of
where we exploited the compactness of the support of
the Goertzel algorithm can be substituted by merely a
the signal {x[n]}.
single complex multiplication, instead of performing it
The derivation of the generalized Goertzel algorithm
in the usual manner.
is analog to the technique presented in Section 2. Com-
From equation (5) we can express
pared to that, however, we extend formula (22) at the
very beginning by unity in the form of n−N
N−1
−j2π k
yk [N] = x[n]e N u[N − n]
N N
ej2π k N · e−j2π k N = 1 for k ∈ R, (23) n=0
(28)
n−N
leading to
N−1
−j2π k
= x[n]e N
N N
N−1
n
n=0
X(ωk ) = ej2π k N · e−j2π k N x[n]e−j2π k N (24)
and also
n=0
n − (N − 1)
N−1
−j2π k
N−n yk [N − 1] = x[n]e N u[(N − 1) − n]
N
N−1
j2π k
= e−j2π k N x[n]e N (25) n=0
(29)
n−N
n=0
N−1
−j2π k 1
= x[n]e N e−j2π k N .
n=0
N−n
N−1
j2π k
−j2π k N . (26) A comparison of (28) and (29) leads to the formula
=e x[n]e
n=0 which characterizes the relationship between the last
two samples of the convolution:
Since the sum in (26) is identical to (3), the derivation
of the generalized algorithm can proceed using the same k
yk [N] = yk [N − 1] · e+j2π N . (30)
steps as in Section 2.1, with one noteworthy change: the
equation that characterizes the output using state vari- This means that the very last iteration of the tradi-
ables (17) will now be of the form tional Goertzel algorithm can be replaced by a simple
multiplication by ej2π Nk . Relation (30) holds for yk[N]
2π k
−j N
yk [n] = s[n] − e s[n − 1] · e−j2π k . (27)
and yk[N-1] due to the limited support of x[n]. Nothing
similar, however, holds for samples yk[N-1] and yk[N-2],
Indeed this is so, since the “correction constant”, e- due to the term u[·].
j2πk
, depends only on the index of the frequency compo-
Combining ej2π Nk and the phase correction constant
nent, which remains constant throughout the computa-
tion. The complex constant is equal to one for k Î Z, for non-integer k (see (27)) results in the overall con-
which shows that this is indeed a generalization. In fact, stant
the only variation compared to the standard Goertzel 2π k 2π k
algorithm is the multiplication by this constant at the D = e−j2π k · e+j N = e−j N (N−1) . (31)
very end of the algorithm.
This way the shortened generalized algorithm is
The constant e-j2πk affects only the phase of the result,
obtained, as is summarized in Figure 4.
not the module. Among other things, this means that
Sysel and Rajmic EURASIP Journal on Advances in Signal Processing 2012, 2012:56 Page 7 of 8
http://asp.eurasipjournals.com/content/2012/1/56
3.3 Computational and memory complexities the last iteration and it is possible to start processing the
The computational complexity of the generalized Goert- input sample x[N] in the time spared.
zel algorithm described in Section 3.1 (without the
shortening in Section 3.2) grows by one complex multi- 3.4 Yet another approach utilizing standard Goertzel
plication (i.e., four real multiplications and two real algorithm
additions) compared to the traditional approach. The It will be shown that, by a trick, the computation
memory requirements increase by two positions, which required for k Î ℝ can be transformed into integer-
contain the real and imaginary parts of the correction valued problem, where the standard Goertzel algorithm
constant e-j2πk. can be utilized—so no modifications are needed. How-
Although saving one iteration in the main loop accord- ever, it is at the cost of raising the computational com-
ing to Section 3.2 results in lowering the computational plexity, which is even greater than with the generalized
effort by two additions and one multiplication, the need Goertzel algorithm (Figure 4).
for the final complex multiplication cancels such a bene- Starting from (22) again, the k Î ℝ can be divided
fit. This means: there is no advantage in shortening the into its integer part ⌊k⌋ Î Z and the remainder
main loop in case of integer-valued k; in such a case the k ∈ [0, 1), i.e., k = k + k̂. This way, (22) can be rewrit-
traditional algorithm as defined in Section 2 is the most ten as
efficient one.
However, in the case of non-integer-valued k the itera-
N−1
n n
tion reduction does make sense, since joining the correc- X(ωk ) = x[n]e−j2π k̂ N e−j2π k N . (32)
tion constants into a single one (31) leads to the overall n=0
growth of computation complexity by three real multipli- If we denote the signal created by multiplying ele-
cations (it would be four real multiplications and two real n
additions if the reduction was not exploited.) Considering mentwise {x[n]} and {e−j2π k̂ N } by {x̂[n]}, the previous
the memory, such a case requires two more positions for relation can be written in the form of
the real and imaginary parts of (31), compared to the stan-
dard algorithm.
N−1
n
X(ωk ) = x̂[n]e−j2π k N , (33)
It is evident that the computational and memory com- n=0
plexities of the generalized case are only negligibly
greater. The main advantage of shortening the loop whose right side is a usual DFT of signal x̂ (which is
according to Section 3.2 can be seen in that, for example, complex!) and thus can be computed by the standard
in continuous operation, it is not necessary to perform Goertzel algorithm.
Sysel and Rajmic EURASIP Journal on Advances in Signal Processing 2012, 2012:56 Page 8 of 8
http://asp.eurasipjournals.com/content/2012/1/56
5 Conclusion
The article presented the generalization of the Goertzel
algorithm. The novel approach allows us to employ also
the non-integer-valued multiples of the fundamental fre-
quency, making it possible to compute the Fourier
transform in discrete-time (DTFT) this way. The main
advantage consists in that in various applications where
the Goertzel algorithm is utilized, it is no longer neces-
sary to round the frequencies of desire, thus obtaining
more accurate results. The article shows that this is
reached at the cost of only a negligible rise in computa-
tional and memory complexities. Furthermore, it has
been shown that the very last iteration of the algorithm
can be substituted with a multiplication which is little
more effective. Submit your manuscript to a
journal and benefit from:
Acknowledgements 7 Convenient online submission
This work was supported by projects of the Czech Ministry of Education, 7 Rigorous peer review
Youth and Sports MSM0021630513, the Czech Ministry of Industry and Trade
FR-TI2/220, and the Czech Science Foundation 102/09/1846. 7 Immediate publication on acceptance
7 Open access: articles freely available online
Competing interests 7 High visibility within the field
The authors declare that they have no competing interests. 7 Retaining the copyright to your article
Received: 10 May 2011 Accepted: 6 March 2012
Published: 6 March 2012 Submit your next manuscript at 7 springeropen.com