MATLAB: Kindly verify the code of DTMF decoding step

dtmf

I want to decode DTMF tones by using FIR Filter. The filters that are required to be used in filter bank are cnstructed by Sinusoidal impulse response of the form h[n]= (2/L)cos(2*pi*fb*n/fs) where 0<n<L
L is filter length fb defines the freq location of passband e.g we can pick 697Hz
the book says to generate bandpass filter for 770 Hz component with L=50 and fs=12000. This has to be done by creating a vector of filter co-efficients ,h770 which are determined by evaluatiing above stated equation. plot the filter coefficients using stem().
I have done it in this way. Is it ok
h=[];
L=50;
fs=12000;
fb=770;
for n=1:L
h(n)=(2/L)*cos(2*pi*fb*n/fs);
end
stem(h)

Best Answer

Hi, Notice how Walter has indexed the for loop from 0, but was careful to index the vector h from 1.
h=[];
L=50;
fs=12000;
fb=770;
for n=0:L
h(n+1)=(2/L)*cos(2*pi*fb*n/fs);
end
stem(h)
So that it is legal MATLAB indexing, however, I would say to avoid the for loop entirely. This is cleaner MATLAB.
L=50;
fs=12000;
fb=770;
% if you really want 0<n<L
h = (2/L)*cos(2*pi*fb*(1:L-1)/fs);
stem(h);