-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDraw_Conditioning.m
More file actions
executable file
·233 lines (182 loc) · 7.24 KB
/
Draw_Conditioning.m
File metadata and controls
executable file
·233 lines (182 loc) · 7.24 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Janez Presern, Ales Skorjanc, Tomaz Rodic, Jan Benda 2011-2015
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function draws the responses to the desensitization tests
% for a selected conditioning amplitude
% Function requires:
% dt.. sampling rate
% stim . stimulus description (amplitudes changes)
% ampMax .. maximum stimulus amplitude used in modeling
% Imax .. maximum current by control
% x50k50 .. midpoint and slope for the control I-R
% var .. fitted variables and constants
% var_names .. names of variables
% cmap1,cmap2 .. color maps
% marmap .. marker map for plotting
% fn .. filename (Results_XX) to identify the model
% iteration
% Function outputs:
% f .. figure handle
function [f] = Draw_Conditioning (dt, stim,...
ampMax, Imax, x50k50,...
var, var_names,...
cmap1, cmap2, marmap, fn)
%%%% Conditioning stimuli loop
for l = 5 % select which conditioning amplitude you wish
% open new figure
f = figure;
%%%%%%%%%%%%%%%%%%%%%%%%%% Calculate and draw the stimulus %%%%%%%%%%%%%%%%%%%%%%
s(1) = axes ('OuterPosition', [0 0.8 1 0.2]);
set(gca,'XTickLabel',[]);
stimAmp = [];
hold on;
for val1 = 1:size (stim(1,l).t,1)
for val3 = 1:size (stim(1,l).t,3)
x0 = 0;
y0 = 0;
for val2 = 1:7
x1 = x0 + stim(1,l).t(val1,val2,val3);
y1 = y0 + stim(1,l).amp(val1,val2,val3);
line([x0 x1],[y0 y1], 'Color',cmap2(val3,:));
x0 = x1;
y0 = y1;
end;
stimAmp(val1, val3) = sum (stim(1,l).amp(val1,1:4,val3));
end;
end;
xlim([0,1100]);
ylabel ('stimulus amplitude [\mum]');
hold off;
grid on;
title(horzcat(fn,': ','Desensitization of MS neuron using two-step paradigm'),'interpreter','none');
%%%%%%%%%%%%%%%%%%%%%%%%%% Calculate and draw the responses %%%%%%%%%%%%%%%
s(2) = axes ('OuterPosition', [0 0.4 1 0.4]);
% prepares the variables for the both the conditioning stimulus peak and
% peak due to the test stimulus
peakInitial = NaN(size(stim(1,l).t,1),size(stim(1,l).t,3));
peakRecovery = peakInitial;
ix1 = peakInitial;
ix2 = [];
% prepare variable to store current, computed in the response to
% conditioning as a reference for peak extraction.
condResp = [];
% hold th figure
hold on;
%%%%% Amplitude loop - start at slikca value as it mathces the line of NaN
%%%%% Delay loop
for n = 1 : size (stim(1,l).t,3)
%%%%% amplitudes
for m = l : size(stim(1,l).t,1)
% clears the variables, makes sure no left-over artefacts from previous run are drawn (or
% extracted)
results.g = [];
results.t = [];
% checks if the data imput contains a number or NaN
if ~isnan(stim(1,l).t(m,1:3,n))
[~,~,results]=Modeling_DRG_TCM_Engine(horzcat('DRG_TCM_Model_mh','_Report'),...
stim(1,l).t(m,:,n),stim(1,l).amp(m,:,n),...
var,var_names,dt);
% calculates index to grab peaks in the correct time window
% stores the current computed in the response to the
% conditioning stimuli, storing only max. delay current to ensure the
% proper length of the vector for further computation;
% However it stores peak values and index
if m == l
condResp = results.g;
[peakInitial(m,n), ix1(m,n)] = min(condResp);
%%% problem with no peaks at the 0 stimuli
if ix1(m,n) >= int64(sum(stim(1,l).t(m,1:3,n))/dt);
ix1(m,n) = int64(sum(stim(1,l).t(m,1:3,n))/dt);
end
else
% if no value is stored, copy the value along the
% dimensions of the matrix for simpler use
peakInitial(m,:) = peakInitial(l,:);
ix1(m,:) = ix1(l,:);
end;
% recovery peak extraction
[pks, ix2] = findpeaks (-results.g(ix1(m,n):end),'npeaks',1);
ix2 = ix1(m,n) + ix2;
end;
peakRecovery (m,n) = 0;
if ~isempty(pks)
peakRecovery (m,n) = -pks-condResp(ix2);
end;
plot(results.t,results.g,'-','Color',cmap2(n,:));
plot(results.t(ix2),-pks,'.b','MarkerSize',15);
end;
end;
xlim([0,1100]);
xlabel ('time [ms]');
ylabel ('I/I_{max}');
grid on;
hold off;
%%%%%%%%%% drawing intensity - response - no normalizaiton %%%%%%%%%%%%%%%%
s(3) = axes ('OuterPosition', [0 0 0.5 0.3]);
conAmp = [0.0,0.8,1.5,2.2,2.9,3.6,4.3,5.0,5.7,6.4,7.1,7.8,8.5];
delayy = [4.0, 20.0, 40.0, 100.0, 400.0, 1000.0];
xx = linspace(0,9,100);
xxx = linspace(1,1000,1000);
% conditioning stimuli
x50 = nan (size(stimAmp,2),6);
k50 = nan (size(stimAmp,2),6);
% offsets to zero and normalizes the input values
offset = peakRecovery;
normal = offset./repmat(min(offset),[13,1,1]);
markers = ['o'];%,'+','*','x','^','v'];
hold on;
plot (ampMax,Imax'/min(Imax),'s','Color',cmap1(14,:),'MarkerSize',5, 'LineWidth',2);
for i = 1:size(stimAmp,2)
plot ((stimAmp(:,i)), (peakRecovery(:,i)./min(Imax)), marmap(i),'Color',cmap2(i,:),'LineWidth',2);
end;
set(gca,'XTick',conAmp);
hold off;
xlabel ('Stimulus [\mum]');
ylabel ('I/I_{max}');
grid on;
ylim ([0 1.01]);
xlim ([0 9]);
%%%%%%%%%%% Drawing intensity - response after normalization %%%%%%%%%%%%%%
s(4) = axes ('OuterPosition', [0.5 0.0 0.5 0.3]);
for l = 5
x = stimAmp(:,l);
yy = normal;
x = x(l:end);
yy = yy (l:end,:);
% calls the fit and plots for each delay in the matrix
opt = optimset('MaxFunEval',10000);
ff = @Boltzmann;
hold on;
for bb = 1 : size(yy,2);
y = (yy(:,bb));
%%%%% computing x50 & k50 using fminsearch
[param, ~, ~, ~]=fminsearch(ff,[5,0.5],opt,x(2:end),y(2:end));
% puts Stim50 and k @ stim50 into separate variables
x50(l,bb) = param(1);
k50(l,bb) = param(2);
fit = 1./(1+exp((param(1)-xx)/param(2)));
% plot fits
plot(xx,fit, '-','Color',cmap2(bb,:),'LineWidth',2);
%%% plot fits
[param, ~, ~, ~]=fminsearch(ff,[5,0.5],opt,ampMax,...
Imax'/min(Imax));
fit = 1./(1+exp((param(1)-xx)/param(2)));
plot(xx,fit, '-','Color',cmap1(7,:),'LineWidth',2);
plot (x50(l,bb),0.5, 'Color',cmap1(5,:),'MarkerSize',10,'Marker','x','LineWidth',2);
plot (x50k50(1),0.5,'Color',cmap1(5,:),'MarkerSize',10,'Marker','x','LineWidth',2);
%%% plot points
plot(x,y,marmap(bb),'Color',cmap2(bb,:),'LineWidth',2);
plot (ampMax,...
Imax'/min(Imax),...
's','MarkerSize',5,'Color',cmap1(14,:),'LineWidth',2);
end;
hold off;
set(gca,'XTick', conAmp);
set(gca,'XTickLabel', conAmp);
xlabel ('Stimulus [\mum]');
ylabel ('I/I_{max}');
xlim ([0 9]);
ylim ([0 1]);
grid on;
end;
end;