-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneratePopMicroStim.m
64 lines (59 loc) · 2.07 KB
/
GeneratePopMicroStim.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
%%% Paul Adkisson
%%% 11.5.21
%%% Purpose Generate micro-stimulation current for a variety of PRs and
%%% Amplitudes
function GeneratePopMicroStim(t, t_task, t_taskoff, stim_duration, stim_freqs, ...
gL, stim_amps, save_amp, N, sim_path, plot_ustim)
I_ustim_base = zeros(length(t), N);
dt = t(2) - t(1);
if ~isempty(stim_freqs)
for j = 1:length(stim_freqs)
stim_amp = stim_amps(j);
stim_freq = stim_freqs(j);
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, j) = stim_amp;
elseif t(mod_i) > stim_duration && t(mod_i) <= 2*stim_duration
I_ustim_base(i, j) = -stim_amp;
end
end
end
else
I_ustim_base = zeros(length(t), N);
for j = 1:length(stim_amps)
stim_amp = stim_amps(j);
I_ustim_base(:, j) = stim_amp;
end
end
I_ustim_base(t<t_task|t>t_taskoff, :) = 0;
z_thia = 0.002; %Thia's z=2mm
ball_r = ones(1, N)*z_thia;
electric_r = mirror_est(ball_r);
I_ustim = I_ustim_base.*electric_r;
true_amps = I_ustim(t==t_task, :);
Vmir = true_amps ./ gL;
basepath = strcat(sim_path, "/ustim");
mkdir(basepath)
save(strcat(basepath, "/r.mat"), 'ball_r')
if ~isempty(stim_freqs)
save(strcat(basepath, sprintf("/%0.2fuA_pulse.mat", save_amp*1e6)), "I_ustim", 'Vmir')
else
save(strcat(basepath, sprintf("/%0.2fuA_galvanic.mat", save_amp*1e6)), "I_ustim", 'Vmir')
end
if plot_ustim
figure;
hold on
scatter(ball_r*1e6, Vmir*1e3)
xlabel("Distance from Electrode (um)")
ylabel("Stimulation Depolarization (mV)")
figure;
scatter(ball_r*1e6, Vmir*gL*1e9)
xlabel("Distance from Electrode (um)")
ylabel("Internal Stimulation Amplitude (nA)")
end
end