Mercurial > hg > map
comparison userProgramsTim/pitchModel_RM.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 pitchModel_RM | |
2 % Modification of testMAP_14 to replicate the pitch model published | |
3 % in JASA 2006. | |
4 % | |
5 % test_MAP1_14 is a general purpose test routine that can be adjusted to | |
6 % test a number of different applications of MAP1_14 | |
7 % | |
8 % A range of options are supplied in the early part of the program | |
9 % | |
10 % One use of the function is to create demonstrations; filenames <demoxx> | |
11 % to illustrate particular features | |
12 % | |
13 % #1 | |
14 % Identify the file (in 'MAPparamsName') containing the model parameters | |
15 % | |
16 % #2 | |
17 % Identify the kind of model required (in 'AN_spikesOrProbability'). | |
18 % A full brainstem model (spikes) can be computed or a shorter model | |
19 % (probability) that computes only so far as the auditory nerve | |
20 % | |
21 % #3 | |
22 % Choose between a tone signal or file input (in 'signalType') | |
23 % | |
24 % #4 | |
25 % Set the signal rms level (in leveldBSPL) | |
26 % | |
27 % #5 | |
28 % Identify the channels in terms of their best frequencies in the vector | |
29 % BFlist. | |
30 % | |
31 % Last minute changes to the parameters fetched earlier can be made using | |
32 % the cell array of strings 'paramChanges'. | |
33 % Each string must have the same format as the corresponding line in the | |
34 % file identified in 'MAPparamsName' | |
35 % | |
36 % When the demonstration is satisfactory, freeze it by renaming it <demoxx> | |
37 | |
38 dbstop if error | |
39 restorePath=path; | |
40 addpath (['..' filesep 'MAP'], ['..' filesep 'wavFileStore'], ... | |
41 ['..' filesep 'utilities']) | |
42 | |
43 % Pitch model modification here | |
44 global ICrate % used to collect rate profile from showMAP temporary | |
45 rates=[]; F0count=0; | |
46 | |
47 % F0s=[150 200 250]; % fundamental frequency | |
48 % harmonics= 3:5; | |
49 | |
50 % F0s=[3000]; % fundamental frequency | |
51 F0s=50:5:1000; | |
52 harmonics= 1; | |
53 % F0s=150; | |
54 for F0=F0s | |
55 F0count=F0count+1; | |
56 | |
57 | |
58 %% #1 parameter file name | |
59 MAPparamsName='Normal'; | |
60 | |
61 | |
62 %% #2 probability (fast) or spikes (slow) representation | |
63 AN_spikesOrProbability='spikes'; | |
64 | |
65 % or | |
66 % NB probabilities are not corrected for refractory effects | |
67 % AN_spikesOrProbability='probability'; | |
68 | |
69 | |
70 %% #3 pure tone, harmonic sequence or speech file input | |
71 signalType= 'tones'; | |
72 sampleRate= 50000; | |
73 duration=0.50; % seconds | |
74 % toneFrequency= 1000; % or a pure tone (Hz8 | |
75 | |
76 % F0=210; | |
77 toneFrequency= F0*harmonics; % harmonic sequence (Hz) | |
78 | |
79 rampDuration=.005; % raised cosine ramp (seconds) | |
80 | |
81 % or | |
82 | |
83 % signalType= 'file'; | |
84 % fileName='twister_44kHz'; | |
85 | |
86 | |
87 %% #4 rms level | |
88 % signal details | |
89 leveldBSPL= 50; % dB SPL | |
90 | |
91 | |
92 %% #5 number of channels in the model | |
93 % 21-channel model (log spacing) | |
94 numChannels=21; | |
95 lowestBF=250; highestBF= 8000; | |
96 BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels)); | |
97 | |
98 % or specify your own channel BFs | |
99 % numChannels=1; | |
100 BFlist=toneFrequency; | |
101 % BFlist=500; | |
102 | |
103 | |
104 %% #6 change model parameters | |
105 paramChanges=[]; | |
106 | |
107 % or | |
108 % Parameter changes can be used to change one or more model parameters | |
109 % *after* the MAPparams file has been read | |
110 % This example declares only one fiber type with a calcium clearance time | |
111 % constant of 80e-6 s (HSR fiber) when the probability option is selected. | |
112 | |
113 % paramChanges={'AN_IHCsynapseParams.ANspeedUpFactor=5;', ... | |
114 % 'IHCpreSynapseParams.tauCa=86e-6;'}; | |
115 | |
116 % paramChanges={'DRNLParams.rateToAttenuationFactorProb = 0;'}; | |
117 | |
118 % paramChanges={'IHCpreSynapseParams.tauCa=86e-6;', | |
119 % 'AN_IHCsynapseParams.numFibers= 1000;'}; | |
120 | |
121 % fixed MOC attenuation(using negative factor) | |
122 % paramChanges={'DRNLParams.rateToAttenuationFactorProb=-0.005;'}; | |
123 | |
124 % slow the CN chopping rate | |
125 % paramChanges={'IHCpreSynapseParams.tauCa= 70e-6;'...' | |
126 % 'MacGregorMultiParams.tauGk= [0.75e-3:.0001 : 3e-3];'... | |
127 % ' MacGregorParams.dendriteLPfreq=4000;'... | |
128 % 'MacGregorParams.tauGk= 1e-4;'... | |
129 % 'MacGregorParams.currentPerSpike=220e-8;'... | |
130 % }; | |
131 paramChanges={... | |
132 'MacGregorMultiParams.currentPerSpike=25e-9;'... | |
133 'MacGregorMultiParams.tauGk= [0.1e-3:.00005 : 1e-3];'... | |
134 'MacGregorParams.currentPerSpike=40e-9;'... | |
135 }; | |
136 | |
137 %% delare 'showMap' options to control graphical output | |
138 | |
139 showMapOptions.printModelParameters=0; % prints all parameters | |
140 showMapOptions.showModelOutput=1; % plot of all stages | |
141 showMapOptions.printFiringRates=1; % prints stage activity levels | |
142 showMapOptions.showACF=0; % shows SACF (probability only) | |
143 showMapOptions.showEfferent=0; % tracks of AR and MOC | |
144 showMapOptions.surfProbability=0; % 2D plot of HSR response | |
145 showMapOptions.surfSpikes=0; % 2D plot of spikes histogram | |
146 showMapOptions.ICrates=1; % IC rates by CNtauGk | |
147 | |
148 % disable certain silly options | |
149 if strcmp(AN_spikesOrProbability, 'spikes') | |
150 % avoid nonsensical options | |
151 showMapOptions.surfProbability=0; | |
152 showMapOptions.showACF=0; | |
153 else | |
154 showMapOptions.surfSpikes=0; | |
155 end | |
156 if strcmp(signalType, 'file') | |
157 % needed for labeling plot | |
158 showMapOptions.fileName=fileName; | |
159 else | |
160 showMapOptions.fileName=[]; | |
161 end | |
162 | |
163 %% Generate stimuli | |
164 | |
165 switch signalType | |
166 case 'tones' | |
167 inputSignal=createMultiTone(sampleRate, toneFrequency, ... | |
168 leveldBSPL, duration, rampDuration); | |
169 | |
170 case 'file' | |
171 %% file input simple or mixed | |
172 [inputSignal sampleRate]=wavread(fileName); | |
173 dt=1/sampleRate; | |
174 inputSignal=inputSignal(:,1); | |
175 targetRMS=20e-6*10^(leveldBSPL/20); | |
176 rms=(mean(inputSignal.^2))^0.5; | |
177 amp=targetRMS/rms; | |
178 inputSignal=inputSignal*amp; | |
179 silence= zeros(1,round(0.1/dt)); | |
180 inputSignal= [silence inputSignal' silence]; | |
181 end | |
182 | |
183 | |
184 %% run the model | |
185 tic | |
186 | |
187 fprintf('\n') | |
188 disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)]) | |
189 disp([num2str(numChannels) ' channel model']) | |
190 disp([num2str(F0) ' F0']) | |
191 disp('Computing ...') | |
192 | |
193 MAP1_14(inputSignal, sampleRate, BFlist, ... | |
194 MAPparamsName, AN_spikesOrProbability, paramChanges); | |
195 | |
196 | |
197 % the model run is now complete. Now display the results | |
198 UTIL_showMAP(showMapOptions, paramChanges) | |
199 | |
200 %% pitch model Collect and analyse data | |
201 % ICrate is global and computed in showMAP | |
202 % a vector of 'stage4' rates; one value for each tauCNGk | |
203 rates=[rates; ICrate]; | |
204 figure(92), imagesc(rates) | |
205 ylabel ('F0 no'), xlabel('tauGk') | |
206 % figure(92), plot(rates), ylim([0 inf]) | |
207 | |
208 h=figure(99); CNmovie(F0count)=getframe(h); | |
209 figure(91), plot(rates'),ylim([0 inf]) | |
210 pause (0.1) | |
211 path(restorePath) | |
212 | |
213 end | |
214 %% show results | |
215 toc | |
216 figure(91), plot(F0s,rates'), xlabel('F0'), ylabel('rate'),ylim([0 inf]) | |
217 % figure(99),clf,movie(CNmovie,1,4) | |
218 | |
219 | |
220 function inputSignal=createMultiTone(sampleRate, toneFrequency, ... | |
221 leveldBSPL, duration, rampDuration) | |
222 % Create pure tone stimulus | |
223 dt=1/sampleRate; % seconds | |
224 time=dt: dt: duration; | |
225 inputSignal=sum(sin(2*pi*toneFrequency'*time), 1); | |
226 amp=10^(leveldBSPL/20)*28e-6; % converts to Pascals (peak) | |
227 inputSignal=amp*inputSignal; | |
228 | |
229 % apply ramps | |
230 % catch rampTime error | |
231 if rampDuration>0.5*duration, rampDuration=duration/2; end | |
232 rampTime=dt:dt:rampDuration; | |
233 ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ... | |
234 ones(1,length(time)-length(rampTime))]; | |
235 inputSignal=inputSignal.*ramp; | |
236 ramp=fliplr(ramp); | |
237 inputSignal=inputSignal.*ramp; | |
238 | |
239 % add 10 ms silence | |
240 silence= zeros(1,round(0.005/dt)); | |
241 inputSignal= [silence inputSignal silence]; | |
242 |