-
Notifications
You must be signed in to change notification settings - Fork 85
/
delayed_lti_timeresp.jl
78 lines (57 loc) · 1.42 KB
/
delayed_lti_timeresp.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
using ControlSystems, Plots
gr()
sys = feedback(1.0, ss(-1.0, 2, 1, 0) * (delay(2.0) + delay(3.0) + delay(2.5)))
sys = feedback(ss(-1.0, 1, 1, 0), delay(1.0))
t = 0:0.02:8
@time y, t, x = lsim(sys, t-> [t>=0 ? 1.0 : 0.0], t)
@time y, t, x = lsim(sys, [1.0], t)
@time y, t, x = lsim(sys, (out, t) -> (out .= (t>=0 ? 1.0 : 0.0)), t)
@time y, t, x = lsim(sys, (out, t) -> (out[1] = (t>=0 ? 1.0 : 0.0)), t)
function u0(out,t)
if t > 0
out[1] = 1
else
out[1] = 0
end
return
end
@time res = lsim(sys, u0, t)
plot(res)
s = tf("s")
P = delay(2.6)*ss((s+3.0)/(s^2+0.3*s+1))
C = 0.06 * ss(1.0 + 1/s);
P*C
T = feedback(P*C,1.0)
t = 0:0.1:70
res = lsim(T, t -> (t<0 ? 0 : 1 ), t)
plot(res, c = :blue)
w = 10 .^ (-2:0.01:2)
marginplot(P*C, w)
marginplot(P*C)
notch = ss(tf([1, 0.2, 1],[1, .8, 1]));
C = ss(0.05 * (1 + 1/s));
Tnotch = feedback(P*C*notch, 1.0)
plot(step(Tnotch))
y, t, x = step(C, method=:zoh)
y2, t2, x2 = step(Tnotch)
plot(step(Tnotch))
plot(step(Tnotch, 40))
plot(step(T, 100))
G = delay(5)/(s+1)
T = feedback(G, 0.5)
w = 10 .^ (-2:0.01:3)
bodeplot(T, w, plotphase=false)
# Test conversion, promotion
G = 1 + 0.5 * delay(3)
w = 10 .^(-2:0.001:2)
bodeplot(G, w, plotphase=false)
G = delay(1) * ((0.8*s^2+s+2)/(s^2+s))
T = feedback(G,1)
# Not possible with direct term
plot(step(T))
bodeplot(T)
G = 1/(s+1) + delay(4)
T = feedback(1,G)
# Not possible to lsim with direct term
plot(step(T))
bodeplot(T)