import numpy as np
import matplotlib.pyplot as plt
# Generating angular frequency values
omega = np.logspace(-2, 2, 400) # for a wider frequency range in this example
# Dummy values for omega1 (ω1)
omega1 = 1
# Calculating the plateau height based on the slopes and cutoff frequencies
plateau_height = 10 * np.log10(omega1)
magnitude = np.piecewise(omega, [omega < omega1, omega > omega1],
[lambda omega: plateau_height + 20 * np.log10(omega/omega1),
lambda omega: plateau_height + 20 * np.log10(omega1/omega)])
plt.figure(figsize=(10,6))
plt.semilogx(omega, magnitude, 'k')
plt.title("Bode Plot (Frequency Response)")
plt.xlabel("ω (angular frequency)")
plt.ylabel("|Vo/Vi| dB")
plt.grid(which='both', axis='both')
plt.ylim(-30, plateau_height+10) # Adjusting y limits for better visibility
plt.axhline(0, color='black',linewidth=0.5)
# Dashed lines for omega1
plt.axvline(omega1, color='black', linestyle='--', linewidth=1)
# Dashed line for the plateau height and its label
plt.axhline(plateau_height, color='black', linestyle='--', linewidth=1)
plt.annotate('|R/R₁|', xy=(1e-2, plateau_height+2), horizontalalignment='left')
# Annotations for slopes and cutoff frequencies
plt.annotate('20dB/dec', xy=(omega1/3.5, plateau_height-10), horizontalalignment='right')
plt.annotate('-20dB/dec', xy=(omega1*3.5, plateau_height-10), horizontalalignment='left')
plt.annotate('ω1', xy=(0.85*omega1, -25), horizontalalignment='center')
plt.tight_layout()
plt.savefig("Bode Plot of Practical Differentiator when RC1=R1C.pdf")