-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.jl
57 lines (39 loc) · 861 Bytes
/
test.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# using Revise
# using Kalman
# using PyPlot
# PyPlot.ion()
using Kalman
A = (0:1:800) + 20
Ad = A + 25*(rand(length(A)) - 0.5)
plot(A,"b")
plot(Ad,"r-")
x0 = [0.0 ,0.0 ,1.0]
P0 = 00ones(3,3)
state0 = Kalman.State(x0,P0)
std_process = 0.001*[1 , 0.1,3]
F(x) = [x[1] + x[2] + x[3]^2,x[2] + x[3],x[3] * 0.8]
Q = std_process*std_process'
process = Kalman.Process(F,Q)
H = [1.0 0.0 0.0]
R = ones(1,1)*52
observer = Kalman.Observer(H,R)
kalman = KalmanFilter(state0,process,observer)
filt = Float64[]e
dif = Float64[]
@time for i=1:length(Ad)
update!(kalman,[Ad[i]])
push!(filt,predict(kalman;steps = 3).x[1])
push!(dif,kalman.observer.residual[1])
predict!(kalman)
# push!(filt,kalman.state.x[1])
end
unshift!(filt,0)
unshift!(filt,0)
unshift!(filt,0)
plot(filt)
plot(dif)
kalman
dif
mean(dif)
# dif
predict(kalman;steps = 20)