From 6e787a660b0a1a456d42d8a420dfe790431dfc40 Mon Sep 17 00:00:00 2001 From: Nicolas Tobler Date: Thu, 2 Jun 2022 01:28:17 +0200 Subject: working on presentation --- buch/papers/ellfilter/python/elliptic2.py | 38 +++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'buch/papers/ellfilter/python/elliptic2.py') diff --git a/buch/papers/ellfilter/python/elliptic2.py b/buch/papers/ellfilter/python/elliptic2.py index 29c6f47..cfa16ea 100644 --- a/buch/papers/ellfilter/python/elliptic2.py +++ b/buch/papers/ellfilter/python/elliptic2.py @@ -1,5 +1,6 @@ # %% +import enum import matplotlib.pyplot as plt import scipy.signal import numpy as np @@ -8,7 +9,9 @@ from matplotlib.patches import Rectangle import plot_params -def ellip_filter(N): +N=5 + +def ellip_filter(N, mode=-1): order = N passband_ripple_db = 3 @@ -26,7 +29,16 @@ def ellip_filter(N): fs=None ) - w, mag_db, phase = scipy.signal.bode((a, b), w=np.linspace(0*omega_c,2*omega_c, 4000)) + if mode == 0: + w = np.linspace(0*omega_c,omega_c, 2000) + elif mode == 1: + w = np.linspace(omega_c,1.00992*omega_c, 2000) + elif mode == 2: + w = np.linspace(1.00992*omega_c,2*omega_c, 2000) + else: + w = np.linspace(0*omega_c,2*omega_c, 4000) + + w, mag_db, phase = scipy.signal.bode((a, b), w=w) mag = 10**(mag_db/20) @@ -40,9 +52,9 @@ def ellip_filter(N): plt.figure(figsize=(4,2.5)) -for N in [5]: - w, FN2, mag, a, b = ellip_filter(N) - plt.semilogy(w, FN2, label=f"$N={N}, k=0.1$", linewidth=1) +for mode, c in enumerate(["green", "orange", "red"]): + w, FN2, mag, a, b = ellip_filter(N, mode=mode) + plt.semilogy(w, FN2, label=f"$N={N}, k=0.1$", linewidth=1, color=c) plt.gca().add_patch(Rectangle( (0, 0), @@ -53,21 +65,21 @@ plt.gca().add_patch(Rectangle( )) plt.gca().add_patch(Rectangle( (1, 1), - 0.01, 1e2-1, + 0.00992, 1e2-1, fc ='orange', alpha=0.2, lw = 10, )) plt.gca().add_patch(Rectangle( - (1.01, 100), + (1.00992, 100), 1, 1e6, fc ='red', alpha=0.2, lw = 10, )) -zeros = [0,0.87,1] +zeros = [0,0.87,0.995] poles = [1.01,1.155] import matplotlib.transforms @@ -99,7 +111,7 @@ plt.ylim([1e-4,1e6]) plt.grid() plt.xlabel("$w$") plt.ylabel("$F^2_N(w)$") -plt.legend() +# plt.legend() plt.tight_layout() plt.savefig("F_N_elliptic.pgf") plt.show() @@ -107,7 +119,9 @@ plt.show() plt.figure(figsize=(4,2.5)) -plt.plot(w, mag, linewidth=1) +for mode, c in enumerate(["green", "orange", "red"]): + w, FN2, mag, a, b = ellip_filter(N, mode=mode) + plt.plot(w, mag, linewidth=1, color=c) plt.gca().add_patch(Rectangle( (0, np.sqrt(2)/2), @@ -118,14 +132,14 @@ plt.gca().add_patch(Rectangle( )) plt.gca().add_patch(Rectangle( (1, 0.1), - 0.01, np.sqrt(2)/2 - 0.1, + 0.00992, np.sqrt(2)/2 - 0.1, fc ='orange', alpha=0.2, lw = 10, )) plt.gca().add_patch(Rectangle( - (1.01, 0), + (1.00992, 0), 1, 0.1, fc ='red', alpha=0.2, -- cgit v1.2.1 From d4e52d5bd83bed95d7712c34e14ccde3ff72810e Mon Sep 17 00:00:00 2001 From: Nicolas Tobler Date: Tue, 9 Aug 2022 23:54:32 +0200 Subject: Improved plot color choices --- buch/papers/ellfilter/python/elliptic2.py | 55 +++++++++++++------------------ 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'buch/papers/ellfilter/python/elliptic2.py') diff --git a/buch/papers/ellfilter/python/elliptic2.py b/buch/papers/ellfilter/python/elliptic2.py index cfa16ea..20a7428 100644 --- a/buch/papers/ellfilter/python/elliptic2.py +++ b/buch/papers/ellfilter/python/elliptic2.py @@ -50,20 +50,20 @@ def ellip_filter(N, mode=-1): return w/omega_c, FN2 / epsilon2, mag, a, b -plt.figure(figsize=(4,2.5)) +f, axs = plt.subplots(2, 1, figsize=(5,3), sharex=True) for mode, c in enumerate(["green", "orange", "red"]): w, FN2, mag, a, b = ellip_filter(N, mode=mode) - plt.semilogy(w, FN2, label=f"$N={N}, k=0.1$", linewidth=1, color=c) + axs[0].semilogy(w, FN2, label=f"$N={N}, k=0.1$", linewidth=1, color=c) -plt.gca().add_patch(Rectangle( +axs[0].add_patch(Rectangle( (0, 0), 1, 1, fc ='green', alpha=0.2, lw = 10, )) -plt.gca().add_patch(Rectangle( +axs[0].add_patch(Rectangle( (1, 1), 0.00992, 1e2-1, fc ='orange', @@ -71,7 +71,7 @@ plt.gca().add_patch(Rectangle( lw = 10, )) -plt.gca().add_patch(Rectangle( +axs[0].add_patch(Rectangle( (1.00992, 100), 1, 1e6, fc ='red', @@ -83,54 +83,41 @@ zeros = [0,0.87,0.995] poles = [1.01,1.155] import matplotlib.transforms -plt.plot( # mark errors as vertical bars +axs[0].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, + axs[0].transData, + axs[0].transAxes, ), ) -plt.plot( # mark errors as vertical bars +axs[0].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, + axs[0].transData, + axs[0].transAxes, ), ) -plt.xlim([0,2]) -plt.ylim([1e-4,1e6]) -plt.grid() -plt.xlabel("$w$") -plt.ylabel("$F^2_N(w)$") -# plt.legend() -plt.tight_layout() -plt.savefig("F_N_elliptic.pgf") -plt.show() - - - -plt.figure(figsize=(4,2.5)) for mode, c in enumerate(["green", "orange", "red"]): w, FN2, mag, a, b = ellip_filter(N, mode=mode) - plt.plot(w, mag, linewidth=1, color=c) + axs[1].plot(w, mag, linewidth=1, color=c) -plt.gca().add_patch(Rectangle( +axs[1].add_patch(Rectangle( (0, np.sqrt(2)/2), 1, 1, fc ='green', alpha=0.2, lw = 10, )) -plt.gca().add_patch(Rectangle( +axs[1].add_patch(Rectangle( (1, 0.1), 0.00992, np.sqrt(2)/2 - 0.1, fc ='orange', @@ -138,7 +125,7 @@ plt.gca().add_patch(Rectangle( lw = 10, )) -plt.gca().add_patch(Rectangle( +axs[1].add_patch(Rectangle( (1.00992, 0), 1, 0.1, fc ='red', @@ -146,11 +133,13 @@ plt.gca().add_patch(Rectangle( lw = 10, )) -plt.grid() -plt.xlim([0,2]) -plt.ylim([0,1]) -plt.xlabel("$w$") -plt.ylabel("$|H(w)|$") +axs[0].set_xlim([0,2]) +axs[0].set_ylim([1e-4,1e6]) +axs[0].grid() +axs[0].set_ylabel("$F^2_N(w)$") +axs[1].grid() +axs[1].set_ylim([0,1]) +axs[1].set_ylabel("$|H(w)|$") plt.tight_layout() plt.savefig("elliptic.pgf") plt.show() -- cgit v1.2.1