# S-Domain Fit

 Description S-domain system identification in LTPDA. Algorithm Fit Algorithm. Examples Usage example of s-domain system identification tool. References Bibliographic references.

## S-domain system identification in LTPDA

System identification in s-domain is performed with the function sDomainFit. It is based on a modeified version of the vector fitting algorithm. Details on the core agorithm can be found in [1 - 2].

## Fit Algorithm

The function performs a fitting loop to automatically identify model order and parameters in s-domain. Output is a s-domain model expanded in partial fractions:

```              r1              rN
f(s) = ------- + ... + ------- + d
s - p1          s - pN
```

Since the function can fit more than one input analysis object at a time with a common set of poles, output parfrac are embedded in a matrix (note that this characteristic will be probably changed becausse of the introduction of the collection class).

Identification loop stops when the stop condition is reached. Stop criterion is based on three different approachs:

1. Mean Squared Error and variation
Check if the normalized mean squared error is lower than the value specified in FITTOL and if the relative variation of the mean squared error is lower than the value specified in MSEVARTOL. E.g. FITTOL = 1e-3, MSEVARTOL = 1e-2 search for a fit with normalized meam square error lower than 1e-3 and MSE relative variation lower than 1e-2.
2. Log residuals difference and root mean squared error
• Log Residuals difference
Check if the minimum of the logarithmic difference between data and residuals is larger than a specified value. ie. if the conditioning value is 2, the function ensures that the difference between data and residuals is at lest two order of magnitude lower than data itsleves.
• Root Mean Squared Error
Check that the variation of the root mean squared error is lower than 10^(-1*value).
3. Residuals spectral flatness and root mean squared error
• Residuals Spectral Flatness
In case of a fit on noisy data, the residuals from a good fit are expected to be as much as possible similar to a white noise. This property can be used to test the accuracy of a fit procedure. In particular it can be tested that the spectral flatness coefficient of the residuals is larger than a certain qiantity sf such that 0 < sf < 1.
• Root Mean Squared Error
Check that the variation of the root mean squared error is lower than 10^(-1*value).

The function can also perform a single loop without taking care of the stop conditions. This happens when 'AutoSearch' parameter is set to 'off'.

## Usage example of s-domain system identification tool

In this example we fit a given frequency response to get a partial fraction model. For the meaning of any parameter please refer to ao and sDomainFit documentation pages.

```    pl = plist(...
'fsfcn', '(1e-3./(f).^2 + 1e3./(0.001+f) + 1e5.*f.^2).*1e-10',...
'f1', 1e-6,...
'f2', 5,...
'nf', 100);

a = ao(pl);
a.setName;

% Fit parameter list
pl_fit = plist(...
'AutoSearch','on',...
'StartPolesOpt','clog',...
'maxiter',50,...
'minorder',7,...
'maxorder',15,...
'weightparam','abs',...
'CONDTYPE','MSE',...
'FITTOL',1e-3,...
'MSEVARTOL',1e-2,...
'Plot','on',...
'ForceStability','off');

% Do fit
mod = sDomainFit(a, pl_fit);
```

mod is a matrix object containing a parfrac object.

```    >> mod
---- matrix 1 ----
name: fit(a)
size: 1x1
01: parfrac | parfrac(fit(a))
description:
UUID: 2dc1ac28-4199-42d2-9b1a-b420252b3f8c
------------------
```
```    >> mod.objs
---- parfrac 1 ----
model:       fit(a)
res:         [1.69531090137847e-006;-1.69531095674486e-006;1.39082537801437e-007;-1.39094453401266e-007;3.9451875151135e-007;-3.94524993613367e-007;4.53671387948961e-007;-4.53664974359603e-007;1124.81020427899;0.000140057852149302-i*0.201412268649905;0.000140057852149302+i*0.201412268649905]
poles:       [-1.18514026248382e-006;1.18514354570495e-006;-0.00457311582050939;0.0045734088943545;-0.0316764149343339;0.0316791653277322;-0.276256442292693;0.27627799022013;330754.550617933;-0.0199840558095427+i*118.439896186467;-0.0199840558095427-i*118.439896186467]
dir:         0
pmul:        [1;1;1;1;1;1;1;1;1;1;1]
iunits:      []
ounits:      []
description:
UUID:        2afc4c82-7c2a-4fe3-8910-d8590884d58c
-------------------
```

## References

1. B. Gustavsen and A. Semlyen, "Rational approximation of frequency domain responses by Vector Fitting", IEEE Trans. Power Delivery vol. 14, no. 3, pp. 1052-1061, July 1999.
2. B. Gustavsen, "Improving the Pole Relocating Properties of Vector Fitting", IEEE Trans. Power Delivery vol. 21, no. 3, pp. 1587-1592, July 2006.