aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/ellfilter/python/elliptic2.py
diff options
context:
space:
mode:
Diffstat (limited to 'buch/papers/ellfilter/python/elliptic2.py')
-rw-r--r--buch/papers/ellfilter/python/elliptic2.py85
1 files changed, 78 insertions, 7 deletions
diff --git a/buch/papers/ellfilter/python/elliptic2.py b/buch/papers/ellfilter/python/elliptic2.py
index 92fefd9..29c6f47 100644
--- a/buch/papers/ellfilter/python/elliptic2.py
+++ b/buch/papers/ellfilter/python/elliptic2.py
@@ -6,13 +6,14 @@ import numpy as np
import matplotlib
from matplotlib.patches import Rectangle
+import plot_params
def ellip_filter(N):
order = N
passband_ripple_db = 3
stopband_attenuation_db = 20
- omega_c = 1000
+ omega_c = 1
a, b = scipy.signal.ellip(
order,
@@ -34,14 +35,14 @@ def ellip_filter(N):
FN2 = ((1/mag**2) - 1)
- return w/omega_c, FN2 / epsilon2
+ return w/omega_c, FN2 / epsilon2, mag, a, b
plt.figure(figsize=(4,2.5))
for N in [5]:
- w, FN2 = ellip_filter(N)
- plt.semilogy(w, FN2, label=f"$N={N}$")
+ w, FN2, mag, a, b = ellip_filter(N)
+ plt.semilogy(w, FN2, label=f"$N={N}, k=0.1$", linewidth=1)
plt.gca().add_patch(Rectangle(
(0, 0),
@@ -53,7 +54,7 @@ plt.gca().add_patch(Rectangle(
plt.gca().add_patch(Rectangle(
(1, 1),
0.01, 1e2-1,
- fc ='green',
+ fc ='orange',
alpha=0.2,
lw = 10,
))
@@ -61,18 +62,88 @@ plt.gca().add_patch(Rectangle(
plt.gca().add_patch(Rectangle(
(1.01, 100),
1, 1e6,
- fc ='green',
+ fc ='red',
alpha=0.2,
lw = 10,
))
+
+zeros = [0,0.87,1]
+poles = [1.01,1.155]
+
+import matplotlib.transforms
+plt.plot( # mark errors as vertical bars
+ zeros,
+ np.zeros_like(zeros),
+ "o",
+ mfc='none',
+ color='black',
+ transform=matplotlib.transforms.blended_transform_factory(
+ plt.gca().transData,
+ plt.gca().transAxes,
+ ),
+)
+plt.plot( # mark errors as vertical bars
+ poles,
+ np.ones_like(poles),
+ "x",
+ mfc='none',
+ color='black',
+ transform=matplotlib.transforms.blended_transform_factory(
+ plt.gca().transData,
+ plt.gca().transAxes,
+ ),
+)
+
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.tight_layout()
+plt.savefig("F_N_elliptic.pgf")
plt.show()
+plt.figure(figsize=(4,2.5))
+plt.plot(w, mag, linewidth=1)
+
+plt.gca().add_patch(Rectangle(
+ (0, np.sqrt(2)/2),
+ 1, 1,
+ fc ='green',
+ alpha=0.2,
+ lw = 10,
+))
+plt.gca().add_patch(Rectangle(
+ (1, 0.1),
+ 0.01, np.sqrt(2)/2 - 0.1,
+ fc ='orange',
+ alpha=0.2,
+ lw = 10,
+))
+
+plt.gca().add_patch(Rectangle(
+ (1.01, 0),
+ 1, 0.1,
+ fc ='red',
+ alpha=0.2,
+ lw = 10,
+))
+
+plt.grid()
+plt.xlim([0,2])
+plt.ylim([0,1])
+plt.xlabel("$w$")
+plt.ylabel("$|H(w)|$")
+plt.tight_layout()
+plt.savefig("elliptic.pgf")
+plt.show()
+
+print("zeros", a)
+print("poles", b)
+
+
+
+