import numpy as np import matplotlib.pyplot as plt # Define the frequency range for the Bode plot omega = np.logspace(-2, 2, 1000) # Frequency range from 0.01 to 100 rad/s # Define the transfer function parameters T_values = [0.2, 1, 5] # Create subplots fig, (ax_mag, ax_phase) = plt.subplots(2, 1, figsize=(10, 8)) # Plot for each T value for T in T_values: G_mag = 20 * np.log10(1 / np.sqrt(1 + (omega * T)**2)) G_phase = -np.degrees(np.arctan(omega * T)) ax_mag.plot(omega, G_mag, label=f'T = {T}') ax_phase.plot(omega, G_phase, label=f'T = {T}') # Magnitude plot settings ax_mag.set_xscale('log') ax_mag.set_title('Bode Magnitude Plot') ax_mag.set_ylabel('Magnitude (dB)') ax_mag.grid(True) ax_mag.legend() # Phase plot settings ax_phase.set_xscale('log') ax_phase.set_title('Bode Phase Plot') ax_phase.set_ylabel('Phase (degrees)') ax_phase.set_xlabel('Frequency (rad/s)') ax_phase.grid(True) ax_phase.legend() plt.tight_layout() plt.show()