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 / testPrograms / temp.m @ 38:c2204b18f4a2

History | View | Annotate | Download (10.9 KB)

1 38:c2204b18f4a2 rmeddis
function vectorStrength=testAN(probeFrequency,BFlist, levels, ...
2
    paramsName,paramChanges)
3
% testAN generates rate/level functions for AN and brainstem units.
4
%  also other information like PSTHs, MOC efferent activity levels.
5
% Vector strength calculations require the computation of period
6
% histograms. for this reason the sample rate must always be an integer
7
% multiple of the tone frequency. This applies to both the sampleRate and
8
% the spikes sampling rate.
9
% A full 'spikes' model is used.
10
% paramChanges is a cell array of strings containing MATLAB statements that
11
% change model parameters. See MAPparamsNormal for examples.
12
% e.g.
13
% testAN(1000,1000, -10:10:80,'Normal',{});
14 35:25d53244d5c8 rmeddis
15 38:c2204b18f4a2 rmeddis
16
global IHC_VResp_VivoParams  IHC_cilia_RPParams IHCpreSynapseParams
17
global AN_IHCsynapseParams
18
global ANoutput dtSpikes CNoutput ICoutput ICmembraneOutput ANtauCas
19
global ARattenuation MOCattenuation
20
tic
21 36:3ea506487b3b rmeddis
dbstop if error
22
restorePath=path;
23 38:c2204b18f4a2 rmeddis
addpath (['..' filesep 'MAP'], ['..' filesep 'utilities'], ...
24
    ['..' filesep 'parameterStore'],  ['..' filesep 'wavFileStore'],...
25
    ['..' filesep 'testPrograms'])
26 35:25d53244d5c8 rmeddis
27 38:c2204b18f4a2 rmeddis
if nargin<5, paramChanges={'IHCpreSynapseParams.tauCa= [30e-6 90e-6];'}; end
28
if nargin<4, paramsName='PL'; end
29
if nargin<3, levels=-10:10:80; end
30
if nargin==0, probeFrequency=1000; BFlist=1000; end
31
nLevels=length(levels);
32 36:3ea506487b3b rmeddis
33 38:c2204b18f4a2 rmeddis
toneDuration=.2;   rampDuration=0.005;   silenceDuration=.02;
34
localPSTHbinwidth=0.001;
35 36:3ea506487b3b rmeddis
36 38:c2204b18f4a2 rmeddis
%% guarantee that the sample rate is an interger multiple
37
%   of the probe frequency
38
% we want 5 bins per period for spikes
39
spikesSampleRate=5*probeFrequency;
40
% model sample rate must be an integer multiple of this and in the region
41
% of 50000
42
sampleRate=spikesSampleRate*round(50000/spikesSampleRate);
43
dt=1/sampleRate;
44
% avoid very slow spikes sampling rate
45
spikesSampleRate=spikesSampleRate*ceil(10000/spikesSampleRate);
46 36:3ea506487b3b rmeddis
47 38:c2204b18f4a2 rmeddis
%% pre-allocate storage
48
AN_HSRonset=zeros(nLevels,1);
49
AN_HSRsaturated=zeros(nLevels,1);
50
AN_LSRonset=zeros(nLevels,1);
51
AN_LSRsaturated=zeros(nLevels,1);
52
CNLSRrate=zeros(nLevels,1);
53
CNHSRsaturated=zeros(nLevels,1);
54
ICHSRsaturated=zeros(nLevels,1);
55
ICLSRsaturated=zeros(nLevels,1);
56
vectorStrength=zeros(nLevels,1);
57 36:3ea506487b3b rmeddis
58 38:c2204b18f4a2 rmeddis
AR=zeros(nLevels,1);
59
MOC=zeros(nLevels,1);
60 36:3ea506487b3b rmeddis
61 38:c2204b18f4a2 rmeddis
figure(15), clf
62
set(gcf,'position',[980   356   401   321])
63
figure(5), clf
64
set(gcf,'position', [980 34 400 295])
65
drawnow
66 36:3ea506487b3b rmeddis
67
68 38:c2204b18f4a2 rmeddis
%% main computational loop (vary level)
69
levelNo=0;
70
for leveldB=levels
71
    levelNo=levelNo+1;
72
    amp=28e-6*10^(leveldB/20);
73
    fprintf('%4.0f\t', leveldB)
74 36:3ea506487b3b rmeddis
75 38:c2204b18f4a2 rmeddis
    %% generate tone and silences
76
    time=dt:dt:toneDuration;
77
    rampTime=dt:dt:rampDuration;
78
    ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ...
79
        ones(1,length(time)-length(rampTime))];
80
    ramp=ramp.*fliplr(ramp);
81
82
    silence=zeros(1,round(silenceDuration/dt));
83
84
    inputSignal=amp*sin(2*pi*probeFrequency'*time);
85
    inputSignal= ramp.*inputSignal;
86
    inputSignal=[silence inputSignal];
87
88
    %% run the model
89
    AN_spikesOrProbability='spikes';
90
    nExistingParamChanges=length(paramChanges);
91
    paramChanges{nExistingParamChanges+1}=...
92
        ['AN_IHCsynapseParams.spikesTargetSampleRate=' ...
93
        num2str(spikesSampleRate) ';'];
94 36:3ea506487b3b rmeddis
95 38:c2204b18f4a2 rmeddis
    MAP1_14(inputSignal, 1/dt, BFlist, ...
96
        paramsName, AN_spikesOrProbability, paramChanges);
97
98
    nTaus=length(ANtauCas);
99
100
    %% Auditory nerve evaluate and display (Fig. 5)
101
    %LSR (same as HSR if no LSR fibers present)
102
    [nANFibers nTimePoints]=size(ANoutput);
103
    numLSRfibers=nANFibers/nTaus;
104
    numHSRfibers=numLSRfibers;
105
106
    LSRspikes=ANoutput(1:numLSRfibers,:);
107
    PSTH=UTIL_PSTHmaker(LSRspikes, dtSpikes, localPSTHbinwidth);
108
    PSTHLSR=mean(PSTH,1)/localPSTHbinwidth;  % across fibers rates
109
    PSTHtime=localPSTHbinwidth:localPSTHbinwidth:...
110
        localPSTHbinwidth*length(PSTH);
111
    AN_LSRonset(levelNo)= max(PSTHLSR); % peak in 5 ms window
112
    AN_LSRsaturated(levelNo)= mean(PSTHLSR(round(length(PSTH)/2):end));
113
114
    % AN HSR
115
    HSRspikes= ANoutput(end- numHSRfibers+1:end, :);
116
    PSTH=UTIL_PSTHmaker(HSRspikes, dtSpikes, localPSTHbinwidth);
117
    PSTH=mean(PSTH,1)/localPSTHbinwidth; % sum across fibers (HSR only)
118
    AN_HSRonset(levelNo)= max(PSTH);
119
    AN_HSRsaturated(levelNo)= mean(PSTH(round(length(PSTH)/2): end));
120
121
    figure(5), subplot(2,2,2)
122
    hold off, bar(PSTHtime,PSTH, 'b')
123
    hold on,  bar(PSTHtime,PSTHLSR,'r')
124
    ylim([0 1000])
125
    xlim([0 length(PSTH)*localPSTHbinwidth])
126
    grid on
127
    set(gcf,'name',['PSTH: ' num2str(BFlist), ' Hz: ' num2str(leveldB) ' dB']);
128
129
    % AN - CV
130
    %  CV is computed 5 times. Use the middle one (3) as most typical
131
    cvANHSR=  UTIL_CV(HSRspikes, dtSpikes);
132
133
    % AN - vector strength
134
    PSTH=sum(CNoutput (11:20,:));
135
    [PH, binTimes]=UTIL_periodHistogram...
136
        (PSTH, dtSpikes, probeFrequency);
137
    VS=UTIL_vectorStrength(PH);
138
    vectorStrength(levelNo)=VS;
139
    disp(['sat rate= ' num2str(AN_HSRsaturated(levelNo)) ...
140
        ';   phase-locking VS = ' num2str(VS)])
141
    title(['AN HSR: CV=' num2str(cvANHSR(3),'%5.2f') ...
142
        'VS=' num2str(VS,'%5.2f')])
143
144
    %% CN - first-order neurons
145
146
    % CN driven by LSR fibers
147
    [nCNneurons c]=size(CNoutput);
148
    nLSRneurons=round(nCNneurons/nTaus);
149
    CNLSRspikes=CNoutput(1:nLSRneurons,:);
150
    PSTH=UTIL_PSTHmaker(CNLSRspikes, dtSpikes, localPSTHbinwidth);
151
    PSTH=sum(PSTH)/nLSRneurons;
152
%     CNLSRrate(levelNo)=mean(PSTH(round(length(PSTH)/2):end))/localPSTHbinwidth;
153
    CNLSRrate(levelNo)=mean(PSTH)/localPSTHbinwidth;
154
155
    %CN HSR
156
    MacGregorMultiHSRspikes=...
157
        CNoutput(end-nLSRneurons+1:end,:);
158
    PSTH=UTIL_PSTHmaker(MacGregorMultiHSRspikes, dtSpikes, localPSTHbinwidth);
159
    PSTH=sum(PSTH)/nLSRneurons;
160
    PSTH=mean(PSTH,1)/localPSTHbinwidth; % sum across fibers (HSR only)
161
162
%     CNHSRsaturated(levelNo)=mean(PSTH(length(PSTH)/2:end));
163
    CNHSRsaturated(levelNo)=mean(PSTH);
164
165
    figure(5), subplot(2,2,3)
166
    bar(PSTHtime,PSTH)
167
    ylim([0 1000])
168
    xlim([0 length(PSTH)*localPSTHbinwidth])
169
    cvMMHSR= UTIL_CV(MacGregorMultiHSRspikes, dtSpikes);
170
    title(['CN    CV= ' num2str(cvMMHSR(3),'%5.2f')])
171
172
    %% IC LSR
173
    [nICneurons c]=size(ICoutput);
174
    nLSRneurons=round(nICneurons/nTaus);
175
    ICLSRspikes=ICoutput(1:nLSRneurons,:);
176
    PSTH=UTIL_PSTHmaker(ICLSRspikes, dtSpikes, localPSTHbinwidth);
177
%     ICLSRsaturated(levelNo)=mean(PSTH(round(length(PSTH)/2):end))/localPSTHbinwidth;
178
    ICLSRsaturated(levelNo)=mean(PSTH)/localPSTHbinwidth;
179
180
    %IC HSR
181
    MacGregorMultiHSRspikes=...
182
        ICoutput(end-nLSRneurons+1:end,:);
183
    PSTH=UTIL_PSTHmaker(MacGregorMultiHSRspikes, dtSpikes, localPSTHbinwidth);
184
    ICHSRsaturated(levelNo)= (sum(PSTH)/nLSRneurons)/toneDuration;
185 36:3ea506487b3b rmeddis
186 38:c2204b18f4a2 rmeddis
    AR(levelNo)=min(ARattenuation);
187
    MOC(levelNo)=min(MOCattenuation(length(MOCattenuation)/2:end));
188
189
    time=dt:dt:dt*size(ICmembraneOutput,2);
190
    figure(5), subplot(2,2,4)
191
    % plot HSR (last of two)
192
    plot(time,ICmembraneOutput(end-nLSRneurons+1, 1:end),'k')
193
    ylim([-0.07 0])
194
    xlim([0 max(time)])
195
    title(['IC  ' num2str(leveldB,'%4.0f') 'dB'])
196
    drawnow
197
198
    figure(5), subplot(2,2,1)
199
    plot(20*log10(MOC), 'k'), hold on
200
    plot(20*log10(AR), 'r'), hold off
201
    title(' MOC'), ylabel('dB attenuation')
202
    ylim([-30 0])
203
204
%     x=input('prompt')
205
end % level
206 36:3ea506487b3b rmeddis
207 38:c2204b18f4a2 rmeddis
%% plot with levels on x-axis
208
figure(5), subplot(2,2,1)
209
plot(levels,20*log10(MOC), 'k'),hold on
210
plot(levels,20*log10(AR), 'r'), hold off
211
title(' MOC'), ylabel('dB attenuation')
212
ylim([-30 0])
213
xlim([0 max(levels)])
214 36:3ea506487b3b rmeddis
215 38:c2204b18f4a2 rmeddis
fprintf('\n')
216
toneDuration=2;
217
rampDuration=0.004;
218
silenceDuration=.02;
219
nRepeats=200;   % no. of AN fibers
220
fprintf('toneDuration  %6.3f\n', toneDuration)
221
fprintf(' %6.0f  AN fibers (repeats)\n', nRepeats)
222
fprintf('levels')
223
fprintf('%6.2f\t', levels)
224
fprintf('\n')
225 36:3ea506487b3b rmeddis
226 38:c2204b18f4a2 rmeddis
%% ---------------------- display summary results (Fig 15)
227
figure(15), clf
228
nRows=2; nCols=2;
229 36:3ea506487b3b rmeddis
230 38:c2204b18f4a2 rmeddis
% AN rate - level ONSET functions
231
subplot(nRows,nCols,1)
232
plot(levels,AN_LSRonset,'ro'), hold on
233
plot(levels,AN_HSRonset,'ko'), hold off
234
ylim([0 1000])
235
if length(levels)>1
236
    xlim([min(levels) max(levels)])
237 36:3ea506487b3b rmeddis
end
238
239 38:c2204b18f4a2 rmeddis
ttl=['tauCa= ' num2str(IHCpreSynapseParams.tauCa)];
240
title( ttl)
241
xlabel('level dB SPL'), ylabel('peak rate (sp/s)'), grid on
242
text(0, 800, 'AN onset', 'fontsize', 14)
243
244
% AN rate - level ADAPTED function
245
subplot(nRows,nCols,2)
246
plot(levels,AN_LSRsaturated, 'ro'), hold on
247
plot(levels,AN_HSRsaturated, 'ko'), hold off
248
ylim([0 400])
249
set(gca,'ytick',0:50:300)
250
if length(levels)>1
251
xlim([min(levels) max(levels)])
252 36:3ea506487b3b rmeddis
end
253 38:c2204b18f4a2 rmeddis
set(gca,'xtick',[levels(1):20:levels(end)])
254
%     grid on
255
ttl=[   'spont=' num2str(mean(AN_HSRsaturated(1,:)),'%4.0f')...
256
    '  sat=' num2str(mean(AN_HSRsaturated(end,1)),'%4.0f')];
257
title( ttl)
258
xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)')
259
text(0, 340, 'AN adapted', 'fontsize', 14), grid on
260 36:3ea506487b3b rmeddis
261 38:c2204b18f4a2 rmeddis
% CN rate - level function
262
subplot(nRows,nCols,3)
263
plot(levels,CNLSRrate, 'ro'), hold on
264
plot(levels,CNHSRsaturated, 'ko'), hold off
265
ylim([0 400])
266
set(gca,'ytick',0:50:300)
267
if length(levels)>1
268
xlim([min(levels) max(levels)])
269
end
270
set(gca,'xtick',[levels(1):20:levels(end)])
271
%     grid on
272
ttl=[   'spont=' num2str(mean(CNHSRsaturated(1,:)),'%4.0f') '  sat=' ...
273
    num2str(mean(CNHSRsaturated(end,1)),'%4.0f')];
274
title( ttl)
275
xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)')
276
text(0, 350, 'CN', 'fontsize', 14), grid on
277 36:3ea506487b3b rmeddis
278 38:c2204b18f4a2 rmeddis
% IC rate - level function
279
subplot(nRows,nCols,4)
280
plot(levels,ICLSRsaturated, 'ro'), hold on
281
plot(levels,ICHSRsaturated, 'ko'), hold off
282
ylim([0 400])
283
set(gca,'ytick',0:50:300)
284
if length(levels)>1
285
xlim([min(levels) max(levels)])
286
end
287
set(gca,'xtick',[levels(1):20:levels(end)]), grid on
288
ttl=['spont=' num2str(mean(ICHSRsaturated(1,:)),'%4.0f') ...
289
    '  sat=' num2str(mean(ICHSRsaturated(end,1)),'%4.0f')];
290
title( ttl)
291
xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)')
292
text(0, 350, 'IC', 'fontsize', 14)
293
set(gcf,'name',' AN CN IC rate/level')
294 36:3ea506487b3b rmeddis
295 38:c2204b18f4a2 rmeddis
fprintf('\n')
296
disp('levels vectorStrength')
297
fprintf('%3.0f \t %6.4f \n', [levels; vectorStrength'])
298
fprintf('\n')
299
fprintf('Phase locking, max vector strength=\t %6.4f\n\n',...
300
    max(vectorStrength))
301 36:3ea506487b3b rmeddis
302 38:c2204b18f4a2 rmeddis
allData=[ levels'  AN_HSRonset AN_HSRsaturated...
303
    AN_LSRonset AN_LSRsaturated ...
304
    CNHSRsaturated CNLSRrate...
305
    ICHSRsaturated ICLSRsaturated];
306
fprintf('\n levels \tANHSR Onset \tANHSR adapted\tANLSR Onset \tANLSR adapted\tCNHSR\tCNLSR\tICHSR  \tICLSR \n');
307
UTIL_printTabTable(round(allData))
308
fprintf('VS (phase locking)= \t%6.4f\n\n',...
309
    max(vectorStrength))
310 36:3ea506487b3b rmeddis
311 38:c2204b18f4a2 rmeddis
UTIL_showStruct(IHC_cilia_RPParams, 'IHC_cilia_RPParams')
312
UTIL_showStruct(IHCpreSynapseParams, 'IHCpreSynapseParams')
313
UTIL_showStruct(AN_IHCsynapseParams, 'AN_IHCsynapseParams')
314
315 35:25d53244d5c8 rmeddis
fprintf('\n')
316 38:c2204b18f4a2 rmeddis
disp('levels vectorStrength')
317
fprintf('%3.0f \t %6.4f \n', [levels; vectorStrength'])
318
fprintf('\n')
319
fprintf('Phase locking, max vector strength= \t%6.4f\n\n',...
320
    max(vectorStrength))
321 35:25d53244d5c8 rmeddis
322 38:c2204b18f4a2 rmeddis
allData=[ levels'  AN_HSRonset AN_HSRsaturated...
323
    AN_LSRonset AN_LSRsaturated ...
324
    CNHSRsaturated CNLSRrate...
325
    ICHSRsaturated ICLSRsaturated];
326
fprintf('\n levels \tANHSR Onset \tANHSR adapted\tANLSR Onset \tANLSR adapted\tCNHSR\tCNLSR\tICHSR  \tICLSR \n');
327
UTIL_printTabTable(round(allData))
328
fprintf('VS (phase locking)= \t%6.4f\n\n',...
329
    max(vectorStrength))
330 36:3ea506487b3b rmeddis
331 38:c2204b18f4a2 rmeddis
path(restorePath)
332 36:3ea506487b3b rmeddis
toc