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 / multithreshold 1.46 / testFM.m @ 29:b51bf546ca3f

History | View | Annotate | Download (7.71 KB)

1
function testFM(BFlist,paramsName,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 inputStimulusParams outerMiddleEarParams DRNLParams 
14
global IHC_VResp_VivoParams IHCpreSynapseParams  AN_IHCsynapseParams
15

    
16
dbstop if error
17
% masker and probe levels are relative to this threshold
18
thresholdAtCF=10; % dB SPL
19
thresholdAtCF=5; % dB SPL
20

    
21
if nargin<1, showPSTHs=1;end
22

    
23
sampleRate=50000;
24

    
25
% fetch BF from GUI: use only the first target frequency
26
maskerFrequency=BFlist;
27
maskerDuration=.1;
28

    
29
targetFrequency=maskerFrequency;
30
probeLeveldB=20+thresholdAtCF;	% H&D use 20 dB SL/ TMC uses 10 dB SL
31
probeDuration=0.008; % HD use 15 ms probe (fig 3).
32
probeDuration=0.015; % HD use 15 ms probe (fig 3).
33

    
34
rampDuration=.001;  % HD use 1 ms linear ramp
35
initialSilenceDuration=0.02;
36
finalSilenceDuration=0.05;      % useful for showing recovery
37

    
38
maskerLevels=[-80   10 20 30 40 60 ] + thresholdAtCF;
39
% maskerLevels=[-80   40 60 ] + thresholdAtCF;
40

    
41
dt=1/sampleRate;
42

    
43
figure(7), clf
44
set(gcf,'position',[613    36   360   247])
45
set(gcf,'name', ['forward masking: thresholdAtCF=' num2str(thresholdAtCF)])
46

    
47
if showPSTHs
48
    figure(8), clf
49
    set(gcf,'name', 'Harris and Dallos simulation')
50
    set(gcf,'position',[980    36   380   249])
51
end
52

    
53
% Plot Harris and Dallos result for comparison
54
gapDurations=[0.001	0.002	0.005	0.01	0.02	0.05	0.1	0.3];
55
HDmaskerLevels=[+10	+20	+30	+40	+60];
56
HDresponse=[
57
    1 1 1 1 1 1 1 1;
58
    0.8  	0.82	0.81	0.83	0.87	0.95	1	    1;
59
    0.48	0.5	    0.54	0.58	0.7	    0.85	0.95	1;
60
    0.3	    0.31	0.35	0.4	    0.5	    0.68	0.82	0.94;
61
    0.2 	0.27	0.27	0.29	0.42	0.64	0.75	0.92;
62
    0.15	0.17	0.18	0.23	0.3	     0.5	0.6	    0.82];
63

    
64
figure(7)
65
semilogx(gapDurations,HDresponse,'o'), hold on
66
legend(strvcat(num2str(maskerLevels')),'location','southeast')
67
title([ 'masker dB: ' num2str(HDmaskerLevels)])
68

    
69
%% Run the trials
70
maxProbeResponse=0;
71
levelNo=0;
72
resultsMatrix=zeros(length(maskerLevels), length(gapDurations));
73
summaryFiringRates=[];
74

    
75
% initial silence
76
time=dt: dt: initialSilenceDuration;
77
initialSilence=zeros(1,length(time));
78

    
79
% probe
80
time=dt: dt: probeDuration;
81
amp=28e-6*10^(probeLeveldB/20);
82
probe=amp*sin(2*pi.*targetFrequency*time);
83
% ramps
84
% catch rampTime error
85
if rampDuration>0.5*probeDuration, rampDuration=probeDuration/2; end
86
rampTime=dt:dt:rampDuration;
87
% raised cosine ramp
88
ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ...
89
    ones(1,length(time)-length(rampTime))];
90
%  onset ramp
91
probe=probe.*ramp;
92
%  offset ramp makes complete ramp for probe
93
ramp=fliplr(ramp);
94
% apply ramp mask to probe. Probe does not change below
95
probe=probe.*ramp;
96

    
97
% final silence
98
time=dt: dt: finalSilenceDuration;
99
finalSilence=zeros(1,length(time));
100

    
101
PSTHplotCount=0;
102
longestSignalDuration=initialSilenceDuration + maskerDuration +...
103
    max(gapDurations) + probeDuration + finalSilenceDuration ;
104
for maskerLeveldB=maskerLevels
105
    levelNo=levelNo+1;
106
    allDurations=[];
107
    allFiringRates=[];
108

    
109
    %masker
110
    time=dt: dt: maskerDuration;
111
    masker=sin(2*pi.*maskerFrequency*time);
112
    % masker ramps
113
    if rampDuration>0.5*maskerDuration
114
        % catch ramp duration error
115
        rampDuration=maskerDuration/2;
116
    end
117
    % NB masker ramp (not probe ramp)
118
    rampTime=dt:dt:rampDuration;
119
    % raised cosine ramp
120
    ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi))...
121
        ones(1,length(time)-length(rampTime))];
122
    %  onset ramp
123
    masker=masker.*ramp;
124
    %  offset ramp
125
    ramp=fliplr(ramp);
126
    % apply ramp
127
    masker=masker.*ramp;
128
    amp=28e-6*10^(maskerLeveldB/20);
129
    maskerPa=amp*masker;
130

    
131
    for gapDuration=gapDurations
132
        time=dt: dt: gapDuration;
133
        gap=zeros(1,length(time));
134

    
135
        inputSignal=...
136
            [initialSilence maskerPa gap probe finalSilence];
137

    
138
        % **********************************  run MAP model
139
        
140
        global  ANprobRateOutput  tauCas  ...
141

    
142
    showPlotsAndDetails=0;
143

    
144
AN_spikesOrProbability='probability';
145

    
146
MAP1_14(inputSignal, 1/dt, targetFrequency, ...
147
    paramsName, AN_spikesOrProbability);
148
 
149
    [nFibers c]=size(ANprobRateOutput);
150
    nLSRfibers=nFibers/length(tauCas);
151
            ANresponse=ANprobRateOutput(end-nLSRfibers:end,:);
152
            ANresponse=sum(ANresponse)/nLSRfibers;
153
    
154
        % analyse results
155
        probeStart=initialSilenceDuration+maskerDuration+gapDuration;
156
        PSTHbinWidth=dt;
157
        responseDelay=0.005;
158
        probeTimes=probeStart+responseDelay:...
159
            PSTHbinWidth:probeStart+probeDuration+responseDelay;
160
        probeIDX=round(probeTimes/PSTHbinWidth);
161
        probePSTH=ANresponse(probeIDX);
162
        firingRate=mean(probePSTH);
163
        % NB this only works if you start with the lowest level masker
164
        maxProbeResponse=max([maxProbeResponse firingRate]);
165
        allDurations=[allDurations gapDuration];
166
        allFiringRates=[allFiringRates firingRate];
167
        
168
        %% show PSTHs
169
        if showPSTHs
170
            nLevels=length(maskerLevels);
171
            nDurations=length(gapDurations);
172
            figure(8)
173
            PSTHbinWidth=1e-3;
174
            PSTH=UTIL_PSTHmaker(ANresponse, dt, PSTHbinWidth);
175
            PSTH=PSTH*dt/PSTHbinWidth;
176
            PSTHplotCount=PSTHplotCount+1;
177
            subplot(nLevels,nDurations,PSTHplotCount)
178
            probeTime=PSTHbinWidth:PSTHbinWidth:...
179
                PSTHbinWidth*length(PSTH);
180
            bar(probeTime, PSTH)
181
            if strcmp(AN_spikesOrProbability, 'spikes')
182
                ylim([0 500])
183
            else
184
                ylim([0 500])
185
            end
186
            xlim([0 longestSignalDuration])
187
            grid on
188

    
189
            if PSTHplotCount< (nLevels-1) * nDurations+1
190
                set(gca,'xticklabel',[])
191
            end
192

    
193
            if ~isequal(mod(PSTHplotCount,nDurations),1)
194
                set(gca,'yticklabel',[])
195
            else
196
                ylabel([num2str(maskerLevels...
197
                    (round(PSTHplotCount/nDurations) +1))])
198
            end
199

    
200
            if PSTHplotCount<=nDurations
201
                title([num2str(1000*gapDurations(PSTHplotCount)) 'ms'])
202
            end
203
        end % showPSTHs
204

    
205
    end     % gapDurations duration
206
    summaryFiringRates=[summaryFiringRates allFiringRates'];
207

    
208
    figure(7), hold on
209
    semilogx(allDurations, allFiringRates/maxProbeResponse)
210
    ylim([0 1]), hold on
211
    ylim([0 inf]), xlim([min(gapDurations) max(gapDurations)])
212
    xlim([0.001 1])
213
    pause(0.1) % to allow for CTRL/C interrupts
214
    resultsMatrix(levelNo,:)=allFiringRates;
215
end          % maskerLevel
216

    
217
disp('delay/ rates')
218
disp(num2str(round( [1000*allDurations' summaryFiringRates])))
219

    
220
% replot with best adjustment
221
% figure(34), clf% use for separate plot
222
figure(7), clf
223
peakProbe=max(max(resultsMatrix));
224
resultsMatrix=resultsMatrix/peakProbe;
225
semilogx(gapDurations,HDresponse,'o'), hold on
226
title(['FrMsk: probe ' num2str(probeLeveldB)...
227
    'dB SL: peakProbe=' num2str(peakProbe,'%5.0f') ' sp/s'])
228
xlabel('gap duration (s)'), ylabel ('probe response')
229
semilogx(allDurations, resultsMatrix'), ylim([0 1])
230
ylim([0 inf]),
231
xlim([0.001 1])
232
legend(strvcat(num2str(maskerLevels'-thresholdAtCF)), -1)
233

    
234
% ------------------------------------------------- display parameters
235
disp(['parameter file was: ' paramsName])
236
fprintf('\n')
237
% UTIL_showStruct(inputStimulusParams, 'inputStimulusParams')
238
% UTIL_showStruct(outerMiddleEarParams, 'outerMiddleEarParams')
239
% UTIL_showStruct(DRNLParams, 'DRNLParams')
240
% UTIL_showStruct(IHC_VResp_VivoParams, 'IHC_VResp_VivoParams')
241
UTIL_showStruct(IHCpreSynapseParams, 'IHCpreSynapseParams')
242
UTIL_showStruct(AN_IHCsynapseParams, 'AN_IHCsynapseParams')
243

    
244