#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 29 14:49:03 2023

@author: mariano
"""

# Inicialización e importación de módulos

# Módulos externos
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy.signal as sig


# Ahora importamos las funciones de PyTC2

from pytc2.sistemas_lineales import analyze_sys, pretty_print_bicuad_omegayq, tf2sos_analog, pretty_print_SOS

from pytc2.general import print_subtitle


def sim_aprox(aproxs, orders2analyze, ripple, attenuation):

    all_sys = []
    filter_names = []

    for (this_aprox, this_order, this_ripple, this_att) in zip(aproxs, orders2analyze, ripple, attenuation):

        if this_aprox == '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 this_aprox == 'Chebyshev1':

            z,p,k = sig.cheb1ap(this_order, this_ripple)

        elif this_aprox == 'Chebyshev2':

            z,p,k = sig.cheb2ap(this_order, this_ripple)

        elif this_aprox == 'Bessel':

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

        elif this_aprox == '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))

        this_label = this_aprox + '_ord_' + str(this_order) + '_rip_' + str(this_ripple)+ '_att_' + str(this_att)
        
        print_subtitle(this_label)
        # factorizamos en SOS's
        this_sos = tf2sos_analog(num, den)
        
        pretty_print_SOS(this_sos, mode='omegayq')
        
        filter_names.append(this_label)
        

    analyze_sys( all_sys, filter_names )



        
aprox_name = 'Butterworth'
#aprox_name = 'Chebyshev1'
#aprox_name = 'Chebyshev2'
#aprox_name = 'Bessel'
#aprox_name = 'Cauer'

# parametrizamos el orden para cada aproximación
orders2analyze = [2, 3, 4]

# Mismo requerimiento de ripple y atenuación
aproxs = [aprox_name] * len(orders2analyze)
ripple = [3] * len(orders2analyze) # dB \alpha_{max} <-- Sin parametrizar, lo dejo en Butterworth
attenuation = [40] * len(orders2analyze) # dB \alpha_{min} <-- Sin parametrizar, att fija


sim_aprox(aproxs, orders2analyze, ripple, attenuation)


c8e2d189089bb698e4149911573a4108ccc98a24
<mask token>


def sim_aprox(aproxs, orders2analyze, ripple, attenuation):
    all_sys = []
    filter_names = []
    for this_aprox, this_order, this_ripple, this_att in zip(aproxs,
        orders2analyze, ripple, attenuation):
        if this_aprox == '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 this_aprox == 'Chebyshev1':
            z, p, k = sig.cheb1ap(this_order, this_ripple)
        elif this_aprox == 'Chebyshev2':
            z, p, k = sig.cheb2ap(this_order, this_ripple)
        elif this_aprox == 'Bessel':
            z, p, k = sig.besselap(this_order, norm='delay')
        elif this_aprox == '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))
        this_label = this_aprox + '_ord_' + str(this_order) + '_rip_' + str(
            this_ripple) + '_att_' + str(this_att)
        print_subtitle(this_label)
        this_sos = tf2sos_analog(num, den)
        pretty_print_SOS(this_sos, mode='omegayq')
        filter_names.append(this_label)
    analyze_sys(all_sys, filter_names)


<mask token>

<mask token>


def sim_aprox(aproxs, orders2analyze, ripple, attenuation):
    all_sys = []
    filter_names = []
    for this_aprox, this_order, this_ripple, this_att in zip(aproxs,
        orders2analyze, ripple, attenuation):
        if this_aprox == '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 this_aprox == 'Chebyshev1':
            z, p, k = sig.cheb1ap(this_order, this_ripple)
        elif this_aprox == 'Chebyshev2':
            z, p, k = sig.cheb2ap(this_order, this_ripple)
        elif this_aprox == 'Bessel':
            z, p, k = sig.besselap(this_order, norm='delay')
        elif this_aprox == '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))
        this_label = this_aprox + '_ord_' + str(this_order) + '_rip_' + str(
            this_ripple) + '_att_' + str(this_att)
        print_subtitle(this_label)
        this_sos = tf2sos_analog(num, den)
        pretty_print_SOS(this_sos, mode='omegayq')
        filter_names.append(this_label)
    analyze_sys(all_sys, filter_names)


<mask token>
sim_aprox(aproxs, orders2analyze, ripple, attenuation)

<mask token>


def sim_aprox(aproxs, orders2analyze, ripple, attenuation):
    all_sys = []
    filter_names = []
    for this_aprox, this_order, this_ripple, this_att in zip(aproxs,
        orders2analyze, ripple, attenuation):
        if this_aprox == '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 this_aprox == 'Chebyshev1':
            z, p, k = sig.cheb1ap(this_order, this_ripple)
        elif this_aprox == 'Chebyshev2':
            z, p, k = sig.cheb2ap(this_order, this_ripple)
        elif this_aprox == 'Bessel':
            z, p, k = sig.besselap(this_order, norm='delay')
        elif this_aprox == '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))
        this_label = this_aprox + '_ord_' + str(this_order) + '_rip_' + str(
            this_ripple) + '_att_' + str(this_att)
        print_subtitle(this_label)
        this_sos = tf2sos_analog(num, den)
        pretty_print_SOS(this_sos, mode='omegayq')
        filter_names.append(this_label)
    analyze_sys(all_sys, filter_names)


aprox_name = 'Butterworth'
orders2analyze = [2, 3, 4]
aproxs = [aprox_name] * len(orders2analyze)
ripple = [3] * len(orders2analyze)
attenuation = [40] * len(orders2analyze)
sim_aprox(aproxs, orders2analyze, ripple, attenuation)

<mask token>
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy.signal as sig
from pytc2.sistemas_lineales import analyze_sys, pretty_print_bicuad_omegayq, tf2sos_analog, pretty_print_SOS
from pytc2.general import print_subtitle


def sim_aprox(aproxs, orders2analyze, ripple, attenuation):
    all_sys = []
    filter_names = []
    for this_aprox, this_order, this_ripple, this_att in zip(aproxs,
        orders2analyze, ripple, attenuation):
        if this_aprox == '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 this_aprox == 'Chebyshev1':
            z, p, k = sig.cheb1ap(this_order, this_ripple)
        elif this_aprox == 'Chebyshev2':
            z, p, k = sig.cheb2ap(this_order, this_ripple)
        elif this_aprox == 'Bessel':
            z, p, k = sig.besselap(this_order, norm='delay')
        elif this_aprox == '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))
        this_label = this_aprox + '_ord_' + str(this_order) + '_rip_' + str(
            this_ripple) + '_att_' + str(this_att)
        print_subtitle(this_label)
        this_sos = tf2sos_analog(num, den)
        pretty_print_SOS(this_sos, mode='omegayq')
        filter_names.append(this_label)
    analyze_sys(all_sys, filter_names)


aprox_name = 'Butterworth'
orders2analyze = [2, 3, 4]
aproxs = [aprox_name] * len(orders2analyze)
ripple = [3] * len(orders2analyze)
attenuation = [40] * len(orders2analyze)
sim_aprox(aproxs, orders2analyze, ripple, attenuation)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 29 14:49:03 2023

@author: mariano
"""

# Inicialización e importación de módulos

# Módulos externos
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy.signal as sig


# Ahora importamos las funciones de PyTC2

from pytc2.sistemas_lineales import analyze_sys, pretty_print_bicuad_omegayq, tf2sos_analog, pretty_print_SOS

from pytc2.general import print_subtitle


def sim_aprox(aproxs, orders2analyze, ripple, attenuation):

    all_sys = []
    filter_names = []

    for (this_aprox, this_order, this_ripple, this_att) in zip(aproxs, orders2analyze, ripple, attenuation):

        if this_aprox == '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 this_aprox == 'Chebyshev1':

            z,p,k = sig.cheb1ap(this_order, this_ripple)

        elif this_aprox == 'Chebyshev2':

            z,p,k = sig.cheb2ap(this_order, this_ripple)

        elif this_aprox == 'Bessel':

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

        elif this_aprox == '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))

        this_label = this_aprox + '_ord_' + str(this_order) + '_rip_' + str(this_ripple)+ '_att_' + str(this_att)
        
        print_subtitle(this_label)
        # factorizamos en SOS's
        this_sos = tf2sos_analog(num, den)
        
        pretty_print_SOS(this_sos, mode='omegayq')
        
        filter_names.append(this_label)
        

    analyze_sys( all_sys, filter_names )



        
aprox_name = 'Butterworth'
#aprox_name = 'Chebyshev1'
#aprox_name = 'Chebyshev2'
#aprox_name = 'Bessel'
#aprox_name = 'Cauer'

# parametrizamos el orden para cada aproximación
orders2analyze = [2, 3, 4]

# Mismo requerimiento de ripple y atenuación
aproxs = [aprox_name] * len(orders2analyze)
ripple = [3] * len(orders2analyze) # dB \alpha_{max} <-- Sin parametrizar, lo dejo en Butterworth
attenuation = [40] * len(orders2analyze) # dB \alpha_{min} <-- Sin parametrizar, att fija


sim_aprox(aproxs, orders2analyze, ripple, attenuation)

