【问题标题】:How to simulate a system output with a sine wave input?如何用正弦波输入模拟系统输出?
【发布时间】:2021-02-02 22:45:27
【问题描述】:

我希望模拟我拥有的某个齿轮系统的输出。齿轮系统的外观对这个问题并不特别重要,我设法从机械系统中得到所需的微分方程。 这是我的代码

% parameters
N2  = 90;
N1  = 36;
Jn1 = 0.5;
Jn2 = 0.8;
J2  = 2;
D   = 8;
K   = 5;
J   = (N2/N1)^2 * Jn1 + Jn2 + J2;

% define the system
sys = ss([0 1; -K/J -D/J], [0; N2/(N1*J)], [1 0], 0);

% initial state: (position, velocity) [rad; rad/s]
x0 = [0; 0];

% define the time span
t = linspace(0, 15, 10000)';

% define the input step
T1 = zeros(length(t), 1);
T1(t>=0) = 1;

% compute the system step response at once
theta1 = lsim(sys, T1, t, x0);

% compute the system response as aggregate of the forced and unforced
% temporal evolutions
theta2 = lsim(sys, T1, t, [0; 0]) + initial(sys, x0, t);

% plot results
figure('color', 'white');
hold on;
yyaxis left;
plot(t, T1, '-.', 'linewidth', 2);
ylabel('[N]');
yyaxis right;
plot(t, theta1, 'linewidth', 3);
plot(t, theta2, 'k--');
xlabel('t [s]');
ylabel('[rad]');
grid minor;
legend({'$T_1$', '$\theta_1$', '$\theta_2$'}, 'Interpreter', 'latex',...
       'location', 'southeast');
hold off;

这应该可以生成一个图表,显示位置,我的输出,用于 ​​Heaviside/step 输入。我的问题是,我将如何为正弦波输入执行此操作。我想我应该有sin(w*t) 而不是(t>=0),其中 w 是我的脉冲频率。不过,我似乎无法完成这项工作。任何帮助将非常感激! :)

【问题讨论】:

  • 我从未使用过lsim,但是将T1 定义为正弦波而不是阶跃函数就足够了吗?例如,T1 = sin(2*pi*f*t + phi),其中f 是所需频率,phi 是初始相位
  • lsim 实际上是一个易于使用的命令,基本上您可以在 MATLAB 下使用任意数量的输入和时间来模拟系统。这是一个有用的链接mathworks.com/help/control/ref/lti.lsim.html另外,是的;将T1 定义为正弦波而不是阶跃函数就足够了,但由于某种原因,它对我不起作用。我建议您使用我的代码并实施您的解决方案,给我一些反馈。我在 R2018b 上运行我的代码
  • “它不适合我”是什么意思?你有错误吗?输出错了吗?

标签: matlab trigonometry simulink control-theory


【解决方案1】:

这是我的问题的解决方案:)

function x = integrate(t, u, x0)
    % parameters
    N2  = 90;
    N1  = 36;
    Jn1 = 0.5;
    Jn2 = 0.8;
    J2  = 2;
    D   = 8;
    K   = 5;
    J   = (N2/N1)^2 * Jn1 + Jn2 + J2;

    % integrate the differential equation
    [t, x] = ode23(@fun, t, x0);

    % plot results
    figure('color', 'white');
    
    % plot position
    yyaxis left;
    plot(t, x(:, 1));
    ylabel('$x$ [rad]', 'Interpreter', 'latex');
    
    % plot velocity
    yyaxis right;
    plot(t, x(:, 2));
    ylabel('$\dot{x}$ [rad/s]', 'Interpreter', 'latex');
    
    grid minor;
    xlabel('$t$ [s]', 'Interpreter', 'latex');

    function g = fun(t, x)
        g = zeros(2, 1);
        g(1) = x(2);
        g(2) = (-K/J)*x(1) + (-D/J)*x(2) + (N2/(N1*J)*u(t));
    end
end

现在我们可以使用匿名函数,例如:

t = linspace(0, 120, 10000)';
x0 = [0.1; 0];
x = integrate(t, @(t)(sin(1.5*t)), x0);

【讨论】:

    【解决方案2】:

    试运行

    这些是我目前在 MATLAB R2019b 上得到的输出结果。正如 Luis' 评论所建议的那样,我还将正弦曲线声明为 T1 作为输入。目前不确定这个结果是否是预期的输出。

    代码片段:

    t = linspace(0, 15, 10000)';
    f = 0.1; 
    phi = 0; 
    T1 = sin(2*pi*f*t + phi);
    

    f → 正弦输入的频率(本例中为 0.1Hz)。
    phi → 正弦输入/初始相位的相位偏移(本例中为 0)。
    t → 时间向量指示正弦曲线的样本。
    0 → 开始时间(本例中为 0 秒)。
    15 → 结束时间(本例中为 15 秒)。
    10000 → 数量在开始时间 (0s) 和结束时间 (15s) 之间采样。


    脚本实现:

    % parameters
    N2  = 90;
    N1  = 36;
    Jn1 = 0.5;
    Jn2 = 0.8;
    J2  = 2;
    D   = 8;
    K   = 5;
    J   = (N2/N1)^2 * Jn1 + Jn2 + J2;
    
    % define the system
    sys = ss([0 1; -K/J -D/J], [0; N2/(N1*J)], [1 0], 0);
    
    % initial state: (position, velocity) [rad; rad/s]
    x0 = [0; 0];
    
    % define the time span
    t = linspace(0, 15, 10000)';
    
    % define the input step
    T1 = zeros(length(t), 1);
    T1(t>=0) = 1;
    
    f = 0.1; %Sinusoid frequency = 0.1Hz%
    phi = 0; %Phase = 0%
    T1 = sin(2*pi*f*t + phi);
    
    % compute the system step response at once
    theta1 = lsim(sys, T1, t, x0);
    
    % compute the system response as aggregate of the forced and unforced
    % temporal evolutions
    theta2 = lsim(sys, T1, t, [0; 0]) + initial(sys, x0, t);
    
    % plot results
    figure('color', 'white');
    hold on;
    yyaxis left;
    plot(t, T1, '-.', 'linewidth', 2);
    ylabel('[N]');
    yyaxis right;
    plot(t, theta1, 'linewidth', 3);
    plot(t, theta2, 'k--');
    xlabel('t [s]');
    ylabel('[rad]');
    grid minor;
    legend({'$T_1$', '$\theta_1$', '$\theta_2$'}, 'Interpreter', 'latex',...
           'location', 'southeast');
    hold off;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-08
      • 1970-01-01
      • 2013-02-11
      • 2023-04-06
      • 2015-04-15
      • 1970-01-01
      相关资源
      最近更新 更多