<jupyter_start><jupyter_text>Bode and Polar Plots<jupyter_code>import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style

style.use("classic")

%config InlineBackend.figure_format = 'retina'
%matplotlib inline<jupyter_output><empty_output><jupyter_text>First order system$$G(s) = \frac{1}{\tau s + 1}$$ Second order system$$G(s) = \frac{1}{\tau^2 s^2 + 2 \tau \xi s + 1}$$where $\xi$ is the dampening constant.* $\xi < 1$ : Under-damped system* $\xi = 1$ : Critically damped system* $\xi > 1$ : Over-damped system<jupyter_code>tau = 1.33
omega = np.linspace(0.01, 100, 100000)<jupyter_output><empty_output><jupyter_text>Bode plots  First order system<jupyter_code>AR_by_Kp = 1 / np.sqrt(1 + (omega * tau) ** 2)
phi = np.arctan(-omega * tau)


plt.figure(facecolor='white')
plt.grid()
plt.loglog(omega, AR_by_Kp, color='black', linewidth=1.2)
plt.xlabel(r"$\omega$", fontsize=16)
plt.ylabel(r"$\frac{A.R.}{K_p}$", fontsize=16)

plt.figure(facecolor='white')
plt.grid()
plt.semilogx(omega, phi, color='black', linewidth=1.2)
plt.xlabel(r"$\omega$", fontsize=16)
plt.ylabel(r"$\phi = \arctan(-\omega \tau)$", fontsize=16);<jupyter_output><empty_output><jupyter_text>Second order system<jupyter_code>def SecOrderAR_by_Kp(xi):
    return 1 / np.sqrt((1 - (omega * tau) ** 2) ** 2 + (2 * omega * tau * xi) ** 2)


def SecOrderPhi(xi):
    return -np.pi / 2 - np.arctan(-(1 - (omega * tau) ** 2) / (2 * omega * tau * xi))


plt.figure(facecolor='white')
plt.grid()
plt.loglog(omega, SecOrderAR_by_Kp(0.10), color='r', linewidth=1.2, label=r'$\xi = 0.1$')
plt.loglog(omega, SecOrderAR_by_Kp(0.50), color='g', linewidth=1.2, label=r'$\xi = 0.5$')
plt.loglog(omega, SecOrderAR_by_Kp(1.00), color='b', linewidth=1.2, label=r'$\xi = 1$')
plt.loglog(omega, SecOrderAR_by_Kp(2.00), color='k', linewidth=1.2, label=r'$\xi = 2$')
plt.xlabel(r"$\omega$", fontsize=16)
plt.ylabel(r"$\frac{A.R.}{K_p} = \frac{1}{\sqrt{(1 - \omega^2 \tau^2)^2 + (2 \omega \tau \xi)^2}}$", fontsize=16)
plt.legend(loc='best', fontsize=8)

plt.figure(facecolor='white')
plt.grid()
plt.semilogx(omega, 180 * SecOrderPhi(0.10) / np.pi, color='r', linewidth=1.2, label=r'$\xi = 0.1$')
plt.semilogx(omega, 180 * SecOrderPhi(0.50) / np.pi, color='g', linewidth=1.2, label=r'$\xi = 0.5$')
plt.semilogx(omega, 180 * SecOrderPhi(1.00) / np.pi, color='b', linewidth=1.2, label=r'$\xi = 1$')
plt.semilogx(omega, 180 * SecOrderPhi(2.00) / np.pi, color='k', linewidth=1.2, label=r'$\xi = 2$')
plt.xlabel(r"$\omega$", fontsize=16)
plt.ylabel(r"$\phi= \arctan(\frac{-2 \omega \tau \xi}{1 - \omega^2 \tau^2})$", fontsize=16)
plt.legend(loc='best', fontsize=8);<jupyter_output><empty_output><jupyter_text>Polar plots  First order system$$G(j \omega) = \frac{1}{j \tau \omega + 1} = re^{i\phi}$$<jupyter_code>plt.figure(facecolor='white', figsize=(7, 7))
plt.polar(phi, AR_by_Kp, 'b');<jupyter_output><empty_output><jupyter_text>Second order system<jupyter_code>plt.figure(facecolor='white', figsize=(9, 7))
plt.polar(SecOrderPhi(0.5), SecOrderAR_by_Kp(0.5), 'r', label=r'$\xi=0.5$')
plt.polar(SecOrderPhi(1.0), SecOrderAR_by_Kp(1.0), 'g', label=r'$\xi=1.0$')
plt.polar(SecOrderPhi(1.5), SecOrderAR_by_Kp(1.5), 'b', label=r'$\xi=1.5$')
plt.polar(SecOrderPhi(2.0), SecOrderAR_by_Kp(2.0), 'k', label=r'$\xi=2.0$')
plt.legend(loc='best', bbox_to_anchor=[1.15, 1], fontsize=8);<jupyter_output><empty_output><jupyter_text>First order sytem  with dead time$$G(s) = \frac{1}{\tau s + 1} - \frac{K e^{-\tau_d s}}{\tau s + 1}$$where $\tau_d$ is the dead time constant.<jupyter_code>K = 1
taud = 1

phi1phi2 = -omega * taud + phi

plt.figure(figsize=(9, 7))
plt.polar(phi1phi2 , K * AR_by_Kp, 'b');<jupyter_output><empty_output><jupyter_text>Second order sytem  with dead time<jupyter_code>plt.figure(figsize=(9, 7))
plt.polar(SecOrderPhi(0.5) - omega * taud, K * SecOrderAR_by_Kp(0.5), 'r', label=r'$\xi=0.5$')
plt.polar(SecOrderPhi(1.0) - omega * taud, K * SecOrderAR_by_Kp(1.0), 'g', label=r'$\xi=1.0$')
plt.polar(SecOrderPhi(1.5) - omega * taud, K * SecOrderAR_by_Kp(1.5), 'b', label=r'$\xi=1.5$')
plt.polar(SecOrderPhi(2.0) - omega * taud, K * SecOrderAR_by_Kp(2.0), 'k', label=r'$\xi=2.0$')
plt.legend(loc='best', bbox_to_anchor=[1.15, 1], fontsize=8);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22266541529798217, 'fraction_numerical': 0.04974190520882215, 'mean_word_length': 5.766666666666667, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '585943', 'license': 'MIT', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1897, 'n_words': 317, 'path': 'Bode and Polar Plots.ipynb', 'repo_name': 'kraanky/process-control', 'size': '4262'}