4 Goertzel Algorithm For Frequency Detection: University of Applied Sciences Hamburg
4 Goertzel Algorithm For Frequency Detection: University of Applied Sciences Hamburg
· Telephone key pads generate Dual-Tone Multi-Frequency (DTMF) signals to dial a telephone
number. When any key is pressed the sinusoids of the corresponding row and column frequencies
are generated (comp. Fig. 4-1) and summed producing dual tones.
· The frequencies in Fig. 4-1 were chosen to avoid harmonics. No frequency is an integer multiple
of another, the difference between any tow frequencies does not equal any of the frequencies.
This makes it easier to detect exactly which tones are present. In some applications the duration
of each tone pair is about 70 ms.
· A DTMF decoding system needs two subsystems: a set of Bandpass filters to isolate individual
frequency components and a detector to determine whether or not a given component is present.
The detector must score each BPF output and determine which two frequencies are most likely to
be contained in the DTMF tone (comp. Fig. 4-2).
· Frequency selection with the Goertzel algorithm based on DFT will be introduced with this chap-
ter.
Fig. 4-1: DTMF encoding table for touch tone dialing. Keys A-D are not implemented on commercial
and household telephone sets, but are used in military and other applications.(TI applic. Note SPRA096)
Fig. 4-2: Two sine wave generators for each key. Decoding with a bandpass filter bank and a detector.
· Starting point is given with definition of the discrete Fourier transform which is discrete in time
and frequency. It uses only a finite length segment NT of the sampled signal x(n) (time window-
ing). It evaluates the spectrum X(k) only at a discrete set of frequencies fk = k fS /N.
N -1 N -1
X ( k ) = å x ( n )e = å x(n)WNkn , k = 0,1,2,...N - 1
- jkn 2Np
n =0 n =0
· Because of WN-kN = 1 = ej2πk = cos2πk + jsin2πk the DFT definition can be enhanced:
N -1 N -1
X (k ) = å x(n)W W kn
N
- kN
N = å x(n)WN- k ( N - n )
n =0 n =0
· The right sum can be understood as a convolution of an input sequence x(n) with the k dependent
impulse response hk(n) of a filter:
¥ N -1
yk (n) = å k
x (i
i = -¥
)h ( n - i ) = å N
x (i )W - k ( n -i )
i =0
· The evaluation with n = N provides the frequency coefficient X(k) which is under investigation:
N -1
yk (n) |n = N = å x(i)WN- k ( N -i ) = X (k )
i =0
· With time domain representation it means, that the convolution has to process N input samples
x(n) and with the Nth output value the DFT coefficient is provided.
· In order to operate with simple difference equations we should step over from the impulse re-
sponse to the transfer function using the definition of the z-transform:
¥ N -1
H ( z) = å N
W - kn
n = -¥
u ( n) z -n
= å N
(W k
z ) -n
n=0
· Because the sum is not very handy in z transformations it will always be substituted with results
of infinite geometric series:
1 Y ( z)
H ( z) = - k -1
=
1 - WN z X ( z)
1 - WN+ k z -1 1 - WN+ k z -1
H ( z) = =
(1 - WN z )(1 - WN z ) 1 - WN+ k z -1 - WN- k z -1 + WN- kWN+ k z - 2
- k -1 + k -1
· The transfer function contains a denominator which is well known from the oscillating sine wave
generators. It operates as a frequency selective bandpass filter.
1 - WN+ k z -1
H ( z) =
1 - 2 cos(2p Nk ) z -1 + z - 2
· The corresponding difference equations are as follows (comp. Fig. 4-3). Whereby the nominator
related equation has to be evaluated only once for each set of N input samples x(n):
Fig. 4-3: Goertzel algorithm represented by a filter block with a decimating output evaluation.
· The power of a sine wave signal is given by : Pk = Ak2/2 ( compare current load of a resistor)
The amplitude Ak of this sine wave has to derived from the DFT coefficient X(k).
We compare a Fourier series expansion with the inverse DFT (IDFT) and exploit similarities.
¥
x(t ) = A0 + å Ak cos(2pkf0t + jk )
k =1
¥
x(t ) = å ck e j 2pkf 0t , ck = 12 (ak - jbk )
k =1
N
1
x(n) =
N
å
k =0
X ( k )e j 2 p kn / N
Pk = Ak2/2 =
2
Pk = 2 Re( X (k )) + Im( X (k ))
2 2
Fig. 4-4: Estimation of the input signal power based on the Goertzel algorithm.
figure(1)
freqz(1,[1 -a 1]);
% Goertzel filter power output: evaluation of difference equation
for l=1:M % IIR transposed form II output with NM input samples
[v,z]=filter(0.004,[1 -a 1],x((l-1)*N+1:l*N));
Pk(l)=k2dN*1*((250*(v(N)+br*(a*v(N)-z(1))))^2+(250*(bi*(a*v(N)-z(1))))^2);
% decimated power output
end
figure(2)
[v,z]=filter(0.004,[1 -a 1],x);
plot(t,v);axis([ts te 1.1*min(v) 1.1*max(v)]), grid
figure(3)
%input x and output Pk stairs plot
subplot(2,1,1),
plot(t,x), axis([ts te 1.1*min(x) 1.1*max(x)]), grid
title(['Signal x, f1= ',num2str(f1),' Hz, xa1= ',num2str(xa1),...
', f2= ',num2str(f2),' Hz, xa2= ',num2str(xa2),...
', Xrms= ',num2str(Xrms),', fs= ',num2str(fs),' Hz'])
tG=0:N*T:M*N*T; % M intervalls with NT width
subplot(2,1,2), stairs(tG,[0 Pk]); % M+1 Pk values
axis([ts te -0.1*max(Pk) 1.1*max(Pk)]), grid
title(['Output Pk, M= ',num2str(M),', N= ',num2str(N),', fk= ',num2str(fk),...
' Hz, fs= ',num2str(fs),' Hz']); xlabel('Time in seconds');
Code 4-2: Goertzel algorithm continued.
Fig. 4-5: Compare direct form II and transposed form II in order to evaluate the Matlab filter function.
DSP with FPGAs 4-15
Signal x, f1= 1500 Hz, xa1= 0.707, f2= 2000 Hz, xa2= 0, Xrms= 0.1, fs= 8000 Hz
0.5
-0.5
0.25
0.2
0.15
0.1
0.05
0
0 0.01 0.02 0.03 0.04 0.05 0.06
Time in seconds
Fig. 4-6: Single tone with superposed noise. Power estimation Pk of test signal xa1.
DSP with FPGAs 4-16
290
0.8
240
Magnitude (dB)
190 0.6
140
0.4
90
40 0.2
-10
0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7
0
Normalized Angular Frequency (´p rads/sample)
-0.2
60
30
Phase (degrees)
-0.4
0
-30 -0.6
-60
-0.8
-90 0 0.01 0.02 0.03 0.04 0.05 0.06
-120
0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7
Normalized Angular Frequency (´p rads/sample)
Fig. 4-7: Frequency selective filter frequency response and output signal v(n).
Signal x, f1= 1500 Hz, xa1= 0.707, f2= 2000 Hz, xa2= 0.707, Xrms= 0.1, fs= 8000 Hz
-1
Fig. 4-8: Dual tone with superposed noise. Power estimation Pk of test signal xa1.
Signal x, f1= 1500 Hz, xa1= 0.707, f2= 1950 Hz, xa2= 0.707, Xrms= 0.1, fs= 8000 Hz
-1
0.06
0.04
0.02
0
0 0.01 0.02 0.03 0.04 0.05 0.06
Time in seconds
Fig. 4-9: Dual tone with superposed noise. Power estimation Pk of test signal xa2 with mismatch.
DSP with FPGAs 4-19