0% found this document useful (0 votes)
98 views

4 Goertzel Algorithm For Frequency Detection: University of Applied Sciences Hamburg

The document discusses the Goertzel algorithm for frequency detection. It explains that the Goertzel algorithm can be used to detect the frequencies present in dual-tone multi-frequency (DTMF) signals used for touch-tone dialing. A DTMF decoding system uses bandpass filters and a detector to identify the row and column frequencies present. The Goertzel algorithm performs this detection using a digital Fourier transform approach based on convolving the input with complex exponentials to calculate DFT coefficients and identify the frequencies.

Uploaded by

drashokyvuce
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

4 Goertzel Algorithm For Frequency Detection: University of Applied Sciences Hamburg

The document discusses the Goertzel algorithm for frequency detection. It explains that the Goertzel algorithm can be used to detect the frequencies present in dual-tone multi-frequency (DTMF) signals used for touch-tone dialing. A DTMF decoding system uses bandpass filters and a detector to identify the row and column frequencies present. The Goertzel algorithm performs this detection using a digital Fourier transform approach based on convolving the input with complex exponentials to calculate DFT coefficients and identify the frequencies.

Uploaded by

drashokyvuce
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

university of applied sciences hamburg

DEPARTEMENT OF ELECTRICAL ENGINEERING


Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

4 Goertzel Algorithm for Frequency Detection

· 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.

DSP with FPGAs 4-1

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

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)

DSP with FPGAs 4-2

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

Fig. 4-2: Two sine wave generators for each key. Decoding with a bandpass filter bank and a detector.

DSP with FPGAs 4-3

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

4.1 Basic DFT Equations and DFT Coefficients

· 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.

· Measurement window NT. Evaluation of the spectrum at frequencies fk = k fS /N with distance Δf


= 1/NT. Frequency index or bin k = N fk/fS.

N -1 N -1
X ( k ) = å x ( n )e = å x(n)WNkn , k = 0,1,2,...N - 1
- jkn 2Np

n =0 n =0

DSP with FPGAs 4-4

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

· 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:

yk (n) = x(n) * hk (n)

¥ N -1
yk (n) = å k
x (i
i = -¥
)h ( n - i ) = å N
x (i )W - k ( n -i )

i =0

DSP with FPGAs 4-5

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

· 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:

hk (n) = WN- knu (n)

¥ N -1
H ( z) = å N
W - kn

n = -¥
u ( n) z -n
= å N
(W k
z ) -n

n=0

DSP with FPGAs 4-6

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

· 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)

· Such a transfer function of first order corresponds to a simple difference equation:

yk (n) = WN- k yk (n - 1) + x(n)


-k
· But with a complex coefficient WN we would have to evaluate real and imaginary output signal
components. Therefore it is convenient to enhance the transfer function’s denominator and
nominator with a conjugate complex term in order to provide a denominator with real coeffi-
cients :

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

DSP with FPGAs 4-7

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

· 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):

DSP with FPGAs 4-8

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

Fig. 4-3: Goertzel algorithm represented by a filter block with a decimating output evaluation.

DSP with FPGAs 4-9

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

4.2 Goertzel Filter operates as Decimation Bandpass


· DMTF applications need to evaluate real signals instead of a complex DFT coefficient.
Therefore the power of the output signal y(n=N) will be calculated because its squared values
provide a real magnitude and an appropriate scaling.

· 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

DSP with FPGAs 4-10

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

Pk = Ak2/2 =

2
Pk = 2 Re( X (k )) + Im( X (k ))
2 2

DSP with FPGAs 4-11

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

Fig. 4-4: Estimation of the input signal power based on the Goertzel algorithm.

DSP with FPGAs 4-12

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

% Goertzel filter: decimation bandpass for frequency detection


% A input signal will be generated which consists of two superposed sine waves and
% white noise.
% The sampled output is represented as a stairstep signal.
% The frequency response of the G(z) is generated.
f1=1500; f2=2000; % input frequencies
xa1=0.707; xa2=0.0; % amplitudes
Xrms=0.1; % root mean square of noise
fs=8000; % sample frequency
fk=1500; N=100; M=5; % selected frequency, decimation value, number of cycles
T=1/fs; k=fk*N/fs; % selected frequency bin
% input signal samples
t=0:T:(N*M-1)*T; % sample number range NMT
x=xa1*sin(2*pi*f1*t)+xa2*sin(2*pi*f2*t)+Xrms*randn(1,M*N);
% The randn function generates arrays of random numbers whose elements are normally
% distributed with mean 0 and variance 1.
ts=0; te=N*M*T;% start time, end time
% Goertzel filter initialisation
a=2*cos(2*pi*k/N); % feed back coefficient
WkN=exp(-j*2*pi*k/N); br=real(-WkN); bi=imag(-WkN);
% real and imaginary part of complex coefficient
k2dN=2/N^2;% scaling of output
Pk=zeros(1,M);% initialisation of output power Pk with M zeros

Code 4-1: Evaluation of Goertzel algorithm. Signal power, frequency response.

DSP with FPGAs 4-13

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

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.

DSP with FPGAs 4-14

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

Fig. 4-5: Compare direct form II and transposed form II in order to evaluate the Matlab filter function.
DSP with FPGAs 4-15

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

Signal x, f1= 1500 Hz, xa1= 0.707, f2= 2000 Hz, xa2= 0, Xrms= 0.1, fs= 8000 Hz

0.5

-0.5

0 0.01 0.02 0.03 0.04 0.05 0.06

Output Pk, M= 5, N= 100, fk= 1500 Hz, fs= 8000 Hz

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

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

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).

DSP with FPGAs 4-17

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

Signal x, f1= 1500 Hz, xa1= 0.707, f2= 2000 Hz, xa2= 0.707, Xrms= 0.1, fs= 8000 Hz

-1

0 0.01 0.02 0.03 0.04 0.05 0.06

Output Pk, M= 5, N= 100, fk= 1500 Hz, fs= 8000 Hz


0.3
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-8: Dual tone with superposed noise. Power estimation Pk of test signal xa1.

DSP with FPGAs 4-18

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com


university of applied sciences hamburg
DEPARTEMENT OF ELECTRICAL ENGINEERING
Prof. Dr. B. Schwarz AND COMPUTER SCIENCE

Signal x, f1= 1500 Hz, xa1= 0.707, f2= 1950 Hz, xa2= 0.707, Xrms= 0.1, fs= 8000 Hz

-1

0 0.01 0.02 0.03 0.04 0.05 0.06

Output Pk, M= 5, N= 100, fk= 2000 Hz, fs= 8000 Hz

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

PDF created with FinePrint pdfFactory trial version http://www.fineprint.com

You might also like