% FIR Filter examples
%
close all;clear
N = 128; n = [0:N-1].';
fpass=.08 % e.g. 80/1000
fstop=.16 % e.g. 160/1000
rpass = 1
rstop = 30

f = [fpass fstop]
amp = [1 0]
devpass = 10.^(rpass/20)-1;
devstop = 10.^(-rstop/20);
dev = [devpass devstop]

[nOrd,wn,beta,type]=kaiserord(f,amp,dev,1)
w = kaiser(nOrd+1,beta);
b=fir1(nOrd,wn,type,w) % or b=fir1(nOrd,wn,type,w,'noscale')
figure;freqz(b,1,N,1)
nOrd
b1 = b;
a1 = 1;

h = filter(b,1,[1;zeros(N-1,1)]);
figure
subplot(2,1,1);stem(n,h);axis tight
subplot(2,1,2);stem(n(1:nOrd+1),h(1:nOrd+1));axis tight

[nOrd,f0,a0,w]=firpmord(f,amp,dev,1)
b = firpm(nOrd,f0,a0,w)
figure;freqz(b,1,N,1)
nOrd
b2 = b;
a2 = 1;

h = filter(b,1,[1;zeros(N-1,1)]);
figure
subplot(2,1,1);stem(n,h);axis tight
subplot(2,1,2);stem(n(1:nOrd+1),h(1:nOrd+1));axis tight


[nOrd,wn]=ellipord(fpass*2,fstop*2,rpass,rstop)
[b,a]=ellip(nOrd,rpass,rstop,wn)
figure;freqz(b,a,N,1)
h = filter(b,a,[1;zeros(N-1,1)]);
figure
subplot(2,1,1);stem(n,h);axis tight
b3 = b;
a3 = a;

fvtool(b1,a1,b2,a2,b3,a3)

fdatool
