comparison testPrograms/testAN.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 vectorStrength=testAN(probeFrequency,BFlist, levels, ... 1 function vectorStrength=testAN(probeFrequency,BFlist, levels, ...
2 paramsName,paramChanges) 2 paramsName,paramChanges)
3 % generates rate/level functions for AN and brainstem units. 3 % testAN generates rate/level functions for AN and brainstem units.
4 % also other information like PSTHs, MOC efferent activity levels. 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.
5 % e.g. 12 % e.g.
6 % testAN(1000,1000, -10:10:80,'Normal',[]); 13 % testAN(1000,1000, -10:10:80,'Normal',{});
14
7 15
8 global IHC_VResp_VivoParams IHC_cilia_RPParams IHCpreSynapseParams 16 global IHC_VResp_VivoParams IHC_cilia_RPParams IHCpreSynapseParams
9 global AN_IHCsynapseParams 17 global AN_IHCsynapseParams
10 global ANoutput ANdt CNoutput ICoutput ICmembraneOutput ANtauCas 18 global ANoutput dtSpikes CNoutput ICoutput ICmembraneOutput ANtauCas
11 global ARattenuation MOCattenuation 19 global ARattenuation MOCattenuation
12 tic 20 tic
13 dbstop if error 21 dbstop if error
14 restorePath=path; 22 restorePath=path;
15 addpath (['..' filesep 'MAP'], ['..' filesep 'utilities'], ... 23 addpath (['..' filesep 'MAP'], ['..' filesep 'utilities'], ...
21 if nargin<3, levels=-10:10:80; end 29 if nargin<3, levels=-10:10:80; end
22 if nargin==0, probeFrequency=1000; BFlist=1000; end 30 if nargin==0, probeFrequency=1000; BFlist=1000; end
23 nLevels=length(levels); 31 nLevels=length(levels);
24 32
25 toneDuration=.2; rampDuration=0.002; silenceDuration=.02; 33 toneDuration=.2; rampDuration=0.002; silenceDuration=.02;
26 localPSTHbinwidth=0.001; 34 localPSTHbinwidth=0.0005;
27 35
28 %% guarantee that the sample rate is at least 10 times the frequency 36 %% guarantee that the sample rate is an interger multiple
29 sampleRate=50000; 37 % of the probe frequency
30 while sampleRate< 10* probeFrequency 38 % we want 5 bins per period for spikes
31 sampleRate=sampleRate+10000; 39 spikesSampleRate=5*probeFrequency;
32 end 40 % model sample rate must be an integer multiple of this and in the region
33 41 % of 50000
34 %% adjust sample rate so that the pure tone stimulus has an integer 42 sampleRate=spikesSampleRate*round(50000/spikesSampleRate);
35 %% numver of epochs in a period
36 dt=1/sampleRate; 43 dt=1/sampleRate;
37 period=1/probeFrequency; 44 % avoid very slow spikes sampling rate
38 ANspeedUpFactor=5; %anticipating MAP (needs clearing up) 45 spikesSampleRate=spikesSampleRate*ceil(10000/spikesSampleRate);
39 ANdt=dt*ANspeedUpFactor;
40 ANdt=period/round(period/ANdt);
41 dt=ANdt/ANspeedUpFactor;
42 sampleRate=1/dt;
43 46
44 %% pre-allocate storage 47 %% pre-allocate storage
45 AN_HSRonset=zeros(nLevels,1); 48 AN_HSRonset=zeros(nLevels,1);
46 AN_HSRsaturated=zeros(nLevels,1); 49 AN_HSRsaturated=zeros(nLevels,1);
47 AN_LSRonset=zeros(nLevels,1); 50 AN_LSRonset=zeros(nLevels,1);
81 inputSignal=amp*sin(2*pi*probeFrequency'*time); 84 inputSignal=amp*sin(2*pi*probeFrequency'*time);
82 inputSignal= ramp.*inputSignal; 85 inputSignal= ramp.*inputSignal;
83 inputSignal=[silence inputSignal]; 86 inputSignal=[silence inputSignal];
84 87
85 %% run the model 88 %% run the model
86 AN_spikesOrProbability='spikes'; 89 AN_spikesOrProbability='spikes';
90 nExistingParamChanges=length(paramChanges);
91 paramChanges{nExistingParamChanges+1}=...
92 ['AN_IHCsynapseParams.spikesTargetSampleRate=' ...
93 num2str(spikesSampleRate) ';'];
94
87 MAP1_14(inputSignal, 1/dt, BFlist, ... 95 MAP1_14(inputSignal, 1/dt, BFlist, ...
88 paramsName, AN_spikesOrProbability, paramChanges); 96 paramsName, AN_spikesOrProbability, paramChanges);
89 97
90 nTaus=length(ANtauCas); 98 nTaus=length(ANtauCas);
91 99
94 [nANFibers nTimePoints]=size(ANoutput); 102 [nANFibers nTimePoints]=size(ANoutput);
95 numLSRfibers=nANFibers/nTaus; 103 numLSRfibers=nANFibers/nTaus;
96 numHSRfibers=numLSRfibers; 104 numHSRfibers=numLSRfibers;
97 105
98 LSRspikes=ANoutput(1:numLSRfibers,:); 106 LSRspikes=ANoutput(1:numLSRfibers,:);
99 PSTH=UTIL_PSTHmaker(LSRspikes, ANdt, localPSTHbinwidth); 107 PSTH=UTIL_PSTHmaker(LSRspikes, dtSpikes, localPSTHbinwidth);
100 PSTHLSR=mean(PSTH,1)/localPSTHbinwidth; % across fibers rates 108 PSTHLSR=mean(PSTH,1)/localPSTHbinwidth; % across fibers rates
101 PSTHtime=localPSTHbinwidth:localPSTHbinwidth:... 109 PSTHtime=localPSTHbinwidth:localPSTHbinwidth:...
102 localPSTHbinwidth*length(PSTH); 110 localPSTHbinwidth*length(PSTH);
103 AN_LSRonset(levelNo)= max(PSTHLSR); % peak in 5 ms window 111 AN_LSRonset(levelNo)= max(PSTHLSR); % peak in 5 ms window
104 AN_LSRsaturated(levelNo)= mean(PSTHLSR(round(length(PSTH)/2):end)); 112 AN_LSRsaturated(levelNo)= mean(PSTHLSR(round(length(PSTH)/2):end));
105 113
106 % HSR 114 % AN HSR
107 HSRspikes= ANoutput(end- numHSRfibers+1:end, :); 115 HSRspikes= ANoutput(end- numHSRfibers+1:end, :);
108 PSTH=UTIL_PSTHmaker(HSRspikes, ANdt, localPSTHbinwidth); 116 PSTH=UTIL_PSTHmaker(HSRspikes, dtSpikes, localPSTHbinwidth);
109 PSTH=mean(PSTH,1)/localPSTHbinwidth; % sum across fibers (HSR only) 117 PSTH=mean(PSTH,1)/localPSTHbinwidth; % sum across fibers (HSR only)
110 AN_HSRonset(levelNo)= max(PSTH); 118 AN_HSRonset(levelNo)= max(PSTH);
111 AN_HSRsaturated(levelNo)= mean(PSTH(round(length(PSTH)/2): end)); 119 AN_HSRsaturated(levelNo)= mean(PSTH(round(length(PSTH)/2): end));
112 120
113 figure(5), subplot(2,2,2) 121 figure(5), subplot(2,2,2)
118 grid on 126 grid on
119 set(gcf,'name',['PSTH: ' num2str(BFlist), ' Hz: ' num2str(leveldB) ' dB']); 127 set(gcf,'name',['PSTH: ' num2str(BFlist), ' Hz: ' num2str(leveldB) ' dB']);
120 128
121 % AN - CV 129 % AN - CV
122 % CV is computed 5 times. Use the middle one (3) as most typical 130 % CV is computed 5 times. Use the middle one (3) as most typical
123 cvANHSR= UTIL_CV(HSRspikes, ANdt); 131 cvANHSR= UTIL_CV(HSRspikes, dtSpikes);
124 132
125 % AN - vector strength 133 % AN - vector strength
126 PSTH=sum(HSRspikes); 134 PSTH=sum(HSRspikes);
127 [PH, binTimes]=UTIL_periodHistogram... 135 [PH, binTimes]=UTIL_periodHistogram...
128 (PSTH, ANdt, probeFrequency); 136 (PSTH, dtSpikes, probeFrequency);
129 VS=UTIL_vectorStrength(PH); 137 VS=UTIL_vectorStrength(PH);
130 vectorStrength(levelNo)=VS; 138 vectorStrength(levelNo)=VS;
131 disp(['sat rate= ' num2str(AN_HSRsaturated(levelNo)) ... 139 disp(['sat rate= ' num2str(AN_HSRsaturated(levelNo)) ...
132 '; phase-locking VS = ' num2str(VS)]) 140 '; phase-locking VS = ' num2str(VS)])
133 title(['AN HSR: CV=' num2str(cvANHSR(3),'%5.2f') ... 141 title(['AN HSR: CV=' num2str(cvANHSR(3),'%5.2f') ...
137 145
138 % CN driven by LSR fibers 146 % CN driven by LSR fibers
139 [nCNneurons c]=size(CNoutput); 147 [nCNneurons c]=size(CNoutput);
140 nLSRneurons=round(nCNneurons/nTaus); 148 nLSRneurons=round(nCNneurons/nTaus);
141 CNLSRspikes=CNoutput(1:nLSRneurons,:); 149 CNLSRspikes=CNoutput(1:nLSRneurons,:);
142 PSTH=UTIL_PSTHmaker(CNLSRspikes, ANdt, localPSTHbinwidth); 150 PSTH=UTIL_PSTHmaker(CNLSRspikes, dtSpikes, localPSTHbinwidth);
143 PSTH=sum(PSTH)/nLSRneurons; 151 PSTH=sum(PSTH)/nLSRneurons;
144 CNLSRrate(levelNo)=mean(PSTH(round(length(PSTH)/2):end))/localPSTHbinwidth; 152 % CNLSRrate(levelNo)=mean(PSTH(round(length(PSTH)/2):end))/localPSTHbinwidth;
153 CNLSRrate(levelNo)=mean(PSTH)/localPSTHbinwidth;
145 154
146 %CN HSR 155 %CN HSR
147 MacGregorMultiHSRspikes=... 156 MacGregorMultiHSRspikes=...
148 CNoutput(end-nLSRneurons+1:end,:); 157 CNoutput(end-nLSRneurons+1:end,:);
149 PSTH=UTIL_PSTHmaker(MacGregorMultiHSRspikes, ANdt, localPSTHbinwidth); 158 PSTH=UTIL_PSTHmaker(MacGregorMultiHSRspikes, dtSpikes, localPSTHbinwidth);
150 PSTH=sum(PSTH)/nLSRneurons; 159 PSTH=sum(PSTH)/nLSRneurons;
151 PSTH=mean(PSTH,1)/localPSTHbinwidth; % sum across fibers (HSR only) 160 PSTH=mean(PSTH,1)/localPSTHbinwidth; % sum across fibers (HSR only)
152 161
153 CNHSRsaturated(levelNo)=mean(PSTH(length(PSTH)/2:end)); 162 % CNHSRsaturated(levelNo)=mean(PSTH(length(PSTH)/2:end));
163 CNHSRsaturated(levelNo)=mean(PSTH);
154 164
155 figure(5), subplot(2,2,3) 165 figure(5), subplot(2,2,3)
156 bar(PSTHtime,PSTH) 166 bar(PSTHtime,PSTH)
157 ylim([0 1000]) 167 ylim([0 1000])
158 xlim([0 length(PSTH)*localPSTHbinwidth]) 168 xlim([0 length(PSTH)*localPSTHbinwidth])
159 cvMMHSR= UTIL_CV(MacGregorMultiHSRspikes, ANdt); 169 cvMMHSR= UTIL_CV(MacGregorMultiHSRspikes, dtSpikes);
160 title(['CN CV= ' num2str(cvMMHSR(3),'%5.2f')]) 170 title(['CN CV= ' num2str(cvMMHSR(3),'%5.2f')])
161 171
162 %% IC LSR 172 %% IC LSR
163 [nICneurons c]=size(ICoutput); 173 [nICneurons c]=size(ICoutput);
164 nLSRneurons=round(nICneurons/nTaus); 174 nLSRneurons=round(nICneurons/nTaus);
165 ICLSRspikes=ICoutput(1:nLSRneurons,:); 175 ICLSRspikes=ICoutput(1:nLSRneurons,:);
166 PSTH=UTIL_PSTHmaker(ICLSRspikes, ANdt, localPSTHbinwidth); 176 PSTH=UTIL_PSTHmaker(ICLSRspikes, dtSpikes, localPSTHbinwidth);
167 ICLSRsaturated(levelNo)=mean(PSTH(round(length(PSTH)/2):end))/localPSTHbinwidth; 177 % ICLSRsaturated(levelNo)=mean(PSTH(round(length(PSTH)/2):end))/localPSTHbinwidth;
178 ICLSRsaturated(levelNo)=mean(PSTH)/localPSTHbinwidth;
168 179
169 %IC HSR 180 %IC HSR
170 MacGregorMultiHSRspikes=... 181 MacGregorMultiHSRspikes=...
171 ICoutput(end-nLSRneurons+1:end,:); 182 ICoutput(end-nLSRneurons+1:end,:);
172 PSTH=UTIL_PSTHmaker(MacGregorMultiHSRspikes, ANdt, localPSTHbinwidth); 183 PSTH=UTIL_PSTHmaker(MacGregorMultiHSRspikes, dtSpikes, localPSTHbinwidth);
173 ICHSRsaturated(levelNo)= (sum(PSTH)/nLSRneurons)/toneDuration; 184 ICHSRsaturated(levelNo)= (sum(PSTH)/nLSRneurons)/toneDuration;
174 185
175 AR(levelNo)=min(ARattenuation); 186 AR(levelNo)=min(ARattenuation);
176 MOC(levelNo)=min(MOCattenuation(length(MOCattenuation)/2:end)); 187 MOC(levelNo)=min(MOCattenuation(length(MOCattenuation)/2:end));
177 188
188 plot(20*log10(MOC), 'k'), hold on 199 plot(20*log10(MOC), 'k'), hold on
189 plot(20*log10(AR), 'r'), hold off 200 plot(20*log10(AR), 'r'), hold off
190 title(' MOC'), ylabel('dB attenuation') 201 title(' MOC'), ylabel('dB attenuation')
191 ylim([-30 0]) 202 ylim([-30 0])
192 203
193 204 % x=input('prompt')
194 end % level 205 end % level
195 206
196 %% plot with levels on x-axis 207 %% plot with levels on x-axis
197 figure(5), subplot(2,2,1) 208 figure(5), subplot(2,2,1)
198 plot(levels,20*log10(MOC), 'k'),hold on 209 plot(levels,20*log10(MOC), 'k'),hold on
217 nRows=2; nCols=2; 228 nRows=2; nCols=2;
218 229
219 % AN rate - level ONSET functions 230 % AN rate - level ONSET functions
220 subplot(nRows,nCols,1) 231 subplot(nRows,nCols,1)
221 plot(levels,AN_LSRonset,'ro'), hold on 232 plot(levels,AN_LSRonset,'ro'), hold on
222 plot(levels,AN_HSRonset,'ko'), hold off 233 plot(levels,AN_HSRonset,'ko', 'MarkerEdgeColor','k', 'markerFaceColor','k'), hold off
223 ylim([0 1000]), xlim([min(levels) max(levels)]) 234 ylim([0 1000])
235 if length(levels)>1
236 xlim([min(levels) max(levels)])
237 end
238
224 ttl=['tauCa= ' num2str(IHCpreSynapseParams.tauCa)]; 239 ttl=['tauCa= ' num2str(IHCpreSynapseParams.tauCa)];
225 title( ttl) 240 title( ttl)
226 xlabel('level dB SPL'), ylabel('peak rate (sp/s)'), grid on 241 xlabel('level dB SPL'), ylabel('peak rate (sp/s)'), grid on
227 text(0, 800, 'AN onset', 'fontsize', 14) 242 text(0, 800, 'AN onset', 'fontsize', 14)
228 243
229 % AN rate - level ADAPTED function 244 % AN rate - level ADAPTED function
230 subplot(nRows,nCols,2) 245 subplot(nRows,nCols,2)
231 plot(levels,AN_LSRsaturated, 'ro'), hold on 246 plot(levels,AN_LSRsaturated, 'ro'), hold on
232 plot(levels,AN_HSRsaturated, 'ko'), hold off 247 plot(levels,AN_HSRsaturated, 'ko', 'MarkerEdgeColor','k', 'markerFaceColor','k'), hold off
233 ylim([0 400]) 248 ylim([0 400])
234 set(gca,'ytick',0:50:300) 249 set(gca,'ytick',0:50:300)
250 if length(levels)>1
235 xlim([min(levels) max(levels)]) 251 xlim([min(levels) max(levels)])
252 end
236 set(gca,'xtick',[levels(1):20:levels(end)]) 253 set(gca,'xtick',[levels(1):20:levels(end)])
237 % grid on 254 % grid on
238 ttl=[ 'spont=' num2str(mean(AN_HSRsaturated(1,:)),'%4.0f')... 255 ttl=[ 'spont=' num2str(mean(AN_HSRsaturated(1,:)),'%4.0f')...
239 ' sat=' num2str(mean(AN_HSRsaturated(end,1)),'%4.0f')]; 256 ' sat=' num2str(mean(AN_HSRsaturated(end,1)),'%4.0f')];
240 title( ttl) 257 title( ttl)
241 xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)') 258 xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)')
242 text(0, 340, 'AN adapted', 'fontsize', 14), grid on 259 text(0, 340, 'AN adapted', 'fontsize', 14), grid on
243 260
244 % CN rate - level ADAPTED function 261 % CN rate - level function
245 subplot(nRows,nCols,3) 262 subplot(nRows,nCols,3)
246 plot(levels,CNLSRrate, 'ro'), hold on 263 plot(levels,CNLSRrate, 'ro'), hold on
247 plot(levels,CNHSRsaturated, 'ko'), hold off 264 plot(levels,CNHSRsaturated, 'ko', 'MarkerEdgeColor','k', 'markerFaceColor','k'), hold off
248 ylim([0 400]) 265 ylim([0 400])
249 set(gca,'ytick',0:50:300) 266 set(gca,'ytick',0:50:300)
267 if length(levels)>1
250 xlim([min(levels) max(levels)]) 268 xlim([min(levels) max(levels)])
269 end
251 set(gca,'xtick',[levels(1):20:levels(end)]) 270 set(gca,'xtick',[levels(1):20:levels(end)])
252 % grid on 271 % grid on
253 ttl=[ 'spont=' num2str(mean(CNHSRsaturated(1,:)),'%4.0f') ' sat=' ... 272 ttl=[ 'spont=' num2str(mean(CNHSRsaturated(1,:)),'%4.0f') ' sat=' ...
254 num2str(mean(CNHSRsaturated(end,1)),'%4.0f')]; 273 num2str(mean(CNHSRsaturated(end,1)),'%4.0f')];
255 title( ttl) 274 title( ttl)
256 xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)') 275 xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)')
257 text(0, 350, 'CN', 'fontsize', 14), grid on 276 text(0, 350, 'CN', 'fontsize', 14), grid on
258 277
259 % IC rate - level ADAPTED function 278 % IC rate - level function
260 subplot(nRows,nCols,4) 279 subplot(nRows,nCols,4)
261 plot(levels,ICLSRsaturated, 'ro'), hold on 280 plot(levels,ICLSRsaturated, 'ro'), hold on
262 plot(levels,ICHSRsaturated, 'ko'), hold off 281 plot(levels,ICHSRsaturated, 'ko', 'MarkerEdgeColor','k', 'markerFaceColor','k'), hold off
263 ylim([0 400]) 282 ylim([0 400])
264 set(gca,'ytick',0:50:300) 283 set(gca,'ytick',0:50:300)
284 if length(levels)>1
265 xlim([min(levels) max(levels)]) 285 xlim([min(levels) max(levels)])
286 end
266 set(gca,'xtick',[levels(1):20:levels(end)]), grid on 287 set(gca,'xtick',[levels(1):20:levels(end)]), grid on
267 ttl=['spont=' num2str(mean(ICHSRsaturated(1,:)),'%4.0f') ... 288 ttl=['spont=' num2str(mean(ICHSRsaturated(1,:)),'%4.0f') ...
268 ' sat=' num2str(mean(ICHSRsaturated(end,1)),'%4.0f')]; 289 ' sat=' num2str(mean(ICHSRsaturated(end,1)),'%4.0f')];
269 title( ttl) 290 title( ttl)
270 xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)') 291 xlabel('level dB SPL'), ylabel ('adapted rate (sp/s)')