-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathDisturbances.jl
85 lines (69 loc) · 1.85 KB
/
Disturbances.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
module Disturbances
using LinearAlgebra
wx_data = nothing;
wu_data = nothing;
w_xmax = nothing;
w_umax = nothing;
d_u = 3;
d_x = 3;
len = 100001;
t_inc = 10;
function write_data()
f = open("WX.dat", "w");
write(f, rand(len*d_x).*sign.(randn(len*d_x)));
close(f);
f = open("WU.dat", "w");
write(f, rand(len*d_u).*sign.(randn(len*d_u)));
close(f);
end
function read_data()
f = open("WX.dat", "r");
global wx_data = zeros(len, d_x);
for i=1:len
for j=1:d_x
global wx_data[i,j] = read(f, Float64);
end
if norm(wx_data[i,:]) > 1
wx_data[i,:] = wx_data[i,:] / norm(wx_data[i,:]);
end
end
close(f);
f = open("WU.dat", "r");
global wu_data = zeros(len, d_u);
for i=1:len
for j=1:d_u
global wu_data[i,j] = read(f, Float64);
end
if norm(wu_data[i,:]) > 1
wu_data[i,:] = wu_data[i,:] / norm(wu_data[i,:]);
end
end
close(f);
end
function Matched(t)
index1 = Int(floor(t/t_inc));
index2 = Int(ceil(t/t_inc));
if index2 > len
println("WARNING: Requested noise outside time domain.");
index2 = len;
end
delta = (t - index1*t_inc)/t_inc;
return w_umax*(wu_data[index1+1,:]*(1-delta) + wu_data[index2+1,:]*delta);
end
function Unmatched(t)
index1 = Int(floor(t/t_inc));
index2 = Int(ceil(t/t_inc));
if index2 > len
println("WARNING: Requested noise outside time domain.");
index2 = len;
end
delta = (t - index1*t_inc)/t_inc;
return w_xmax*(wx_data[index1+1,:]*(1-delta) + wx_data[index2+1,:]*delta);
end
function set_w_umax(x); global w_umax = x; end
function set_w_xmax(x); global w_xmax = x; end
function set_t_inc(x); global t_inc = x; end
function set_d_u(x); global d_u = x; end
function set_d_x(x); global d_x = x; end
end
nothing