【问题标题】:Plot step response without using step function在不使用阶跃函数的情况下绘制阶跃响应
【发布时间】:2017-01-14 18:00:26
【问题描述】:

我想绘制阶跃响应。我知道我可以将阶跃函数与状态空间方程一起使用,但我尝试使用绘图函数获得相同的结果。这是我的代码示例:

for i=1:201
    u(i) = 1;
    x1(i+1) = (-(b/J)*x1(i) + (K/J)*x2(i));
    x2(i+1) = (-(K/L)*x1(i) - (R/L)*x2(i) + (1/L)*u(i));
    y(i) = x1(i);
end

这是状态空间方程:

A = [-b/J   K/J
    -K/L   -R/L];
B = [0
    1/L];
C = [1   0];
D = 0;

如果我这样做:

t = 0:1:200;
plot(t, y)

它不起作用,我希望得到与下面的 step 函数相同的结果:

sys = ss(A,B,C,D);
step(sys)

你可以找到我的状态空间方程here

【问题讨论】:

    标签: matlab plot response


    【解决方案1】:

    不匹配的原因是sys是一个连续时间模型,而y的计算将其视为一个离散时间系统。

    以下是在离散时间域中估计连续时间系统的阶跃响应的一种方法:

    % Given from the problem statement
    A = [-b/J   K/J
        -K/L   -R/L];
    B = [0
        1/L];
    C = [1   0];
    D = 0;
    
    % this is your continuous-time model
    sys = ss(A,B,C,D);
    
    % define the sample rate of the equivalent discrete-time model
    Ts = 1/10; 
    % this needs to be something smaller than the time-constants in your model,
    % so that you have enough resolution to represent the continuous-time
    % signal.
    
    % convert the system to the equivalent discrete-time model
    sysd = c2d(sys,Ts);
    
    % define how long a step response you'd like to compute
    T = 7; 
    % this should be long enough to cover the length of the step response
    
    
    t = 0:Ts:T; % time-grid for the plot
    nSmp = length(t); % total number of samples to be computed
    
    % initializations
    y = NaN(1, nSmp); % output vector
    u = ones(1, nSmp); % unit step input 
    X = [0; 0]; % state vector, initialized to 0
    
    % compute the samples of the step-response
    %  (i prefer to use vectorized form to keep the code concise)
    for i=1:nSmp
        y(i) = sysd.C * X + sysd.D * u(i);
        X = sysd.A * X + sysd.B * u(i);
    end
    
    % plot continous-time step response
    figure;
    step(sys);
    
    % plot simulated discrete-time step response
    figure;
    plot(t, y, 'r')
    xlabel('Time (s)');
    ylabel('Amplitude');
    title('Simulated Step Response');
    

    【讨论】:

    • 非常感谢,太好了。接下来我需要添加 PID 控制器。你能告诉我如何得到错误、整合错误和导数错误吗?我需要这 3 个值来通过遗传算法生成 PID 参数
    • @Masaj:恐怕我无法正确回答这个问题。您最好将其作为一个新问题发布,以便其他人可以。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多