Skip to content

Commit

Permalink
fix #161
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Oct 28, 2024
1 parent a532622 commit 9b4e3eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/arx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ end

function arx(ds::AbstractVector{<:AbstractIdData}, na, nb; inputdelay = ones(Int, size(nb)), λ = 0, estimator = \)
allequal(sampletime(d) for d in ds) || throw(ArgumentError("All data sets must have the same sample time"))
yA = getARXregressor.(ds, na, nb; inputdelay)
yA = [getARXregressor(d, na, nb; inputdelay) for d in ds]
y_train = reduce(vcat, first.(yA))
A = reduce(vcat, last.(yA))
w = ls(A, y_train, λ, estimator) |> vec
Expand Down
1 change: 1 addition & 0 deletions src/subspace2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function subspaceid(
t0 = max(s1,s2)+1
s = s1*p + s2*m
N = t - r + 1 - t0
verbose && @info "Estimating with r = $r, s1 = $s1, s2 = $s2, stability constraint = $stable, zeroD = $zeroD, focus = $focus, scaleU = $scaleU"

@views @inbounds function hankel(u::AbstractArray, t0, r)
d = size(u, 2)
Expand Down
17 changes: 17 additions & 0 deletions test/test_arx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,20 @@ Gest = arx(d, na, nb, inputdelay = inputdelay)

Gests = arx(d, na, nb, inputdelay = inputdelay, stochastic = true)
@test compareTFs(G1, Gests)

## Multiple data sets
Gest = arx([d, d], na, nb; inputdelay)

# From https://github.com/baggepinnen/ControlSystemIdentification.jl/issues/161
N = 20000 # Number of time steps
t = 1:N
Δt = 1 # Sample time
u = randn(2, N) # A random control input
G = ssrand(1, size(u, 1), size(u, 1); Ts=Δt)
y = lsim(G, u, t)[1][:]
d = iddata(y, u, Δt)
na = 2
nb = [3, 3]

Gest = arx([d, d], na, nb, inputdelay=[0,0])
@test freqresptest(G, Gest, 0.0001)

0 comments on commit 9b4e3eb

Please sign in to comment.