简体   繁体   English

matlab中的步绘图功能

[英]step plot function in matlab

I am trying to plot step responses in MATLAB and cannot figure it out for anything, I have graphed a Bode plot for 3 different k values for the following differential equation in time domain: 我试图在MATLAB中绘制阶跃响应并且无法解决任何问题,我已经为时域中的以下微分方程绘制了3个不同k值的波特图:

d^2y(t)/dt + (v/m)dy(t)/dt + (k/m)y(t) = (k/m)x(t)

in frequency the equation is: 在频率上,等式是:

H(jw)=((k/m))/((〖jw)〗^2+(v/m)(jw)+(k/m) )=k/(m(〖jw)〗^2+v(jw)+k)

the values of k are 1, 0.09, 4 k的值是1,09,4

The equations to solve for v is as follows: 求解v的方程式如下:

v=sqrt(2)*sqrt(k*m) where m=1

I now must do the same for step, but am trying to no avail. 我现在必须做同样的步骤,但我试图无济于事。 Can anyone provide any suggestions? 有人可以提供任何建议吗?

Here is the code for my Bode plot and my attempted but failed step plots: 这是我的Bode情节的代码和我尝试但失败的步骤图:

w=logspace(-2,2,100);

%Creating different vectors based upon K value
%then calculating the frequencey response based upon
%these values

b1=[1];
a1=[1 2^(.5) 1];
H1=freqs(b1,a1,w);
b2=[.09];
a2=[1 (2^.5)*(.09^.5) .09];
H2=freqs(b2,a2,w);
b3=[4];  
a3=[1 2*(2^.5) 4];
H3=freqs(b3,a3,w);

%Ploting frequency response on top plot
%with loglog scale

subplot(2,1,1)
loglog(H1,w,'r')
axis([.04 10 .01 10])
hold on
loglog(H2,w,'g')
loglog(H3,w,'c')
xlabel('Omega')
ylabel('Frequency Response')
title('Bode plot with various K values')
legend('H1, K=1','H2, K=.09','H3, K=4')
hold off

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%creating transfer function, how the functions
%respond in time

h1=tf(b1,a1);
h2=tf(b2,a2);
h3=tf(b3,a3);

t=linspace(0,30);
[y1,t1]=step(h1,t);
[y2,t2]=step(h2,t);
[y3,t3]=step(h3,t);

%Ploting step response on bottom plot
%with respect to time

subplot(2,1,2)
plot(t1,abs(y1),'r')
hold on
plot(t2,abs(y2),'g')
plot(t3,abs(y3),'c')
legend('h1, K=1','h2, K=.09','h3, K=4')
xlabel('time(s)')
ylabel('Amplitude')
title('Step response with various K values')

Have you tried using the step function? 你尝试过使用step功能吗? You already have the coefficients defined in your code above for each of the TFs. 您已经在上面的代码中为每个TF定义了系数。 step takes in a TF object and gives you the step response in the time domain. step接受TF对象并在时域中为您提供步骤响应。

First, take those coefficients and create TF objects. 首先,取这些系数并创建TF对象。 After, run a step response. 之后,运行一步响应。 Using the code you already provided above, do something like this: 使用上面提供的代码,执行以下操作:

b=[1];
a=[1 2^(.5) 1];
% I would personally do: a = [1 sqrt(2) 1];
H1=tf(b, a); % Transfer Function #1
b=[.09];
a=[1 (2^.5)*(.09^.5) .09];
% I would personally do a = [1 sqrt(2*0.09) 0.09];
H2=tf(b, a); % Transfer Function #2
b=[4];  
a=[1 2*(2^.5) 4];
% I would personally do a = [1 2*sqrt(2) 4];
H3=tf(b, a); % Transfer Function #3

% Plot the step responses for all three
% Going from 0 to 5 seconds in intervals of 0.01
[y1,t1] = step(H1, 0:0.01:5);
[y2,t2] = step(H2, 0:0.01:5);
[y3,t3] = step(H3, 0:0.01:5);

% Plot the responses
plot(t1, y1, t1, y2, t3, y3)
legend('H1(s)', 'H2(s)', 'H3(s)');
xlabel('Time (s)');
ylabel('Amplitude');

This is the figure I get: 这是我得到的数字:

SO问题的阶跃响应

FYI, powering anything to the half is the same as sqrt() . 仅供参考,为一半提供动力与sqrt()相同。 You should consider using that instead to make your code less obfuscated. 您应该考虑使用它来减少代码混淆。 Judging from your code, it looks like you are trying to modify the frequency of natural oscillations in each second-order underdamped model you are trying to generate while keeping the damping ratio the same. 从您的代码判断,看起来您正在尝试修改您尝试生成的每个二阶欠阻尼模型中的自然振荡频率,同时保持阻尼比相同。 As you increase k , the system should get faster and the steady-state value should also become larger and closer towards 1 - ensuring that you compensate for the DC gain of course. 当你增加k ,系统应该变得更快并且稳态值也应该变得更大并且更接近1 - 确保你当然补偿DC增益。 (I'm a former instructor on automatic control systems). (我以前是自动控制系统的讲师)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM