diff --git a/src/FRTN35_lab1.jl b/src/FRTN35_lab1.jl index 7db7989e9b65bb821884ef1c6c46c2453c6fe0c9..4134330e323adaebaaaf80d86821c289da1bae86 100644 --- a/src/FRTN35_lab1.jl +++ b/src/FRTN35_lab1.jl @@ -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 -prbs = PRBSGenerator() -duration = 5 -y = zeros(0:h:duration) -u = zeros(0:h:duration) +# If you have time, estimate ARX model ===================================================== +prbs = PRBSGenerator() +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)