Fitting filters and transfer functions models¶
The package consists of the following modules:
PyDynamic.identification.fit_filter
: leastsquares fit to a given complex frequency responsePyDynamic.identification.fit_transfer
: identification of transfer function models
Fitting filters to frequency response¶
This module contains several functions to carry out a leastsquares fit to a given complex frequency response.
This module contains the following functions:
LSIIR()
: Leastsquares IIR filter fit to a given frequency responseLSFIR()
: Leastsquares 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.

PyDynamic.identification.fit_filter.
LSIIR
(Hvals, Nb, Na, f, Fs, tau=0, justFit=False)[source]¶ Leastsquares IIR filter fit to a given frequency response.
This method uses GaussNewton nonlinear optimization and pole mapping for filter stabilization
Parameters:  Hvals (numpy array of (complex) 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) –
Returns:  b,a (IIR filter coefficients as numpy arrays)
 tau (filter time delay in samples)
References
 Eichstädt et al. 2010 [Eichst2010]
 Vuerinckx et al. 1996 [Vuer1996]

PyDynamic.identification.fit_filter.
LSFIR
(H, N, tau, f, Fs, Wt=None)[source]¶ Leastsquares fit of a digital FIR filter to a given frequency response.
Parameters:  H ((complex) 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 secondorder model to complexvalued frequency response

PyDynamic.identification.fit_transfer.
fit_sos
(f, H, UH=None, weighting=None, MCruns=None, scaling=0.001)[source]¶ Fit secondorder model to complexvalued frequency response
Fit secondorder model (springdamper model) with parameters \(S_0, delta\) and \(f_0\) to complexvalued 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
PyDynamic.uncertainty.propagate_DFT.AmpPhase2DFT
.Parameters:  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 onedimensional, 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 leastsquares design matrix for improved fit quality
Returns:  p (np.ndarray) – vector of estimated model parameters [S0, delta, f0]
 Up (np.ndarray) – covariance associated with parameter estimate