Fitting filters and transfer functions models

The package consists of the following modules:

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.

PyDynamic.identification.fit_filter.LSIIR(Hvals, Nb, Na, f, Fs, tau=0, justFit=False)[source]

Least-squares IIR filter fit to a given frequency response.

This method uses Gauss-Newton non-linear optimization and pole mapping for filter stabilization

Parameters:
  • 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) –
Returns:

  • b,a (IIR filter coefficients as numpy arrays)
  • tau (filter time delay in samples)

References

PyDynamic.identification.fit_filter.LSFIR(H, N, tau, f, Fs, Wt=None)[source]

Least-squares fit of a digital FIR filter to a given frequency response.

Parameters:
  • 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
PyDynamic.identification.fit_transfer.fit_sos(f, H, UH=None, weighting=None, MCruns=None, scaling=0.001)[source]

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

  • p (np.ndarray) – vector of estimated model parameters [S0, delta, f0]
  • Up (np.ndarray) – covariance associated with parameter estimate