alfa_max = 3 # dB Máxima Atenuación en la Banda de Paso. alfa_min = 40 #dB Mínima Atenuación en la Banda de Stop. eps = 1 # Ripple my_N = [2, 3, 4] #Orden de mis Filtros. # Diseño de los Filtros: # --------------------------------------------------------------------------- # N = 2: # Filtro Chebyshev Tipo I: z1, p1, k1 = sig.cheb1ap(my_N[0], eps) NUM1, DEN1 = sig.zpk2tf(z1, p1, k1) tf_ch1 = tf(NUM1, DEN1) # Filtro Chebyshev Tipo II o Chebyshev Inverso: z2, p2, k2 = sig.cheb2ap(my_N[0], alfa_min) NUM2, DEN2 = sig.zpk2tf(z2, p2, k2) tf_ch2 = tf(NUM2, DEN2) analyze_sys([tf_ch1, tf_ch2], ['Cheby Tipo I Orden 2', 'Cheby Tipo II o Inverso Orden 2']) # --------------------------------------------------------------------------- # N = 3:
for (this_order, this_ripple, this_att) in zip(orders2analyze, ripple, attenuation): if aprox_name == 'Butterworth': z, p, k = sig.buttap(this_order) eps = np.sqrt(10**(this_ripple / 10) - 1) num, den = sig.zpk2tf(z, p, k) num, den = sig.lp2lp(num, den, eps**(-1 / this_order)) z, p, k = sig.tf2zpk(num, den) elif aprox_name == 'Chebyshev1': z, p, k = sig.cheb1ap(this_order, this_ripple) elif aprox_name == 'Chebyshev2': z, p, k = sig.cheb2ap(this_order, this_ripple) elif aprox_name == 'Bessel': z, p, k = sig.besselap(this_order, norm='mag') elif aprox_name == 'Cauer': z, p, k = sig.ellipap(this_order, this_ripple, this_att) num, den = sig.zpk2tf(z, p, k)
p1_lp = np.roots ( den1_lp ) p2_lp = np.roots ( den2_lp ) my_z_lp = np.array ([]) my_p_lp = np.concatenate ( (p1_lp, p2_lp), axis = None ) my_k_lp = 1 NUM, DEN = sig.zpk2tf ( my_z_lp, my_p_lp, my_k_lp ) NUM_lp, DEN_lp = sig.lp2lp ( NUM, DEN, w0 ) my_tf_lp = transf_f (NUM_lp,DEN_lp) # --------------------------------------------------------------------------- # Ahora Utilizando la función Cheby Tipo 1 dentro del módulo scipy: z, p, k = sig.cheb1ap (orden_filtro, eps) NUM_ch, DEN_ch = sig.zpk2tf ( z, p, k ) # --------------------------------------------------------------------------- # Filtro Destino - Filtro High-Pass: # Calculo w0: NUM_hp, DEN_hp = sig.lp2hp ( NUM, DEN, w0 ) my_tf_hp = transf_f ( NUM_hp, DEN_hp ) my_z_hp, my_p_hp, my_k_hp = sig.tf2zpk (NUM_hp, DEN_hp )
print('\n', my_tf_bw) #pretty_print_lti(my_tf_bw) print('\nDenominador Factorizado de la Transferencia Normalizada:', convert2SOS(my_tf_bw)) NUM1, DEN1 = sig.lp2lp(NUM1, DEN1, wb) my_tf_bw = tfunction(NUM1, DEN1) # ---------------------------------------------------------------------------- print('\n\nFiltro Chebyshev de Orden 5:\n') # Filtro de Chebyshev: Uso de los Métodos dentro del Paquete signal de Scipy. z2, p2, k2 = sig.cheb1ap(orden_filtro, eps) # Obtengo los Coeficientes de mi Transferencia. NUM2, DEN2 = sig.zpk2tf(z2, p2, k2) # Obtengo la Transferencia Normalizada my_tf_ch = tfunction(NUM2, DEN2) print('\n', my_tf_ch) #pretty_print_lti(my_tf_ch) print('\nDenominador Factorizado de la Transferencia Normalizada:', convert2SOS(my_tf_ch)) # ----------------------------------------------------------------------------
all_sys = [] analog_filters = [] digital_filters = [] filter_names = [] analog_filters_names = [] digital_filters_names = [] if aprox_name == 'Butterworth': z, p, k = sig.buttap(order2analyze) elif aprox_name == 'Chebyshev1': z, p, k = sig.cheb1ap(order2analyze, ripple) elif aprox_name == 'Chebyshev2': z, p, k = sig.cheb2ap(order2analyze, ripple) elif aprox_name == 'Bessel': z, p, k = sig.besselap(order2analyze, norm='mag') elif aprox_name == 'Cauer': z, p, k = sig.ellipap(order2analyze, ripple, attenuation) num, den = sig.zpk2tf(z, p, k)
ripple = 0.5 attenuation = 40 orders2analyze = range(2,7) all_sys = [] filter_names = [] for ii in orders2analyze: if aprox_name == 'Butterworth': z,p,k = sig.buttap(ii) elif aprox_name == 'Chebyshev1': z,p,k = sig.cheb1ap(ii, ripple) elif aprox_name == 'Chebyshev2': z,p,k = sig.cheb2ap(ii, ripple) elif aprox_name == 'Bessel': z,p,k = sig.besselap(ii, norm='mag') elif aprox_name == 'Cauer': z,p,k = sig.ellipap(ii, ripple, attenuation) num, den = sig.zpk2tf(z,p,k)
def compute_normalised_by_order(self, ap, n, aa) -> ApproximationErrorCode: """ Generates normalised transfer function prioritising the fixed order """ # Computing needed constants zeros, poles, gain = ss.cheb1ap(n, ap) self.h_aux = ss.ZerosPolesGain(zeros, poles, gain) return ApproximationErrorCode.OK
eps = np.sqrt(10**(alfa_max / 10) - 1) z, p, k = sig.lp2lp_zpk(z, p, k, omega_butter) elif aprox_name == 'Chebyshev1': if force_order > 0: this_order = force_order else: this_order, _ = sig.cheb1ord(omega_p, omega_s, alfa_max, alfa_min, analog=True) z, p, k = sig.cheb1ap(this_order, alfa_max) elif aprox_name == 'Chebyshev2': if force_order > 0: this_order = force_order else: this_order, _ = sig.cheb2ord(omega_p, omega_s, alfa_max, alfa_min, analog=True) z, p, k = sig.cheb2ap(this_order, alfa_min) elif aprox_name == 'Bessel':
def filter_data(): a = sig.cheb1ap(6, 3) plt.plot(a[1]) plt.show()
# Cálculo del Epsilon (Ripple) eps = np.sqrt ( 10**(ripple_/10) - 1 ) wb = eps**(-1/order_filter) # Omega_Butter / Renormalización. NUM, DEN = sig.zpk2tf (z, p, k) NUM, DEN = sig.lp2lp ( NUM, DEN, wb ) z, p, k = sig.tf2zpk ( NUM, DEN ) elif (aprox_name == 'Chebyshev1'): # Le paso Orden y ripple (alfa_máx) z, p, k = sig.cheb1ap (order_filter, ripple_) elif (aprox_name == 'Bessel'): z, p, k = sig.besselap ( order_filter, norm = 'mag' ) else: sys.exit(' No Existe esa Aproximación o Está mal Escrita.') # Genero el Numerador y Denominador de mi Transferencia NUM, DEN = sig.zpk2tf(z, p, k)