Anda di halaman 1dari 25

BITS Pilani

Pilani Campus

DSP Lecture 14
RKTiwary
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 Fig. and summed producing dual tones.

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.
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The frequencies in Fig. 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 Fig. next

3
4
The Goertzel Algorithm

think

Given a signal x[n] with corresponding 8-point DFT X[k], what is the
most efficient way, in terms of total multiplications required, to
compute X[5] from x[n]?

using a radix-2 FFT algorithm isnt the best choice:


Computing X[5] requires roughly 8 log 2 8 = 24 complex multiplications

Calculating X[5] =

requires only 8 complex multiplications and is strikingly simple

FFT algorithms may be useful for a wide class of problems, they are by
no means the most efficient choice in all situations.
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The Goertzel Algorithm

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Specifically, processing a signal x[n] through an LTI filter with
impulse response h[n] = WNnku[n] and evaluating the result,
yk[n], at n = N will give the corresponding N-point DFT
coefficient X[k] = yk[N].
This LTI filtering process is illustrated below.

Representing the filter by its z-transform, we have

H(z)=

the filtering operation can be equivalently performed by the system

7
Instead of performing the computation of the DFT as in via
convolution. we can use the difference equation corresponding to the
filter given by to compute yk(n) recursively, Thus we have

But with a complex coefficient WN -k we would have to evaluate real


and imaginary output signal components. Therefore it is convenient
to enhance the transfer functions denominator and nominator with
a conjugate complex term in order to provide a denominator with
real coefficients :

8
The transfer function contains a denominator which is well
known from the oscillating sine wave generators. It operates
as a frequency selective bandpass filter.

The corresponding difference equations are as follows Fig.


Whereby the nominator related equation has to be evaluated
only once for each set of N input samples x(n):

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Matlab Implementation

% 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);

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


% 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

11
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

12
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');

13
DFT Estimation with the Goertzel Algorithm

This example shows how to use the Goertzel function to


implement a DFT-based DTMF detection algorithm.

Dual-tone Multi-Frequency (DTMF) signaling is the basis for


voice communications control and is widely used worldwide in
modern telephony to dial numbers and configure switchboards.

It is also used in systems such as in voice mail, electronic mail


and telephone banking.

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Generating DTMF Tones
A DTMF signal consists of the sum of two sinusoids - or tones -
with frequencies taken from two mutually exclusive groups.

These frequencies were chosen to prevent any harmonics from


being incorrectly detected by the receiver as some other DTMF
frequency.
Each pair of tones contains one frequency of the low group
(697 Hz, 770 Hz, 852 Hz, 941 Hz) and one frequency of the
high group (1209 Hz, 1336 Hz, 1477Hz) and represents a
unique symbol.
The frequencies allocated to the push-buttons of the telephone
pad are shown below:

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


1209 Hz 1336 Hz 1477 Hz
_ _ _ _ _ _ _ _ _ _
| | | |
| | ABC | DEF |
697 Hz | 1 | 2 | 3 |
|_ _ _ |_ _ _|_ _ _|
| | | |
| GHI | JKL | MNO |
770 Hz | 4 | 5 | 6 |
|_ _ _ |_ _ _|_ _ _|
| | | |
| PRS | TUV | WXY |
852 Hz | 7 | 8 | 9 |
|_ _ _ |_ _ _|_ _ _|
| | | |
| | | |
941 Hz | * | 0 | # |
16
|_ _ _ |_ _ _|_ _ _|
BITS Pilani

dspdtmf
Generate and plot a DTMF signal for each button on the telephone
pad. Each signal has a sample rate of 8 Khz and a duration of 100ms

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


% Dual tone multifrequency tone detection
clf;
d = input('type in the telephone digit= ', 's');
symbol = abs(d);
tm = [49 50 51 65;52 53 54 66; 55 56 57 67; 42
48 35 68];
for p = 1:4;
for q= 1:4;
if tm(p,q)==abs(d); break,end
end
if tm(p,q)==abs(d); break,end
end
f1= [697 770 852 941];
f2 = [1209 1336 1477 1633];
n= 0:204;
x= sin (2*pi*n*f1(p)/8000)+ sin
(2*pi*n*f2(q)/8000);
19
k =[ 18 20 22 24 31 34 38 42];
val = zeros(1,8);
for m= 1:8;
Fx(m) = gfft (x, 205, k(m));
end

val = abs(Fx);
stem (k,val); grid; xlabel('k');
ylabel('|X[K]|');
limit= 80;
for s= 5:8;
if val(s)> limit, break, end
end
for r= 1:4;
if val(r)> limit, break, end
end
disp(['Touch-tone symbol = ',setstr(tm(r,s-
4))])
20
Compute and display the magnitude response of the third-order
IIR lowpass filter described by the following transfer function:

Express the numerator and denominator as polynomial


convolutions. Find the frequency response at 2001 points
spanning the complete unit circle.

21
Plot the magnitude response expressed in decibels.

b0 = 0.05634; b1 = [1 1]; b2 = [1 -1.0166 1];


a1 = [1 -0.683]; a2 = [1 -1.4461 0.7957];
b = b0*conv(b1,b2); a = conv(a1,a2);
[h,w] = freqz(b,a,'whole',2001);

plot(w/pi,20*log10(abs(h)))
ax = gca;
ax.YLim = [-100 20];
ax.XTick = 0:.5:2;
xlabel('Normalized Frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Design an FIR lowpass filter of order 80 using a Kaiser window
with =8 . Specify a normalized cutoff frequency of
rad/sample.
Display the magnitude and phase responses of the filter.

b = fir1(80,0.5,kaiser(81,8));
freqz(b,1)

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Design an FIR bandpass filter with passband between and
rad/sample and 3 dB of ripple.
The first stopband goes from 0 to rad/sample
and has an attenuation of 40 dB.
The second stopband goes from 0.9 rad/sample to the
Nyquist frequency and has an attenuation of 30 dB.
Compute the frequency response.
Plot its magnitude in both linear units and decibels.
Highlight the passband.

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


sf1 = 0.1; pf1 = 0.35; pf2 = 0.8; sf2 = 0.9;
pb = linspace(pf1,pf2,1e3)*pi;
bp = designfilt('bandpassfir', ... 'StopbandAttenuation1',40,
'StopbandFrequency1', sf1,...
'PassbandFrequency1',pf1,'PassbandRipple',3,'PassbandFrequency2',pf2, ...
'StopbandFrequency2',sf2,'StopbandAttenuation2',30);
[h,w] = freqz(bp,1024);
hpb = freqz(bp,pb);
subplot(2,1,1)
plot(w/pi,abs(h),pb/pi,abs(hpb),'.-')
axis([0 1 -1 2])
legend('Response','Passband','Location','South')
ylabel('Magnitude')
subplot(2,1,2)
plot(w/pi,db(h),pb/pi,db(hpb),'.-')
axis([0 1 -60 10])
xlabel('Normalized Frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')

25

Anda mungkin juga menyukai