rational
Perform rational fitting to complex frequency-dependent data
Since R2020a. Recommended over rationalfit
.
Description
Use the rational
object and an interpolative algorithm to
create a rational fit to frequency-dependent data.
The fit is given by the equation:
Creation
Syntax
Description
[
also returns the error of the fit. Use any of input argument combinations
from the previous syntaxes.fit
,error
] = rational(___)
specifies options to control aspects of fit or sets properties. You can set the NumPoles, Poles, Residues, and DirectTerm properties (since R2023a) using name-value
arguments. For example, fit
= rational(___,Name=Value)fit = rational(s,MaxPoles=1002)
sets the maximum number of poles for the fit. Specify name-value arguments
after any of the input arguments from the previous syntaxes.
Input Arguments
freq
— Nonnegative frequencies
vector
Nonnegative frequencies, specified as a vector of nonnegative frequencies in Hz.
Data Types: double
data
— Network parameter data
vector | 2-D array | 3-D array
Network parameter data, specified as a vector, a 2-D array or a 3-D array. The length of the data values must equal the length of the frequency values.
s
— N-port S-parameters
N-by-N matrix of elements of
S
N-port S-parameters, specified as an N-by-N matrix of elements of S sharing identical poles.
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: TendsToZero = true
|
'TendsToZero',true
Tolerance
— Relative error tolerance
-40
(default) | scalar
Relative error tolerance, specified as a scalar less than or equal to zero in dB.
Example: Tolerance=-30
Data Types: double
TendsToZero
— Behavior of fit for large S-parameters
true or 1
(default) | false or 0
Behavior of fit for large S-parameters, specified as
1
(true
) or
0
(false
). When
true
, the direct term in the fit is set to
zero so that the rational fit F(S)
tends to zero
as S
approaches infinity. When
false
, a nonzero direct term is
allowed.
Example: TendsToZero=true
Data Types: logical
MaxPoles
— Maximum number of poles
1000
(default) | scalar nonnegative integer
Maximum number of poles, specified as a scalar nonnegative integer.
Example: MaxPoles=1002
Data Types: double
ErrorMetric
— Error metrics in rational
object
'default'
(default) | 'Relative'
Error metrics in the rational
object, specified
as one of the following:
If you specify
'ErrorMetric'
as'default'
, therational
object distributes the error evenly.If you specify
'ErrorMetric'
as'Relative'
, therational
object fits both peaks and valleys or gets smaller error for smaller values.
Example: ErrorMetric='Relative'
Data Types: char
NoiseFloor
— Ignores low-level noise in data
-inf
(default) | scalar
Ignores low-level noise in the data, specified as a scalar.
Example: NoiseFloor=-60
Data Types: double
Causal
— Pole stability
true or 1
(default) | false or 0
Pole stability, specified as a logical true
(1
) or false
(0
). When you specify true, all the poles of
the fit are stable. When you specify false,the poles can be anywhere
in the complex plane.
Example: Causal=false
Qlimit
— Maximum value of quality factor
1000
(default) | positive scalar
Maximum value of the quality factor of the poles of the fit, specified as a positive scalar.
Example: Qlimit=1100
Data Types: double
ColumnReduce
— Data reduction
true or 1
(default) | false or 0
| logical
Data reduction, specified as a logical 1
(true
) or 0
(false
). When you specify true, the function
reduces the data for the fitter to save memory and computation time.
Reduce data for the fitter in order to save memory and computation
time, specified as a logical true
or
false
.
Example: ColumnReduce=false
Display
— Display options for fitting algorithm
'off'
(default) | 'on'
| 'plot'
| 'both'
Display options for the fitting algorithm of the rational object, specified as one of the following:
'off'
— No display'on'
— Printed information'plot'
— Plots of the interpolation progress'both'
— Both printed information and plots.
Example: Display='on'
Data Types: char
Properties
NumPorts
— Number of ports
scalar integer
This property is read-only.
Number of ports in the original S-parameter data, returned as a scalar
integer. The value of the NumPorts
is determined from
the S-parameter data.
NumPoles
— Number of poles
nonegative integer
Number or length of poles in
the fit, specified as a nonegative integer (since R2023a). If you do not
specify the NumPoles
property, then the object sets the
property automatically.
Example: 10
Poles
— Poles of fit
row vector
Poles of the fit or complex values of A in the equation
provided in the description, specified as a row
vector of length NumPoles
-by-1
.
When you specify this property, the object sets the Residues, DirectTerm, and ErrDB properties or you can set them
separately (since R2023a).
If you do not specify the Poles
property, then the
object sets the property automatically.
Example: [-5.4e+10 + 4.7e+10i;-5.4e+10 -
4.7e+10i]
specifies poles for a two-pole fit
Data Types: double
Residues
— Residues in fit
3-D matrix
Residues in the fit or complex values of C in the
equation provided in the description, specified
as a 3-D matrix. The first two dimension of
Residues
must be of the same length as the
first two dimension of data
and the last dimension of
Residues
must be of the same length as
Poles
. If you specify this property, the object
sets the DirectTerm and ErrDB properties or you can set them
separately (since R2023a).
If you do not specify the Residues
property, then the
object sets the property automatically as a 3-D matrix of length
NumPorts
-by-NumPorts
-by-NumPoles
.
Data Types: double
DirectTerm
— Direct term in fit
2-D matrix
Direct term in the fit or the value of D in the
equation provided in the description, specified
as a 2-D matrix. The length of this matrix must be the same as the first
two dimensions of the data
. If you specify this
property, the object sets the ErrDB property (since R2023a).
Note
You must specify this argument with Poles
and
Residues
.
If you do not specify this property, then the object sets the property
automatically as a t2-D matrix of length
NumPorts
-by-NumPorts
.
Example: [0 0;0 0]
Data Types: double
ErrDB
— Error between fit and original data
scalar
This property is read-only.
Error between the fit and the original data, returned as a scalar in dB.
Object Functions
timeresp | Time response for rational objects |
stepresp | Step-signal response for rational object and rationalfit function
object |
freqresp | Frequency response of rational object and rationalfit function
object |
pwlresp | Calculate time response of piecewise linear input signal |
impulse | Impulse response for rational function object |
ispassive | Return true if rational fit output is passive at all frequencies |
makepassive | Enforce passivity of rational fit |
passivity | Plot passivity of N-by-N rational fit output |
generateSPICE | Generate SPICE file from rationalfit of
S-parameters |
abcd | Construct state-space matrices from rational
object |
zpk | Compute zeros, poles, and gain of rational object |
Examples
Fit passive.s2p
File
Create S-Parameters from the file named passive.s2p
.
S = sparameters('passive.s2p');
Perform rational fitting of the S-parameters.
fit = rational(S);
Zeros, Poles, Gain, and DC Gain of Fit
Create an S-Parameters object from the file named default.s2p
. Perform rational fitting of the S-Parameters.
S = sparameters('default.s2p'); fit = rational(S,Display='plot')
fit = rational with properties: NumPorts: 2 NumPoles: 52 Poles: [52x1 double] Residues: [2x2x52 double] DirectTerm: [2x2 double] ErrDB: -22.6872
Calculate the zeros, poles, gain, and DC gain of the rational object.
[z,p,k,dcgain] = zpk(fit)
z=2×2 cell array
{51x1 double} {51x1 double}
{51x1 double} {51x1 double}
p=2×2 cell array
{52x1 double} {52x1 double}
{52x1 double} {52x1 double}
k = 2×2
1010 ×
1.0544 -0.0194
0.9158 0.0377
dcgain = 2×2
0.1289 -0.0838
-0.1209 0.7649
Fit Peaks and Valleys in rational
Object
Create an S-parameters object from the specified S2P file.
S = sparameters('sawfilterpassive.s2p');
f = S.Frequencies;
Create a rational
object with the tolerance of -
40 dB.
fit = rational(S,Tolerance=-40);
Compare the fit to the data. You can see the deviations at the smaller values on a semi-log plot.
dresp = freqresp(fit,f); plot(f,20*log10(abs(squeeze(S.Parameters(2,1,:)))),... f,20*log10(abs(squeeze(dresp(2,1,:)))),f,20*log10(abs(squeeze(S.Parameters(2,1,:)-dresp(2,1,:))))) title('Default Fitting for sawfilterpassive.s2p'); ylabel('dB'); xlabel('Frequency (Hz)'); legend('Data','Fit','Error','Location','northwest');
Create a rational
object with 'ErrorMetric'
set to 'Relative'
to fit both peaks and valleys.
rfit = rational(S,Tolerance=-40,ErrorMetric='Relative');
Compare the fit to the data. The peaks and valleys are fitted.
rresp = freqresp(rfit,f); figure(2) plot(f,20*log10(abs(squeeze(S.Parameters(2,1,:)))),... f,20*log10(abs(squeeze(rresp(2,1,:)))), f, 20*log10(abs(squeeze(S.Parameters(2,1,:)-rresp(2,1,:))))); title('Relative Error Fitting for sawfilterpassive.s2p'); ylabel('dB'); xlabel('Frequency (Hz)'); legend('Data','Fit','Error','Location','northwest');
Ignore Low-Level Noise in Fitter Data
Create an S-parameters object from the specified S2P file.
S = sparameters('passive.s2p');
f = S.Frequencies;
data = S.Parameters;
Set one of the data entries to zero.
data(2,2,:) = 0;
Create a rational
object with the tolerance of -40
dB.
fit = rational(f,data,Tolerance=-40);
Compare the fit to the data. The fit and the data match closely.
xresp = freqresp(fit,f); figure(3) plot(f,abs(squeeze(data(2,1,:))),f,abs(squeeze(xresp(2,1,:))))
Add noise to the data and create a rational
object.
rng(1); noisyData = data + 1e-4 * rand(size(S.Parameters)); nfit = rational(f,noisyData,Tolerance=-40);
Compare the fit to the data with noise. Noise cannot be fitted because this is a data with a higher order fit with a worse error metric.
nresp = freqresp(nfit,f); figure(4) plot(f,abs(squeeze(noisyData(2,2,:))),f,abs(squeeze(nresp(2,2,:))))
Create a rational
object with the noise floor of -60
dB and plot the fit. The fitter ignores low-level noise.
ffit = rational(f,noisyData,Tolerance=-40,NoiseFloor=-60); fresp = freqresp(ffit,f); figure(5) plot(f,abs(squeeze(noisyData(2,2,:))),f,abs(squeeze(fresp(2,2,:))))
Control Poles in Rational Object
Since R2023a
Create an S-parameter object.
S = sparameters('default.s2p');
Perform a default fit.
fit = rational(S)
fit = rational with properties: NumPorts: 2 NumPoles: 52 Poles: [52x1 double] Residues: [2x2x52 double] DirectTerm: [2x2 double] ErrDB: -22.6872
Limit the number of poles to four, and note that and that the error in fit1
is higher than the error in fit
.
fit1 = rational(S,NumPoles=4)
fit1 = rational with properties: NumPorts: 2 NumPoles: 4 Poles: [4x1 double] Residues: [2x2x4 double] DirectTerm: [2x2 double] ErrDB: -14.7945
Force the rational object to use twice the number of poles in fit
. Note that the error in fit2
is lower than fit1
.
fit2 = rational(S,Poles=2*fit.Poles)
fit2 = rational with properties: NumPorts: 2 NumPoles: 52 Poles: [52x1 double] Residues: [2x2x52 double] DirectTerm: [2x2 double] ErrDB: -18.7258
References
[1] Nakatsukasa, Yuji, Olivier Sète, and Lloyd N. Trefethen. “The AAA Algorithm for Rational Approximation.” SIAM Journal on Scientific Computing 40, no. 3 (January 2018): A1494–1522. https://doi.org/10.1137/16M1106122.
Version History
Introduced in R2020aR2023b: Recommended over rationalfit
rational
is
recommend over rationalfit
because it enables faster simulation
and improved fitting of complex frequency-dependent data.
R2023a: Specify poles and residues in rational
object
The rational
object now allow you to specify:
Number of poles
Poles
Residues
Direct term
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)