You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a DiscreteTransferFunction from a `ControlSystems.TransferFunction`.
10
+
11
+
The sample time of `G` is used to create a periodic `Clock` object with which the transfer funciton is associated. If this is not desired, pass a custom `ShiftIndex` via the `z` keyword argument. To let the transfer function inherit the sample time of of the surrounding context (clock inference), pass and empty `z = ShiftIndex()`.
12
+
"""
13
+
function ModelingToolkitSampledData.DiscreteTransferFunction(G::TransferFunction{<:Discrete}; z =nothing, kwargs...)
14
+
issiso(G) ||throw(ArgumentError("Only SISO systems are supported"))
Copy file name to clipboardExpand all lines: src/discrete_blocks.jl
+42-10Lines changed: 42 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -718,25 +718,57 @@ With the coeffiencents specified in decreasing orders of ``z``, i.e., ``b = [b_{
718
718
- `output`: Output signal
719
719
720
720
# Extended help:
721
-
This component supports SISO systems only. To simulate MIMO transfer functions, use [ControlSystemsBase.jl](https://juliacontrol.github.io/ControlSystems.jl/stable/man/creating_systems/) to convert the transfer function to a statespace system, optionally compute a minimal realization using [`minreal`](https://juliacontrol.github.io/ControlSystems.jl/stable/lib/constructors/#ControlSystemsBase.minreal), and then use a [`DiscreteStateSpace`](@ref) component instead.
721
+
This component supports SISO systems only. To simulate MIMO transfer functions, use [ControlSystemsBase.jl](https://juliacontrol.github.io/ControlSystems.jl/stable/man/creating_systems/) to convert the transfer function to a statespace system.
722
722
723
-
See also [ControlSystemsMTK.jl](https://juliacontrol.github.io/ControlSystemsMTK.jl/stable/) for an interface between [ControlSystems.jl](https://juliacontrol.github.io/ControlSystems.jl/stable/) and ModelingToolkit.jl for advanced manipulation of transfer functions and linear statespace systems. For linearization, see [`linearize`](@ref) and [Linear Analysis](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/linear_analysis/).
723
+
See also [ControlSystemsMTK.jl](https://juliacontrol.github.io/ControlSystemsMTK.jl/stable/) for an interface between [ControlSystems.jl](https://juliacontrol.github.io/ControlSystems.jl/stable/) and ModelingToolkit.jl for advanced manipulation of transfer functions and linear statespace systems.
724
724
"""
725
+
@componentfunctionDiscreteTransferFunction(; a = [1], b = [1],
726
+
verbose =true,
727
+
z =ShiftIndex(),
728
+
name,
729
+
)
730
+
na =length(a)
731
+
nb =length(b)
732
+
verbose && nb > na &&@warn"DiscreteTransferFunction: Numerator degree is larger than denominator degree, this is not a proper transfer function. Simulation of a model including this transfer funciton will require at least $(nb-na) samples additional delay in series. Silence this warning with verbose=false"
733
+
@parametersbegin
734
+
(b[1:nb] = b), [description ="Numerator coefficients of transfer function (e.g., z - 1 is specified as [1,-1])"]
735
+
(a[1:na] = a), [description ="Denominator coefficients of transfer function (e.g., z^2 - 0.78z + 0.37 is specified as [1, -0.78, 0.37])"]
736
+
end
737
+
a =collect(a)
738
+
b =collect(b)
739
+
systems =@namedbegin
740
+
input =RealInput()
741
+
output =RealOutput()
742
+
end
743
+
@variablesbegin
744
+
(u(t) =0.0), [description ="Input flowing through connector `input`"]
745
+
(y(t) =0.0), [description ="Output flowing through connector `output`"]
746
+
end
747
+
equations = [
748
+
sum(y(z-k+1) * a[k] for k in1:na) ~sum(u(z-k+1) * b[k] for k in1:nb)
DiscreteTransferFunction(b, a; kwargs...) =DiscreteTransferFunction(; b, a, kwargs...)
756
+
725
757
# @mtkmodel DiscreteTransferFunction begin
726
758
# @parameters begin
727
-
# b = [1], [description = "Numerator coefficients of transfer function (e.g., z - 1 is specified as [1,-1])"]
728
-
# a = [1], [description = "Denominator coefficients of transfer function (e.g., z^2 - 0.78z + 0.37 is specified as [1, -0.78, 0.37])"]
759
+
# b[1:1] = [1], [description = "Numerator coefficients of transfer function (e.g., z - 1 is specified as [1,-1])"]
760
+
# a[1:1] = [1], [description = "Denominator coefficients of transfer function (e.g., z^2 - 0.78z + 0.37 is specified as [1, -0.78, 0.37])"]
729
761
# end
730
762
# @structural_parameters begin
731
763
# verbose = true
732
-
# Ts = SampleTime()
733
-
# z = ShiftIndex()
764
+
#Ts = SampleTime()
765
+
#z = ShiftIndex()
734
766
# end
735
767
# begin
736
-
# na = length(a)
737
-
# nb = length(b)
768
+
# @show na = length(a)
769
+
# @show nb = length(b)
770
+
# @show a
738
771
# verbose && nb > na && @warn "DiscreteTransferFunction: Numerator degree is larger than denominator degree, this is not a proper transfer function. Simulation of a model including this transfer funciton will require at least $(nb-na) samples additional delay in series. Silence this warning with verbose=false"
739
-
# Ts = SampleTime()
740
772
# end
741
773
# @components begin
742
774
# input = RealInput()
@@ -753,7 +785,7 @@ See also [ControlSystemsMTK.jl](https://juliacontrol.github.io/ControlSystemsMTK
753
785
# end
754
786
# end
755
787
756
-
#DiscreteTransferFunction(b, a; kwargs...) = DiscreteTransferFunction(; b, a, kwargs...)
0 commit comments