-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateMicroStim.m
75 lines (72 loc) · 2.65 KB
/
GenerateMicroStim.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
66
67
68
69
70
71
72
73
74
75
%%% Paul Adkisson
%%% 11.5.21
%%% Purpose Generate micro-stimulation current
function GenerateMicroStim(t, t_task, t_taskoff, stim_duration, stim_freq, ...
min_r, max_r, num_affected, thresh_cor, gL, ...
pulse_amps, dc_amps, N, sim_path, plot)
I_ustim_base = zeros(length(t), N);
dt = t(2) - t(1);
stim_amps = [pulse_amps, dc_amps];
for j = 1:length(stim_amps)
stim_amp = stim_amps(j);
is_pulse = j <= length(pulse_amps);
if is_pulse
for i = 1:length(t)
if floor(1/(stim_freq*dt)) >= length(t)
mod_i = i;
else
mod_i = mod(i, floor(1/(stim_freq*dt))) + 1;
end
if t(mod_i) <= stim_duration
I_ustim_base(i, :) = stim_amp;
elseif t(mod_i) > stim_duration && t(mod_i) <= 2*stim_duration
I_ustim_base(i, :) = -stim_amp;
end
end
else
I_ustim_base = ones(length(t), N)*stim_amp;
end
I_ustim_base(t<t_task|t>t_taskoff, :) = 0;
regular_r = (max_r - min_r) / (num_affected-1);
ball_r = min_r:regular_r:max_r;
electric_r = mirror_est(ball_r);
I_ustim = [I_ustim_base(:, 1:num_affected).*electric_r, zeros(length(t), N-num_affected)];
true_amps = I_ustim(t==t_task, 1:num_affected);
Vmir = true_amps ./ gL;
basepath = strcat(sim_path, "/ustim");
mkdir(basepath)
save(strcat(basepath, "/r.mat"), 'ball_r')
if is_pulse
I_ustim = I_ustim * thresh_cor;
Vmir = Vmir * thresh_cor;
save(strcat(basepath, sprintf("/%0.2fuA_pulse.mat", stim_amp*1e6)), "I_ustim", 'Vmir')
else
save(strcat(basepath, sprintf("/%0.2fuA_galvanic.mat", stim_amp*1e6)), "I_ustim", 'Vmir')
end
if plot
figure;
hold on
scatter(ball_r*1e6, Vmir*1e3)
xlabel("Distance from Electrode (um)")
ylabel("Stimulation Depolarization (mV)")
if is_pulse
title("Pulse")
elseif stim_amp == 0
title("Control")
else
title("Galvanic")
end
figure;
scatter(ball_r*1e6, Vmir*gL*1e9)
xlabel("Distance from Electrode (um)")
ylabel("Internal Stimulation Amplitude (nA)")
if is_pulse
title("Pulse")
elseif stim_amp == 0
title("Control")
else
title("Galvanic")
end
end
end
end