-
Notifications
You must be signed in to change notification settings - Fork 0
/
circuit.m
68 lines (47 loc) · 918 Bytes
/
circuit.m
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
% Coupled RC oscillator
nOsc = 2;
% 100 uF
c1 = 1e-4;
c2 = 1e-4;
c12 = 1e-4;
C = [c1+c12 -c12; -c12 c2+c12];
invC = inv(C);
r1 = 5e4;
r2 = 5e4;
R = [r1 r2];
invR = diag(1./R);
v0 = 5*ones(nOsc, 1);
dt = 0.01;
T = 25;
% SDE
% random noise gain
% TODO connect to kuramoto gain
rng default
Kn = 0.2;
gV = Kn*randn(nOsc);
drift = @(t, X) -invC*invR*X;
diffusion = @(t, X) -invC*invR*gV;
sdeMdl = sde(drift, diffusion);
[sdeV, t] = simulate(sdeMdl, T/dt, NTrials=1, DeltaTime=dt);
% State Space
A = -invC*invR;
B = eye(nOsc); % TODO add noisy control/source
C = eye(nOsc);
D = eye(nOsc);
ssMdl = ss(A,B,C,D);
% control input
% u = [sin(t); cos(t)];
u = zeros(length(t), 2);
[vss, t_out] = lsim(ssMdl, u, t, v0);
% Plots
tiledlayout(2,1);
nexttile
plot(t, squeeze(sdeV))
title('sde'); grid on
ylim([-1 max(v0)])
xlim([0 T])
nexttile
plot(t_out, vss)
title('ss'); grid on
ylim([-1 max(v0)])
xlim([0 T])