Question

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:

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

The equations to solve for v is as follows:

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:

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')
Was it helpful?

Solution

Have you tried using the step function? You already have the coefficients defined in your code above for each of the TFs. step takes in a TF object and gives you the step response in the time domain.

First, take those coefficients and create TF objects. 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:

Step Response of SO Question

FYI, powering anything to the half is the same as 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. (I'm a former instructor on automatic control systems).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top