Fitting filters and transfer functions models¶
The package consists of the following modules:
PyDynamic.identification.fit_filter: least-squares fit to a given complex frequency response
PyDynamic.identification.fit_transfer: identification of transfer function models
Fitting filters to frequency response¶
This module contains several functions to carry out a least-squares fit to a given complex frequency response.
This module contains the following functions:
LSIIR(): Least-squares IIR filter fit to a given frequency response
LSFIR(): Least-squares fit of a digital FIR filter to a given frequency response
Deprecated since version 1.2.71: The module identification will be combined with the module deconvolution and renamed to model_estimation in the next major release 2.0.0. From then on you should only use the new module model_estimation instead.
LSIIR(Hvals, Nb, Na, f, Fs, tau=0, justFit=False)¶
Least-squares IIR filter fit to a given frequency response.
This method uses Gauss-Newton non-linear optimization and pole mapping for filter stabilization
- Hvals (numpy array of frequency response values of shape (M,)) –
- Nb (integer numerator polynomial order) –
- Na (integer denominator polynomial order) –
- f (numpy array of frequencies at which Hvals is given of shape) –
- (M,) –
- Fs (sampling frequency) –
- tau (integer initial estimate of time delay) –
- justFit (boolean, when true then no stabilization is carried out) –
- b,a (IIR filter coefficients as numpy arrays)
- tau (filter time delay in samples)
LSFIR(H, N, tau, f, Fs, Wt=None)¶
Least-squares fit of a digital FIR filter to a given frequency response.
- H (frequency response values of shape (M,)) –
- N (FIR filter order) –
- tau (delay of filter) –
- f (frequencies of shape (M,)) –
- Fs (sampling frequency of digital filter) –
- Wt ((optional) vector of weights of shape (M,) or shape (M,M)) –
Returns: Return type:
filter coefficients bFIR (ndarray) of shape (N+1,)
Identification of transfer function models¶
Collection of methods for the identification of transfer function models
This module contains the following function:
fit_sos(): Fit second-order model to complex-valued frequency response
fit_sos(f, H, UH=None, weighting=None, MCruns=None, scaling=0.001)¶
Fit second-order model to complex-valued frequency response
Fit second-order model (spring-damper model) with parameters \(S_0, delta\) and \(f_0\) to complex-valued frequency response with uncertainty associated with real and imaginary parts.
For a transformation of an uncertainty associated with amplitude and phase to one associated with real and imaginary parts, see
- f (np.ndarray of shape (M,)) – vector of frequencies
- H (np.ndarray of shape (2M,)) – real and imaginary parts of measured frequency response values at frequencies f
- UH (np.ndarray of shape (2M,) or (2M,2M)) – uncertainties associated with real and imaginary parts When UH is one-dimensional, it is assumed to contain standard uncertainties; otherwise it is taken as covariance matrix. When UH is not specified no uncertainties assoc. with the fit are calculated.
- weighting (str or array) – Type of weighting (None, ‘diag’, ‘cov’) or array of weights ( length two times of f)
- MCruns (int, optional) – Number of Monte Carlo trials for propagation of uncertainties. When MCruns is ‘None’, matrix multiplication is used for the propagation of uncertainties. However, in some cases this can cause trouble.
- scaling (float) – scaling of least-squares design matrix for improved fit quality
- p (np.ndarray) – vector of estimated model parameters [S0, delta, f0]
- Up (np.ndarray) – covariance associated with parameter estimate