Mercurial > hg > map
comparison userProgramsRM/test_Dolan_and_Nuttall.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 | |
children |
comparison
equal
deleted
inserted
replaced
37:771a643d5c29 | 38:c2204b18f4a2 |
---|---|
1 function test_Dolan_and_Nuttall | |
2 % test_MAP1_14 is a general purpose test routine that can be adjusted to | |
3 % test a number of different applications of MAP1_14 | |
4 % | |
5 % A range of options are supplied in the early part of the program | |
6 % | |
7 % One use of the function is to create demonstrations; filenames <demoxx> | |
8 % to illustrate particular features | |
9 % | |
10 % #1 | |
11 % Identify the file (in 'MAPparamsName') containing the model parameters | |
12 % | |
13 % #2 | |
14 % Identify the kind of model required (in 'AN_spikesOrProbability'). | |
15 % A full brainstem model (spikes) can be computed or a shorter model | |
16 % (probability) that computes only so far as the auditory nerve | |
17 % | |
18 % #3 | |
19 % Choose between a tone signal or file input (in 'signalType') | |
20 % | |
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 global dt dtSpikes savedBFlist saveAN_spikesOrProbability saveMAPparamsName... | |
36 savedInputSignal OMEextEarPressure TMoutput OMEoutput ARattenuation ... | |
37 DRNLoutput IHC_cilia_output IHCrestingCiliaCond IHCrestingV... | |
38 IHCoutput ANprobRateOutput ANoutput savePavailable ANtauCas ... | |
39 CNtauGk CNoutput ICoutput ICmembraneOutput ICfiberTypeRates ... | |
40 MOCattenuation | |
41 global OMEParams DRNLParams IHC_cilia_RPParams IHCpreSynapseParams | |
42 global AN_IHCsynapseParams MacGregorParams MacGregorMultiParams | |
43 global ICrate | |
44 | |
45 | |
46 dbstop if error | |
47 restorePath=path; | |
48 addpath (['..' filesep 'MAP'], ['..' filesep 'wavFileStore'], ... | |
49 ['..' filesep 'utilities']) | |
50 | |
51 %% #1 parameter file name | |
52 MAPparamsName='Normal'; | |
53 | |
54 | |
55 %% #2 probability (fast) or spikes (slow) representation | |
56 AN_spikesOrProbability='spikes'; | |
57 % or | |
58 % AN_spikesOrProbability='probability'; | |
59 | |
60 | |
61 %% #3 pure tone, harmonic sequence or speech file input | |
62 signalType= 'tones'; | |
63 toneFrequency= 4000; % or a pure tone (Hz) | |
64 | |
65 sampleRate= 44100; % must agree with noise | |
66 duration=0.010; % seconds | |
67 beginSilence=0.010; | |
68 endSilence=0.010; | |
69 rampDuration=.001; % raised cosine ramp (seconds) | |
70 noiseRampDuration=0.002; | |
71 | |
72 % or | |
73 % harmonic sequence (Hz) | |
74 % F0=210; | |
75 % toneFrequency= F0:F0:8000; | |
76 | |
77 % or | |
78 % signalType= 'file'; | |
79 % fileName='twister_44kHz'; | |
80 | |
81 | |
82 | |
83 % %% #4 rms level | |
84 % % signal details | |
85 % leveldBSPL= 80; % dB SPL (80 for Lieberman) | |
86 % leveldBSPLNoise=-30; | |
87 | |
88 %% #5 number of channels in the model | |
89 % 21-channel model (log spacing) | |
90 numChannels=21; | |
91 lowestBF=250; highestBF= 8000; | |
92 BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels)); | |
93 | |
94 % % or specify your own channel BFs | |
95 % numChannels=1; | |
96 % BFlist=toneFrequency; | |
97 | |
98 | |
99 %% #6 change model parameters | |
100 | |
101 paramChanges={}; | |
102 | |
103 % Parameter changes can be used to change one or more model parameters | |
104 % *after* the MAPparams file has been read | |
105 % This example declares only one fiber type with a calcium clearance time | |
106 % constant of 80e-6 s (HSR fiber) when the probability option is selected. | |
107 % paramChanges={'AN_IHCsynapseParams.ANspeedUpFactor=5;', ... | |
108 % 'IHCpreSynapseParams.tauCa=86e-6; '}; | |
109 % paramChanges={'DRNLParams.MOCtauProb =.25;', ... | |
110 % 'DRNLParams.rateToAttenuationFactorProb = 0.02; '}; | |
111 | |
112 paramChanges={'AN_IHCsynapseParams.numFibers= 50; ',... | |
113 'DRNLParams.MOCtauProb =.15;', ... | |
114 'DRNLParams.rateToAttenuationFactorProb = 0.00; '}; | |
115 | |
116 % paramChanges={'AN_IHCsynapseParams.numFibers= 50; ',... | |
117 % 'DRNLParams.rateToAttenuationFactorProb = -0.007;'}; | |
118 | |
119 | |
120 %% delare 'showMap' options to control graphical output | |
121 showMapOptions.printModelParameters=1; % prints all parameters | |
122 showMapOptions.showModelOutput=0; % plot of all stages | |
123 showMapOptions.printFiringRates=1; % prints stage activity levels | |
124 showMapOptions.showACF=0; % shows SACF (probability only) | |
125 showMapOptions.showEfferent=1; % tracks of AR and MOC | |
126 showMapOptions.surfProbability=1; % 2D plot of HSR response | |
127 showMapOptions.surfSpikes=1; % 2D plot of spikes histogram | |
128 showMapOptions.ICrates=0; % IC rates by CNtauGk | |
129 | |
130 % disable certain silly options | |
131 if strcmp(AN_spikesOrProbability, 'spikes') | |
132 % avoid nonsensical options | |
133 showMapOptions.surfProbability=0; | |
134 showMapOptions.showACF=0; | |
135 end | |
136 | |
137 if strcmp(signalType, 'file') | |
138 % needed for labeling plot | |
139 showMapOptions.fileName=fileName; | |
140 else | |
141 showMapOptions.fileName=[]; | |
142 end | |
143 | |
144 fprintf('\n') | |
145 disp([num2str(numChannels) ' channel model: ' AN_spikesOrProbability]) | |
146 disp('Computing ...') | |
147 | |
148 %%systematic | |
149 probeLevels=30:10:80; | |
150 noiseLevels=[-100 30]; | |
151 noRepeats=10; | |
152 | |
153 % probeLevels=80; | |
154 % noiseLevels=[-30]; | |
155 % noRepeats=10; | |
156 | |
157 peakCAPs=zeros(4,length(probeLevels)); | |
158 | |
159 for noiseCondition=1:length(noiseLevels) | |
160 leveldBSPLNoise=noiseLevels(noiseCondition); | |
161 levelNo=0; | |
162 for probeLevel=probeLevels | |
163 leveldBSPL=probeLevel; | |
164 levelNo=levelNo+1; | |
165 summedCAP=[]; | |
166 for repeatNo= 1:noRepeats | |
167 disp(['repeat no: ' num2str(repeatNo)]) | |
168 %% Generate stimuli | |
169 | |
170 switch signalType | |
171 case 'tones' | |
172 % Create pure tone stimulus | |
173 dt=1/sampleRate; % seconds | |
174 time=dt: dt: duration; | |
175 inputSignal=sum(sin(2*pi*toneFrequency'*time), 1); | |
176 amp=10^(leveldBSPL/20)*28e-6; % converts to Pascals (peak) | |
177 inputSignal=amp*inputSignal; | |
178 % apply ramps | |
179 % catch rampTime error | |
180 if rampDuration>0.5*duration, rampDuration=duration/2; end | |
181 rampTime=dt:dt:rampDuration; | |
182 ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ... | |
183 ones(1,length(time)-length(rampTime))]; | |
184 inputSignal=inputSignal.*ramp; | |
185 ramp=fliplr(ramp); | |
186 inputSignal=inputSignal.*ramp; | |
187 % add silence | |
188 intialSilence= zeros(1,round(beginSilence/dt)); | |
189 finalSilence= zeros(1,round(endSilence/dt)); | |
190 inputSignal= [intialSilence inputSignal finalSilence]; | |
191 | |
192 % [inputNoise sampleRateN]=wavread('babble'); | |
193 [inputNoise sampleRateN]=wavread('white noise'); | |
194 inputNoise=inputNoise(1:length(inputSignal)); | |
195 inputNoise=inputNoise(:,1); | |
196 targetRMS=20e-6*10^(leveldBSPLNoise/20); | |
197 rms=(mean(inputNoise.^2))^0.5; | |
198 amp=targetRMS/rms; | |
199 inputNoise=inputNoise*amp; | |
200 time=dt: dt: dt*length(inputNoise); | |
201 rampTime=dt:dt:noiseRampDuration; | |
202 ramp=[0.5*(1+cos(2*pi*rampTime/(2*noiseRampDuration)+pi)) ... | |
203 ones(1,length(time)-length(rampTime))]; | |
204 inputNoise=inputNoise'.*ramp; | |
205 ramp=fliplr(ramp); | |
206 inputNoise=inputNoise.*ramp; | |
207 | |
208 inputSignal=inputSignal+inputNoise; | |
209 intialSilence= zeros(1,round(beginSilence/dt)); | |
210 finalSilence= zeros(1,round(endSilence/dt)); | |
211 inputSignal= [intialSilence inputSignal finalSilence]; | |
212 | |
213 toneOnset=2*beginSilence; | |
214 | |
215 figure(2), subplot(3,1,1) | |
216 time=dt:dt:dt*length(inputSignal); | |
217 plot(time,inputSignal,'k') | |
218 | |
219 case 'file' | |
220 %% file input simple or mixed | |
221 [inputSignal sampleRate]=wavread(fileName); | |
222 dt=1/sampleRate; | |
223 inputSignal=inputSignal(:,1); | |
224 targetRMS=20e-6*10^(leveldBSPL/20); | |
225 rms=(mean(inputSignal.^2))^0.5; | |
226 amp=targetRMS/rms; | |
227 inputSignal=inputSignal*amp; | |
228 intialSilence= zeros(1,round(0.1/dt)); | |
229 finalSilence= zeros(1,round(0.2/dt)); | |
230 inputSignal= [intialSilence inputSignal' finalSilence]; | |
231 | |
232 end | |
233 | |
234 | |
235 %% run the model | |
236 tic | |
237 | |
238 MAP1_14(inputSignal, sampleRate, BFlist, ... | |
239 MAPparamsName, AN_spikesOrProbability, paramChanges); | |
240 | |
241 | |
242 %% the model run is now complete. Now display the results | |
243 % UTIL_showMAP(showMapOptions, paramChanges) | |
244 | |
245 wholeNerveCAP = UTIL_CAPgenerator... | |
246 (ANoutput, dtSpikes, BFlist, AN_IHCsynapseParams.numFibers, 1); | |
247 | |
248 if isempty(summedCAP) | |
249 summedCAP=wholeNerveCAP; | |
250 else | |
251 summedCAP=summedCAP+wholeNerveCAP; | |
252 end | |
253 | |
254 switch AN_spikesOrProbability | |
255 case 'spikes' | |
256 ANoutput = sum(ANoutput, 1); | |
257 case 'probability' | |
258 ANoutput = ANprobRateOutput(13+21,:); | |
259 end | |
260 figure(2), subplot(3,1,2), plot(ANoutput) | |
261 spikeTimes=dtSpikes:dtSpikes:dtSpikes* length(wholeNerveCAP); | |
262 figure(2), subplot(3,1,3), plot(spikeTimes,summedCAP/repeatNo) | |
263 ylim([-50 50]) | |
264 end % repeat | |
265 | |
266 spikeTimes=dtSpikes:dtSpikes:dtSpikes* length(wholeNerveCAP); | |
267 idx=find(spikeTimes>toneOnset & ... | |
268 spikeTimes>toneOnset+duration+.005); | |
269 averageCAP=summedCAP/repeatNo; | |
270 peakCAP=max(averageCAP(idx)); | |
271 peakCAPs(noiseCondition,levelNo)=peakCAPs(noiseCondition,levelNo)+ peakCAP; | |
272 | |
273 if strcmp(signalType,'tones') | |
274 disp(['duration=' num2str(duration)]) | |
275 disp(['level=' num2str(leveldBSPL)]) | |
276 disp(['toneFrequency=' num2str(toneFrequency)]) | |
277 disp(['leveldBSPLNoise=' num2str(leveldBSPLNoise)]) | |
278 | |
279 disp(['attenuation factor =' ... | |
280 num2str(DRNLParams.rateToAttenuationFactor, '%5.3f') ]) | |
281 disp(['attenuation factor (probability)=' ... | |
282 num2str(DRNLParams.rateToAttenuationFactorProb, '%5.3f') ]) | |
283 disp(AN_spikesOrProbability) | |
284 end | |
285 | |
286 | |
287 disp([ 'peak CAP ' num2str(peakCAP)]) | |
288 | |
289 for i=1:length(paramChanges) | |
290 disp(paramChanges{i}) | |
291 end | |
292 end % probe level | |
293 figure(9), subplot(3,1,3), plot(probeLevels,peakCAPs) | |
294 end % condition | |
295 %% | |
296 | |
297 path(restorePath) | |
298 |