Main Content

invfreqs

R2026b

Identify continuous-time filter parameters from frequency response data

Description

[b,a] = invfreqs(h,w,n,m) returns the real numerator and denominator coefficient vectors b and a of the transfer function h.

example

[b,a] = invfreqs(h,w,n,m,wt) weights the fit-errors versus frequency using wt.

[b,a] = invfreqs(h,w,n,m,wt,iter) provides an algorithm that guarantees stability of the resulting linear system by searching for the best fit using a numerical, iterative scheme.

example

[b,a] = invfreqs(h,w,n,m,wt,iter,tol) uses tol to decide convergence of the iterative algorithm.

[b,a] = invfreqs(h,w,n,m,wt,iter,tol,"trace") displays a textual progress report of the iteration. For more information, see Algorithms.

[b,a] = invfreqs(h,w,"complex",n,m,___) creates a complex filter. In this case no symmetry is enforced, and the frequency is specified between –π and π radians per sample. This syntax can include any combination of wt,iter,tol, and "trace" input arguments from the previous syntaxes.

Examples

collapse all

Convert a simple transfer function to frequency-response data and then back to the original filter coefficients.

a = [1 2 3 2 1 4];
b = [1 2 3 2 3];

[h,w] = freqs(b,a,64);
[bb,aa] = invfreqs(h,w,4,5)
bb = 1×5

    1.0000    2.0000    3.0000    2.0000    3.0000

aa = 1×6

    1.0000    2.0000    3.0000    2.0000    1.0000    4.0000

bb and aa are equivalent to b and a, respectively. However, the system is unstable because aa has poles with positive real part. View the poles of bb and aa.

zplane(bb,aa)

Figure contains an axes object. The axes object with title Pole-Zero Plot, xlabel Real Part, ylabel Imaginary Part contains 3 objects of type line. One or more of the lines displays its values using only markers

Use the iterative algorithm of invfreqs to find a stable approximation to the system.

[bbb,aaa] = invfreqs(h,w,4,5,[],30)
bbb = 1×5

    0.7485    2.2246    3.2889    4.7671   -0.2494

aaa = 1×6

    1.0000    3.2983    7.8655    9.6639    9.3641    0.0004

Verify that the system is stable by plotting the new poles.

zplane(bbb,aaa)

Figure contains an axes object. The axes object with title Pole-Zero Plot, xlabel Real Part, ylabel Imaginary Part contains 3 objects of type line. One or more of the lines displays its values using only markers

Generate two vectors, mag and phase, that simulate magnitude and phase data gathered in a laboratory. Also generate a vector, w, of frequencies.

rng('default')

fs = 1000;
t = 0:1/fs:2;
mag = periodogram(sin(2*pi*100*t)+randn(size(t))/10,[],[],fs);
phase = randn(size(mag))/10;
w = linspace(0,fs/2,length(mag))';

Use invfreqs to convert the data into a continuous-time transfer function. Plot the result.

[b,a] = invfreqs(mag.*exp(1j*phase),w,2,2,[],4);

freqs(b,a)

Figure contains 2 axes objects. Axes object 1 with xlabel Frequency (rad/s), ylabel Phase (degrees) contains an object of type line. Axes object 2 with xlabel Frequency (rad/s), ylabel Magnitude contains an object of type line.

Input Arguments

collapse all

Frequency response, specified as a vector.

Data Types: single | double

Angular frequencies at which h is computed, specified as a vector.

Desired order of the numerator and denominator polynomials, specified as positive integer scalars.

Data Types: single | double

Weighting factors, specified as a vector. wt is a vector of weighting factors that is the same length as w.

Data Types: single | double

Number of iterations in the search algorithm, specified as a positive real scalar. The iter parameter tells invfreqs to end the iteration when the algorithm has converged to a solution, or after iter iterations, whichever occurs first.

Tolerance, specified as a scalar. invfreqs defines convergence as occurring when the norm of the (modified) gradient vector is less than tol.

To obtain a weight vector of all ones, use

invfreqs(h,w,n,m,[],iter,tol)

Output Arguments

collapse all

Transfer function coefficients, returned as vectors. Express the transfer function in terms of b and a as

H(s)=B(s)A(s)=b(1)sn+b(2)sn1++b(n+1)a(1)sm+a(2)sm1++a(m+1)

Example: b = [1 3 3 1]/6 and a = [3 0 1 0]/3 specify a third-order Butterworth filter with normalized 3 dB frequency 0.5π rad/sample.

Data Types: double | single
Complex Number Support: Yes

Tips

When building higher order models using high frequencies, it is important to scale the frequencies, dividing by a factor such as half the highest frequency present in w, so as to obtain well-conditioned values of a and b. This corresponds to a rescaling of time.

Algorithms

By default, invfreqs uses an equation error method to identify the best model from the data. The method finds b and a in

argmina,bk=1nWt(k)|h(k)A(ω(k))B(ω(k))|2

by creating a system of linear equations and solving them with the MATLAB® \ operator, where:

  • A(ω(k)) and B(ω(k)) are the Fourier transforms of the polynomials a and b, respectively, at the frequency ω(k).

  • h(k) is the frequency response at the frequency ω(k).

  • Wt(k) contains the weighting factor for the kth frequency.

  • n is the number of frequency points (the length of h, ω, and Wt).

This algorithm is based on Levi [1]. Several variants have been suggested in the literature, where the weighting function Wt gives less importance to high frequencies.

The superior output-error algorithm uses the damped Gauss-Newton method for iterative search [2], with the output of the first algorithm as the initial estimate. The algorithm then solves the direct problem of minimizing the weighted squared 2-norm between the desired frequency response and the response obtained with the estimated coefficients (estimated frequency response).

argmina,bWt(k)[h(k)B(ω(k))A(ω(k))]2

The search stops at the end of the iterth iteration, once the 2-norm of the modified gradient vector is less than tol, or when the 2-norm of the modified gradient vector does not reduce further, whichever occurs first.

If you specify the "trace" argument, the function prints the estimation progress per iteration in the MATLAB command window. For each iteration, invfreqs prints this information:

  • Fit accuracy — Squared 2-norm between the desired and estimated frequency responses. The Current Fit and Previous Fit terms list the squared 2-norm associated with the current and previous iteration, respectively.

  • Filter coefficient estimates — Three-column matrix, where each column lists this information:

    • Current par is the vector of estimated filter coefficients for the current iteration.

    • prev. par is the vector of estimated filter coefficients for the previous iteration.

    • GN-dir is the modified gradient vector from the Gauss-Newton optimization applied to the current iteration.

    The function lists the vectors of estimated filter coefficients as [α1; α2; ⋯; αm; β1; β2; ⋯; βn+1], where

    h(s)=β1sn+β2sn1++βn+1sm+α1sm1+α2sm2++αm.

  • Norm of the Gauss-Newton optimization vector — The Norm of GN-vector lists the 2-norm of the modified gradient vector GN-dir.

References

[1] Levi, E. C. “Complex-Curve Fitting.” IRE Transactions on Automatic Control. Vol. AC-4, 1959, pp. 37–44.

[2] Dennis, J. E., Jr., and R. B. Schnabel. Numerical Methods for Unconstrained Optimization and Nonlinear Equations. Englewood Cliffs, NJ: Prentice-Hall, 1983.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced before R2006a

expand all

See Also

| | |