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

답변 (1개)

Mathieu NOE
Mathieu NOE 2021년 10월 25일

0 개 추천

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

Robert Manalo
Robert Manalo 2021년 10월 25일
Hello mate, thank you for this <3 but how can i get the answer? Im running the code but the output is just the graph. My prof is not accepting it. lol
Mathieu NOE
Mathieu NOE 2021년 10월 25일
the output is y
you can see the values if you type y in the workspace
Robert Manalo
Robert Manalo 2021년 10월 25일
i got it bro. thanks <3
Robert Manalo
Robert Manalo 2021년 10월 28일
Good day mate! Can i asked you about the code the you gave me before? This one really help me and i answer was correct but can you please help me to make it as a function in matlab?
hello
see bleow
c1 = 8;
c2 = 2;
c3 = 7;
b0 = 0.05 * c1;
b1 = 0.03 * c2;
b2 = 0.02 * c3;
a1 = 0.5;
a2 = 0.5;
%% filter numerator / denominator in vector form
B = [b0 b1 b2];
A = [1 a1 a2];
%% manual for loop coding
x = [1; zeros(6,1)];
y = myfilter(x,B,A);
figure(1)
plot(y)
%%%%%%%%%%%%%%%%%%%
function y = myfilter(x,B,A)
samples = length(x);
b0 = B(1);
b1 = B(2);
b2 = B(3);
a1 = A(2);
a2 = A(3);
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
end
Kennedy Allen Aday
Kennedy Allen Aday 2021년 10월 28일
got it bro! <3 thank you so much
Mathieu NOE
Mathieu NOE 2021년 10월 28일
do you accept my answer this time ?
tx
Robert Manalo
Robert Manalo 2021년 10월 30일
yes bro tnx!
Johnny Dela Vega
Johnny Dela Vega 2021년 10월 31일
@Mathieu NOE Hey, can I ask you one question? I have a code for the same problem but was rejected. Can you tell me what is wrong with my 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
Mathieu NOE
Mathieu NOE 2021년 11월 19일
maybe you didn't push the "accept" button...?
all the best

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Install Products에 대해 자세히 알아보기

질문:

2021년 10월 25일

댓글:

2021년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by