aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/ellfilter/python/elliptic2.py
diff options
context:
space:
mode:
authorNicolas Tobler <nicolas.tobler@ost.ch>2022-05-15 23:15:36 +0200
committerNicolas Tobler <nicolas.tobler@ost.ch>2022-05-15 23:15:36 +0200
commit4fd4422b52f6377a82696ea67da9beb13d93e581 (patch)
tree143dfd30b9cd9e92f58a2fa4c294aee4014d270a /buch/papers/ellfilter/python/elliptic2.py
parentAdded title and author (diff)
downloadSeminarSpezielleFunktionen-4fd4422b52f6377a82696ea67da9beb13d93e581.tar.gz
SeminarSpezielleFunktionen-4fd4422b52f6377a82696ea67da9beb13d93e581.zip
draft
Diffstat (limited to 'buch/papers/ellfilter/python/elliptic2.py')
-rw-r--r--buch/papers/ellfilter/python/elliptic2.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/buch/papers/ellfilter/python/elliptic2.py b/buch/papers/ellfilter/python/elliptic2.py
new file mode 100644
index 0000000..92fefd9
--- /dev/null
+++ b/buch/papers/ellfilter/python/elliptic2.py
@@ -0,0 +1,78 @@
+# %%
+
+import matplotlib.pyplot as plt
+import scipy.signal
+import numpy as np
+import matplotlib
+from matplotlib.patches import Rectangle
+
+
+def ellip_filter(N):
+
+ order = N
+ passband_ripple_db = 3
+ stopband_attenuation_db = 20
+ omega_c = 1000
+
+ a, b = scipy.signal.ellip(
+ order,
+ passband_ripple_db,
+ stopband_attenuation_db,
+ omega_c,
+ btype='low',
+ analog=True,
+ output='ba',
+ fs=None
+ )
+
+ w, mag_db, phase = scipy.signal.bode((a, b), w=np.linspace(0*omega_c,2*omega_c, 4000))
+
+ mag = 10**(mag_db/20)
+
+ passband_ripple = 10**(-passband_ripple_db/20)
+ epsilon2 = (1/passband_ripple)**2 - 1
+
+ FN2 = ((1/mag**2) - 1)
+
+ return w/omega_c, FN2 / epsilon2
+
+
+plt.figure(figsize=(4,2.5))
+
+for N in [5]:
+ w, FN2 = ellip_filter(N)
+ plt.semilogy(w, FN2, label=f"$N={N}$")
+
+plt.gca().add_patch(Rectangle(
+ (0, 0),
+ 1, 1,
+ fc ='green',
+ alpha=0.2,
+ lw = 10,
+))
+plt.gca().add_patch(Rectangle(
+ (1, 1),
+ 0.01, 1e2-1,
+ fc ='green',
+ alpha=0.2,
+ lw = 10,
+))
+
+plt.gca().add_patch(Rectangle(
+ (1.01, 100),
+ 1, 1e6,
+ fc ='green',
+ alpha=0.2,
+ lw = 10,
+))
+plt.xlim([0,2])
+plt.ylim([1e-4,1e6])
+plt.grid()
+plt.xlabel("$w$")
+plt.ylabel("$F^2_N(w)$")
+plt.legend()
+plt.savefig("F_N_elliptic.pdf")
+plt.show()
+
+
+