iir filter for loop code

31 views (last 30 days)
Robert Manalo
Robert Manalo on 25 Oct 2021
Commented: Mathieu NOE on 19 Nov 2021 at 10:45
c1 = 8
c2 = 2
c3 = 7
Can you guys help me to find the first seven impulse response of the IIR filter with filter coefficient b0 = 0.05 * c1, b1 = 0.03 * c2, b2 = 0.02 * c3, a1 = 0.5, a2 = 0.5 using for loop code in matlab, this picture may also help
thanks <3

Answers (1)

Mathieu NOE
Mathieu NOE on 25 Oct 2021
helo
here you are
clc
clearvars
c1 = 8;
c2 = 2;
c3 = 7;
b0 = 0.05 * c1;
b1 = 0.03 * c2;
b2 = 0.02 * c3;
a1 = 0.5;
a2 = 0.5;
% manual for loop coding
x = [1; zeros(6,1)];
samples = length(x);
y(1) = b0*x(1) + 0 + 0 + 0 + 0;
y(2) = b0*x(2) + b1*x(1) + 0 + a1*y(1) + 0;
for k = 3:samples
y(k) = b0*x(k) + b1*x(k-1) + b2*x(k-2) + a1*y(k-1) + a2*y(k-2);
end
figure(1)
plot(y)
  10 Comments
Mathieu NOE
Mathieu NOE on 19 Nov 2021 at 10:45
maybe you didn't push the "accept" button...?
all the best

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by