Since matlab and C have somewhat similarities I was wondering if you guys could help me. We have this problem in our class and I am having difficulty fully understanding the code:
The equations inside the for loop and their coefficients are already a part of the question.
%Implementing IIR Direct Form II Filter
w = 2*pi*1600;
f_s = 8000; %the sampling rate for the system
T = 1/f_s; % period
f = @(x)cos(w*T*(x-1));
%the coefficient for the first system
b0_1 = 0.292893;
b1_1 = 0.585786;
b2_1 = 0.292893;
a1_1 = 0.91018;
a2_1 = 0.414213;
%the coefficient for the second system
b0_2 = 1;
b1_2 = -2;
b2_2 = 1;
a1_2 = -0.91018;
a2_2 = 0.414214;
%calculate initial conditions for y1
y1(1) = b0_1*f(0) + b1_1*f(-1) + b2_1*f(-2);
y1(2) = b0_1*f(1) + b1_1*f(0) + b2_1*f(-1) - a1_1*y1(1);
for m = 3:100
y1(m) = b0_1*f(m) + b1_1*f(m-1) + b2_1*f(m-2) - a1_1*y1(m-1) - a2_1*y1(m-2);
%initial conditions for y2
y2(1) = b0_2*y1(1);
y2(2) = b0_2*y1(2) + b1_2*y1(1) - a1_2*y2(1);
for p = 3:100
y2(p) = b0_2*y1(p) + b1_2*y1(p-1) + b2_2*y1(p-2) - a1_2*y2(p-1) - a2_2*y2(p-2);
I don't understand what the initial conditions are doing?
This code is correct since it is given to us.
The basic problem is:
Let the input be x[n] = cos(wnT). Let w = 2pi× 1600. Write a MATLAB program to compute the output y[n].