32 lines
842 B
Python
32 lines
842 B
Python
# Requires 'control' package:
|
|
# pip install control
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
import control as ctrl
|
|
|
|
def nyquist_diagram(T):
|
|
# Define the numerator and denominator of the transfer function
|
|
numerator = [1] # Numerator of the transfer function
|
|
den1 = [1, 1, 1] # First part of the denominator
|
|
den2 = [T, 1] # Second part of the denominator
|
|
|
|
# Convolve the two denominator parts
|
|
denominator = np.convolve(den1, den2)
|
|
|
|
# Create the transfer function
|
|
system = ctrl.TransferFunction(numerator, denominator)
|
|
|
|
# Generate the Nyquist plot
|
|
ctrl.nyquist_plot(system)
|
|
|
|
# Enhance plot appearance
|
|
plt.title('Nyquist Diagram')
|
|
plt.xlabel('Real')
|
|
plt.ylabel('Imaginary')
|
|
plt.grid(True)
|
|
plt.show()
|
|
|
|
# Example usage
|
|
T = 1 # Time constant
|
|
nyquist_diagram(T)
|
|
|