IIR FIlter code using for loop
2 views (last 30 days)
Show older comments

In relation to this problem, I have made a code but was rejected because the answer my code gave was very far from it. Can you guys correct what's wrong with the code.
function y=IIR_Filter(b,a,x)
c=[4 8 1 2 3];
b0=0.05*c(4);
b1=0.03*c(3);
b2=0.02*c(2);
b=[b0 b1 b2];
a=[0.5 0.5];
x=[1 0 0 0 0 0 0];
N=length(a)-1;
M=length(b)-1;
y=zeros(1,length(x));
for n=1:length(x)
y1=0;
for k=1:N
if n-k>=1
y1=y1+a(k+1)*y(n-k);
end
end
y2=0;
for k=0:M
if n-k>=1
y2=y2+b(k+1)*x(n-k);
end
end
y(n)=-y1+y2;
end
0 Comments
Answers (0)
See Also
Categories
Find more on Digital Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!