0% found this document useful (0 votes)
21 views

Simulation (1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Simulation (1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Question 1

--> delta = 0.1; // Define damping ratio δ

--> s = poly(0, 's'); // Define the transfer function G(s) = 1 / (s^2 + 2*δ*s + 36)

--> P = 1/(s^2+2*delta*s+36) // Our function

P = [rational] of s

1
-------------
36 +0.2s +s^2

--> P = syslin('c',P) // Continuous-time system

P = [rational] of s

1
-------------
36 +0.2s +s^2

--> t = 0:0.1:50; // Time vector

--> u = ones(t); // step input of size t


--> y = csim(u, t, P); // for simulating the time response of a system based on a defined input
signal

--> subplot(2, 1, 1);

--> plot(t, y);

delta = 0.1; // Define damping ratio δ

--> s = poly(0, 's'); // Define the transfer function G(s) = 1 / (s^2 + 2*δ*s + 36)

--> P = 1/(s^2+2*delta*s+36) // Our function

P = [rational] of s

1
-------------
36 +0.2s +s^2

--> P = syslin('c',P) // Continuous-time system

P = [rational] of s

1
-------------
36 +0.2s +s^2

--> t = 0:0.1:50; // Time vector

--> u = ones(t); // step input of size t

--> y = csim(u, t, P); // for simulating the time response of a system based on a defined input
signal

--> subplot(2, 1, 1);

--> plot(t, y);

--> // Closed-loop transfer function T(s) = G(s) / (1 + G(s))

--> H = 1; // Unity feedback

--> T = P / (1 + P *H); // Closed-loop transfer function


-->

--> y2 = csim(u, t, T);

--> subplot(2, 1, 2);

--> plot(t, y2);

--> title("Step Response of the Plant – Closed Loop");

--> xlabel("Time (s)");

--> ylabel("Amplitude");

Question 2
s = poly(0, 's');

--> // Define the damping ratio

--> zeta1 = 0.9;

--> zeta2 = 6;

--> zeta3 = 20;

--> // Define the transfer functions for each case

--> H1 = 1 / (s^2 + 2*zeta1*s + 36);

--> H2 = 1 / (s^2 + 2*zeta2*s + 36);

--> H3 = 1 / (s^2 + 2*zeta3*s + 36);

--> // Create the continuous-time systems

--> sys1 = syslin('c', H1);

--> sys2 = syslin('c', H2);

--> sys3 = syslin('c', H3);


--> // Define the time vector (0 to 20 seconds)

--> t = 0:0.1:20;

--> // Define the step input (vector of ones)

--> u = ones(t);

--> // Simulate the responses of each system

--> y1 = csim(u, t, sys1);

--> y2 = csim(u, t, sys2);

--> y3 = csim(u, t, sys3);

--> // Plot the responses

--> plot(t, y1, 'r', t, y2, 'g', t, y3, 'b');

--> legend('z1', 'z2', 'z3');

--> xlabel('Time (s)');

--> ylabel('Output');

--> title('Step Response for a Second-Order System');

Question 6
f=logspace(-5,2,1000);
w=2*%pi*f; // convert to rad/s
Pmag=zeros(1,1000);
Pph=zeros(1,1000);
for k=1:1000, // compute P(jw) at each frequency point
P=1/(-10*w(k)^2+0.1*%i*w(k));
[Pmag(k),Pph(k)]=polar(P);
end
Pmag = 20*log10(Pmag); // convert Pmag to dB
Pph = (180/%pi)*Pph; // convert Pph to degree
figure(2)
subplot(211),plot2d("ln",f,Pmag); // magnitude plot
xlabel("Frequency (Hz)");
ylabel("Magnitude");
subplot(212),plot2d("ln",f,Pph); // phase plot
xlabel("Frequency (Hz)");
ylabel("Phase (degree)");

You might also like