IIR Filter for loop Code

5 ビュー (過去 30 日間)
Robert Manalo
Robert Manalo 2021 年 10 月 11 日
コメント済み: Mathieu NOE 2021 年 10 月 12 日
Can anyone help to code this one using for loop code?
the given filter coefficient
b0 = 0.05
b1 = 0.03
b2 = 0.02
a1 = 0.5
a2 = 0.5

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 10 月 11 日
hello
if you want to simply plot the bode diagram :
Fs = 1000; % assumed for now ...sampling frequency
b0 = 0.05
b1 = 0.03
b2 = 0.02
a1 = 0.5
a2 = 0.5
numd = [b0 b1 b2];
dend = [1 a1 a2];
dbode(numd,dend,1/Fs);
  5 件のコメント
Robert Manalo
Robert Manalo 2021 年 10 月 12 日
thank you mate for this one but what i need is the iir filter using "for loop" code and not about the plotting can you still help me?
Mathieu NOE
Mathieu NOE 2021 年 10 月 12 日
sure
here you are .
BTW I noticed I made a sign error in the beginning :
dend = [1 -a1 -a2]; % instead of dend = [1 a1 a2];
code updated - see at the end the demo of for loop coding
you can see the 3 methods do show the same result (fortunately !)
clc
clearvars
b0 = 0.05;
b1 = 0.03;
b2 = 0.02;
a1 = 0.5;
a2 = 0.5;
numd = [b0 b1 b2];
dend = [1 -a1 -a2];
x = [1 0 0 0 0 0 0 0 0 0 0 0 0 0]; % looks like you're looking for the impulse response ?
y = filter(numd,dend,x);
figure(1)
plot(y)
% the same impulse response can be obtainde by
figure(2)
dimpulse(numd,dend);
% manual for loop coding
x = [1 0 0 0 0 0 0 0 0 0 0 0 0 0];
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(3)
plot(y)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by