From 68c9f83741bffecc9347480642b2cf8937eddb7d Mon Sep 17 00:00:00 2001
From: Fredrik Bagge Carlson <cont-frb@ulund.org>
Date: Thu, 24 Aug 2017 10:49:49 +0200
Subject: [PATCH] Change sysfilter to SysFilter implementation

---
 README.md          |  3 +++
 src/BallAndBeam.jl |  8 +++++++-
 src/FRTN35_lab1.jl |  2 +-
 test/runtests.jl   | 19 ++-----------------
 4 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/README.md b/README.md
index 7592e7b..b82a5ea 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
+[![build status](https://gitlab.control.lth.se/processes/BallAndBeam.jl/badges/master/pipeline.svg)](https://gitlab.control.lth.se/processes/BallAndBeam.jl/commits/master)
+[![coverage report](https://gitlab.control.lth.se/processes/BallAndBeam.jl/badges/master/coverage.svg)](https://gitlab.control.lth.se/processes/BallAndBeam.jl/commits/master)
+
 # Installation (specific to lab 1 FRTN35: Frequency response analysis)
 1. Open a terminal
 2. Type `mkdir FRTN35_lab1; cd FRTN35_lab1`
diff --git a/src/BallAndBeam.jl b/src/BallAndBeam.jl
index ec52790..33dc2ce 100644
--- a/src/BallAndBeam.jl
+++ b/src/BallAndBeam.jl
@@ -16,7 +16,7 @@ module BallAndBeam
 
 export run_experiment, fra, sortfqs,
 bopl, bopl!, nypl, nypl!, plot, fbdesign, ffdesign, opendoc
-export init_sysfilter, sysfilter!, run_control_2DOF # For documentation
+export SysFilter, init_sysfilter, sysfilter!, run_control_2DOF # For documentation
 
 
 using LabProcesses, Plots, Polynomials, ControlSystems, ProgressMeter
@@ -194,6 +194,12 @@ dynamical system, i.e., `U(z) = C(z)E(z)`. Initialize `state` using [`init_sysfi
 """
 sysfilter!
 
+"""
+	sf = SysFilter(sys::StateSpace)
+Create a SysFilter object that can be used to implement control loops and simulators with LTI systems, i.e., `U(z) = C(z)E(z)`. See [`sysfilter!`](@ref) for usage.
+"""
+SysFilter
+
 """
 	y,u,r = run_control_2DOF(process, sysFB[, sysFF]; duration = 10, reference(t) = sign(sin(2π*t)))
 Perform control experiemnt on process where the feedback and feedforward controllers are given by
diff --git a/src/FRTN35_lab1.jl b/src/FRTN35_lab1.jl
index 4134330..d8d912a 100644
--- a/src/FRTN35_lab1.jl
+++ b/src/FRTN35_lab1.jl
@@ -72,6 +72,6 @@ nb = 5 # Order of B polynomial
 arxtf = arx(h, y, u, na, nb) # Estimate trasfer function with ARX method
 
 mag, phase, ω = bode(arxtf, logspace(-1,3,200))
-bopl(G1, lab="Measured transfer function")
+bopl(G123, lab="Measured transfer function")
 plot!(ω, mag[:], subplot=1, lab = "ARX estimate")
 plot!(ω, phase[:], subplot=2)
diff --git a/test/runtests.jl b/test/runtests.jl
index ccd7277..da621af 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -6,22 +6,7 @@ P = LabProcesses.Beam(0.01,0.)
 h = sampletime(P)
 @test h == 0.01
 
-function test_sysfilter()
-        N = 10
-        u = randn(N)
-        b = [1, 1]
-        a = [1, 0.1, 1]
-	  sys = ss(tf(b,a,1))
-	state = init_sysfilter(sys)
-       yf = filt(b,a,u)
-	  yff = similar(yf)
-	for i in eachindex(u)
-		yff[i] = sysfilter!(state, sys, u[i])[1]
-	end
-	@test sum(abs,yf - yff) < √(eps())
-end
 
-test_sysfilter()
 
 settling_time  = 1
 nbr_of_periods = 5
@@ -61,7 +46,7 @@ nbr_of_periods = 2
 w1_100 = logspace(-1,log10(300),500)
 G1     = fra(P, w1_100, amplitude=1, nbr_of_periods=nbr_of_periods, settling_time=settling_time)
 
-true_resp = freqresp(P.sys, w1_100)
+true_resp = freqresp(P.s.sys, w1_100)
 @test sum(abs, log.(abs.(G1[:,2])) - log.(abs.(true_resp[1][:]))) < 3.2 # Some numerical errors expected
 phase_id = angle.(G1[:,2]) |> ControlSystems.unwrap
 phase_true = angle.(true_resp[1][:]) |> ControlSystems.unwrap
@@ -87,7 +72,7 @@ nb = 5
 arxtf = arx(h, y[:], u, na, nb; λ = 0)
 
 w1_100 = logspace(-1,log10(100),500)
-true_resp = freqresp(P.sys, w1_100)
+true_resp = freqresp(P.s.sys, w1_100)
 phase_true = angle.(true_resp[1][:]) |> ControlSystems.unwrap
 arx_resp = freqresp(arxtf, w1_100)
 @test sum(abs, log.(abs.(arx_resp[1][:])) - log.(abs.(true_resp[1][:]))) < 1.25
-- 
GitLab