comparison Copy_of_multithreshold 1.46/testFM.m @ 28:02aa9826efe0

mainly multiThreshold
author Ray Meddis <rmeddis@essex.ac.uk>
date Fri, 01 Jul 2011 12:59:47 +0100
parents
children
comparison
equal deleted inserted replaced
27:d4a7675b0413 28:02aa9826efe0
1 function testFM(showPSTHs)
2 % specify whether you want AN 'probability' or 'spikes'
3 % spikes is more realistic but takes longer
4 % refractory effect is included only for spikes
5 %
6
7 % specify the AN ANresponse bin width (normally 1 ms).
8 % This can influence the measure of the AN onset rate based on the
9 % largest bin in the ANresponse
10 %
11 % Demonstration is based on Harris and Dallos
12
13 global experiment stimulusParameters
14 global inputStimulusParams outerMiddleEarParams DRNLParams
15 global IHC_VResp_VivoParams IHCpreSynapseParams AN_IHCsynapseParams
16
17 dbstop if error
18 % masker and probe levels are relative to this threshold
19 thresholdAtCF=10; % dB SPL
20 thresholdAtCF=5; % dB SPL
21
22 if nargin<1, showPSTHs=1;end
23
24 sampleRate=50000;
25
26 % fetch BF from GUI: use only the first target frequency
27 BFlist=stimulusParameters.targetFrequency(1);
28 maskerFrequency=BFlist;
29 maskerDuration=.1;
30
31 targetFrequency=maskerFrequency;
32 probeLeveldB=20+thresholdAtCF; % H&D use 20 dB SL/ TMC uses 10 dB SL
33 probeDuration=0.008; % HD use 15 ms probe (fig 3).
34 probeDuration=0.015; % HD use 15 ms probe (fig 3).
35
36 rampDuration=.001; % HD use 1 ms linear ramp
37 initialSilenceDuration=0.02;
38 finalSilenceDuration=0.05; % useful for showing recovery
39
40 maskerLevels=[-80 10 20 30 40 60 ] + thresholdAtCF;
41 % maskerLevels=[-80 40 60 ] + thresholdAtCF;
42
43 dt=1/sampleRate;
44
45 figure(7), clf
46 set(gcf,'position',[613 36 360 247])
47 set(gcf,'name', ['forward masking: thresholdAtCF=' num2str(thresholdAtCF)])
48
49 if showPSTHs
50 figure(8), clf
51 set(gcf,'name', 'Harris and Dallos simulation')
52 set(gcf,'position',[980 36 380 249])
53 end
54
55 % Plot Harris and Dallos result for comparison
56 gapDurations=[0.001 0.002 0.005 0.01 0.02 0.05 0.1 0.3];
57 HDmaskerLevels=[+10 +20 +30 +40 +60];
58 HDresponse=[
59 1 1 1 1 1 1 1 1;
60 0.8 0.82 0.81 0.83 0.87 0.95 1 1;
61 0.48 0.5 0.54 0.58 0.7 0.85 0.95 1;
62 0.3 0.31 0.35 0.4 0.5 0.68 0.82 0.94;
63 0.2 0.27 0.27 0.29 0.42 0.64 0.75 0.92;
64 0.15 0.17 0.18 0.23 0.3 0.5 0.6 0.82];
65
66 figure(7)
67 semilogx(gapDurations,HDresponse,'o'), hold on
68 legend(strvcat(num2str(maskerLevels')),'location','southeast')
69 title([ 'masker dB: ' num2str(HDmaskerLevels)])
70
71 %% Run the trials
72 maxProbeResponse=0;
73 levelNo=0;
74 resultsMatrix=zeros(length(maskerLevels), length(gapDurations));
75 summaryFiringRates=[];
76
77 % initial silence
78 time=dt: dt: initialSilenceDuration;
79 initialSilence=zeros(1,length(time));
80
81 % probe
82 time=dt: dt: probeDuration;
83 amp=28e-6*10^(probeLeveldB/20);
84 probe=amp*sin(2*pi.*targetFrequency*time);
85 % ramps
86 % catch rampTime error
87 if rampDuration>0.5*probeDuration, rampDuration=probeDuration/2; end
88 rampTime=dt:dt:rampDuration;
89 % raised cosine ramp
90 ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ...
91 ones(1,length(time)-length(rampTime))];
92 % onset ramp
93 probe=probe.*ramp;
94 % offset ramp makes complete ramp for probe
95 ramp=fliplr(ramp);
96 % apply ramp mask to probe. Probe does not change below
97 probe=probe.*ramp;
98
99 % final silence
100 time=dt: dt: finalSilenceDuration;
101 finalSilence=zeros(1,length(time));
102
103 PSTHplotCount=0;
104 longestSignalDuration=initialSilenceDuration + maskerDuration +...
105 max(gapDurations) + probeDuration + finalSilenceDuration ;
106 for maskerLeveldB=maskerLevels
107 levelNo=levelNo+1;
108 allDurations=[];
109 allFiringRates=[];
110
111 %masker
112 time=dt: dt: maskerDuration;
113 masker=sin(2*pi.*maskerFrequency*time);
114 % masker ramps
115 if rampDuration>0.5*maskerDuration
116 % catch ramp duration error
117 rampDuration=maskerDuration/2;
118 end
119 % NB masker ramp (not probe ramp)
120 rampTime=dt:dt:rampDuration;
121 % raised cosine ramp
122 ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi))...
123 ones(1,length(time)-length(rampTime))];
124 % onset ramp
125 masker=masker.*ramp;
126 % offset ramp
127 ramp=fliplr(ramp);
128 % apply ramp
129 masker=masker.*ramp;
130 amp=28e-6*10^(maskerLeveldB/20);
131 maskerPa=amp*masker;
132
133 for gapDuration=gapDurations
134 time=dt: dt: gapDuration;
135 gap=zeros(1,length(time));
136
137 inputSignal=...
138 [initialSilence maskerPa gap probe finalSilence];
139
140 % ********************************** run MAP model
141
142 global ANprobRateOutput tauCas ...
143
144 MAPparamsName=experiment.name;
145 showPlotsAndDetails=0;
146
147 AN_spikesOrProbability='probability';
148
149 MAP1_14(inputSignal, 1/dt, targetFrequency, ...
150 MAPparamsName, AN_spikesOrProbability);
151
152 [nFibers c]=size(ANprobRateOutput);
153 nLSRfibers=nFibers/length(tauCas);
154 ANresponse=ANprobRateOutput(end-nLSRfibers:end,:);
155 ANresponse=sum(ANresponse)/nLSRfibers;
156
157 % analyse results
158 probeStart=initialSilenceDuration+maskerDuration+gapDuration;
159 PSTHbinWidth=dt;
160 responseDelay=0.005;
161 probeTimes=probeStart+responseDelay:...
162 PSTHbinWidth:probeStart+probeDuration+responseDelay;
163 probeIDX=round(probeTimes/PSTHbinWidth);
164 probePSTH=ANresponse(probeIDX);
165 firingRate=mean(probePSTH);
166 % NB this only works if you start with the lowest level masker
167 maxProbeResponse=max([maxProbeResponse firingRate]);
168 allDurations=[allDurations gapDuration];
169 allFiringRates=[allFiringRates firingRate];
170
171 %% show PSTHs
172 if showPSTHs
173 nLevels=length(maskerLevels);
174 nDurations=length(gapDurations);
175 figure(8)
176 PSTHbinWidth=1e-3;
177 PSTH=UTIL_PSTHmaker(ANresponse, dt, PSTHbinWidth);
178 PSTH=PSTH*dt/PSTHbinWidth;
179 PSTHplotCount=PSTHplotCount+1;
180 subplot(nLevels,nDurations,PSTHplotCount)
181 probeTime=PSTHbinWidth:PSTHbinWidth:...
182 PSTHbinWidth*length(PSTH);
183 bar(probeTime, PSTH)
184 if strcmp(AN_spikesOrProbability, 'spikes')
185 ylim([0 500])
186 else
187 ylim([0 500])
188 end
189 xlim([0 longestSignalDuration])
190 grid on
191
192 if PSTHplotCount< (nLevels-1) * nDurations+1
193 set(gca,'xticklabel',[])
194 end
195
196 if ~isequal(mod(PSTHplotCount,nDurations),1)
197 set(gca,'yticklabel',[])
198 else
199 ylabel([num2str(maskerLevels...
200 (round(PSTHplotCount/nDurations) +1))])
201 end
202
203 if PSTHplotCount<=nDurations
204 title([num2str(1000*gapDurations(PSTHplotCount)) 'ms'])
205 end
206 end % showPSTHs
207
208 end % gapDurations duration
209 summaryFiringRates=[summaryFiringRates allFiringRates'];
210
211 figure(7), hold on
212 semilogx(allDurations, allFiringRates/maxProbeResponse)
213 ylim([0 1]), hold on
214 ylim([0 inf]), xlim([min(gapDurations) max(gapDurations)])
215 xlim([0.001 1])
216 pause(0.1) % to allow for CTRL/C interrupts
217 resultsMatrix(levelNo,:)=allFiringRates;
218 end % maskerLevel
219
220 disp('delay/ rates')
221 disp(num2str(round( [1000*allDurations' summaryFiringRates])))
222
223 % replot with best adjustment
224 % figure(34), clf% use for separate plot
225 figure(7), clf
226 peakProbe=max(max(resultsMatrix));
227 resultsMatrix=resultsMatrix/peakProbe;
228 semilogx(gapDurations,HDresponse,'o'), hold on
229 title(['FrMsk: probe ' num2str(probeLeveldB)...
230 'dB SL: peakProbe=' num2str(peakProbe,'%5.0f') ' sp/s'])
231 xlabel('gap duration (s)'), ylabel ('probe response')
232 semilogx(allDurations, resultsMatrix'), ylim([0 1])
233 ylim([0 inf]),
234 xlim([0.001 1])
235 legend(strvcat(num2str(maskerLevels'-thresholdAtCF)), -1)
236
237 % ------------------------------------------------- display parameters
238 disp(['parameter file was: ' experiment.name])
239 fprintf('\n')
240 % UTIL_showStruct(inputStimulusParams, 'inputStimulusParams')
241 % UTIL_showStruct(outerMiddleEarParams, 'outerMiddleEarParams')
242 % UTIL_showStruct(DRNLParams, 'DRNLParams')
243 % UTIL_showStruct(IHC_VResp_VivoParams, 'IHC_VResp_VivoParams')
244 UTIL_showStruct(IHCpreSynapseParams, 'IHCpreSynapseParams')
245 UTIL_showStruct(AN_IHCsynapseParams, 'AN_IHCsynapseParams')
246
247