IIR Filter for loop Code
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Robert Manalo
el 11 de Oct. de 2021
Comentada: Mathieu NOE
el 12 de Oct. de 2021
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
0 comentarios
Respuesta aceptada
Mathieu NOE
el 11 de Oct. de 2021
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 comentarios
Mathieu NOE
el 12 de Oct. de 2021
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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Digital Filter Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!