comparison testPrograms/temp.m @ 38:c2204b18f4a2 tip

End nov big change
author Ray Meddis <rmeddis@essex.ac.uk>
date Mon, 28 Nov 2011 13:34:28 +0000
parents 3ea506487b3b
children
comparison
equal deleted inserted replaced
37:771a643d5c29 38:c2204b18f4a2
1 function test_MAP1_14 1 function vectorStrength=testAN(probeFrequency,BFlist, levels, ...
2 % test_MAP1_14 is a general purpose test routine that can be adjusted to 2 paramsName,paramChanges)
3 % test a number of different applications of MAP1_14 3 % testAN generates rate/level functions for AN and brainstem units.
4 % 4 % also other information like PSTHs, MOC efferent activity levels.
5 % A range of options are supplied in the early part of the program 5 % Vector strength calculations require the computation of period
6 % 6 % histograms. for this reason the sample rate must always be an integer
7 % One use of the function is to create demonstrations; filenames <demoxx> 7 % multiple of the tone frequency. This applies to both the sampleRate and
8 % to illustrate particular features 8 % the spikes sampling rate.
9 % 9 % A full 'spikes' model is used.
10 % #1 10 % paramChanges is a cell array of strings containing MATLAB statements that
11 % Identify the file (in 'MAPparamsName') containing the model parameters 11 % change model parameters. See MAPparamsNormal for examples.
12 % 12 % e.g.
13 % #2 13 % testAN(1000,1000, -10:10:80,'Normal',{});
14 % Identify the kind of model required (in 'AN_spikesOrProbability'). 14
15 % A full brainstem model (spikes) can be computed or a shorter model 15
16 % (probability) that computes only so far as the auditory nerve 16 global IHC_VResp_VivoParams IHC_cilia_RPParams IHCpreSynapseParams
17 % 17 global AN_IHCsynapseParams
18 % #3 18 global ANoutput dtSpikes CNoutput ICoutput ICmembraneOutput ANtauCas
19 % Choose between a tone signal or file input (in 'signalType') 19 global ARattenuation MOCattenuation
20 % 20 tic
21 % #4
22 % Set the signal rms level (in leveldBSPL)
23 %
24 % #5
25 % Identify the channels in terms of their best frequencies in the vector
26 % BFlist.
27 %
28 % Last minute changes to the parameters fetched earlier can be made using
29 % the cell array of strings 'paramChanges'.
30 % Each string must have the same format as the corresponding line in the
31 % file identified in 'MAPparamsName'
32 %
33 % When the demonstration is satisfactory, freeze it by renaming it <demoxx>
34
35 dbstop if error 21 dbstop if error
36 restorePath=path; 22 restorePath=path;
37 addpath (['..' filesep 'MAP'], ['..' filesep 'wavFileStore'], ... 23 addpath (['..' filesep 'MAP'], ['..' filesep 'utilities'], ...
38 ['..' filesep 'utilities']) 24 ['..' filesep 'parameterStore'], ['..' filesep 'wavFileStore'],...
39 25 ['..' filesep 'testPrograms'])
40 %% #1 parameter file name 26
41 MAPparamsName='Normal'; 27 if nargin<5, paramChanges={'IHCpreSynapseParams.tauCa= [30e-6 90e-6];'}; end
42 28 if nargin<4, paramsName='PL'; end
43 29 if nargin<3, levels=-10:10:80; end
44 %% #2 probability (fast) or spikes (slow) representation 30 if nargin==0, probeFrequency=1000; BFlist=1000; end
45 AN_spikesOrProbability='spikes'; 31 nLevels=length(levels);
46 % or 32
47 AN_spikesOrProbability='probability'; 33 toneDuration=.2; rampDuration=0.005; silenceDuration=.02;
48 34 localPSTHbinwidth=0.001;
49 35
50 %% #3 pure tone, harmonic sequence or speech file input 36 %% guarantee that the sample rate is an interger multiple
51 signalType= 'tones'; 37 % of the probe frequency
52 sampleRate= 50000; 38 % we want 5 bins per period for spikes
53 duration=0.500; % seconds 39 spikesSampleRate=5*probeFrequency;
54 rampDuration=.005; % raised cosine ramp (seconds) 40 % model sample rate must be an integer multiple of this and in the region
55 beginSilence=0.250; 41 % of 50000
56 endSilence=0.250; 42 sampleRate=spikesSampleRate*round(50000/spikesSampleRate);
57 toneFrequency= 1000; % or a pure tone (Hz) 43 dt=1/sampleRate;
58 44 % avoid very slow spikes sampling rate
59 % or 45 spikesSampleRate=spikesSampleRate*ceil(10000/spikesSampleRate);
60 % harmonic sequence (Hz) 46
61 % F0=210; 47 %% pre-allocate storage
62 % toneFrequency= F0:F0:8000; 48 AN_HSRonset=zeros(nLevels,1);
63 49 AN_HSRsaturated=zeros(nLevels,1);
64 % or 50 AN_LSRonset=zeros(nLevels,1);
65 signalType= 'file'; 51 AN_LSRsaturated=zeros(nLevels,1);
66 fileName='twister_44kHz'; 52 CNLSRrate=zeros(nLevels,1);
67 53 CNHSRsaturated=zeros(nLevels,1);
68 54 ICHSRsaturated=zeros(nLevels,1);
69 55 ICLSRsaturated=zeros(nLevels,1);
70 %% #4 rms level 56 vectorStrength=zeros(nLevels,1);
71 % signal details 57
72 leveldBSPL= 70; % dB SPL (80 for Lieberman) 58 AR=zeros(nLevels,1);
73 59 MOC=zeros(nLevels,1);
74 60
75 %% #5 number of channels in the model 61 figure(15), clf
76 % 21-channel model (log spacing) 62 set(gcf,'position',[980 356 401 321])
77 numChannels=21; 63 figure(5), clf
78 lowestBF=250; highestBF= 6000; 64 set(gcf,'position', [980 34 400 295])
79 BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels)); 65 drawnow
80 66
81 % or specify your own channel BFs 67
82 numChannels=1; 68 %% main computational loop (vary level)
83 BFlist=toneFrequency; 69 levelNo=0;
84 70 for leveldB=levels
85 71 levelNo=levelNo+1;
86 %% #6 change model parameters 72 amp=28e-6*10^(leveldB/20);
87 73 fprintf('%4.0f\t', leveldB)
88 paramChanges={}; 74
89 75 %% generate tone and silences
90 % Parameter changes can be used to change one or more model parameters 76 time=dt:dt:toneDuration;
91 % *after* the MAPparams file has been read 77 rampTime=dt:dt:rampDuration;
92 % This example declares only one fiber type with a calcium clearance time 78 ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ...
93 % constant of 80e-6 s (HSR fiber) when the probability option is selected. 79 ones(1,length(time)-length(rampTime))];
94 paramChanges={'AN_IHCsynapseParams.ANspeedUpFactor=5;', ... 80 ramp=ramp.*fliplr(ramp);
95 'IHCpreSynapseParams.tauCa=86e-6; '}; 81
96 82 silence=zeros(1,round(silenceDuration/dt));
97 83
98 84 inputSignal=amp*sin(2*pi*probeFrequency'*time);
99 %% delare 'showMap' options to control graphical output 85 inputSignal= ramp.*inputSignal;
100 showMapOptions.printModelParameters=1; % prints all parameters 86 inputSignal=[silence inputSignal];
101 showMapOptions.showModelOutput=1; % plot of all stages 87
102 showMapOptions.printFiringRates=1; % prints stage activity levels 88 %% run the model
103 showMapOptions.showACF=1; % shows SACF (probability only) 89 AN_spikesOrProbability='spikes';
104 showMapOptions.showEfferent=1; % tracks of AR and MOC 90 nExistingParamChanges=length(paramChanges);
105 showMapOptions.surfProbability=1; % 2D plot of HSR response 91 paramChanges{nExistingParamChanges+1}=...
106 showMapOptions.surfSpikes=1; % 2D plot of spikes histogram 92 ['AN_IHCsynapseParams.spikesTargetSampleRate=' ...
107 showMapOptions.ICrates=0; % IC rates by CNtauGk 93 num2str(spikesSampleRate) ';'];
108 94
109 % disable certain silly options 95 MAP1_14(inputSignal, 1/dt, BFlist, ...
110 if strcmp(AN_spikesOrProbability, 'spikes') 96 paramsName, AN_spikesOrProbability, paramChanges);
111 % avoid nonsensical options 97
112 showMapOptions.surfProbability=0; 98 nTaus=length(ANtauCas);
113 showMapOptions.showACF=0; 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
186 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
207 %% 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
215 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
226 %% ---------------------- display summary results (Fig 15)
227 figure(15), clf
228 nRows=2; nCols=2;
229
230 % 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)])
114 end 237 end
115 238
116 if strcmp(signalType, 'file') 239 ttl=['tauCa= ' num2str(IHCpreSynapseParams.tauCa)];
117 % needed for labeling plot 240 title( ttl)
118 showMapOptions.fileName=fileName; 241 xlabel('level dB SPL'), ylabel('peak rate (sp/s)'), grid on
119 else 242 text(0, 800, 'AN onset', 'fontsize', 14)
120 showMapOptions.fileName=[]; 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)])
121 end 252 end
122 253 set(gca,'xtick',[levels(1):20:levels(end)])
123 %% Generate stimuli 254 % grid on
124 255 ttl=[ 'spont=' num2str(mean(AN_HSRsaturated(1,:)),'%4.0f')...
125 switch signalType 256 ' sat=' num2str(mean(AN_HSRsaturated(end,1)),'%4.0f')];
126 case 'tones' 257 title( ttl)
127 % Create pure tone stimulus 258 xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)')
128 dt=1/sampleRate; % seconds 259 text(0, 340, 'AN adapted', 'fontsize', 14), grid on
129 time=dt: dt: duration; 260
130 inputSignal=sum(sin(2*pi*toneFrequency'*time), 1); 261 % CN rate - level function
131 amp=10^(leveldBSPL/20)*28e-6; % converts to Pascals (peak) 262 subplot(nRows,nCols,3)
132 inputSignal=amp*inputSignal; 263 plot(levels,CNLSRrate, 'ro'), hold on
133 % apply ramps 264 plot(levels,CNHSRsaturated, 'ko'), hold off
134 % catch rampTime error 265 ylim([0 400])
135 if rampDuration>0.5*duration, rampDuration=duration/2; end 266 set(gca,'ytick',0:50:300)
136 rampTime=dt:dt:rampDuration; 267 if length(levels)>1
137 ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ... 268 xlim([min(levels) max(levels)])
138 ones(1,length(time)-length(rampTime))];
139 inputSignal=inputSignal.*ramp;
140 ramp=fliplr(ramp);
141 inputSignal=inputSignal.*ramp;
142 % add silence
143 intialSilence= zeros(1,round(beginSilence/dt));
144 finalSilence= zeros(1,round(endSilence/dt));
145 inputSignal= [intialSilence inputSignal finalSilence];
146
147 case 'file'
148 %% file input simple or mixed
149 [inputSignal sampleRate]=wavread(fileName);
150 dt=1/sampleRate;
151 inputSignal=inputSignal(:,1);
152 targetRMS=20e-6*10^(leveldBSPL/20);
153 rms=(mean(inputSignal.^2))^0.5;
154 amp=targetRMS/rms;
155 inputSignal=inputSignal*amp;
156 intialSilence= zeros(1,round(0.1/dt));
157 finalSilence= zeros(1,round(0.2/dt));
158 inputSignal= [intialSilence inputSignal' finalSilence];
159 end 269 end
160 270 set(gca,'xtick',[levels(1):20:levels(end)])
161 271 % grid on
162 %% run the model 272 ttl=[ 'spont=' num2str(mean(CNHSRsaturated(1,:)),'%4.0f') ' sat=' ...
163 tic 273 num2str(mean(CNHSRsaturated(end,1)),'%4.0f')];
164 fprintf('\n') 274 title( ttl)
165 disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)]) 275 xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)')
166 disp([num2str(numChannels) ' channel model: ' AN_spikesOrProbability]) 276 text(0, 350, 'CN', 'fontsize', 14), grid on
167 disp('Computing ...') 277
168 278 % IC rate - level function
169 MAP1_14(inputSignal, sampleRate, BFlist, ... 279 subplot(nRows,nCols,4)
170 MAPparamsName, AN_spikesOrProbability, paramChanges); 280 plot(levels,ICLSRsaturated, 'ro'), hold on
171 281 plot(levels,ICHSRsaturated, 'ko'), hold off
172 282 ylim([0 400])
173 %% the model run is now complete. Now display the results 283 set(gca,'ytick',0:50:300)
174 UTIL_showMAP(showMapOptions, paramChanges) 284 if length(levels)>1
175 285 xlim([min(levels) max(levels)])
176 if strcmp(signalType,'tones')
177 disp(['duration=' num2str(duration)])
178 disp(['level=' num2str(leveldBSPL)])
179 disp(['toneFrequency=' num2str(toneFrequency)])
180 global DRNLParams
181 disp(['attenuation factor =' ...
182 num2str(DRNLParams.rateToAttenuationFactor, '%5.3f') ])
183 disp(['attenuation factor (probability)=' ...
184 num2str(DRNLParams.rateToAttenuationFactorProb, '%5.3f') ])
185 disp(AN_spikesOrProbability)
186 end 286 end
187 disp(paramChanges) 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
295 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
302 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
311 UTIL_showStruct(IHC_cilia_RPParams, 'IHC_cilia_RPParams')
312 UTIL_showStruct(IHCpreSynapseParams, 'IHCpreSynapseParams')
313 UTIL_showStruct(AN_IHCsynapseParams, 'AN_IHCsynapseParams')
314
315 fprintf('\n')
316 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
322 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
331 path(restorePath)
188 toc 332 toc
189 path(restorePath)
190