To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / testPrograms / testFM.m @ 33:161913b595ae

History | View | Annotate | Download (8.29 KB)

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