cbadc.analog_system.IIRDesign
- class cbadc.analog_system.IIRDesign(wp, ws, gpass, gstop, ftype='ellip')
Bases:
cbadc.analog_system.AnalogSystemAn analog signal designed using standard IIRDesign tools
This class inherits from
cbadc.analog_system.AnalogSystemand is a convenient way of creating IIR filters in an analog system representation.Specifically, we specify the filter by the differential equations
\(\dot{\mathbf{x}}(t) = \mathbf{A} \mathbf{x}(t) + \mathbf{B} u(t) + \mathbf{\Gamma} \mathbf{s}(t)\)
\(\mathbf{y}(t) = \mathbf{C}^\mathsf{T} \mathbf{x}(t) + \mathbf{D} u(t)\)
\(\tilde{\mathbf{s}}(t) = \tilde{\mathbf{\Gamma}}^\mathsf{T} \mathbf{x}(t)\)
where
internally \(\mathbf{A}\) \(\mathbf{B}\), \(\mathbf{C}^\mathsf{T}\), and \(\mathbf{D}\) are determined using the
scipy.signal.iirdesign().Furthermore, as this system is intended as a pure filter and therefore have no
\(\mathbf{\Gamma}\) and \(\tilde{\mathbf{\Gamma}}^\mathsf{T}\) specified.
- Parameters
wp (float or array_like, shape=(2,)) –
Passband and stopband edge frequencies. Possible values are scalars (for lowpass and highpass filters) or ranges (for bandpass and bandstop filters). For digital filters, these are in the same units as fs. By default, fs is 2 half-cycles/sample, so these are normalized from 0 to 1, where 1 is the Nyquist frequency. For example:
Lowpass: wp = 0.2, ws = 0.3
Highpass: wp = 0.3, ws = 0.2
Bandpass: wp = [0.2, 0.5], ws = [0.1, 0.6]
Bandstop: wp = [0.1, 0.6], ws = [0.2, 0.5]
wp and ws are angular frequencies (e.g., rad/s). Note, that for bandpass and bandstop filters passband must lie strictly inside stopband or vice versa.
ws (float or array_like, shape=(2,)) –
Passband and stopband edge frequencies. Possible values are scalars (for lowpass and highpass filters) or ranges (for bandpass and bandstop filters). For digital filters, these are in the same units as fs. By default, fs is 2 half-cycles/sample, so these are normalized from 0 to 1, where 1 is the Nyquist frequency. For example:
Lowpass: wp = 0.2, ws = 0.3
Highpass: wp = 0.3, ws = 0.2
Bandpass: wp = [0.2, 0.5], ws = [0.1, 0.6]
Bandstop: wp = [0.1, 0.6], ws = [0.2, 0.5]
wp and ws are angular frequencies (e.g., rad/s). Note, that for bandpass and bandstop filters passband must lie strictly inside stopband or vice versa.
gpass (float) – The maximum loss in the passband (dB).
gstop (float) – The minimum attenuation in the stopband (dB).
ftype (string, optional) –
IIR filter type, defaults to ellip. Complete list of choices:
Butterworth : ‘butter’
Chebyshev I : ‘cheby1’
Chebyshev II : ‘cheby2’
Cauer/elliptic: ‘ellip’
Bessel/Thomson: ‘bessel’
- N
state space order \(N\).
- Type
int
- N_tilde
number of signal observations \(\tilde{N}\).
- Type
int
- M
number of digital control signals \(M\).
- Type
int
- M_tilde
number of control signal observations \(\tilde{M}\).
- Type
int
- L
number of input signals \(L\).
- Type
int
- A
system matrix \(\mathbf{A}\).
- Type
array_like, shape=(N, N)
- B
input matrix \(\mathbf{B}\).
- Type
array_like, shape=(N, L)
- CT
signal observation matrix \(\mathbf{C}^\mathsf{T}\).
- Type
array_like, shape=(N_tilde, N)
- D
direct matrix
- Type
array_like, shape=(N_tilde, L)
Example
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> import matplotlib.ticker >>> from cbadc.analog_system import IIRDesign >>> wp = 2 * np.pi * 1e3 >>> ws = 2 * np.pi * 2e3 >>> gpass = 0.1 >>> gstop = 80 >>> filter = IIRDesign(wp, ws, gpass, gstop) >>> f = np.logspace(1, 5) >>> w = 2 * np.pi * f >>> tf = filter.transfer_function_matrix(w) >>> fig, ax1 = plt.subplots() >>> ax1.set_title('Analog filter frequency response') >>> ax1.set_ylabel('Amplitude [dB]', color='b') >>> ax1.set_xlabel('Frequency [Hz]') >>> ax1.semilogx(f, 20 * np.log10(np.abs(tf[0, 0, :]))) >>> ax1.grid() >>> ax2 = ax1.twinx() >>> angles = np.unwrap(np.angle(tf[0, 0, :])) >>> ax2.plot(f, angles, 'g') >>> ax2.set_ylabel('Angle (radians)', color='g') >>> ax2.grid() >>> ax2.axis('tight') >>> nticks = 8 >>> ax1.yaxis.set_major_locator(matplotlib.ticker.LinearLocator(nticks)) >>> ax2.yaxis.set_major_locator(matplotlib.ticker.LinearLocator(nticks))
See also
cbadc.analog_system.ButterWorth,cbadc.analog_system.ChebyshevI,cbadc.analog_system.ChebyshevII,cbadc.analog_system.Cauer- Raises
InvalidAnalogSystemError – For faulty analog system parametrization.
Methods
__init__(wp, ws, gpass, gstop[, ftype])Create a IIR filter
Computes the control observation for a given state vector \(\mathbf{x}(t)\) evaluated at time \(t\).
Evaluates the transfer functions between control signals and the system output.
derivative(x, t, u, s)Compute the derivative of the analog system.
Computes the signal observation for a given state vector \(\mathbf{x}(t)\) evaluated at time \(t\).
transfer_function_matrix(omega)Evaluate the analog signal transfer function at the angular frequencies of the omega array.
zpk([input])return zero-pole-gain representation of system
- control_observation(x: numpy.ndarray) numpy.ndarray
Computes the control observation for a given state vector \(\mathbf{x}(t)\) evaluated at time \(t\).
Specifically, returns
\(\tilde{\mathbf{s}}(t) = \tilde{\mathbf{\Gamma}}^\mathsf{T} \mathbf{x}(t)\)
- Parameters
x (array_like, shape=(N,)) – the state vector.
- Returns
the control observation.
- Return type
array_like, shape=(M_tilde,)
- control_signal_transfer_function_matrix(omega: numpy.ndarray) numpy.ndarray
Evaluates the transfer functions between control signals and the system output.
Specifically, evaluates
\(\bar{\mathbf{G}}(\omega) = \mathbf{C}^\mathsf{T} \left(\mathbf{A} - i \omega \mathbf{I}_N\right)^{-1} \mathbf{\Gamma} \in \mathbb{R}^{\tilde{N} \times M}\)
for each angular frequency in omega where \(\mathbf{I}_N\) represents a square identity matrix of the same dimensions as \(\mathbf{A}\) and \(i=\sqrt{-1}\).
- Parameters
omega (array_like, shape=(K,)) – an array_like object containing the angular frequencies for evaluation.
- Returns
the signal transfer function evaluated at K different angular frequencies.
- Return type
array_like, shape=(N_tilde, M, K)
- derivative(x: numpy.ndarray, t: float, u: numpy.ndarray, s: numpy.ndarray) numpy.ndarray
Compute the derivative of the analog system.
Specifically, produces the state derivative
\(\dot{\mathbf{x}}(t) = \mathbf{A} \mathbf{x}(t) + \mathbf{B} \mathbf{u}(t) + \mathbf{\Gamma} \mathbf{s}(t)\)
as a function of the state vector \(\mathbf{x}(t)\), the given time \(t\), the input signal value \(\mathbf{u}(t)\), and the control contribution value \(\mathbf{s}(t)\).
- Parameters
x (array_like, shape=(N,)) – the state vector evaluated at time t.
t (float) – the time t.
u (array_like, shape=(L,)) – the input signal vector evaluated at time t.
s (array_like, shape=(M,)) – the control contribution evaluated at time t.
- Returns
the derivative \(\dot{\mathbf{x}}(t)\).
- Return type
array_like, shape=(N,)
- signal_observation(x: numpy.ndarray) numpy.ndarray
Computes the signal observation for a given state vector \(\mathbf{x}(t)\) evaluated at time \(t\).
Specifically, returns
\(\mathbf{y}(t)=\mathbf{C}^\mathsf{T} \mathbf{x}(t)\)
- Parameters
x (array_like, shape=(N,)) – the state vector.
- Returns
the signal observation.
- Return type
array_like, shape=(N_tilde,)
- transfer_function_matrix(omega: numpy.ndarray) numpy.ndarray
Evaluate the analog signal transfer function at the angular frequencies of the omega array.
Specifically, evaluates
\(\mathbf{G}(\omega) = \mathbf{C}^\mathsf{T} \left(\mathbf{A} - i \omega \mathbf{I}_N\right)^{-1} \mathbf{B} + \mathbf{D}\)
for each angular frequency in omega where \(\mathbf{I}_N\) represents a square identity matrix of the same dimensions as \(\mathbf{A}\) and \(i=\sqrt{-1}\).
- Parameters
omega (array_like, shape=(K,)) – an array_like object containing the angular frequencies for evaluation.
- Returns
the signal transfer function evaluated at K different angular frequencies.
- Return type
array_like, shape=(N_tilde, L, K)
- zpk(input=0)
return zero-pole-gain representation of system
- Parameters
input – determine for which input (in case of L > 1) to compute zpk, defaults to 0.
int – determine for which input (in case of L > 1) to compute zpk, defaults to 0.
optional – determine for which input (in case of L > 1) to compute zpk, defaults to 0.
- Returns
z,p,k the zeros, poles and gain of the system
- Return type
array_like, shape=(?, ?, 1)