%Example 8-5: Comb filter on tone+periodic interference.
%Goal: Eliminate periodic interference, leaving tone.
f1=30;T=1/60;fs=480;aa=0.95;
fmax=180;n=fmax*T;
N=1:100;%Computation interval
M=[81:100];%Display interval
X=cos(2*pi*f1*N/fs);
%Random periodic interference:
C=rand(1,n);%random amplitudes
for i=1:n;%sinusoid+interference
X=X+C(i)*cos(2*pi*i/T*N/fs);
end;%Compute comb filter:
Z=exp(j*2*pi*[-n:n]'/T/fs);
P=aa*exp(j*2*pi*[-n:n]'/T/fs);
B=poly(Z);A=poly(P);
Y=filter(B,A,X);
subplot(221),stem(M,X(M))
subplot(222),stem(M,Y(M))
%Frequency response of comb:
F=linspace(0,fs/2,10000);
W=exp(j*2*pi*F/fs);
H=polyval(B,W)./polyval(A,W);
subplot(223),plot(F,abs(H))
subplot(224),zplane(B,A)