示例#1
0
# ---------------------------------------------------------------------------

# 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:

# Filtro Chebyshev Tipo I:
z1, p1, k1 = sig.cheb1ap(my_N[1], 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[1], alfa_min)
NUM2, DEN2 = sig.zpk2tf(z2, p2, k2)
tf_ch2 = tf(NUM2, DEN2)
示例#2
0
        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)

    all_sys.append(sig.TransferFunction(num, den))
    filter_names.append(aprox_name + '_ord_' + str(this_order) + '_rip_' +
                        str(this_ripple) + '_att_' + str(this_att))

analyze_sys(all_sys, filter_names)
示例#3
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May  8 23:19:00 2019

@author: mariano
"""

import scipy.signal as sig
import numpy as np
from splane import analyze_sys, pzmap, grpDelay, bodePlot

z, p, k = sig.buttap(3)
num_lp, den_lp = sig.zpk2tf(z, p, k)
eps = np.sqrt(10**(0.1) - 1)

num_lp_d, den_lp_d = sig.lp2lp(num_lp, den_lp, eps**(-1 / 3))
num_hp_d, den_hp_d = sig.lp2hp(num_lp_d, den_lp_d)

num_hp_d, den_hp_d = sig.lp2hp(num_lp, den_lp, eps**(-1 / 3))

#%matplotlib qt5
analyze_sys([sig.TransferFunction(num_lp, den_lp)], ['mp_norm'])
analyze_sys([sig.TransferFunction(num_lp_d, den_lp_d)], ['mp_desnorm'])
# ----------------------------------------------------------------------------


# Ploteo de las Señales, Respuestas, y Filtros:
my_tfs = [my_tf_bw , my_tf_ch, my_tf_bessel]

# # Respuesta de Módulo y Fase
# # Diagrama de Polos Y Ceros   
# for i in range ( len(my_tfs) ):
    
#     bodePlot ( my_tfs[i], 1)
#     plt.legend (['Filtro LP Butter Orden 5', 'Filtro LP Cheby Orden 5'])
#     pzmap ( my_tfs[i], 2 )
    
    
analyze_sys(my_tfs, ['Butter', 'Cheby', 'Bessel'])


tt, y1, x = sig.lsim2 ((NUM1, DEN1), train_pulse, t )
tt, y2, x = sig.lsim2 ((NUM2, DEN2), train_pulse, t )
tt, y3, x = sig.lsim2 ((NUM3, DEN3), train_pulse, t )

fig5 = plt.figure ()
fig5.suptitle ("Tren de Pulsos de Amplitud 1V y de 0.125 [rad/seg] Muestreado a Ts = 2.425 seg durante 240 seg")
plt.plot (t, train_pulse)
plt.grid()
plt.xlabel ('t[seg]')
plt.ylabel ('x[t] [V]')
# plt.xlim (0, 450)
plt.ylim (-0.1, 1.1)
示例#5
0
print('\n', my_tf_be)

#pretty_print_lti(my_tf_be)

print('Denominador Factorizado de la Transferencia Normalizada:',
      convert2SOS(my_tf_be))

# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------

# Ploteo de las Señales, Respuestas, y Filtros:
my_tfs = [my_tf_bw, my_tf_ch, my_tf_be]

# Respuesta de Módulo y Fase
# Diagrama de Polos Y Ceros
analyze_sys(my_tfs, ['Butter Orden 5', 'Cheby Orden 5', 'Bessel Orden 5'])

# ----------------------------------------------------------------------------

# Ploteo de la Señal "Escalón":

t0 = -(N // 8) * Ts
tf = np.ceil(N / 2) * Ts
tt = np.linspace(t0, tf, N)

fig10 = plt.figure()
fig10.suptitle('Unit Step Function')
plt.plot(tt, u(tt), 'k')
plt.xlabel('time [seg]')
plt.ylabel('Step Fuction $u(t)$ [V]')
plt.xlim(t0, tf / 2)
from splane import tfadd, tfcascade, analyze_sys, pzmap, grpDelay, bodePlot, pretty_print_lti


nn = 2 # orden
ripple = 3 # dB


eps = np.sqrt(10**(ripple/10)-1)

z,p,k = sig.besselap(nn, norm='delay')
# z,p,k = sig.buttap(nn)


num_lp, den_lp = sig.zpk2tf(z,p,k)
num_lp, den_lp = sig.lp2lp(num_lp, den_lp, eps**(-1/nn) )

num_hp, den_hp = sig.lp2hp(num_lp,den_lp)
lp_sys = sig.TransferFunction(num_lp,den_lp)
hp_sys = sig.TransferFunction(num_hp,den_hp)
xover = tfadd(lp_sys, hp_sys)
bandpass = tfcascade(lp_sys, hp_sys)

pretty_print_lti(lp_sys)
pretty_print_lti(hp_sys)
pretty_print_lti(xover)
pretty_print_lti(bandpass)


analyze_sys([lp_sys, hp_sys, xover, bandpass], ['lp', 'hp', 'xover', 'bandpass'])

tf = sig.TransferFunction(num, den)

print("*Coeficientes de la transferencia Besselworth NORMALIZADA:\n")
print("\tNumerador:")
for c in tf.num:
    print(f"\t\t{c:.3f}")
print("\tDenominador:")
for c in tf.den:
    print(f"\t\t{c:.3f}")
print("\n")

print("*Polos y ceros de la transferencia Besselworth NORMALIZADA:\n")
print("\tPolos:")
for c in tf.poles:
    print(f"\t\t{c:.3f}")
print("\tCeros:")
for c in tf.zeros:
    print(f"\t\t{c:.3f}")

all_sys.append(tf)
filter_names.append("Besselworth orden 4")

#Defino el rango a imprimir y el punto a mostrar
ini = 0.1
end = 10.1
n = 100000
bode_lenght = np.linspace(ini, end, n)
printW = 1
#imprimo todos los Bode
analyze_sys(all_sys, filter_names, bode_lenght, printW=printW)
示例#8
0
# bodePlot(this_lti, label = 'HP', fig_id=fig_id, axes_hdl=axes_hdl )
# all_sys += [this_lti]

# str_aux = 'Sección HP'
# str_labels += [str_aux]
# print( str_aux )
# print( '-' * len(str_aux) )

# pretty_print_lti(this_lti)
# print( '\n\n')

# for ii in np.arange(1, p_bp_n.shape[0]/2, dtype='int'):

#     this_k = 1
#     this_z = []
#     this_p = p_bp_n[ii*2:ii*2+2]
#     this_lti = sig.TransferFunction(sig.lti(this_z,this_p,this_k))

#     str_aux = 'Sección LP'
#     print( str_aux )
#     print( '-' * len(str_aux) )

#     pretty_print_lti(this_lti)

#     print( '\n\n')

#     all_sys += [this_lti]
#     str_labels += [str_aux]

analyze_sys(all_sys, str_labels)
示例#9
0
        this_order = force_order
    else:
        this_order = besselord(omega_p, omega_s, alfa_max, alfa_min, omega_d,
                               max_pc_delay)

    z, p, k = sig.besselap(this_order, norm='mag')

elif aprox_name == 'Cauer':

    if force_order > 0:
        this_order = force_order
    else:
        this_order, _ = sig.ellipord(omega_p,
                                     omega_s,
                                     alfa_max,
                                     alfa_min,
                                     analog=True)

    z, p, k = sig.ellipap(this_order, alfa_max, alfa_min)

if (tipo_de_filtro == "Pasa_Alto"):
    z, p, k = sig.lp2hp_zpk(z, p, k)

this_lti = sig.ZerosPolesGain(z, p, k).to_tf()

#this_lti = sig.ZerosPolesGain(z, p, k).to_tf()

pretty_print_lti(this_lti)

analyze_sys([this_lti], [aprox_name], [ideal_filter])
示例#10
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May  8 23:14:49 2019

@author: mariano
"""

import scipy.signal as sig
import numpy as np
from splane import tfadd, tfcascade, analyze_sys, pzmap, grpDelay, bodePlot, pretty_print_lti

kn = 1

# num
qn = 1e6
wn = 2
# num
qd = np.sqrt(2)/2
wd = 1

tf_bicuad = sig.TransferFunction(kn*np.array([1, wn/qn, wn**2]), np.array([1, wd/qd, wd**2]))


pretty_print_lti(tf_bicuad)


analyze_sys([tf_bicuad], ['bicuad'])

示例#11
0
# num
qn = -2
wn = 10
# den
qp = 2
wp = 10

# kn = 1/wn**2
# kp = 1/wp**2

kn = -1
kp = 1

# coeficientes
# num = kn * np.array([1, 0, wn**2])
# # Omega y Q
num = kn * np.array([1, wn / qn, wn**2])

den = kp * np.array([1, wp / qp, wp**2])

# todavía tiene algunos bugs ...
# tf_bicuad_sos = tf2sos_analog(num, den)

tf_bicuad_sos = np.hstack((num, den)).reshape((1, 6))

pretty_print_SOS(tf_bicuad_sos, mode='omegayq')

plt.close('all')
analyze_sys(tf_bicuad_sos, 'mi_bicuad')
示例#12
0
    print_console_alert('Order forced to {:d}'.format(force_order))

print_console_subtitle('Total transfer function')
pretty_print_lti(lowpass_proto_lti)

if p.shape[0] > 2:

    print_console_subtitle('Cascade of second order systems (SOS' 's)')
    lowpass_sos_proto = zpk2sos_analog(z, p, k)

    # pretty_print_SOS(lowpass_sos_proto)
    pretty_print_SOS(lowpass_sos_proto, mode='omegayq')

    print_console_subtitle('Respuesta en frecuencia')

    analyze_sys(lowpass_sos_proto, str_designed_filter)

else:
    print_console_subtitle('Respuesta en frecuencia')

    analyze_sys(lowpass_proto_lti,
                '{:s} orden {:d}'.format(aprox_name, this_order))

# Freq. transformation
#######################

if aprox_type != 'LP':

    print_console_alert('Frequency transformation LP -> ' + aprox_type)

    if aprox_type == 'HP':