% Short demo script to show Parks McClellan algorithm
% This version compares effect of N for HP and LP filters

% Parameters:
% 	N - size of FIR filter *** MUST BE ODD FOR PLOTS TO WORK OUT! ***

% Last revised 11/8/99 - rms



% Show log plot, too


% Show magnitude in dB, for LP filters
for N = 21:1:31,

F = [0 .4 .5 1];
A = [1 1 0 0];

b = remez(N-1,F,A);

n = -(N-1)/2 : (N-1)/2;
w = 0:pi/100:pi;
[H] = dtft(b,n,w);

plot(w/pi,20*log10(abs(H)),'r')
hold on
plot(F(1:2),20*log10(A(1:2)))
hold off
xlabel('\omega/\pi','fontsize',14)
ylabel('|X(e^j^\omega)|','fontsize',14)
ylabel('Magnitude in dB','fontsize',14)
axis([0 1 -60 10])
iN = num2str(N);
title(['Equiripple Filter, N = ',iN],'fontsize',14)
pause
end


% Repeat, but for HP filters
for N = 21:31,

F = [0 .5 .6 1];
A = [0 0 1 1];

b = remez(N-1,F,A);

n = -(N-1)/2 : (N-1)/2;
w = 0:pi/100:pi;
[H] = dtft(b,n,w);

plot(w/pi,20*log10(abs(H)),'r')
hold on
plot(F(3:4),20*log10(A(3:4)))
hold off
xlabel('\omega/\pi','fontsize',14)
ylabel('|X(e^j^\omega)|','fontsize',14)
ylabel('Magnitude in dB','fontsize',14)
axis([0 1 -60 10])
iN = num2str(N);
title(['Equiripple Filter, N = ',iN],'fontsize',14)
pause
end



% And again for BP filters
for N = 21:31,

F = [0 .4 .5 .6 .7 1];
A = [0 0 1 1 0 0];

b = remez(N-1,F,A);

n = -(N-1)/2 : (N-1)/2;
w = 0:pi/100:pi;
[H] = dtft(b,n,w);

plot(w/pi,20*log10(abs(H)),'r')
hold on
plot(F(3:4),20*log10(A(3:4)))
hold off
xlabel('\omega/\pi','fontsize',14)
ylabel('|X(e^j^\omega)|','fontsize',14)
ylabel('Magnitude in dB','fontsize',14)
axis([0 1 -60 10])
iN = num2str(N);
title(['Equiripple Filter, N = ',iN],'fontsize',14)
pause
end



% And once again for bandstop filters
for N = 21:31,

F = [0 .4 .5 .6 .7 1];
A = [1 1 0 0 1 1];

b = remez(N-1,F,A);

n = -(N-1)/2 : (N-1)/2;
w = 0:pi/100:pi;
[H] = dtft(b,n,w);

plot(w/pi,20*log10(abs(H)),'r')
hold on
plot(F(3:4),20*log10(A(3:4)))
hold off
xlabel('\omega/\pi','fontsize',14)
ylabel('|X(e^j^\omega)|','fontsize',14)
ylabel('Magnitude in dB','fontsize',14)
axis([0 1 -60 10])
iN = num2str(N);
title(['Equiripple Filter, N = ',iN],'fontsize',14)
pause
end
