Skip to content

Commit 8ffa969

Browse files
committed
add example
1 parent f80946b commit 8ffa969

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@ The transfer function can be a vector $f(s) = \[y_1, \dots, y_m\]$ and the Vecto
1212

1313
A rational representation of a transfer function makes it easier to find a [state space canonical realization](https://en.wikipedia.org/wiki/Realization_(systems)#Canonical_realizations) of a system and to [perform convolutions](https://doi.org/10.4236/jamp.2022.106144).
1414

15+
## Usage Example
16+
17+
```julia
18+
using RationalVectorFitting
19+
using Plots
20+
21+
Ns = 101
22+
freq = exp10.(range(0, 4, length = Ns))
23+
s = 2im * pi * freq
24+
poles0 = [-5.0, -100 - 500im, -100 + 500im]
25+
residues0 = [2.0, 30 - 40im, 30 + 40im]
26+
d0 = 0.5
27+
h0 = 0.0
28+
f = rational(s, poles0, residues0, d0, h0)
29+
init_poles = -2pi * exp10.(range(0, 4, length = 3))
30+
poles, residues, d, h, fitted, error_norm = vector_fitting(s, f, init_poles)
31+
begin
32+
p1 = plot(freq, abs.(f), label="f(s)", linecolor=:blue, xlabel="Frequency [Hz]", xaxis=:log, yaxis=:log, legend=:right)
33+
plot!(freq, abs.(fitted), label="fitted(s)", linecolor=:darkorange)
34+
plot!(freq, abs.(f - fitted), label="deviation", linecolor=:green)
35+
display(p1)
36+
end
37+
```
38+
1539
## References
1640

1741
[1] B. Gustavsen and A. Semlyen, "Rational approximation of frequency domain responses by vector fitting," in IEEE Transactions on Power Delivery, vol. 14, no. 3, pp. 1052-1061, July 1999, [doi: 10.1109/61.772353](https://doi.org/10.1109/61.772353).

0 commit comments

Comments
 (0)