Skip to content
Snippets Groups Projects
Commit af7034c1 authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

add arx task

parent d233cae0
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -12,15 +12,15 @@ nbr_of_periods = 3
# and run three experiments. You may modify the freqency vectors
# any way you want and add/remove experiments as needed.
w1_100 = logspace(log10(1),log10(300),800)
w1_100 = logspace(log10(1),log10(300),8)
G1 = fra(P, w1_100, amplitude=1, nbr_of_periods=nbr_of_periods, settling_time=settling_time)
@save "workspace.jld"
w1_200 = logspace(log10(5),log10(50),20)
w1_200 = logspace(log10(50),log10(100),10)
G2 = fra(P, w1_200, amplitude=2, nbr_of_periods=nbr_of_periods, settling_time=settling_time)
@save "workspace.jld"
w1_300 = logspace(log10(10),log10(30),20)
w1_300 = logspace(log10(100),log10(300),20)
G3 = fra(P, w1_300, amplitude=2, nbr_of_periods=nbr_of_periods, settling_time=settling_time)
@save "workspace.jld"
......@@ -53,24 +53,25 @@ y,u,r = run_control_2DOF(P, sysFB, sysFF, duration=5, reference = t->2sig
plot([y u r], lab = ["y" "u" "r"])
# If you have time, estimate ARX model
# If you have time, estimate ARX model =====================================================
prbs = PRBSGenerator()
duration = 5
duration = 10
y = zeros(0:h:duration)
u = zeros(0:h:duration)
LabProcesses.initialize(P)
for (i,t) = enumerate(0:h:duration)
y[i] = measure(P)
u[i] = prbs()-0.5 + 0.5*u[max(1,i-1)]
u[i] = prbs()-0.5 #+ 0.5*u[max(1,i-1)]
control(P, u[i])
end
LabProcesses.finalize(P)
plot([u y])
na = 6
nb = 5
arxtf = arx(h, y[:], u, na, nb; λ = 0)
bodeplot([P.sys, arxtf], logspace(-1,3,200))
na = 6 # Order of A polynomial
nb = 5 # Order of B polynomial
arxtf = arx(h, y, u, na, nb) # Estimate trasfer function with ARX method
plot(result.error[1:end-1])
plot([u y])
mag, phase, ω = bode(arxtf, logspace(-1,3,200))
bopl(G1, lab="Measured transfer function")
plot!(ω, mag[:], subplot=1, lab = "ARX estimate")
plot!(ω, phase[:], subplot=2)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment