To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / MAP / MAP1_14.m

History | View | Annotate | Download (49 KB)

1 0:f233164f4c86 rmeddis
2
function  MAP1_14(inputSignal, sampleRate, BFlist, MAPparamsName, ...
3
    AN_spikesOrProbability, paramChanges)
4
% To test this function use test_MAP1_14 in this folder
5
%
6 32:82fb37eb430e rmeddis
% example:
7
% <navigate to 'MAP1_14\MAP'>
8
%  [inputSignal FS] = wavread('../wavFileStore/twister_44kHz');
9
%  MAP1_14(inputSignal, FS, -1, 'Normal', 'probability', [])
10
%
11 0:f233164f4c86 rmeddis
% All arguments are mandatory.
12
%
13 28:02aa9826efe0 rmeddis
%  BFlist is a vector of BFs but can be '-1' to allow MAPparams to choose
14
%  MAPparamsName='Normal';          % source of model parameters
15 0:f233164f4c86 rmeddis
%  AN_spikesOrProbability='spikes'; % or 'probability'
16
%  paramChanges is a cell array of strings that can be used to make last
17
%   minute parameter changes, e.g., to simulate OHC loss
18 28:02aa9826efe0 rmeddis
%  e.g.  paramChanges{1}= 'DRNLParams.a=0;'; % disable OHCs
19
%  e.g.  paramchanges={};                    % no changes
20 0:f233164f4c86 rmeddis
% The model parameters are established in the MAPparams<***> file
21
%  and stored as global
22
23
restorePath=path;
24
addpath (['..' filesep 'parameterStore'])
25
26
global OMEParams DRNLParams IHC_cilia_RPParams IHCpreSynapseParams
27
global AN_IHCsynapseParams MacGregorParams MacGregorMultiParams
28
29
% All of the results of this function are stored as global
30 38:c2204b18f4a2 rmeddis
global  savedParamChanges savedBFlist saveAN_spikesOrProbability ...
31
    saveMAPparamsName savedInputSignal dt dtSpikes ...
32
    OMEextEarPressure TMoutput OMEoutput DRNLoutput...
33
    IHC_cilia_output IHCrestingCiliaCond IHCrestingV...
34
    IHCoutput ANprobRateOutput ANoutput savePavailable saveNavailable ...
35
    ANtauCas CNtauGk CNoutput ICoutput ICmembraneOutput ICfiberTypeRates...
36
    MOCattenuation ARattenuation
37 35:25d53244d5c8 rmeddis
38 0:f233164f4c86 rmeddis
39
% Normally only ICoutput(logical spike matrix) or ANprobRateOutput will be
40
% needed by the user; so the following will suffice
41 38:c2204b18f4a2 rmeddis
%   global dtSpikes ICoutput ANprobRateOutput
42 0:f233164f4c86 rmeddis
43
% Note that sampleRate has not changed from the original function call and
44
%  ANprobRateOutput is sampled at this rate
45
% However ANoutput, CNoutput and IC output are stored as logical
46 38:c2204b18f4a2 rmeddis
%  'spike' matrices using a lower sample rate (see dtSpikes).
47 0:f233164f4c86 rmeddis
48
% When AN_spikesOrProbability is set to probability,
49
%  no spike matrices are computed.
50
% When AN_spikesOrProbability is set to 'spikes',
51
%  no probability output is computed
52
53
% Efferent control variables are ARattenuation and MOCattenuation
54
%  These are scalars between 1 (no attenuation) and 0.
55 38:c2204b18f4a2 rmeddis
%  They are represented with dt=1/sampleRate (not dtSpikes)
56 0:f233164f4c86 rmeddis
%  They are computed using either AN probability rate output
57
%   or IC (spikes) output as approrpriate.
58
% AR is computed using across channel activity
59
% MOC is computed on a within-channel basis.
60
61 26:b03ef38fe497 rmeddis
if nargin<1
62
    error(' MAP1_14 is not a script but a function that must be called')
63
end
64
65
if nargin<6
66
    paramChanges=[];
67
end
68
% Read parameters from MAPparams<***> file in 'parameterStore' folder
69 28:02aa9826efe0 rmeddis
% Beware, 'BFlist=-1' is a legitimate argument for MAPparams<>
70
%  It means that the calling program allows MAPparams to specify the list
71 26:b03ef38fe497 rmeddis
cmd=['method=MAPparams' MAPparamsName ...
72
    '(BFlist, sampleRate, 0, paramChanges);'];
73
eval(cmd);
74
BFlist=DRNLParams.nonlinCFs;
75 0:f233164f4c86 rmeddis
76
% save as global for later plotting if required
77
savedBFlist=BFlist;
78
saveAN_spikesOrProbability=AN_spikesOrProbability;
79
saveMAPparamsName=MAPparamsName;
80 38:c2204b18f4a2 rmeddis
savedParamChanges=paramChanges;
81 0:f233164f4c86 rmeddis
82
dt=1/sampleRate;
83
duration=length(inputSignal)/sampleRate;
84
% segmentDuration is specified in parameter file (must be >efferent delay)
85
segmentDuration=method.segmentDuration;
86
segmentLength=round(segmentDuration/ dt);
87
segmentTime=dt*(1:segmentLength); % used in debugging plots
88
89
% all spiking activity is computed using longer epochs
90 38:c2204b18f4a2 rmeddis
ANspeedUpFactor=ceil(sampleRate/AN_IHCsynapseParams.spikesTargetSampleRate);
91
% ANspeedUpFactor=AN_IHCsynapseParams.ANspeedUpFactor;  % e.g.5 times
92 0:f233164f4c86 rmeddis
93
% inputSignal must be  row vector
94
[r c]=size(inputSignal);
95
if r>c, inputSignal=inputSignal'; end       % transpose
96
% ignore stereo signals
97
inputSignal=inputSignal(1,:);               % drop any second channel
98
savedInputSignal=inputSignal;
99
100
% Segment the signal
101
% The sgment length is given but the signal length must be adjusted to be a
102
% multiple of both the segment length and the reduced segmentlength
103
[nSignalRows signalLength]=size(inputSignal);
104
segmentLength=ceil(segmentLength/ANspeedUpFactor)*ANspeedUpFactor;
105
% Make the signal length a whole multiple of the segment length
106
nSignalSegments=ceil(signalLength/segmentLength);
107
padSize=nSignalSegments*segmentLength-signalLength;
108
pad=zeros(nSignalRows,padSize);
109
inputSignal=[inputSignal pad];
110
[ignore signalLength]=size(inputSignal);
111
112 38:c2204b18f4a2 rmeddis
% spiking activity is computed at longer sampling intervals (dtSpikes)
113
%  so it has a smaller number of epochs per segment(see 'ANspeeUpFactor' above)
114 0:f233164f4c86 rmeddis
% AN CN and IC all use this sample interval
115 38:c2204b18f4a2 rmeddis
dtSpikes=dt*ANspeedUpFactor;
116 0:f233164f4c86 rmeddis
reducedSegmentLength=round(segmentLength/ANspeedUpFactor);
117
reducedSignalLength= round(signalLength/ANspeedUpFactor);
118
119
%% Initialise with respect to each stage before computing
120
%  by allocating memory,
121
%  by computing constants
122
%  by establishing easy to read variable names
123
% The computations are made in segments and boundary conditions must
124
%  be established and stored. These are found in variables with
125
%  'boundary' or 'bndry' in the name
126
127
%% OME ---
128
% external ear resonances
129
OMEexternalResonanceFilters=OMEParams.externalResonanceFilters;
130
[nOMEExtFilters c]=size(OMEexternalResonanceFilters);
131
% details of external (outer ear) resonances
132
OMEgaindBs=OMEexternalResonanceFilters(:,1);
133
OMEgainScalars=10.^(OMEgaindBs/20);
134
OMEfilterOrder=OMEexternalResonanceFilters(:,2);
135
OMElowerCutOff=OMEexternalResonanceFilters(:,3);
136
OMEupperCutOff=OMEexternalResonanceFilters(:,4);
137
% external resonance coefficients
138
ExtFilter_b=cell(nOMEExtFilters,1);
139
ExtFilter_a=cell(nOMEExtFilters,1);
140
for idx=1:nOMEExtFilters
141
    Nyquist=sampleRate/2;
142
    [b, a] = butter(OMEfilterOrder(idx), ...
143
        [OMElowerCutOff(idx) OMEupperCutOff(idx)]...
144
        /Nyquist);
145
    ExtFilter_b{idx}=b;
146
    ExtFilter_a{idx}=a;
147
end
148
OMEExtFilterBndry=cell(2,1);
149
OMEextEarPressure=zeros(1,signalLength); % pressure at tympanic membrane
150
151
% pressure to velocity conversion using smoothing filter (50 Hz cutoff)
152
tau=1/(2*pi*50);
153
a1=dt/tau-1; a0=1;
154
b0=1+ a1;
155
TMdisp_b=b0; TMdisp_a=[a0 a1];
156
% figure(9), freqz(TMdisp_b, TMdisp_a)
157
OME_TMdisplacementBndry=[];
158
159
% OME high pass (simulates poor low frequency stapes response)
160 38:c2204b18f4a2 rmeddis
OMEhighPassHighCutOff=OMEParams.OMEstapesHPcutoff;
161 0:f233164f4c86 rmeddis
Nyquist=sampleRate/2;
162
[stapesDisp_b,stapesDisp_a] = butter(1, OMEhighPassHighCutOff/Nyquist, 'high');
163
% figure(10), freqz(stapesDisp_b, stapesDisp_a)
164
165
OMEhighPassBndry=[];
166
167
% OMEampStapes might be reducdant (use OMEParams.stapesScalar)
168
stapesScalar= OMEParams.stapesScalar;
169
170
% Acoustic reflex
171
efferentDelayPts=round(OMEParams.ARdelay/dt);
172
% smoothing filter
173
a1=dt/OMEParams.ARtau-1; a0=1;
174
b0=1+ a1;
175
ARfilt_b=b0; ARfilt_a=[a0 a1];
176
177
ARattenuation=ones(1,signalLength);
178
ARrateThreshold=OMEParams.ARrateThreshold; % may not be used
179
ARrateToAttenuationFactor=OMEParams.rateToAttenuationFactor;
180
ARrateToAttenuationFactorProb=OMEParams.rateToAttenuationFactorProb;
181
ARboundary=[];
182
ARboundaryProb=0;
183
184
% save complete OME record (stapes displacement)
185
OMEoutput=zeros(1,signalLength);
186
TMoutput=zeros(1,signalLength);
187
188
%% BM ---
189
% BM is represented as a list of locations identified by BF
190
DRNL_BFs=BFlist;
191
nBFs= length(DRNL_BFs);
192
193
% DRNLchannelParameters=DRNLParams.channelParameters;
194
DRNLresponse= zeros(nBFs, segmentLength);
195
196
MOCrateToAttenuationFactor=DRNLParams.rateToAttenuationFactor;
197
rateToAttenuationFactorProb=DRNLParams.rateToAttenuationFactorProb;
198 26:b03ef38fe497 rmeddis
MOCrateThresholdProb=DRNLParams.MOCrateThresholdProb;
199 35:25d53244d5c8 rmeddis
minMOCattenuation=10^(DRNLParams.minMOCattenuationdB/20);
200 0:f233164f4c86 rmeddis
201
% smoothing filter for MOC
202
a1=dt/DRNLParams.MOCtau-1; a0=1;
203
b0=1+ a1;
204
MOCfilt_b=b0; MOCfilt_a=[a0 a1];
205 35:25d53244d5c8 rmeddis
206
a1=dt/DRNLParams.MOCtauProb-1; a0=1;
207
b0=1+ a1;
208
MOCfiltProb_b=b0; MOCfiltProb_a=[a0 a1];
209
210
211 0:f233164f4c86 rmeddis
% figure(9), freqz(stapesDisp_b, stapesDisp_a)
212
MOCboundary=cell(nBFs,1);
213
MOCprobBoundary=cell(nBFs,1);
214
215
MOCattSegment=zeros(nBFs,reducedSegmentLength);
216
MOCattenuation=ones(nBFs,signalLength);
217
218 34:e097e9044ef6 rmeddis
% if DRNLParams.a>0
219
%     DRNLcompressionThreshold=10^((1/(1-DRNLParams.c))* ...
220
%     log10(DRNLParams.b/DRNLParams.a));
221
% else
222
%     DRNLcompressionThreshold=inf;
223
% end
224 35:25d53244d5c8 rmeddis
% DRNLcompressionThreshold=DRNLParams.cTh;
225 0:f233164f4c86 rmeddis
DRNLlinearOrder= DRNLParams.linOrder;
226
DRNLnonlinearOrder= DRNLParams.nonlinOrder;
227
228
DRNLa=DRNLParams.a;
229 35:25d53244d5c8 rmeddis
% DRNLa2=DRNLParams.a2;
230
% DRNLb=DRNLParams.b;
231 0:f233164f4c86 rmeddis
DRNLc=DRNLParams.c;
232
linGAIN=DRNLParams.g;
233 38:c2204b18f4a2 rmeddis
ctBM=10e-9*10^(DRNLParams.ctBMdB/20);
234
CtS=ctBM/DRNLa;
235 0:f233164f4c86 rmeddis
%
236
% gammatone filter coefficients for linear pathway
237
bw=DRNLParams.linBWs';
238
phi = 2 * pi * bw * dt;
239
cf=DRNLParams.linCFs';
240
theta = 2 * pi * cf * dt;
241
cos_theta = cos(theta);
242
sin_theta = sin(theta);
243
alpha = -exp(-phi).* cos_theta;
244
b0 = ones(nBFs,1);
245
b1 = 2 * alpha;
246
b2 = exp(-2 * phi);
247
z1 = (1 + alpha .* cos_theta) - (alpha .* sin_theta) * i;
248
z2 = (1 + b1 .* cos_theta) - (b1 .* sin_theta) * i;
249
z3 = (b2 .* cos(2 * theta)) - (b2 .* sin(2 * theta)) * i;
250
tf = (z2 + z3) ./ z1;
251
a0 = abs(tf);
252
a1 = alpha .* a0;
253
GTlin_a = [b0, b1, b2];
254
GTlin_b = [a0, a1];
255
GTlinOrder=DRNLlinearOrder;
256
GTlinBdry=cell(nBFs,GTlinOrder);
257
258
% nonlinear gammatone filter coefficients
259
bw=DRNLParams.nlBWs';
260
phi = 2 * pi * bw * dt;
261
cf=DRNLParams.nonlinCFs';
262
theta = 2 * pi * cf * dt;
263
cos_theta = cos(theta);
264
sin_theta = sin(theta);
265
alpha = -exp(-phi).* cos_theta;
266
b0 = ones(nBFs,1);
267
b1 = 2 * alpha;
268
b2 = exp(-2 * phi);
269
z1 = (1 + alpha .* cos_theta) - (alpha .* sin_theta) * i;
270
z2 = (1 + b1 .* cos_theta) - (b1 .* sin_theta) * i;
271
z3 = (b2 .* cos(2 * theta)) - (b2 .* sin(2 * theta)) * i;
272
tf = (z2 + z3) ./ z1;
273
a0 = abs(tf);
274
a1 = alpha .* a0;
275
GTnonlin_a = [b0, b1, b2];
276
GTnonlin_b = [a0, a1];
277
GTnonlinOrder=DRNLnonlinearOrder;
278
GTnonlinBdry1=cell(nBFs, GTnonlinOrder);
279
GTnonlinBdry2=cell(nBFs, GTnonlinOrder);
280
281
% complete BM record (BM displacement)
282
DRNLoutput=zeros(nBFs, signalLength);
283
284
285
%% IHC ---
286
% IHC cilia activity and receptor potential
287
% viscous coupling between BM and stereocilia displacement
288
% Nyquist=sampleRate/2;
289
% IHCcutoff=1/(2*pi*IHC_cilia_RPParams.tc);
290
% [IHCciliaFilter_b,IHCciliaFilter_a]=...
291
%     butter(1, IHCcutoff/Nyquist, 'high');
292
a1=dt/IHC_cilia_RPParams.tc-1; a0=1;
293
b0=1+ a1;
294
% high pass (i.e. low pass reversed)
295
IHCciliaFilter_b=[a0 a1]; IHCciliaFilter_a=b0;
296 38:c2204b18f4a2 rmeddis
% i.e. b= [1  dt/tc-1]  and a= dt/IHC_cilia_RPParams.tc
297 0:f233164f4c86 rmeddis
% figure(9), freqz(IHCciliaFilter_b, IHCciliaFilter_a)
298
299
IHCciliaBndry=cell(nBFs,1);
300
301
% IHC apical conductance (Boltzman function)
302
IHC_C= IHC_cilia_RPParams.C;
303
IHCu0= IHC_cilia_RPParams.u0;
304
IHCu1= IHC_cilia_RPParams.u1;
305
IHCs0= IHC_cilia_RPParams.s0;
306
IHCs1= IHC_cilia_RPParams.s1;
307
IHCGmax= IHC_cilia_RPParams.Gmax;
308 8:eafe11c86f44 rmeddis
IHCGa= IHC_cilia_RPParams.Ga; % (leakage)
309
310
IHCGu0 = IHCGa+IHCGmax./(1+exp(IHCu0/IHCs0).*(1+exp(IHCu1/IHCs1)));
311 9:ecad0ea62b43 rmeddis
IHCrestingCiliaCond=IHCGu0;
312 0:f233164f4c86 rmeddis
313
% Receptor potential
314
IHC_Cab= IHC_cilia_RPParams.Cab;
315
IHC_Gk= IHC_cilia_RPParams.Gk;
316
IHC_Et= IHC_cilia_RPParams.Et;
317
IHC_Ek= IHC_cilia_RPParams.Ek;
318
IHC_Ekp= IHC_Ek+IHC_Et*IHC_cilia_RPParams.Rpc;
319
320 9:ecad0ea62b43 rmeddis
IHCrestingV= (IHC_Gk*IHC_Ekp+IHCGu0*IHC_Et)/(IHCGu0+IHC_Gk);
321 8:eafe11c86f44 rmeddis
322 0:f233164f4c86 rmeddis
IHC_Vnow= IHCrestingV*ones(nBFs,1); % initial voltage
323
IHC_RP= zeros(nBFs,segmentLength);
324
325
% complete record of IHC receptor potential (V)
326
IHCciliaDisplacement= zeros(nBFs,segmentLength);
327
IHCoutput= zeros(nBFs,signalLength);
328
IHC_cilia_output= zeros(nBFs,signalLength);
329
330
331
%% pre-synapse ---
332
% Each BF is replicated using a different fiber type to make a 'channel'
333
% The number of channels is nBFs x nANfiberTypes
334
% Fiber types are specified in terms of tauCa
335
nANfiberTypes= length(IHCpreSynapseParams.tauCa);
336 32:82fb37eb430e rmeddis
ANtauCas= IHCpreSynapseParams.tauCa;
337 30:1a502830d462 rmeddis
nANchannels= nANfiberTypes*nBFs;
338
synapticCa= zeros(nANchannels,segmentLength);
339 0:f233164f4c86 rmeddis
340
% Calcium control (more calcium, greater release rate)
341
ECa=IHCpreSynapseParams.ECa;
342
gamma=IHCpreSynapseParams.gamma;
343
beta=IHCpreSynapseParams.beta;
344
tauM=IHCpreSynapseParams.tauM;
345 30:1a502830d462 rmeddis
mICa=zeros(nANchannels,segmentLength);
346 0:f233164f4c86 rmeddis
GmaxCa=IHCpreSynapseParams.GmaxCa;
347
synapse_z= IHCpreSynapseParams.z;
348
synapse_power=IHCpreSynapseParams.power;
349
350
% tauCa vector is established across channels to allow vectorization
351 36:3ea506487b3b rmeddis
%  (one tauCa per channel).
352
%  Do not confuse with ANtauCas vector (one per fiber type)
353 32:82fb37eb430e rmeddis
tauCa=repmat(ANtauCas, nBFs,1);
354 30:1a502830d462 rmeddis
tauCa=reshape(tauCa, nANchannels, 1);
355 0:f233164f4c86 rmeddis
356 30:1a502830d462 rmeddis
% presynapse startup values (vectors, length:nANchannels)
357 0:f233164f4c86 rmeddis
% proportion (0 - 1) of Ca channels open at IHCrestingV
358
mICaCurrent=((1+beta^-1 * exp(-gamma*IHCrestingV))^-1)...
359
    *ones(nBFs*nANfiberTypes,1);
360
% corresponding startup currents
361
ICaCurrent= (GmaxCa*mICaCurrent.^3) * (IHCrestingV-ECa);
362
CaCurrent= ICaCurrent.*tauCa;
363
364
% vesicle release rate at startup (one per channel)
365
% kt0 is used only at initialisation
366
kt0= -synapse_z * CaCurrent.^synapse_power;
367
368
369
%% AN ---
370
% each row of the AN matrices represents one AN fiber
371
% The results computed either for probabiities *or* for spikes (not both)
372
% Spikes are necessary if CN and IC are to be computed
373
nFibersPerChannel= AN_IHCsynapseParams.numFibers;
374 30:1a502830d462 rmeddis
nANfibers= nANchannels*nFibersPerChannel;
375 26:b03ef38fe497 rmeddis
AN_refractory_period= AN_IHCsynapseParams.refractory_period;
376 0:f233164f4c86 rmeddis
377
y=AN_IHCsynapseParams.y;
378
l=AN_IHCsynapseParams.l;
379
x=AN_IHCsynapseParams.x;
380
r=AN_IHCsynapseParams.r;
381
M=round(AN_IHCsynapseParams.M);
382
383
% probability            (NB initial 'P' on everything)
384 30:1a502830d462 rmeddis
PAN_ydt = repmat(AN_IHCsynapseParams.y*dt, nANchannels,1);
385
PAN_ldt = repmat(AN_IHCsynapseParams.l*dt, nANchannels,1);
386
PAN_xdt = repmat(AN_IHCsynapseParams.x*dt, nANchannels,1);
387
PAN_rdt = repmat(AN_IHCsynapseParams.r*dt, nANchannels,1);
388 0:f233164f4c86 rmeddis
PAN_rdt_plus_ldt = PAN_rdt + PAN_ldt;
389
PAN_M=round(AN_IHCsynapseParams.M);
390
391
% compute starting values
392
Pcleft    = kt0* y* M ./ (y*(l+r)+ kt0* l);
393
Pavailable    = Pcleft*(l+r)./kt0;
394
Preprocess    = Pcleft*r/x; % canbe fractional
395
396 30:1a502830d462 rmeddis
ANprobability=zeros(nANchannels,segmentLength);
397
ANprobRateOutput=zeros(nANchannels,signalLength);
398 26:b03ef38fe497 rmeddis
lengthAbsRefractoryP= round(AN_refractory_period/dt);
399 34:e097e9044ef6 rmeddis
cumANnotFireProb=ones(nANchannels,signalLength);
400 0:f233164f4c86 rmeddis
% special variables for monitoring synaptic cleft (specialists only)
401 30:1a502830d462 rmeddis
savePavailableSeg=zeros(nANchannels,segmentLength);
402
savePavailable=zeros(nANchannels,signalLength);
403 38:c2204b18f4a2 rmeddis
% only one stream of available transmitter will be saved
404
saveNavailableSeg=zeros(1,reducedSegmentLength);
405
saveNavailable=zeros(1,reducedSignalLength);
406 0:f233164f4c86 rmeddis
407
% spikes     % !  !  !    ! !        !   !  !
408 38:c2204b18f4a2 rmeddis
lengthAbsRefractory= round(AN_refractory_period/dtSpikes);
409 0:f233164f4c86 rmeddis
410 38:c2204b18f4a2 rmeddis
AN_ydt= repmat(AN_IHCsynapseParams.y*dtSpikes, nANfibers,1);
411
AN_ldt= repmat(AN_IHCsynapseParams.l*dtSpikes, nANfibers,1);
412
AN_xdt= repmat(AN_IHCsynapseParams.x*dtSpikes, nANfibers,1);
413
AN_rdt= repmat(AN_IHCsynapseParams.r*dtSpikes, nANfibers,1);
414 0:f233164f4c86 rmeddis
AN_rdt_plus_ldt= AN_rdt + AN_ldt;
415
AN_M= round(AN_IHCsynapseParams.M);
416
417
% kt0  is initial release rate
418
% Establish as a vector (length=channel x number of fibers)
419
kt0= repmat(kt0', nFibersPerChannel, 1);
420
kt0=reshape(kt0, nANfibers,1);
421
422
% starting values for reservoirs
423
AN_cleft    = kt0* y* M ./ (y*(l+r)+ kt0* l);
424
AN_available    = round(AN_cleft*(l+r)./kt0); %must be integer
425
AN_reprocess    = AN_cleft*r/x;
426
427
% output is in a logical array spikes = 1/ 0.
428
ANspikes= false(nANfibers,reducedSegmentLength);
429
ANoutput= false(nANfibers,reducedSignalLength);
430
431
432
%% CN (first brain stem nucleus - could be any subdivision of CN)
433
% Input to a CN neuorn is a random selection of AN fibers within a channel
434
%  The number of AN fibers used is ANfibersFanInToCN
435
% CNtauGk (Potassium time constant) determines the rate of firing of
436
%  the unit when driven hard by a DC input (not normally >350 sp/s)
437 30:1a502830d462 rmeddis
% If there is more than one value, everything is replicated accordingly
438
439 0:f233164f4c86 rmeddis
ANavailableFibersPerChan=AN_IHCsynapseParams.numFibers;
440 30:1a502830d462 rmeddis
ANfibersFanInToCN=MacGregorMultiParams.fibersPerNeuron;
441 0:f233164f4c86 rmeddis
442 30:1a502830d462 rmeddis
CNtauGk=MacGregorMultiParams.tauGk; % row vector of CN types (by tauGk)
443
nCNtauGk=length(CNtauGk);
444
445
% the total number of 'channels' is now greater
446 34:e097e9044ef6 rmeddis
% 'channel' is defined as collections of units with the same parameters
447
%  i.e. same BF, same ANtau, same CNtauGk
448 30:1a502830d462 rmeddis
nCNchannels=nANchannels*nCNtauGk;
449
450
nCNneuronsPerChannel=MacGregorMultiParams.nNeuronsPerBF;
451
tauGk=repmat(CNtauGk, nCNneuronsPerChannel,1);
452
tauGk=reshape(tauGk,nCNneuronsPerChannel*nCNtauGk,1);
453
454
% Now the number of neurons has been increased
455
nCNneurons=nCNneuronsPerChannel*nCNchannels;
456 0:f233164f4c86 rmeddis
CNmembranePotential=zeros(nCNneurons,reducedSegmentLength);
457
458
% establish which ANfibers (by name) feed into which CN nuerons
459 30:1a502830d462 rmeddis
CNinputfiberLists=zeros(nANchannels*nCNneuronsPerChannel, ANfibersFanInToCN);
460 0:f233164f4c86 rmeddis
unitNo=1;
461 30:1a502830d462 rmeddis
for ch=1:nANchannels
462 0:f233164f4c86 rmeddis
    % Each channel contains a number of units =length(listOfFanInValues)
463
    for idx=1:nCNneuronsPerChannel
464 30:1a502830d462 rmeddis
        for idx2=1:nCNtauGk
465
            fibersUsed=(ch-1)*ANavailableFibersPerChan + ...
466
                ceil(rand(1,ANfibersFanInToCN)* ANavailableFibersPerChan);
467
            CNinputfiberLists(unitNo,:)=fibersUsed;
468
            unitNo=unitNo+1;
469
        end
470 0:f233164f4c86 rmeddis
    end
471
end
472
473
% input to CN units
474
AN_PSTH=zeros(nCNneurons,reducedSegmentLength);
475
476
% Generate CNalphaFunction function
477
%  by which spikes are converted to post-synaptic currents
478
CNdendriteLPfreq= MacGregorMultiParams.dendriteLPfreq;
479
CNcurrentPerSpike=MacGregorMultiParams.currentPerSpike;
480
CNspikeToCurrentTau=1/(2*pi*CNdendriteLPfreq);
481 38:c2204b18f4a2 rmeddis
t=dtSpikes:dtSpikes:5*CNspikeToCurrentTau;
482 15:35af36fe0a35 rmeddis
CNalphaFunction= (1 / ...
483
    CNspikeToCurrentTau)*t.*exp(-t /CNspikeToCurrentTau);
484
CNalphaFunction=CNalphaFunction*CNcurrentPerSpike;
485
486 38:c2204b18f4a2 rmeddis
% figure(98), plot(t,CNalphaFunction), xlim([0 .020]), xlabel('time (s)'), ylabel('I')
487 0:f233164f4c86 rmeddis
% working memory for implementing convolution
488 15:35af36fe0a35 rmeddis
489 0:f233164f4c86 rmeddis
CNcurrentTemp=...
490
    zeros(nCNneurons,reducedSegmentLength+length(CNalphaFunction)-1);
491
% trailing alphas are parts of humps carried forward to the next segment
492
CNtrailingAlphas=zeros(nCNneurons,length(CNalphaFunction));
493
494
CN_tauM=MacGregorMultiParams.tauM;
495
CN_tauTh=MacGregorMultiParams.tauTh;
496
CN_cap=MacGregorMultiParams.Cap;
497
CN_c=MacGregorMultiParams.c;
498
CN_b=MacGregorMultiParams.dGkSpike;
499
CN_Ek=MacGregorMultiParams.Ek;
500
CN_Eb= MacGregorMultiParams.Eb;
501
CN_Er=MacGregorMultiParams.Er;
502
CN_Th0= MacGregorMultiParams.Th0;
503
CN_E= zeros(nCNneurons,1);
504
CN_Gk= zeros(nCNneurons,1);
505
CN_Th= MacGregorMultiParams.Th0*ones(nCNneurons,1);
506
CN_Eb=CN_Eb.*ones(nCNneurons,1);
507
CN_Er=CN_Er.*ones(nCNneurons,1);
508
CNtimeSinceLastSpike=zeros(nCNneurons,1);
509
% tauGk is the main distinction between neurons
510
%  in fact they are all the same in the standard model
511 30:1a502830d462 rmeddis
tauGk=repmat(tauGk,nANchannels,1);
512 0:f233164f4c86 rmeddis
513
CNoutput=false(nCNneurons,reducedSignalLength);
514
515
516
%% MacGregor (IC - second nucleus) --------
517 30:1a502830d462 rmeddis
nICcells=nANchannels*nCNtauGk;  % one cell per channel
518
CN_PSTH=zeros(nICcells ,reducedSegmentLength);
519 0:f233164f4c86 rmeddis
520 32:82fb37eb430e rmeddis
% ICspikeWidth=0.00015;   % this may need revisiting
521 38:c2204b18f4a2 rmeddis
% epochsPerSpike=round(ICspikeWidth/dtSpikes);
522 32:82fb37eb430e rmeddis
% if epochsPerSpike<1
523
%     error(['MacGregorMulti: sample rate too low to support ' ...
524
%         num2str(ICspikeWidth*1e6) '  microsec spikes']);
525
% end
526 0:f233164f4c86 rmeddis
527
% short names
528
IC_tauM=MacGregorParams.tauM;
529
IC_tauGk=MacGregorParams.tauGk;
530
IC_tauTh=MacGregorParams.tauTh;
531
IC_cap=MacGregorParams.Cap;
532
IC_c=MacGregorParams.c;
533
IC_b=MacGregorParams.dGkSpike;
534
IC_Th0=MacGregorParams.Th0;
535
IC_Ek=MacGregorParams.Ek;
536
IC_Eb= MacGregorParams.Eb;
537
IC_Er=MacGregorParams.Er;
538
539
IC_E=zeros(nICcells,1);
540
IC_Gk=zeros(nICcells,1);
541
IC_Th=IC_Th0*ones(nICcells,1);
542
543
% Dendritic filtering, all spikes are replaced by CNalphaFunction functions
544
ICdendriteLPfreq= MacGregorParams.dendriteLPfreq;
545
ICcurrentPerSpike=MacGregorParams.currentPerSpike;
546
ICspikeToCurrentTau=1/(2*pi*ICdendriteLPfreq);
547 38:c2204b18f4a2 rmeddis
t=dtSpikes:dtSpikes:3*ICspikeToCurrentTau;
548 0:f233164f4c86 rmeddis
IC_CNalphaFunction= (ICcurrentPerSpike / ...
549
    ICspikeToCurrentTau)*t.*exp(-t / ICspikeToCurrentTau);
550
% figure(98), plot(t,IC_CNalphaFunction)
551
552
% working space for implementing alpha function
553
ICcurrentTemp=...
554
    zeros(nICcells,reducedSegmentLength+length(IC_CNalphaFunction)-1);
555
ICtrailingAlphas=zeros(nICcells, length(IC_CNalphaFunction));
556
557
ICfiberTypeRates=zeros(nANfiberTypes,reducedSignalLength);
558 30:1a502830d462 rmeddis
ICoutput=false(nICcells,reducedSignalLength);
559 0:f233164f4c86 rmeddis
560
ICmembranePotential=zeros(nICcells,reducedSegmentLength);
561
ICmembraneOutput=zeros(nICcells,signalLength);
562
563
564
%% Main program %%  %%  %%  %%  %%  %%  %%  %%  %%  %%  %%  %%  %%  %%
565
566
%  Compute the entire model for each segment
567
segmentStartPTR=1;
568
reducedSegmentPTR=1; % when sampling rate is reduced
569
while segmentStartPTR<signalLength
570
    segmentEndPTR=segmentStartPTR+segmentLength-1;
571
    % shorter segments after speed up.
572
    shorterSegmentEndPTR=reducedSegmentPTR+reducedSegmentLength-1;
573
574 19:5b23b9f11806 rmeddis
    inputPressureSegment=inputSignal...
575 0:f233164f4c86 rmeddis
        (:,segmentStartPTR:segmentStartPTR+segmentLength-1);
576
577
    % segment debugging plots
578
    % figure(98)
579 19:5b23b9f11806 rmeddis
    % plot(segmentTime,inputPressureSegment), title('signalSegment')
580 0:f233164f4c86 rmeddis
581
582
    % OME ----------------------
583
584
    % OME Stage 1: external resonances. Add to inputSignal pressure wave
585 19:5b23b9f11806 rmeddis
    y=inputPressureSegment;
586 0:f233164f4c86 rmeddis
    for n=1:nOMEExtFilters
587
        % any number of resonances can be used
588
        [x  OMEExtFilterBndry{n}] = ...
589
            filter(ExtFilter_b{n},ExtFilter_a{n},...
590 19:5b23b9f11806 rmeddis
            inputPressureSegment, OMEExtFilterBndry{n});
591 0:f233164f4c86 rmeddis
        x= x* OMEgainScalars(n);
592
        % This is a parallel resonance so add it
593
        y=y+x;
594
    end
595 19:5b23b9f11806 rmeddis
    inputPressureSegment=y;
596
    OMEextEarPressure(segmentStartPTR:segmentEndPTR)= inputPressureSegment;
597 0:f233164f4c86 rmeddis
598
    % OME stage 2: convert input pressure (velocity) to
599
    %  tympanic membrane(TM) displacement using low pass filter
600
    [TMdisplacementSegment  OME_TMdisplacementBndry] = ...
601 19:5b23b9f11806 rmeddis
        filter(TMdisp_b,TMdisp_a,inputPressureSegment, ...
602 0:f233164f4c86 rmeddis
        OME_TMdisplacementBndry);
603
    % and save it
604
    TMoutput(segmentStartPTR:segmentEndPTR)= TMdisplacementSegment;
605
606
    % OME stage 3: middle ear high pass effect to simulate stapes inertia
607
    [stapesDisplacement  OMEhighPassBndry] = ...
608
        filter(stapesDisp_b,stapesDisp_a,TMdisplacementSegment, ...
609
        OMEhighPassBndry);
610
611
    % OME stage 4:  apply stapes scalar
612
    stapesDisplacement=stapesDisplacement*stapesScalar;
613
614
    % OME stage 5:    acoustic reflex stapes attenuation
615
    %  Attenuate the TM response using feedback from LSR fiber activity
616
    if segmentStartPTR>efferentDelayPts
617
        stapesDisplacement= stapesDisplacement.*...
618
            ARattenuation(segmentStartPTR-efferentDelayPts:...
619
            segmentEndPTR-efferentDelayPts);
620
    end
621
622
    % segment debugging plots
623
    % figure(98)
624
    % plot(segmentTime, stapesDisplacement), title ('stapesDisplacement')
625
626
    % and save
627
    OMEoutput(segmentStartPTR:segmentEndPTR)= stapesDisplacement;
628
629
630
    %% BM ------------------------------
631
    % Each location is computed separately
632
    for BFno=1:nBFs
633
634
        %            *linear* path
635
        linOutput = stapesDisplacement * linGAIN;  % linear gain
636 34:e097e9044ef6 rmeddis
637 0:f233164f4c86 rmeddis
        for order = 1 : GTlinOrder
638
            [linOutput GTlinBdry{BFno,order}] = ...
639 34:e097e9044ef6 rmeddis
                filter(GTlin_b(BFno,:), GTlin_a(BFno,:), linOutput, ...
640
                GTlinBdry{BFno,order});
641 0:f233164f4c86 rmeddis
        end
642
643
        %           *nonLinear* path
644
        % efferent attenuation (0 <> 1)
645
        if segmentStartPTR>efferentDelayPts
646
            MOC=MOCattenuation(BFno, segmentStartPTR-efferentDelayPts:...
647
                segmentEndPTR-efferentDelayPts);
648
        else    % no MOC available yet
649
            MOC=ones(1, segmentLength);
650
        end
651 35:25d53244d5c8 rmeddis
        % apply MOC to nonlinear input function
652
%         figure(88), plot(MOC)
653 23:6cce421531e2 rmeddis
        nonlinOutput=stapesDisplacement.* MOC;
654 0:f233164f4c86 rmeddis
655 23:6cce421531e2 rmeddis
        %       first gammatone filter (nonlin path)
656 0:f233164f4c86 rmeddis
        for order = 1 : GTnonlinOrder
657
            [nonlinOutput GTnonlinBdry1{BFno,order}] = ...
658
                filter(GTnonlin_b(BFno,:), GTnonlin_a(BFno,:), ...
659 23:6cce421531e2 rmeddis
                nonlinOutput, GTnonlinBdry1{BFno,order});
660 0:f233164f4c86 rmeddis
        end
661 34:e097e9044ef6 rmeddis
662 38:c2204b18f4a2 rmeddis
663 35:25d53244d5c8 rmeddis
        % Nick's compression algorithm
664 38:c2204b18f4a2 rmeddis
        abs_x= abs(nonlinOutput);
665
        signs= sign(nonlinOutput);
666
        belowThreshold= abs_x<CtS;
667
        nonlinOutput(belowThreshold)= DRNLa *nonlinOutput(belowThreshold);
668
        aboveThreshold=~belowThreshold;
669
        nonlinOutput(aboveThreshold)= signs(aboveThreshold) *ctBM .* ...
670
            exp(DRNLc *log( DRNLa*abs_x(aboveThreshold)/ctBM ));
671
672 35:25d53244d5c8 rmeddis
673 34:e097e9044ef6 rmeddis
%         %    original   broken stick instantaneous compression
674 35:25d53244d5c8 rmeddis
%         holdY=nonlinOutput;
675
%         abs_x = abs(nonlinOutput);
676
%         nonlinOutput=sign(nonlinOutput).*min(DRNLa*abs_x, DRNLb*abs_x.^DRNLc);
677
%
678
679
%         %   new broken stick instantaneous compression
680
%         y= nonlinOutput.* DRNLa;  % linear section attenuation/gain.
681 34:e097e9044ef6 rmeddis
%         % compress parts of the signal above the compression threshold
682 35:25d53244d5c8 rmeddis
%         %         holdY=y;
683
%         abs_y = abs(y);
684
%         idx=find(abs_y>DRNLcompressionThreshold);
685 34:e097e9044ef6 rmeddis
%         if ~isempty(idx)>0
686 35:25d53244d5c8 rmeddis
%             %             y(idx)=sign(y(idx)).* (DRNLcompressionThreshold + ...
687
%             %                 (abs_y(idx)-DRNLcompressionThreshold).^DRNLc);
688
%             y(idx)=sign(y(idx)).* (DRNLcompressionThreshold + ...
689
%                 (abs_y(idx)-DRNLcompressionThreshold)*DRNLa2);
690 34:e097e9044ef6 rmeddis
%         end
691
%         nonlinOutput=y;
692
693
694 38:c2204b18f4a2 rmeddis
% if segmentStartPTR==10*segmentLength+1
695
%     figure(90)
696
%     plot(holdY,'b'), hold on
697
%     plot(nonlinOutput, 'r'), hold off
698
%     ylim([-1e-5 1e-5])
699
%     pause(1)
700
% end
701 34:e097e9044ef6 rmeddis
702 38:c2204b18f4a2 rmeddis
%       second filter removes distortion products
703 0:f233164f4c86 rmeddis
        for order = 1 : GTnonlinOrder
704
            [ nonlinOutput GTnonlinBdry2{BFno,order}] = ...
705 19:5b23b9f11806 rmeddis
                filter(GTnonlin_b(BFno,:), GTnonlin_a(BFno,:), ...
706
                nonlinOutput, GTnonlinBdry2{BFno,order});
707 0:f233164f4c86 rmeddis
        end
708
709
        %  combine the two paths to give the DRNL displacement
710
        DRNLresponse(BFno,:)=linOutput+nonlinOutput;
711 34:e097e9044ef6 rmeddis
%         disp(num2str(max(linOutput)))
712 0:f233164f4c86 rmeddis
    end % BF
713
714
    % segment debugging plots
715
    % figure(98)
716
    %     if size(DRNLresponse,1)>3
717
    %         imagesc(DRNLresponse)  % matrix display
718 35:25d53244d5c8 rmeddis
    %         title('DRNLresponse');
719 0:f233164f4c86 rmeddis
    %     else
720
    %         plot(segmentTime, DRNLresponse)
721
    %     end
722
723
    % and save it
724
    DRNLoutput(:, segmentStartPTR:segmentEndPTR)= DRNLresponse;
725
726
727
    %% IHC ------------------------------------
728
    %  BM displacement to IHCciliaDisplacement is  a high-pass filter
729
    %   because of viscous coupling
730
    for idx=1:nBFs
731
        [IHCciliaDisplacement(idx,:)  IHCciliaBndry{idx}] = ...
732
            filter(IHCciliaFilter_b,IHCciliaFilter_a, ...
733
            DRNLresponse(idx,:), IHCciliaBndry{idx});
734
    end
735
736
    % apply scalar
737
    IHCciliaDisplacement=IHCciliaDisplacement* IHC_C;
738
739
    % and save it
740
    IHC_cilia_output(:,segmentStartPTR:segmentStartPTR+segmentLength-1)=...
741
        IHCciliaDisplacement;
742
743
    % compute apical conductance
744 9:ecad0ea62b43 rmeddis
    G=IHCGmax./(1+exp(-(IHCciliaDisplacement-IHCu0)/IHCs0).*...
745 0:f233164f4c86 rmeddis
        (1+exp(-(IHCciliaDisplacement-IHCu1)/IHCs1)));
746 9:ecad0ea62b43 rmeddis
    Gu=G + IHCGa;
747 0:f233164f4c86 rmeddis
748
    % Compute receptor potential
749
    for idx=1:segmentLength
750
        IHC_Vnow=IHC_Vnow+ (-Gu(:, idx).*(IHC_Vnow-IHC_Et)-...
751
            IHC_Gk*(IHC_Vnow-IHC_Ekp))*  dt/IHC_Cab;
752
        IHC_RP(:,idx)=IHC_Vnow;
753
    end
754
755
    % segment debugging plots
756
    %     if size(IHC_RP,1)>3
757
    %         surf(IHC_RP), shading interp, title('IHC_RP')
758
    %     else
759
    %         plot(segmentTime, IHC_RP)
760
    %     end
761
762
    % and save it
763
    IHCoutput(:, segmentStartPTR:segmentStartPTR+segmentLength-1)=IHC_RP;
764
765
766
    %% synapse -----------------------------
767
    % Compute the vesicle release rate for each fiber type at each BF
768 36:3ea506487b3b rmeddis
769
    % replicate IHC_RP for each fiber type to obtain the driving voltage
770 0:f233164f4c86 rmeddis
    Vsynapse=repmat(IHC_RP, nANfiberTypes,1);
771
772
    % look-up table of target fraction channels open for a given IHC_RP
773
    mICaINF=    1./( 1 + exp(-gamma  * Vsynapse)  /beta);
774 36:3ea506487b3b rmeddis
775
    % fraction of channels open - apply time membrane constant
776 0:f233164f4c86 rmeddis
    for idx=1:segmentLength
777
        % mICaINF is the current 'target' value of mICa
778
        mICaCurrent=mICaCurrent+(mICaINF(:,idx)-mICaCurrent)*dt./tauM;
779
        mICa(:,idx)=mICaCurrent;
780
    end
781 36:3ea506487b3b rmeddis
782
    % calcium current
783 0:f233164f4c86 rmeddis
    ICa=   (GmaxCa* mICa.^3) .* (Vsynapse- ECa);
784 36:3ea506487b3b rmeddis
    % apply calcium channel time constant
785 0:f233164f4c86 rmeddis
    for idx=1:segmentLength
786
        CaCurrent=CaCurrent +  ICa(:,idx)*dt - CaCurrent*dt./tauCa;
787
        synapticCa(:,idx)=CaCurrent;
788
    end
789 34:e097e9044ef6 rmeddis
    synapticCa=-synapticCa; % treat synapticCa as positive substance
790 0:f233164f4c86 rmeddis
791
    % NB vesicleReleaseRate is /s and is independent of dt
792
    vesicleReleaseRate = synapse_z * synapticCa.^synapse_power; % rate
793
794
    % segment debugging plots
795
    %     if size(vesicleReleaseRate,1)>3
796
    %         surf(vesicleReleaseRate), shading interp, title('vesicleReleaseRate')
797
    %     else
798
    %         plot(segmentTime, vesicleReleaseRate)
799
    %     end
800
801
802 36:3ea506487b3b rmeddis
    %% AN -------------------------------
803 0:f233164f4c86 rmeddis
    switch AN_spikesOrProbability
804
        case 'probability'
805
            for t = 1:segmentLength;
806
                M_Pq=PAN_M-Pavailable;
807
                M_Pq(M_Pq<0)=0;
808
                Preplenish = M_Pq .* PAN_ydt;
809
                Pejected = Pavailable.* vesicleReleaseRate(:,t)*dt;
810
                Preprocessed = M_Pq.*Preprocess.* PAN_xdt;
811
812
                ANprobability(:,t)= min(Pejected,1);
813
                reuptakeandlost= PAN_rdt_plus_ldt .* Pcleft;
814
                reuptake= PAN_rdt.* Pcleft;
815
816
                Pavailable= Pavailable+ Preplenish- Pejected+ Preprocessed;
817
                Pcleft= Pcleft + Pejected - reuptakeandlost;
818
                Preprocess= Preprocess + reuptake - Preprocessed;
819
                Pavailable(Pavailable<0)=0;
820
                savePavailableSeg(:,t)=Pavailable;    % synapse tracking
821 34:e097e9044ef6 rmeddis
822 0:f233164f4c86 rmeddis
            end
823 34:e097e9044ef6 rmeddis
824 0:f233164f4c86 rmeddis
            % and save it as *rate*
825
            ANrate=ANprobability/dt;
826
            ANprobRateOutput(:, segmentStartPTR:...
827
                segmentStartPTR+segmentLength-1)=  ANrate;
828
            % monitor synapse contents (only sometimes used)
829
            savePavailable(:, segmentStartPTR:segmentStartPTR+segmentLength-1)=...
830
                savePavailableSeg;
831 34:e097e9044ef6 rmeddis
832
            %% Apply refractory effect
833
               % the probability of a spike's occurring in the preceding
834 36:3ea506487b3b rmeddis
               %  refractory window: t= (tnow-refractory period) :dt: tnow
835 34:e097e9044ef6 rmeddis
               %    pFired= 1 - II(1-p(t)),
836 38:c2204b18f4a2 rmeddis
               % we need a running account of cumProb=II(1-p(t)) in order
837
               % not to have to recompute this for each value of t
838 34:e097e9044ef6 rmeddis
               %   cumProb(t)= cumProb(t-1)*(1-p(t))/(1-p(t-refracPeriod))
839
               %   cumProb(0)=0
840
               %   pFired(t)= 1-cumProb(t)
841
               % This gives the fraction of firing events that must be
842
               %  discounted because of a firing event in the refractory
843
               %  period
844
               %   p(t)= ANprobOutput(t) * pFired(t)
845
               % where ANprobOutput is the uncorrected firing probability
846
               %  based on vesicle release rate
847
               % NB this covers only the absoute refractory period
848
               % not the relative refractory period. To approximate this it
849
               % is necessary to extend the refractory period by 50%
850 0:f233164f4c86 rmeddis
851 34:e097e9044ef6 rmeddis
                for t = segmentStartPTR:segmentEndPTR;
852
                    if t>1
853
                    ANprobRateOutput(:,t)= ANprobRateOutput(:,t)...
854
                        .* cumANnotFireProb(:,t-1);
855
                    end
856
                    % add recent and remove distant probabilities
857
                    refrac=round(lengthAbsRefractoryP * 1.5);
858
                    if t>refrac
859
                        cumANnotFireProb(:,t)= cumANnotFireProb(:,t-1)...
860
                            .*(1-ANprobRateOutput(:,t)*dt)...
861
                            ./(1-ANprobRateOutput(:,t-refrac)*dt);
862
                    end
863
                end
864
%                 figure(88), plot(cumANnotFireProb'), title('cumNotFire')
865
%                 figure(89), plot(ANprobRateOutput'), title('ANprobRateOutput')
866
867 38:c2204b18f4a2 rmeddis
            %% Estimate acoustic reflex efferent effect:  0 < ARattenuation > 1
868 19:5b23b9f11806 rmeddis
            [r c]=size(ANrate);
869
            if r>nBFs % Only if LSR fibers are computed
870
                ARAttSeg=mean(ANrate(1:nBFs,:),1); %LSR channels are 1:nBF
871
                % smooth
872
                [ARAttSeg, ARboundaryProb] = ...
873
                    filter(ARfilt_b, ARfilt_a, ARAttSeg, ARboundaryProb);
874
                ARAttSeg=ARAttSeg-ARrateThreshold;
875
                ARAttSeg(ARAttSeg<0)=0;   % prevent negative strengths
876
                ARattenuation(segmentStartPTR:segmentEndPTR)=...
877
                    (1-ARrateToAttenuationFactorProb.* ARAttSeg);
878
            end
879
            %             plot(ARattenuation)
880 0:f233164f4c86 rmeddis
881 34:e097e9044ef6 rmeddis
            % MOC attenuation based on within-channel HSR fiber activity
882 0:f233164f4c86 rmeddis
            HSRbegins=nBFs*(nANfiberTypes-1)+1;
883
            rates=ANrate(HSRbegins:end,:);
884 27:d4a7675b0413 rmeddis
            if rateToAttenuationFactorProb<0
885
                % negative factor implies a fixed attenuation
886
                MOCattenuation(:,segmentStartPTR:segmentEndPTR)= ...
887
                    ones(size(rates))* -rateToAttenuationFactorProb;
888
            else
889 35:25d53244d5c8 rmeddis
890 27:d4a7675b0413 rmeddis
                for idx=1:nBFs
891
                    [smoothedRates, MOCprobBoundary{idx}] = ...
892 35:25d53244d5c8 rmeddis
                        filter(MOCfiltProb_b, MOCfiltProb_a, rates(idx,:), ...
893 27:d4a7675b0413 rmeddis
                        MOCprobBoundary{idx});
894
                    smoothedRates=smoothedRates-MOCrateThresholdProb;
895 34:e097e9044ef6 rmeddis
                    smoothedRates=max(smoothedRates, 0);
896
897
                    x=(1- smoothedRates* rateToAttenuationFactorProb);
898
                    MOCattenuation(idx,segmentStartPTR:segmentEndPTR)= x;
899 27:d4a7675b0413 rmeddis
                end
900 0:f233164f4c86 rmeddis
            end
901 35:25d53244d5c8 rmeddis
902
            MOCattenuation(MOCattenuation<minMOCattenuation)= minMOCattenuation;
903
904
            % plot(MOCattenuation)
905
906 0:f233164f4c86 rmeddis
        case 'spikes'
907
            ANtimeCount=0;
908
            % implement speed upt
909
            for t = ANspeedUpFactor:ANspeedUpFactor:segmentLength;
910
                ANtimeCount=ANtimeCount+1;
911
                % convert release rate to probabilities
912 38:c2204b18f4a2 rmeddis
                releaseProb=vesicleReleaseRate(:,t)*dtSpikes;
913 0:f233164f4c86 rmeddis
                % releaseProb is the release probability per channel
914
                %  but each channel has many synapses
915
                releaseProb=repmat(releaseProb',nFibersPerChannel,1);
916 30:1a502830d462 rmeddis
                releaseProb=reshape(releaseProb, nFibersPerChannel*nANchannels,1);
917 0:f233164f4c86 rmeddis
918
                % AN_available=round(AN_available); % vesicles must be integer, (?needed)
919
                M_q=AN_M- AN_available;     % number of missing vesicles
920
                M_q(M_q<0)= 0;              % cannot be less than 0
921
922 35:25d53244d5c8 rmeddis
%                 probabilities= 1-(1-releaseProb).^AN_available; % slow
923 0:f233164f4c86 rmeddis
                probabilities= 1-intpow((1-releaseProb), AN_available);
924
                ejected= probabilities> rand(length(AN_available),1);
925
926
                reuptakeandlost = AN_rdt_plus_ldt .* AN_cleft;
927
                reuptake = AN_rdt.* AN_cleft;
928 35:25d53244d5c8 rmeddis
929
%                 probabilities= 1-(1-AN_reprocess.*AN_xdt).^M_q; % slow
930 0:f233164f4c86 rmeddis
                probabilities= 1-intpow((1-AN_reprocess.*AN_xdt), M_q);
931
                reprocessed= probabilities>rand(length(M_q),1);
932
933 35:25d53244d5c8 rmeddis
%                 probabilities= 1-(1-AN_ydt).^M_q; %slow
934 0:f233164f4c86 rmeddis
                 probabilities= 1-intpow((1-AN_ydt), M_q);
935
936
                replenish= probabilities>rand(length(M_q),1);
937
938
                AN_available = AN_available + replenish - ejected ...
939
                    + reprocessed;
940 38:c2204b18f4a2 rmeddis
                saveNavailableSeg(:,ANtimeCount)=AN_available(end,:); % only last channel
941
942 0:f233164f4c86 rmeddis
                AN_cleft = AN_cleft + ejected - reuptakeandlost;
943
                AN_reprocess = AN_reprocess + reuptake - reprocessed;
944
945
                % ANspikes is logical record of vesicle release events>0
946
                ANspikes(:, ANtimeCount)= ejected;
947
            end % t
948
949
            % zero any events that are preceded by release events ...
950
            %  within the refractory period
951
            % The refractory period consist of two periods
952
            %  1) the absolute period where no spikes occur
953
            %  2) a relative period where a spike may occur. This relative
954
            %     period is realised as a variable length interval
955
            %     where the length is chosen at random
956
            %     (esentially a linear ramp up)
957
958
            % Andreas has a fix for this
959
            for t = 1:ANtimeCount-2*lengthAbsRefractory;
960
                % identify all spikes across fiber array at time (t)
961
                % idx is a list of channels where spikes occurred
962
                % ?? try sparse matrices?
963
                idx=find(ANspikes(:,t));
964
                for j=idx  % consider each spike
965
                    % specify variable refractory period
966
                    %  between abs and 2*abs refractory period
967
                    nPointsRefractory=lengthAbsRefractory+...
968
                        round(rand*lengthAbsRefractory);
969
                    % disable spike potential for refractory period
970
                    % set all values in this range to 0
971
                    ANspikes(j,t+1:t+nPointsRefractory)=0;
972
                end
973
            end  %t
974
975
            % segment debugging
976
            % plotInstructions.figureNo=98;
977 38:c2204b18f4a2 rmeddis
            % plotInstructions.displaydt=dtSpikes;
978 0:f233164f4c86 rmeddis
            %  plotInstructions.numPlots=1;
979
            %  plotInstructions.subPlotNo=1;
980
            % UTIL_plotMatrix(ANspikes, plotInstructions);
981
982
            % and save it. NB, AN is now on 'speedUp' time
983
            ANoutput(:, reducedSegmentPTR: shorterSegmentEndPTR)=ANspikes;
984 38:c2204b18f4a2 rmeddis
            % monitor synapse contents (only sometimes used)
985
            saveNavailable(reducedSegmentPTR:reducedSegmentPTR+reducedSegmentLength-1)=...
986
                saveNavailableSeg;
987 0:f233164f4c86 rmeddis
988
989
            %% CN Macgregor first neucleus -------------------------------
990 38:c2204b18f4a2 rmeddis
            % input is from AN so dtSpikes is used throughout
991 0:f233164f4c86 rmeddis
            % Each CNneuron has a unique set of input fibers selected
992
            %  at random from the available AN fibers (CNinputfiberLists)
993
994
            % Create the dendritic current for that neuron
995
            % First get input spikes to this neuron
996
            synapseNo=1;
997 30:1a502830d462 rmeddis
            for ch=1:nCNchannels
998 0:f233164f4c86 rmeddis
                for idx=1:nCNneuronsPerChannel
999
                    % determine candidate fibers for this unit
1000
                    fibersUsed=CNinputfiberLists(synapseNo,:);
1001 38:c2204b18f4a2 rmeddis
                    % ANpsth has a bin width of dtSpikes
1002 0:f233164f4c86 rmeddis
                    %  (just a simple sum across fibers)
1003
                    AN_PSTH(synapseNo,:) = ...
1004
                        sum(ANspikes(fibersUsed,:), 1);
1005
                    synapseNo=synapseNo+1;
1006
                end
1007
            end
1008
1009
            % One alpha function per spike
1010
            [alphaRows alphaCols]=size(CNtrailingAlphas);
1011
1012
            for unitNo=1:nCNneurons
1013
                CNcurrentTemp(unitNo,:)= ...
1014 32:82fb37eb430e rmeddis
                    conv2(AN_PSTH(unitNo,:),CNalphaFunction);
1015 0:f233164f4c86 rmeddis
            end
1016 15:35af36fe0a35 rmeddis
%             disp(['sum(AN_PSTH)= ' num2str(sum(AN_PSTH(1,:)))])
1017 0:f233164f4c86 rmeddis
            % add post-synaptic current  left over from previous segment
1018
            CNcurrentTemp(:,1:alphaCols)=...
1019
                CNcurrentTemp(:,1:alphaCols)+ CNtrailingAlphas;
1020
1021
            % take post-synaptic current for this segment
1022
            CNcurrentInput= CNcurrentTemp(:, 1:reducedSegmentLength);
1023 15:35af36fe0a35 rmeddis
%                 disp(['mean(CNcurrentInput)= ' num2str(mean(CNcurrentInput(1,:)))])
1024 0:f233164f4c86 rmeddis
1025
            % trailingalphas are the ends of the alpha functions that
1026
            % spill over into the next segment
1027
            CNtrailingAlphas= ...
1028
                CNcurrentTemp(:, reducedSegmentLength+1:end);
1029
1030
            if CN_c>0
1031
                % variable threshold condition (slow)
1032
                for t=1:reducedSegmentLength
1033 38:c2204b18f4a2 rmeddis
                    CNtimeSinceLastSpike=CNtimeSinceLastSpike-dtSpikes;
1034 0:f233164f4c86 rmeddis
                    s=CN_E>CN_Th & CNtimeSinceLastSpike<0 ;
1035
                    CNtimeSinceLastSpike(s)=0.0005;         % 0.5 ms for sodium spike
1036
                    dE =(-CN_E/CN_tauM + ...
1037 15:35af36fe0a35 rmeddis
                        CNcurrentInput(:,t)/CN_cap+(...
1038 38:c2204b18f4a2 rmeddis
                        CN_Gk/CN_cap).*(CN_Ek-CN_E))*dtSpikes;
1039
                    dGk=-CN_Gk*dtSpikes./tauGk + CN_b*s;
1040
                    dTh=-(CN_Th-CN_Th0)*dtSpikes/CN_tauTh + CN_c*s;
1041 0:f233164f4c86 rmeddis
                    CN_E=CN_E+dE;
1042
                    CN_Gk=CN_Gk+dGk;
1043
                    CN_Th=CN_Th+dTh;
1044
                    CNmembranePotential(:,t)=CN_E+s.*(CN_Eb-CN_E)+CN_Er;
1045
                end
1046
            else
1047
                % static threshold (faster)
1048 15:35af36fe0a35 rmeddis
                E=zeros(1,reducedSegmentLength);
1049
                Gk=zeros(1,reducedSegmentLength);
1050
                ss=zeros(1,reducedSegmentLength);
1051 0:f233164f4c86 rmeddis
                for t=1:reducedSegmentLength
1052 15:35af36fe0a35 rmeddis
                    % time of previous spike moves back in time
1053 38:c2204b18f4a2 rmeddis
                    CNtimeSinceLastSpike=CNtimeSinceLastSpike-dtSpikes;
1054 15:35af36fe0a35 rmeddis
                    % action potential if E>threshold
1055
                    %  allow time for s to reset between events
1056
                    s=CN_E>CN_Th0 & CNtimeSinceLastSpike<0 ;
1057
                    ss(t)=s(1);
1058
                    CNtimeSinceLastSpike(s)=0.0005; % 0.5 ms for sodium spike
1059 0:f233164f4c86 rmeddis
                    dE = (-CN_E/CN_tauM + ...
1060 15:35af36fe0a35 rmeddis
                        CNcurrentInput(:,t)/CN_cap +...
1061 38:c2204b18f4a2 rmeddis
                        (CN_Gk/CN_cap).*(CN_Ek-CN_E))*dtSpikes;
1062
                    dGk=-CN_Gk*dtSpikes./tauGk +CN_b*s;
1063 0:f233164f4c86 rmeddis
                    CN_E=CN_E+dE;
1064
                    CN_Gk=CN_Gk+dGk;
1065 15:35af36fe0a35 rmeddis
                    E(t)=CN_E(1);
1066
                    Gk(t)=CN_Gk(1);
1067 0:f233164f4c86 rmeddis
                    % add spike to CN_E and add resting potential (-60 mV)
1068 15:35af36fe0a35 rmeddis
                    CNmembranePotential(:,t)=CN_E +s.*(CN_Eb-CN_E)+CN_Er;
1069 0:f233164f4c86 rmeddis
                end
1070
            end
1071 15:35af36fe0a35 rmeddis
%             disp(['CN_E= ' num2str(sum(CN_E(1,:)))])
1072
%             disp(['CN_Gk= ' num2str(sum(CN_Gk(1,:)))])
1073
%             disp(['CNmembranePotential= ' num2str(sum(CNmembranePotential(1,:)))])
1074
%             plot(CNmembranePotential(1,:))
1075
1076 0:f233164f4c86 rmeddis
1077
            % extract spikes.  A spike is a substantial upswing in voltage
1078 15:35af36fe0a35 rmeddis
            CN_spikes=CNmembranePotential> -0.02;
1079
%             disp(['CNspikesbefore= ' num2str(sum(sum(CN_spikes)))])
1080 0:f233164f4c86 rmeddis
1081
            % now remove any spike that is immediately followed by a spike
1082
            % NB 'find' works on columns (whence the transposing)
1083 15:35af36fe0a35 rmeddis
            % for each spike put a zero in the next epoch
1084 0:f233164f4c86 rmeddis
            CN_spikes=CN_spikes';
1085
            idx=find(CN_spikes);
1086
            idx=idx(1:end-1);
1087
            CN_spikes(idx+1)=0;
1088
            CN_spikes=CN_spikes';
1089 15:35af36fe0a35 rmeddis
%             disp(['CNspikes= ' num2str(sum(sum(CN_spikes)))])
1090 0:f233164f4c86 rmeddis
1091
            % segment debugging
1092
            % plotInstructions.figureNo=98;
1093 38:c2204b18f4a2 rmeddis
            % plotInstructions.displaydt=dtSpikes;
1094 0:f233164f4c86 rmeddis
            %  plotInstructions.numPlots=1;
1095
            %  plotInstructions.subPlotNo=1;
1096
            % UTIL_plotMatrix(CN_spikes, plotInstructions);
1097
1098
            % and save it
1099
            CNoutput(:, reducedSegmentPTR:shorterSegmentEndPTR)=...
1100
                CN_spikes;
1101
1102
1103
            %% IC ----------------------------------------------
1104
                %  MacGregor or some other second order neurons
1105
1106 34:e097e9044ef6 rmeddis
                % combine CN neurons in same channel (BF x AN tau x CNtau)
1107
                %  i.e. same BF, same tauCa, same CNtau
1108 0:f233164f4c86 rmeddis
                %  to generate inputs to single IC unit
1109
                channelNo=0;
1110 34:e097e9044ef6 rmeddis
                for idx=1:nCNneuronsPerChannel: ...
1111
                        nCNneurons-nCNneuronsPerChannel+1;
1112 0:f233164f4c86 rmeddis
                    channelNo=channelNo+1;
1113
                    CN_PSTH(channelNo,:)=...
1114
                        sum(CN_spikes(idx:idx+nCNneuronsPerChannel-1,:));
1115
                end
1116
1117
                [alphaRows alphaCols]=size(ICtrailingAlphas);
1118
                for ICneuronNo=1:nICcells
1119
                    ICcurrentTemp(ICneuronNo,:)= ...
1120 32:82fb37eb430e rmeddis
                        conv2(CN_PSTH(ICneuronNo,:),  IC_CNalphaFunction);
1121 0:f233164f4c86 rmeddis
                end
1122
1123
                % add the unused current from the previous convolution
1124
                ICcurrentTemp(:,1:alphaCols)=ICcurrentTemp(:,1:alphaCols)...
1125
                    + ICtrailingAlphas;
1126
                % take what is required and keep the trailing part for next time
1127
                inputCurrent=ICcurrentTemp(:, 1:reducedSegmentLength);
1128
                ICtrailingAlphas=ICcurrentTemp(:, reducedSegmentLength+1:end);
1129
1130
                if IC_c==0
1131 34:e097e9044ef6 rmeddis
                    % faster computation when threshold is stable (c==0)
1132 0:f233164f4c86 rmeddis
                    for t=1:reducedSegmentLength
1133
                        s=IC_E>IC_Th0;
1134
                        dE = (-IC_E/IC_tauM + inputCurrent(:,t)/IC_cap +...
1135 38:c2204b18f4a2 rmeddis
                            (IC_Gk/IC_cap).*(IC_Ek-IC_E))*dtSpikes;
1136
                        dGk=-IC_Gk*dtSpikes/IC_tauGk +IC_b*s;
1137 0:f233164f4c86 rmeddis
                        IC_E=IC_E+dE;
1138
                        IC_Gk=IC_Gk+dGk;
1139
                        ICmembranePotential(:,t)=IC_E+s.*(IC_Eb-IC_E)+IC_Er;
1140
                    end
1141
                else
1142
                    %  threshold is changing (IC_c>0; e.g. bushy cell)
1143
                    for t=1:reducedSegmentLength
1144
                        dE = (-IC_E/IC_tauM + ...
1145
                            inputCurrent(:,t)/IC_cap + (IC_Gk/IC_cap)...
1146 38:c2204b18f4a2 rmeddis
                            .*(IC_Ek-IC_E))*dtSpikes;
1147 0:f233164f4c86 rmeddis
                        IC_E=IC_E+dE;
1148
                        s=IC_E>IC_Th;
1149
                        ICmembranePotential(:,t)=IC_E+s.*(IC_Eb-IC_E)+IC_Er;
1150 38:c2204b18f4a2 rmeddis
                        dGk=-IC_Gk*dtSpikes/IC_tauGk +IC_b*s;
1151 0:f233164f4c86 rmeddis
                        IC_Gk=IC_Gk+dGk;
1152
1153
                        % After a spike, the threshold is raised
1154
                        % otherwise it settles to its baseline
1155 38:c2204b18f4a2 rmeddis
                        dTh=-(IC_Th-Th0)*dtSpikes/IC_tauTh +s*IC_c;
1156 0:f233164f4c86 rmeddis
                        IC_Th=IC_Th+dTh;
1157
                    end
1158
                end
1159
1160
                ICspikes=ICmembranePotential> -0.01;
1161 35:25d53244d5c8 rmeddis
                %figure(2),plot(ICmembranePotential(2,:))
1162 0:f233164f4c86 rmeddis
                % now remove any spike that is immediately followed by a spike
1163
                % NB 'find' works on columns (whence the transposing)
1164
                ICspikes=ICspikes';
1165
                idx=find(ICspikes);
1166
                idx=idx(1:end-1);
1167
                ICspikes(idx+1)=0;
1168
                ICspikes=ICspikes';
1169
1170
                nCellsPerTau= nICcells/nANfiberTypes;
1171
                firstCell=1;
1172
                lastCell=nCellsPerTau;
1173
                for tauCount=1:nANfiberTypes
1174
                    % separate rates according to fiber types
1175 15:35af36fe0a35 rmeddis
                    % currently only the last segment is saved
1176 0:f233164f4c86 rmeddis
                    ICfiberTypeRates(tauCount, ...
1177
                        reducedSegmentPTR:shorterSegmentEndPTR)=...
1178
                        sum(ICspikes(firstCell:lastCell, :))...
1179 38:c2204b18f4a2 rmeddis
                        /(nCellsPerTau*dtSpikes);
1180 0:f233164f4c86 rmeddis
                    firstCell=firstCell+nCellsPerTau;
1181
                    lastCell=lastCell+nCellsPerTau;
1182
                end
1183 15:35af36fe0a35 rmeddis
1184
                ICoutput(:,reducedSegmentPTR:shorterSegmentEndPTR)=ICspikes;
1185 35:25d53244d5c8 rmeddis
                % figure(3),plot(ICoutput(2,:))
1186 15:35af36fe0a35 rmeddis
1187
                % store membrane output on original dt scale
1188 34:e097e9044ef6 rmeddis
                % do this for single channel models only
1189
                % and only for the HSR-driven IC cells
1190
                if round(nICcells/length(ANtauCas))==1  % single channel
1191
                    % select HSR driven cells
1192
                    x= ICmembranePotential(length(ANtauCas),:);
1193
                    % restore original dt
1194
                    x= repmat(x, ANspeedUpFactor,1);
1195 0:f233164f4c86 rmeddis
                    x= reshape(x,1,segmentLength);
1196
                    if nANfiberTypes>1  % save HSR and LSR
1197 15:35af36fe0a35 rmeddis
                        y=repmat(ICmembranePotential(end,:),...
1198
                            ANspeedUpFactor,1);
1199 0:f233164f4c86 rmeddis
                        y= reshape(y,1,segmentLength);
1200
                        x=[x; y];
1201
                    end
1202
                    ICmembraneOutput(:, segmentStartPTR:segmentEndPTR)= x;
1203
                end
1204 35:25d53244d5c8 rmeddis
                % figure(4),plot(ICmembraneOutput(2,:))
1205 0:f233164f4c86 rmeddis
1206
                % estimate efferent effects.
1207 38:c2204b18f4a2 rmeddis
                % AR is based on LSR units. LSR channels are 1:nBF
1208 35:25d53244d5c8 rmeddis
                if nANfiberTypes>1  % use only if model is multi-fiber
1209 38:c2204b18f4a2 rmeddis
                    ARAttSeg=mean(ICspikes(1:nBFs,:),1)/dtSpikes;
1210 0:f233164f4c86 rmeddis
                    [ARAttSeg, ARboundary] = ...
1211
                        filter(ARfilt_b, ARfilt_a, ARAttSeg, ARboundary);
1212 38:c2204b18f4a2 rmeddis
%                    ARAttSeg(ARAttSeg<0)=0;   % prevent negative strengths
1213
                    % scale up to dt from dtSpikes
1214 35:25d53244d5c8 rmeddis
                    x= repmat(ARAttSeg, ANspeedUpFactor,1);
1215
                    x= reshape(x,1,segmentLength);
1216 0:f233164f4c86 rmeddis
                    ARattenuation(segmentStartPTR:segmentEndPTR)=...
1217
                        (1-ARrateToAttenuationFactor* x);
1218 35:25d53244d5c8 rmeddis
                    % max 60 dB attenuation
1219 38:c2204b18f4a2 rmeddis
                    ARattenuation(ARattenuation<0)=0.01;
1220 0:f233164f4c86 rmeddis
                else
1221 35:25d53244d5c8 rmeddis
                    % single fiber type; disable AR because no LSR fibers
1222 0:f233164f4c86 rmeddis
                    ARattenuation(segmentStartPTR:segmentEndPTR)=...
1223
                        ones(1,segmentLength);
1224
                end
1225
1226
                % MOC attenuation using HSR response only
1227 35:25d53244d5c8 rmeddis
                %  separate MOC effect for each BF
1228
                %  there is only one unit per channel
1229 0:f233164f4c86 rmeddis
                HSRbegins=nBFs*(nANfiberTypes-1)+1;
1230 38:c2204b18f4a2 rmeddis
                rates=ICspikes(HSRbegins:end,:)/dtSpikes;
1231 35:25d53244d5c8 rmeddis
                % figure(4),plot(rates(1,:))
1232
1233 0:f233164f4c86 rmeddis
                for idx=1:nBFs
1234
                    [smoothedRates, MOCboundary{idx}] = ...
1235
                        filter(MOCfilt_b, MOCfilt_a, rates(idx,:), ...
1236
                        MOCboundary{idx});
1237 23:6cce421531e2 rmeddis
                    % spont 'rates' is zero for IC
1238 0:f233164f4c86 rmeddis
                    MOCattSegment(idx,:)=smoothedRates;
1239 38:c2204b18f4a2 rmeddis
                    % expand timescale back to model dt from dtSpikes
1240 0:f233164f4c86 rmeddis
                    x= repmat(MOCattSegment(idx,:), ANspeedUpFactor,1);
1241
                    x= reshape(x,1,segmentLength);
1242
                    MOCattenuation(idx,segmentStartPTR:segmentEndPTR)= ...
1243
                        (1- MOCrateToAttenuationFactor*  x);
1244 35:25d53244d5c8 rmeddis
                    % figure(4),plot(x)
1245 0:f233164f4c86 rmeddis
                end
1246 35:25d53244d5c8 rmeddis
                % max attenuation is 30 dB
1247
                MOCattenuation(MOCattenuation<minMOCattenuation)=...
1248
                    minMOCattenuation;
1249
                % figure(4),plot(MOCattenuation)
1250
1251 0:f233164f4c86 rmeddis
                % segment debugging
1252
                % plotInstructions.figureNo=98;
1253 38:c2204b18f4a2 rmeddis
                % plotInstructions.displaydt=dtSpikes;
1254 0:f233164f4c86 rmeddis
                %  plotInstructions.numPlots=1;
1255
                %  plotInstructions.subPlotNo=1;
1256
                % UTIL_plotMatrix(ICspikes, plotInstructions);
1257
1258
    end     % AN_spikesOrProbability
1259
    segmentStartPTR=segmentStartPTR+segmentLength;
1260
    reducedSegmentPTR=reducedSegmentPTR+reducedSegmentLength;
1261
1262
end  % segment
1263
1264 9:ecad0ea62b43 rmeddis
path(restorePath)