Difference in values of output by manual and code

조회 수: 2 (최근 30일)
prashanth A
prashanth A 2019년 4월 29일
댓글: prashanth A 2019년 4월 30일
I am trying to solve a difference equation with initial conditions using 'filter' function. The manual calculation of y(n) and the one procuced by 'fliter' seems to have some difference. What is the error.
The code is shown below:
disp('Solution of a difference equation:')
% The example difference equation considered is
% y(n) = 0.5y(n-1) + x(n)
num_coef = [ 1 ]; % coefficient of x
den_coef = [1 -0.5]; % coefficient of y
n = 0:4; % Considering five samples
x = 6 * ones(1,5) % x(n) = 6u(n)
init_cond = [1]; % y(-1) = 1
y = filter(num_coef, den_coef, x, init_cond) % Solution returned by 'filter'
yM = 12 - (11/2)*(1/2).^n % Solution obtained manually
plot(y);hold on; % PLots for comparison
plot(yM,'r')
  댓글 수: 2
David Wilson
David Wilson 2019년 4월 29일
I've always had trouble with the intial condition which is where I think your problem lies. Note that Zi (in the help) is the initial delay, not the initial value of the y.
prashanth A
prashanth A 2019년 4월 30일
Do I have to delay the signal? How did you solve it?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by