Plot step response of transfer function

조회 수: 197 (최근 30일)
Ye Ken Kok
Ye Ken Kok 2022년 11월 4일
편집: Ye Ken Kok 2022년 11월 5일
I am trying to plot the step function of a difference equation. The equation is given by y(n) + 1/4*y(n-1) + 1/2*y(n-2) = x(n) + 1/2*x(n-1). Where x(n) is supposed to be the input and y(n) is the output. The error is as shown:
Is there no way to plot it using the step function?
Code:
num = [1 -1/4 -1/2];
den = [1 1/2];
s = step(num,den);
stem(s);
  댓글 수: 1
Ye Ken Kok
Ye Ken Kok 2022년 11월 4일
Sorry fot not including the input signal for x(n). Here is the input signal.
F1 = 20;
F2 = 40;
F3 = 60;
Fs = 2*F3;
t = 0:0.001:2-0.001;
n = 0:100;
x = 10*sin(2*pi*F1*t)+10*sin(2*pi*F2*t)+10*sin(2*pi*F3*t);
xn = 10*sin(2*pi*(F1/Fs)*n)+10*sin(2*pi*(F2/Fs)*n)+10*sin(2*pi*(F3/Fs)*n);

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

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 11월 4일
hello
you have 2 mistakes to correct
1 - how to get a z transfer function from the difference equation
your num and den are wrong (signs are wrong and you flipped num with den)
this might help
2 - you have a discrete not a continuous time model so use dstep instead of step
num = [0 1 1/2];
den = [1 1/4 1/2];
s = dstep(num,den);
stem(s);
all the best
  댓글 수: 1
Ye Ken Kok
Ye Ken Kok 2022년 11월 5일
편집: Ye Ken Kok 2022년 11월 5일
Thanks for your answer, I managed to solve it with your help

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

추가 답변 (1개)

Sam Chak
Sam Chak 2022년 11월 4일
It is a input-output difference equation. Thus, you cannot use the continuous-time Laplace transform.
Since the input is not provided, here is just a simple example.
dt = 0.001;
t = 0:dt:20; % sample times
ykm1 = 0; % initial value of y(k - 1)
ykm2 = 0; % initial value of y(k - 2)
xkm1 = 0; % initial x(k - 1)
xk = 0; % initial x(k)
Y = []; % placeholder for y(k) array
X = []; % placeholder for x(k) array
for k = 1:length(t)
% input-output difference equation
% y(n) = - 1/4*y(n-1) - 1/2*y(n-2) + x(n) + 1/2*x(n-1)
yk = - 1/4*ykm1 - 1/2*ykm2 + 1*xk + 1/2*xkm1;
ykm2 = ykm1; % when time advances, y(k - 1) becomes y(k - 2)
ykm1 = yk; % when time advances, y(k) becomes y(k - 1)
xkm1 = xk;
xk = sin(.05*pi*t(k));
Y = [Y yk];
end
plot(t, Y, 'linewidth', 1.5), grid on

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by