Skip to content

Commit

Permalink
Add plus method
Browse files Browse the repository at this point in the history
Signed-off-by: ErikQQY <[email protected]>
  • Loading branch information
ErikQQY committed Dec 27, 2021
1 parent b4f6233 commit 4953565
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ makedocs(;
"FractionalSystems.jl" => "index.md",
"Get Started" => "get_started.md",
"Root Locus" => "rlocus.md",
"Frequency Analysis" => "frequency.md",
"Conversation" => "conversation.md"
],
)
Expand Down
7 changes: 7 additions & 0 deletions docs/src/frequency.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# Frequency domain analysis

Frequency analysis is a powerful tool in system analysis, we can access the properties of the system in frequency domain to reveal the stability, gain margin, phase margin etc.

In FractionalSystems.jl, it is also easy to transform the system to frequency domain:

```julia-repl
julia>
```
72 changes: 49 additions & 23 deletions src/fotf/fotf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,48 @@ Add two fractional order model.
You can't add two systems with different I/O delay.
"""
#=function +(G1::FOTF, G2::FOTF)
function +(G1::FOTF, G2::FOTF)
G = sisoplus(G1, G2)
return G
end
=#
#=
function sisoplus(G1, G2)

"""
sisoplus(G1, G2)
The addition of two single-input-single-output FOTF.
"""
function sisoplus(G1::FOTF, G2::FOTF)
if iszero(G2)
return G1
elseif G1.ioDelay == G2.ioDelay
key=0
G1=simplify(G1)
G2=simplify(G2)
(a1, na1, b1, nb1)=fotfdata(G1)
(a2, na2, b2, nb2)=fotfdata(G2)
key = 0
G1 = simplify(G1)
G2 = simplify(G2)
(a1, na1, b1, nb1) = fotfdata(G1)
(a2, na2, b2, nb2) = fotfdata(G2)
if length(a1) == length(a2)
if all()
if a1 == a2 && na1 == na2
a=a1
na=na1
b=[b1; b2]
nb=[nb1; nb2]
key=1
end
end

if key == 0
a = kron(a1, a2)
na = kronsum(na1, na2)
b = [kron(a1, b2); kron(b1, a2)]
nb = [kronsum(na1, nb2); kronsum(nb1, na2)]
end

G = fotf(a, na, b, nb)
return G
end
end
=#

function simplify(G::FOTF, tol=0.000001)
function simplify(G::FOTF, tol=0.0000000001)
(b, nb) = polyuniq(G.num, G.nn, tol)
(a, na) = polyuniq(G.den, G.nd, tol)

Expand Down Expand Up @@ -107,12 +128,13 @@ end
function polyuniq(a, an, tol)
an = sort(an, rev=true)
ii = sortperm(an, rev=true)

a = a[ii]
ax = diff(an)
key=1
key::Int64 = 1
for i = 1:length(ax)
if abs(ax[i]) <= tol
a[key] = a[key]+a[key+1]
a[key] = a[key] + a[key+1]
deleteat!(a, key+1)
deleteat!(an, key+1)
else
Expand All @@ -131,15 +153,19 @@ end
Return the Kronecker sum of two matrices
"""
function kronsum(A, B)
(ma, na) = size(A)
(mb, nb) = size(B)
function kronsum(A::T, B::T) where {T <: AbstractArray}
ma, na = size(A, 2), size(A, 1)
mb, nb = size(B, 2), size(B, 1)
A = reshape(A, 1, ma, 1, na)
B= reshape(B, mb, 1, nb, 1)
C = reshape(broadcast(+, A, B), (mb*mb, na*nb))
return C
end

function kronsum(A::T, B::T) where {T <: Number}
return A+B
end


"""
fotf2cotf(tf)
Expand Down Expand Up @@ -232,11 +258,11 @@ julia> fotfdata(G)
```
"""
function fotfdata(G::FOTF)
b=G.num
a=G.den
nb=G.nn
na=G.nd
L=G.ioDelay
b = G.num
a = G.den
nb = G.nn
na = G.nd
L = G.ioDelay

return [a, na, b, nb, L]
end
Expand Down
6 changes: 6 additions & 0 deletions src/fotf/freqresp.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using ControlSystems

"""
freqresp(s, G)
The frequency response of FOTF.
"""
function ControlSystems.freqresp(s, G::FOTF)
(a, na, b, nb, L) = fotfdata(G)

Expand All @@ -11,6 +16,7 @@ function ControlSystems.freqresp(s, G::FOTF)
Q = a'*(s[k].^na)
H1[k] = P/Q
end

if L>0
H1 = H1.*exp.(L*s)
end
Expand Down

2 comments on commit 4953565

@ErikQQY
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Tag with name v0.1.0 already exists and points to a different commit"

Please sign in to comment.