FCS Assignment
FCS Assignment
Date: 04.05.2025
Contents:
Code:
import matplotlib.pyplot as plt
import numpy as np
T1, y1 = step_response(sys1, T)
T2, y2 = step_response(sys2, T)
T3, y3 = step_response(sys3, T)
plt.xlabel('Time (seconds)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.legend()
plt.show()
Output:
Result:
Hence the Output was obtained.
| Second Order System Step
Ex. 2
Code:
import numpy as np
# Time vector
systems = [
labels = [
plt.figure(figsize=(10, 6))
plt.xlabel('Amplitude')
plt.ylabel('Time (seconds)')
plt.legend()
plt.grid(True)
plt.show()
Output:
Result:
Hence the Output was obtained.
Ex. 3 | Pole-Zero Map - Python Script
Code:
import matplotlib.pyplot as plt
wn = 1
K=1
T1 = 0
T2 = 0.5
T3 = 1
T4 = 5
plt.figure(figsize=(8, 12))
plt.subplot(4, 1, 1)
pzmap(sys1, title='Pole-Zero Map: T1=0')
plt.subplot(4, 1, 2)
plt.subplot(4, 1, 3)
plt.subplot(4, 1, 4)
plt.tight_layout()
plt.show()
Output:
Result:
Hence the Output was obtained.
| Root Locus Plot - Python
Ex. 4
Script
Code:
import matplotlib.pyplot as plt
plt.show()
Output:
Result:
Hence the Output was obtained.
Ex. 5 | Bode Plot - Python Script
Code:
import numpy as np
titles = [
]
# Create figure with gridspec for nested subplots
row = idx // 2
col = idx % 2
mag_ax = fig.add_subplot(subgs[0])
phase_ax = fig.add_subplot(subgs[1])
# Calculate margins
bode_plot(
sys,
dB=True,
plot_magnitude=True,
plot_phase=True,
omega_limits=(1e-2, 1e3),
display_margins=True,
margins_method='best',
title=title,
# Annotate margins
if not np.isinf(gm):
gm_db = 20 * np.log10(gm)
color='r', ha='center')
if not np.isnan(pm):
color='b', ha='center')
plt.tight_layout()
plt.show()
Output:
Result:
Hence the Output was obtained.
| Design of State Feedback -
Ex. 6
Python Script
Code:
import numpy as np
# System matrices
A = np.array([[0, 1, 0],
[0, 0, 1],
# Check controllability
U = ctrb(A, B)
if np.linalg.matrix_rank(U) != A.shape[0]:
K = place(A, B, desired_poles)
# Closed-loop system
A_cl = A - B @ K
sys_cl = ss(A_cl, B, C, D)
# Plot results
plt.figure(figsize=(10, 6))
plt.grid(True)
plt.legend()
plt.show()
print(K)
Output:
Result:
Hence the Output was obtained.
| Design of State Observer -
Ex. 7
Python Script
Code:
import numpy as np
Rs = 0.47
Lq = 1.23e-3
B = 0.0002
Kb = 0.42
Kt = 0.73
J = 6.5e-4
A = np.array([[-B/J, Kt/J],
[-Kb/Lq, -Rs/Lq]])
B = np.array([[0],
[1/Lq]])
C = np.array([[1, 0]])
D = np.array([[0]])
open_sys = ctrl.ss(A, B, C, D)
wr = 3 # reference omega, ω
Gr = ctrl.tf([nr], dr)
cp = ctrl.poles(Gr)
K = ctrl.acker(A, B, cp)
sys = ctrl.ss(A - B @ K, B, C, D)
Nbar = 1 / ctrl.dcgain(sys)
or_val = 10 * np.real(cp[0])
op = [or_val + 1, or_val - 1]
[np.zeros_like(A), A - L @ C]])
Dco = 0
plt.figure()
plt.grid(True)
t = np.linspace(0, 2, 500)
plt.xlabel('Time (s)')
plt.ylabel('Output')
plt.legend()
plt.show()
Output:
Result:
Hence the Output is obtained.