Exported functions and types
Index
ControlSystemIdentification.FRD
ControlSystemIdentification.Hz
ControlSystemIdentification.N4SIDStateSpace
ControlSystemIdentification.rad
ControlSystemIdentification.apply_fun
ControlSystemIdentification.ar
ControlSystemIdentification.ar
ControlSystemIdentification.arma
ControlSystemIdentification.arma
ControlSystemIdentification.arma_ssa
ControlSystemIdentification.arx
ControlSystemIdentification.arx
ControlSystemIdentification.arxar
ControlSystemIdentification.arxar
ControlSystemIdentification.coherence
ControlSystemIdentification.coherence
ControlSystemIdentification.coherenceplot
ControlSystemIdentification.crosscorplot
ControlSystemIdentification.era
ControlSystemIdentification.era
ControlSystemIdentification.era
ControlSystemIdentification.estimate_residuals
ControlSystemIdentification.estimate_x0
ControlSystemIdentification.filter_bank
ControlSystemIdentification.find_na
ControlSystemIdentification.find_nanb
ControlSystemIdentification.find_similarity_transform
ControlSystemIdentification.getARXregressor
ControlSystemIdentification.getARXregressor
ControlSystemIdentification.getARregressor
ControlSystemIdentification.getARregressor
ControlSystemIdentification.iddata
ControlSystemIdentification.iddata
ControlSystemIdentification.impulseest
ControlSystemIdentification.impulseest
ControlSystemIdentification.impulseestplot
ControlSystemIdentification.kautz
ControlSystemIdentification.laguerre
ControlSystemIdentification.laguerre_oo
ControlSystemIdentification.laguerre_oo
ControlSystemIdentification.minimum_phase
ControlSystemIdentification.model_spectrum
ControlSystemIdentification.model_spectrum
ControlSystemIdentification.n4sid
ControlSystemIdentification.n4sid
ControlSystemIdentification.newpem
ControlSystemIdentification.noise_model
ControlSystemIdentification.okid
ControlSystemIdentification.okid
ControlSystemIdentification.pem
ControlSystemIdentification.pem
ControlSystemIdentification.plr
ControlSystemIdentification.plr
ControlSystemIdentification.predictiondata
ControlSystemIdentification.predplot
ControlSystemIdentification.prefilter
ControlSystemIdentification.prefilter
ControlSystemIdentification.prefilter
ControlSystemIdentification.ramp_in
ControlSystemIdentification.simplot
ControlSystemIdentification.simulate
ControlSystemIdentification.subspaceid
ControlSystemIdentification.subspaceid
ControlSystemIdentification.tfest
ControlSystemIdentification.tfest
ControlSystemIdentification.tfest
ControlSystemIdentification.tfest
ControlSystemIdentification.wtls_estimator
DSP.Filters.resample
DSP.Filters.resample
DSP.Filters.resample
DelimitedFiles.writedlm
StatsBase.predict
StatsBase.predict
StatsBase.predict
StatsBase.residuals
ControlSystemIdentification.FRD
— TypeFRD(w,r)
Represents frequency-response data. w
holds the frequency vector and r
the response. Methods defined on this type include
+-*
length, vec, sqrt
plot
feedback
ControlSystemIdentification.Hz
— TypeRepresents frequencies in Herz for indexing of FRD
objects: frd[2Hz:10Hz]
ControlSystemIdentification.N4SIDStateSpace
— TypeN4SIDStateSpace <: AbstractPredictionStateSpace
The result of statespace model estimation using the n4sid
method.
Fields:
sys
: estimated model in the form of aStateSpace
objectQ
: estimated covariance matrix of the statesR
: estimated covariance matrix of the measurementsS
: estimated cross covariance matrix between states and measurementsK
: kalman observer gainP
: solution to the Riccatti equationx
: estimated state trajectorys
: singular valuesfve
: Fraction of variance explained by singular values
ControlSystemIdentification.rad
— TypeRepresents frequencies in rad/s for indexing of FRD
objects: frd[2rad:10rad]
ControlSystemIdentification.apply_fun
— Functionapply_fun(fun, d::InputOutputData)
Apply fun(y)
to all time series y[,u,[x]] ∈ d
and return a new iddata
with the transformed series.
ControlSystemIdentification.ar
— Methodar(d::AbstractIdData, na; λ=0, estimator=\, scaleB=false, stochastic=false)
Estimate an AR transfer function G = 1/A
, the AR process is defined as A(z⁻¹)y(t) = e(t)
Arguments:
d
: IdData, seeiddata
na
: order of the modelλ
:λ > 0
can be provided for L₂ regularizationestimator
: e.g.\,tls,irls,rtls
scaleB
: Whether or not to scale the numerator using the variance of the prediction error.stochastic
: if true, returns a transfer function with uncertain parameters represented byMonteCarloMeasurements.Particles
.
Estimation of AR models using least-squares is known to struggle with heavy measurement noise, using estimator = tls
can improve the result in this case.
Example
julia> N = 10000
10000
julia> e = [-0.2; zeros(N-1)] # noise e
10000-element Vector{Float64}:
[...]
julia> G = tf([1, 0], [1, -0.9], 1) # AR transfer function
TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Float64}}
1.0z
----------
1.0z - 0.9
Sample Time: 1 (seconds)
Discrete-time transfer function model
julia> y = lsim(G, e, 1:N)[1][:] # Get output of AR transfer function from input noise e
10000-element Vector{Float64}:
[...]
julia> Gest = ar(iddata(y), 1) # Estimate AR transfer function from output y
TransferFunction{Discrete{Float64}, ControlSystems.SisoRational{Float64}}
1.0z
-------------------------
1.0z - 0.8999999999999998
Sample Time: 1.0 (seconds)
Discrete-time transfer function model
julia> G ≈ Gest # Test if estimation was correct
true
julia> eest = lsim(1/Gest, y, 1:N)[1][:] # recover the input noise e from output y and estimated transfer function Gest
10000-element Vector{Float64}:
[...]
julia> isapprox(eest, e, atol = eps()) # input noise correct recovered
true
ControlSystemIdentification.arma
— Methodmodel = arma(d::AbstractIdData, na, nc; initial_order=20, method=:ls)
Estimate a Autoregressive Moving Average model with na
coefficients in the denominator and nc
coefficients in the numerator. Returns the model and the estimated noise sequence driving the system.
Arguments:
d
: iddatainitial_order
: An initial AR model of this order is used to estimate the residualsestimator
: A function(A,y)->minimizeₓ(Ax-y)
default is `but another option is
wtlsestimator(1:length(y)-initialorder,na,nc,ones(nc))`
See also estimate_residuals
ControlSystemIdentification.arma_ssa
— Methodarma_ssa(d::AbstractIdData, na, nc; L=nothing, estimator=\, robust=false)
DOCSTRING
Arguments:
d
: iddatana
: number of denominator parametersnc
: number of numerator parametersL
: length of the lag-embedding used to separate signal and noise.nothing
corresponds to automatic selection.estimator
: The function to solve the least squares problem. Examples\,tls,irls,rtls
.robust
: Use robust PCA to be resistant to outliers.
ControlSystemIdentification.arx
— MethodGtf = arx(d::AbstractIdData, na, nb; inputdelay = ones(Int, size(nb)), λ = 0, estimator=\, stochastic=false)
Fit a transfer Function to data using an ARX model and equation error minimization.
nb
andna
are the number of coefficients of the numerator and denominator polynomials.
Input delay can be added via inputdelay = d
, which corresponds to an additional delay of z^-d
. An inputdelay = 0
results in a direct term. The highest order of the B polynomial is given by nb + inputdelay - 1
. λ > 0
can be provided for L₂ regularization. estimator
defaults to \ (least squares), alternatives are estimator = tls
for total least-squares estimation. arx(Δt,yn,u,na,nb, estimator=wtls_estimator(y,na,nb)
is potentially more robust in the presence of heavy measurement noise. The number of free parameters is na+nb
stochastic
: if true, returns a transfer function with uncertain parameters represented byMonteCarloMeasurements.Particles
.
Supports MISO estimation by supplying an iddata with a matrix u
, with nb = [nb₁, nb₂...] and optional inputdelay = [d₁, d₂...]
ControlSystemIdentification.arxar
— MethodG, H, e = arxar(d::InputOutputData, na::Int, nb::Union{Int, Vector{Int}}, nd::Int)
Estimate the ARXAR model Ay = Bu + v
, where v = He
and H = 1/D
, using generalized least-squares method. For more information see Söderström - Convergence properties of the generalized least squares identification method, 1974.
Arguments:
d
: iddatana
: order of Anb
: number of coefficients in B, the order is determined bynb + inputdelay - 1
. In MISO estimation it takes the form nb = [nb₁, nb₂...].nd
: order of D
Keyword Arguments:
H = nothing
: prior knowledge about the AR noise modelinputdelay = ones(Int, size(nb))
: optional delay of input, inputdelay = 0 results in a direct term, takes the form inputdelay = [d₁, d₂...] in MISO estimationλ = 0
:λ > 0
can be provided for L₂ regularizationestimator = \
: e.g.\,tls,irls,rtls
, the latter three requireusing TotalLeastSquares
δmin = 10e-4
: Minimal change in the power of e, that specifies convergence.iterations = 10
: maximum number of iterations.verbose = false
: if true, more information is printed
Example:
julia> N = 500
500
julia> sim(G, u) = lsim(G, u, 1:N)[1][:]
sim (generic function with 1 method)
julia> A = tf([1, -0.8], [1, 0], 1)
TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Float64}}
1.0z - 0.8
----------
1.0z
Sample Time: 1 (seconds)
Discrete-time transfer function model
julia> B = tf([0, 1], [1, 0], 1)
TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Int64}}
1
-
z
Sample Time: 1 (seconds)
Discrete-time transfer function model
julia> G = minreal(B / A)
TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Float64}}
1.0
----------
1.0z - 0.8
Sample Time: 1 (seconds)
Discrete-time transfer function model
julia> D = tf([1, 0.7], [1, 0], 1)
TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Float64}}
1.0z + 0.7
----------
1.0z
Sample Time: 1 (seconds)
Discrete-time transfer function model
julia> H = 1 / D
TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Float64}}
1.0z
----------
1.0z + 0.7
Sample Time: 1 (seconds)
Discrete-time transfer function model
julia> u, e = randn(1, N), randn(1, N)
[...]
julia> y, v = sim(G, u), sim(H * (1/A), e) # simulate process
[...]
julia> d = iddata(y .+ v, u, 1)
InputOutput data of length 500 with 1 outputs and 1 inputs
julia> na, nb , nd = 1, 1, 1
(1, 1, 1)
julia> Gest, Hest, res = arxar(d, na, nb, nd)
(G = TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Float64}}
0.9987917259291642
-------------------------
1.0z - 0.7937837464682017
Sample Time: 1 (seconds)
Discrete-time transfer function model, H = TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Float64}}
1.0z
-------------------------
1.0z + 0.7019519225937721
Sample Time: 1 (seconds)
Discrete-time transfer function model, e = [...]
ControlSystemIdentification.coherence
— Methodκ = coherence(d; n = length(d)÷10, noverlap = n÷2, window=hamming)
Calculates the magnitude-squared coherence Function. κ close to 1 indicates a good explainability of energy in the output signal by energy in the input signal. κ << 1 indicates that either the system is nonlinear, or a strong noise contributes to the output energy. κ: Coherence function (not squared) N: Noise model
ControlSystemIdentification.coherenceplot
— Functioncoherenceplot(d, [(;n=..., noverlap=...); hz=false)
Calculates and plots the (squared) coherence Function κ. κ close to 1 indicates a good explainability of energy in the output signal by energy in the input signal. κ << 1 indicates that either the system is nonlinear, or a strong noise contributes to the output energy.
hz
indicates Hertz instead of rad/s
Keyword arguments to coherence
are supplied as a named tuple as a second positional argument .
ControlSystemIdentification.crosscorplot
— Functioncrosscorplot(data, [lags])
Plot the cross correlation betweein input and output for lags
that default to 10% of the length of the dataset on the negative side and 50% on the positive side but no more than 100 on each side.
ControlSystemIdentification.era
— Functionera(d::AbstractIdData, r, m = 2r, n = 2r, l = 5r; λ=0)
Eigenvalue realization algorithm. Uses okid
to find the Markov parameters as an initial step.
Arguments:
r
: Model orderl
: Number of Markov parameters to estimate.λ
: Regularization parameter
ControlSystemIdentification.era
— Methodera(YY::AbstractArray{<:Any, 3}, Ts, r::Int, m::Int, n::Int)
Eigenvalue realization algorithm.
Arguments:
YY
: Markov parameters (impulse response) sizen_out×n_in×n_time
Ts
: Sample timer
: Model orderm
: Number of rows in Hankel matrixn
: Number of columns in Hankel matrix
ControlSystemIdentification.estimate_residuals
— Methodestimate_residuals(model, y)
Estimate the residuals driving the dynamics of an ARMA model.
ControlSystemIdentification.estimate_x0
— Functionestimate_x0(sys, d, n = min(length(d), 3 * slowest_time_constant(sys)))
Estimate the initial state of the system
Arguments:
d
:iddata
n
: Number of samples to use.
ControlSystemIdentification.filter_bank
— Methodfilter_bank(basis::AbstractStateSpace{<:Discrete}, signal::AbstractMatrix)
Filter signal
through all systems in basis
ControlSystemIdentification.find_na
— Functionfind_na(y::AbstractVector,n::Int)
Plots the RMSE and AIC For model orders up to n
. Useful for model selection
ControlSystemIdentification.find_nanb
— Functionfind_nanb(d::InputOutputData,na,nb)
Plots the RMSE and AIC For model orders up to n
. Useful for model selection
ControlSystemIdentification.find_similarity_transform
— Functionfind_similarity_transform(sys1, sys2)
Find T such that ControlSystems.similarity_transform(sys1, T) == sys2
Ref: Minimal state-space realization in linear system theory: an overview, B. De Schutter
julia> T = randn(3,3);
julia> sys1 = ssrand(1,1,3);
julia> sys2 = ControlSystems.similarity_transform(sys1, T);
julia> T2 = find_similarity_transform(sys1, sys2);
julia> T2 ≈ T
true
ControlSystemIdentification.getARXregressor
— MethodgetARXregressor(y::AbstractVector,u::AbstractVecOrMat, na, nb; inputdelay = ones(Int, size(nb)))
Returns a shortened output signal y
and a regressor matrix A
such that the least-squares ARX model estimate of order na,nb
is y\A
Return a regressor matrix used to fit an ARX model on, e.g., the form A(z)y = B(z)f(u)
with output y
and input u
where the order of autoregression is na
, the order of input moving average is nb
and an optional input delay inputdelay
. Caution, changing the input delay changes the order to nb + inputdelay - 1
. An inputdelay = 0
results in a direct term.
Example
Here we test the model with the Function f(u) = √(|u|)
A = [1,2*0.7*1,1] # A(z) coeffs
B = [10,5] # B(z) coeffs
u = randn(100) # Simulate 100 time steps with Gaussian input
y = filt(B,A,u)
yr,A = getARXregressor(y,u,3,2) # We assume that we know the system order 3,2
x = A\yr # Estimate model polynomials
plot([yr A*x], lab=["Signal" "Prediction"])
For nonlinear ARX-models, see BasisFunctionExpansions.jl. See also arx
ControlSystemIdentification.getARregressor
— Methodyt,A = getARregressor(y::AbstractVector, na)
Returns values such that x = A\yt
. See getARXregressor
for more details.
ControlSystemIdentification.iddata
— Functioniddata(y, u, x, Ts = nothing)
Returns the appropriate IdData object, depending on the input.
Arguments
y::AbstractArray
: output data (required)u::AbstractArray
: input data (if available)x::AbstractArray
: state data (if available)Ts::Union{Real,Nothing} = nothing
: optional sample time
If the time-series are multivariate, time is in the last dimension.
Operations on iddata
prefilter
resample
- append two along the time dimension
[d1 d2]
- index time series
d[output_index, input_index]
- index the time axis with indices
d[time_indices]
- index the time axis with seconds
d[3Sec:12Sec]
(using ControlSystemIdentification: Sec
) - access number of inputs, outputs and sample time:
d.nu, d.ny, d.Ts
- access the time time vector
d.t
- premultiply to scale outputs
C * d
- postmultiply to scale inputs
d * B
writedlm
ramp_in
,ramp_out
Examples
julia> iddata(randn(10))
Output data of length 10 with 1 outputs
julia> iddata(randn(10), randn(10), 1)
InputOutput data of length 10 with 1 outputs and 1 inputs
julia> d = iddata(randn(2, 10), randn(3, 10), 0.1)
InputOutput data of length 10 with 2 outputs and 3 inputs
julia> [d d] # Concatenate along time
InputOutput data of length 20 with 2 outputs and 3 inputs
julia> d[1:3]
InputOutput data of length 3 with 2 outputs and 3 inputs
julia> d.nu
3
julia> d.t # access time vector
0.0:0.1:0.9
ControlSystemIdentification.impulseest
— Methodir, t, Σ = impulseest(d::AbstractIdData, n; λ=0, estimator=ls)
Estimates the system impulse response by fitting an n
:th order FIR model. Returns impulse-response estimate, time vector and covariance matrix. See also impulseestplot
ControlSystemIdentification.impulseestplot
— Functionimpulseestplot(data,n)
Estimates the system impulse response by fitting an n
:th order FIR model and plots the result with a 95% confidence band. See also impulseestplot
ControlSystemIdentification.kautz
— Methodkautz(a::Vector, h)
Construct a discrete-time Kautz basis of length with poles at a
amd sample time h
.
ControlSystemIdentification.laguerre
— Methodlaguerre(a::Number, Nq)
Construct a Laguerre basis of length Nq
with poles at a
.
ControlSystemIdentification.laguerre_oo
— Methodlaguerre_oo(a::Number, Nq)
Construct an output orthogonalized Laguerre basis of length Nq
with poles at a
.
ControlSystemIdentification.minimum_phase
— Methodminimum_phase(G)
Move zeros and poles of G
from the unstable half plane to the stable. If G
is a statespace system, it's converted to a transfer function first. This can incur loss of precision.
ControlSystemIdentification.model_spectrum
— Methodmodel_spectrum(f, h, args...; kwargs...)
Arguments:
f
: the model-estimation function, e.g.,ar,arma
h
: The sample timeargs
: arguments tof
kwargs
: keyword arguments tof
Example:
using ControlSystemIdentification, DSP
T = 1000
s = sin.((1:T) .* 2pi/10)
S1 = spectrogram(s,window=hanning)
estimator = model_spectrum(ar,1,2)
S2 = spectrogram(s,estimator,window=rect)
plot(plot(S1),plot(S2)) # Requires the package LPVSpectral.jl
ControlSystemIdentification.n4sid
— Methodres = n4sid(data, r=:auto; verbose=false)
Estimate a statespace model using the n4sid method. Returns an object of type N4SIDStateSpace
where the model is accessed as res.sys
.
Implements the simplified algorithm (alg 2) from "N4SID: Subspace Algorithms for the Identification of Combined Deterministic Stochastic Systems" PETER VAN OVERSCHEE and BART DE MOOR
The frequency weighting is borrowing ideas from "Frequency Weighted Subspace Based System Identication in the Frequency Domain", Tomas McKelvey 1996. In particular, we apply the output frequency weight matrix (Fy) as it appears in eqs. (16)-(18).
Arguments:
data
: Identification datadata = iddata(y,u)
y
: Measurements N×nyu
: Control signal N×nur
: Rank of the model (model order)verbose
: Print stuff?Wf
: A frequency-domain model of measurement disturbances. To focus the attention of the model on a narrow frequency band, try something likeWf = Bandstop(lower, upper, fs=1/Ts)
to indicate that there are disturbances outside this band.i
: Algorithm parameter, generally no need to tune thisγ
: Set this to a value between (0,1) to stabilize unstable models such that the largest eigenvalue has magnitude γ.zeroD
: defaults to false
ControlSystemIdentification.noise_model
— Methodnoise_model(sys::AbstractPredictionStateSpace)
Return a model of the noise driving the system, v
, in x' = Ax + Bu + Kv y = Cx + Du + v
The model neglects u and is given by x' = Ax + Kv y = Cx + v
ControlSystemIdentification.okid
— FunctionH = okid(d::AbstractIdData, r, l = 5r; λ=0)
Observer Kalman filter identification. Returns the Markov parameters H
size n_out×n_in×l+1
Arguments:
r
: Model orderl
: Number of Markov parameters to estimate.λ
: Regularization parameter
ControlSystemIdentification.pem
— Methodsys, x0, opt = pem(data; nx, kwargs...)
System identification using the prediction-error method.
Arguments:
data
: iddata object containingy
andu
.y
: Measurements, either a matrix with time along dim 2, or a vector of vectorsu
: Control signals, same structure asy
nx
: Number of poles in the estimated system. Thus number should be chosen as number of system poles plus number of poles in noise models for measurement noise and load disturbances.focus
: Either:prediction
or:simulation
. If:simulation
is chosen, a two stage problem is solved with prediction focus first, followed by a refinement for simulation focus.metric
: A Function determining how the size of the residuals is measured, defaultsse
(e'e), but any Function such asnorm
,e->sum(abs,e)
ore -> e'Q*e
could be used.regularizer(p)=0
: function for regularization. The structure ofp
is detailed belowsolver
Defaults toOptim.BFGS()
stabilize_predictor=true
: Modifies the estimated Kalman gainK
in caseA-KC
is not stable by moving all unstable eigenvalues to the unit circle.difficult=false
: If the identification problem appears to be difficult and ends up in a local minimum, set this flag to true to solve an initial global optimization problem to supply a good initial guess. This is expected to take some time.kwargs
: additional keyword arguments are sent toOptim.Options
.
Return values
sys::StateSpaceNoise
: identified system. Can be converted toStateSpace
byconvert(StateSpace, sys)
orss(sys)
, but this will discard the Kalman gain matrix, seeinnovation_form
to obtain a predictor system.x0
: Estimated initial stateopt
: Optimization problem structure. Contains info of the result of the optimization problem
Structure of parameter vector p
The parameter vector is of type ComponentVector
and the fields A,B,K,x0
can be accessed as p.A
etc. The internal storage is according to
A = size(nx,nx)
B = size(nx,nu)
K = size(nx,ny)
x0 = size(nx)
p = [A[:]; B[:]; K[:]; x0]
ControlSystemIdentification.plr
— MethodG, Gn = plr(d::AbstractIdData,na,nb,nc; initial_order = 20)
Perform pseudo-linear regression to estimate a model on the form Ay = Bu + Cw
The residual sequence is estimated by first estimating a high-order arx model, whereafter the estimated residual sequence is included in a second estimation problem. The return values are the estimated system model, and the estimated noise model. G
and Gn
will always have the same denominator polynomial.
ControlSystemIdentification.predplot
— Functionpredplot(sys, data, x0=nothing; ploty=true, plote=false)
Plot system simulation and measured output to compare them. ploty
determines whether or not to plot the measured signal plote
determines whether or not to plot the residual
ControlSystemIdentification.prefilter
— Methodprefilter(f, d::InputOutputData)
Apply filter coefficients to identification data
ControlSystemIdentification.prefilter
— Methodprefilter(d::AbstractIdData, responsetype::FilterType)
Filter both input and output of the identification data using zero-phase filtering (filtfilt
). Since both input and output is filtered, linear identification will not be affected in any other way than to focus the fit on the selected frequency range, i.e. the range that has high gain in the provided filter. Note, if the system that generated d
is nonlinear, identification might be severely impacted by this transformation. Verify linearity with, e.g., coherenceplot
.
ControlSystemIdentification.prefilter
— Methodprefilter(d::AbstractIdData, l::Number, u::Number)
Filter input and output with a bandpass filter between l
and u
Hz. If l = 0
a lowpass filter will be used, and if u = Inf
a highpass filter will be used.
ControlSystemIdentification.ramp_in
— Methodramp_in(d::InputOutputData, h::Int; rev = false)
Multiply the initial h
samples of input and output signals with a linearly increasing ramp.
ControlSystemIdentification.simplot
— Functionsimplot(sys, data, x0=nothing; ploty=true, plote=false)
Plot system simulation and measured output to compare them. ploty
determines whether or not to plot the measured signal plote
determines whether or not to plot the residual
ControlSystemIdentification.simulate
— Functionsimulate(sys, u, x0 = nothing)
simulate(sys, d, x0 = nothing)
See also simplot
ControlSystemIdentification.subspaceid
— Methodsubspaceid(
data::InputOutputData,
nx = :auto;
verbose = false,
r = nx === :auto ? min(length(data) ÷ 20, 20) : nx + 10, # the maximal prediction horizon used
s1 = r, # number of past outputs
s2 = r, # number of past inputs
W = :MOESP,
zeroD = false,
stable = true,
focus = :prediction,
svd::F1 = svd,
scaleU = true,
Aestimator::F2 = \,
Bestimator::F3 = \,
weights = nothing,
)
Estimate a state-space model using subspace-based identification.
Ref: Ljung, Theory for the user.
Arguments:
data
: Identification dataiddata
nx
: Rank of the model (model order)verbose
: Print stuff?r
: Prediction horizon. The model may perform better on simulation if this is made longer, at the expense of more computation time.s1
: past horizon of outputss2
: past horizon of inputsW
: Weight type, choose between:MOESP, :CVA, :N4SID, :IVM
zeroD
: Force theD
matrix to be zero.stable
: Stabilize unstable system using eigenvalue reflection.focus
::prediction
orsimulation
svd
: The function to use forsvd
scaleU
: Rescale the input channels to have the same energy.Aestimator
: Estimator function used to estimateA,C
.Bestimator
: Estimator function used to estimateB,D
.weights
: A vector of weights can be provided if theBestimator
iswls
.
ControlSystemIdentification.tfest
— FunctionH, N = tfest(data, σ = 0.05)
Estimate a transfer function model using the Correlogram approach. Both H
and N
are of type FRD
(frequency-response data).
σ
determines the width of the Gaussian window applied to the estimated correlation functions before FFT. A larger σ
implies less smoothing.
H
= Syu/Suu Process transfer functionN
= Sy - |Syu|²/Suu Noise PSD
ControlSystemIdentification.tfest
— Functiontfest(
data::FRD,
p0,
link = log ∘ abs;
freq_weight = sqrt(data.w[1]*data.w[end]),
refine = true,
opt = BFGS(),
opts = Optim.Options(
store_trace = true,
show_trace = true,
show_every = 1,
iterations = 100,
allow_f_increases = false,
time_limit = 100,
x_tol = 0,
f_tol = 0,
g_tol = 1e-8,
f_calls_limit = 0,
g_calls_limit = 0,
),
)
Fit a parametric transfer function to frequency-domain data.
The initial pahse of the optimization solves
and the second stage (if refine=true) solves
(abs2(link(B/A) - link(l))
)
Arguments:
data
: AnFRD
onbject with frequency domain data.p0
: Initial parameter guess. Can be aNamedTuple
orComponentVector
with fieldsb,a
specifying numerator and denominator as they appear in the call totf
, i.e.,(b = [1.0], a = [1.0,1.0,1.0])
. Can also be an instace ofTransferFunction
.link
: By default, phase information is discarded in the fitting. To include phase, change tolink = log
.freq_weight
: Apply weighting with the inverse frequency. The value determines the cutoff frequency before which the weight is constant, after which the weight decreases linearly. Defaults to the geometric mean of the smallest and largest frequency.refine
: Indicate whether or not a second optimization stage is performed to refine the results of the first.opt
: The Optim optimizer to use.opts
:Optim.Options
controlling the solver options.
See also minimum_phase
to transform a possibly non-minimum phase system to minimum phase.
ControlSystemIdentification.tfest
— Methodtfest(data::FRD, basis::AbstractStateSpace;
freq_weight = 1 ./ (data.w .+ data.w[2]),
opt = BFGS(),
metric::M = abs2,
opts = Optim.Options(
store_trace = true,
show_trace = true,
show_every = 50,
iterations = 1000000,
allow_f_increases = false,
time_limit = 100,
x_tol = 1e-5,
f_tol = 0,
g_tol = 1e-8,
f_calls_limit = 0,
g_calls_limit = 0,
)
Fit a parametric transfer function to frequency-domain data using a pre-specified basis.
Arguments:
data
: AnFRD
onbject with frequency domain data.
function kautz(a::AbstractVector)
basis
: A basis for the estimation. See, e.g.,laguerre, laguerre_oo, kautz
freq_weight
: A vector of weights per frequency. The default is approximately1/f
.opt
: The Optim optimizer to use.opts
:Optim.Options
controlling the solver options.
ControlSystemIdentification.wtls_estimator
— Functionwtls_estimator(y,na,nb, σu=0)
Create an estimator function for estimation of arx models in the presence of measurement noise. If the noise variance on the input σu
(model errors) is known, this can be specified for increased accuracy.
DSP.Filters.resample
— MethodDSP.resample(sys::AbstractStateSpace{<:Discrete}, Qd::AbstractMatrix, newh::Real)
Change sample time of covariance matrix Qd
beloning to sys
to newh
. This function does not handle the measurement covariance, how to do this depends on context. If the faster sampled signal has the same measurement noise, no change should be made. If the slower sampled signal was downsampled with filtering, the measurement covariance should be increased if the system is changed to a faster sample rate. To maintain the frequency response of the system, the measurement covariance should be modified accordinly.
Arguments:
sys
: A discrete-time system that has dynamics noise covariance matricQd
.Qd
: Covariance matrix of dynamics noise.newh
: The new sample time.
DSP.Filters.resample
— Methodresample(sys::AbstractStateSpace{<:Discrete}, newh::Real)
Change sample-time of sys to newh
.
DSP.Filters.resample
— Methoddr = resample(d::InputOutputData, f)
Resample iddata d
with fraction f
, e.g., f = fs_new / fs_original
.
StatsBase.predict
— Methodpredict(sys, d::AbstractIdData, args...)
predict(sys, y, u, x0 = nothing)
See also predplot
StatsBase.predict
— Methodyh = predict(ar::TransferFunction, y)
Predict AR model
StatsBase.predict
— Methodpredict(ARX::TransferFunction, d::InputOutputData)
One step ahead prediction for an ARX process. The length of the returned prediction is length(d) - max(na, nb)
Example:
julia> predict(tf(1, [1, -1], 1), iddata(1:10, 1:10))
9-element Vector{Int64}:
2
4
6
8
10
12
14
16
18
StatsBase.residuals
— Methodresiduals(ARX::TransferFunction, d::InputOutputData)
Calculates the residuals v = Ay - Bu
of an ARX process and InputOutputData d. The length of the returned residuals is length(d) - max(na, nb)
Example:
julia> ARX = tf(1, [1, -1], 1)
TransferFunction{Discrete{Int64}, ControlSystems.SisoRational{Int64}}
1
-----
z - 1
Sample Time: 1 (seconds)
Discrete-time transfer function model
julia> u = 1:5
1:5
julia> y = lsim(ARX, u, 1:5)[1][:]
5-element Vector{Float64}:
0.0
1.0
3.0
6.0
10.0
julia> d = iddata(y, u)
InputOutput data of length 5 with 1 outputs and 1 inputs
julia> residuals(ARX, d)
4-element Vector{Float64}:
0.0
0.0
0.0
0.0
Missing docstring for ControlSystems.StateSpace
. Check Documenter's build log for details.
DelimitedFiles.writedlm
— FunctionDelimitedFiles.writedlm(io::IO, d::AbstractIdData, args...; kwargs...)
Write identification data to disk.
Missing docstring for LowLevelParticleFilters.KalmanFilter
. Check Documenter's build log for details.