Revision 38:c2204b18f4a2 userProgramsMikaelDeroche

View differences:

userProgramsMikaelDeroche/runMAP1_14.m
1
function runMAP1_14
2
% runMAP1_14 is a general purpose test routine that can be adjusted to
3
% test a number of different applications of MAP1_14
4
%
5
% A range of options are supplied in the early part of the program
6
%
7
% #1
8
% Identify the file (in 'MAPparamsName') containing the model parameters
9
%
10
% #2
11
% Identify the kind of model required (in 'AN_spikesOrProbability').
12
%  A full brainstem model ('spikes') can be computed or a shorter model
13
%  ('probability') that computes only so far as the auditory nerve
14
%
15
% #3
16
% Choose between a tone signal or file input (in 'signalType')
17
%
18
% #4
19
% Set the signal rms level (in leveldBSPL)
20
%
21
% #5
22
% Identify the channels in terms of their best frequencies in the vector
23
%  BFlist.
24
%
25
% Last minute changes to the parameters can be made using
26
%  the cell array of strings 'paramChanges'.
27
%  Each string must have the same format as the corresponding line in the
28
%  file identified in 'MAPparamsName'
29

  
30
dbstop if error
31
restorePath=path;
32
addpath (['..' filesep 'MAP'],    ['..' filesep 'wavFileStore'], ...
33
    ['..' filesep 'utilities'])
34

  
35
%%  #1 parameter file name
36
MAPparamsName='Normal';
37

  
38

  
39
%% #2 probability (fast) or spikes (slow) representation: select one
40
% AN_spikesOrProbability='spikes';
41
%   or
42
AN_spikesOrProbability='probability';
43

  
44

  
45
%% #3 A. pure tone, B. harmonic sequence or C. speech file input
46
% comment out unwanted code
47

  
48
% A. tone
49
sampleRate= 441000;
50
signalType= 'tones';
51
toneFrequency= 5000;            % or a pure tone (Hz)
52
duration=0.500;                 % seconds
53
beginSilence=0.050;               
54
endSilence=0.050;                  
55
rampDuration=.005;              % raised cosine ramp (seconds)
56

  
57
%   or
58
% B. harmonic tone (Hz) - useful to demonstrate a broadband sound
59
% sampleRate= 44100;
60
% signalType= 'tones';
61
% toneFrequency= F0:F0:8000;    
62
% duration=0.500;                 % seconds
63
% beginSilence=0.250;               
64
% endSilence=0.250;                  
65
% F0=210;
66
% rampDuration=.005;              % raised cosine ramp (seconds)
67

  
68
%   or
69
% C. signalType= 'file';
70
% fileName='twister_44kHz';
71

  
72
%% #4 rms level
73
% signal details
74
leveldBSPL= 70;                  % dB SPL (80 for Lieberman)
75

  
76
%% #5 number of channels in the model
77
%   21-channel model (log spacing)
78
numChannels=21;
79
lowestBF=250; 	highestBF= 6000;
80
BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels));
81

  
82
%   or specify your own channel BFs
83
% numChannels=1;
84
% BFlist=toneFrequency;
85

  
86

  
87
%% #6 change model parameters
88

  
89
paramChanges={};
90

  
91
% Parameter changes can be used to change one or more model parameters
92
%  *after* the MAPparams file has been read
93
% This example declares only one fiber type with a calcium clearance time
94
% constant of 80e-6 s (HSR fiber) when the probability option is selected.
95
% paramChanges={'AN_IHCsynapseParams.ANspeedUpFactor=5;', ...
96
%     'IHCpreSynapseParams.tauCa=86e-6; '};
97

  
98

  
99

  
100
%% delare 'showMap' options to control graphical output
101
% see UTIL_showMAP for more options
102
showMapOptions.printModelParameters=1;   % prints all parameters
103
showMapOptions.showModelOutput=1;       % plot of all stages
104
showMapOptions.printFiringRates=1;      % prints stage activity levels
105
showMapOptions.showEfferent=1;          % tracks of AR and MOC
106
showMapOptions.surfProbability=1;       % 2D plot of HSR response 
107

  
108
if strcmp(signalType, 'file')
109
    % needed for labeling plot
110
    showMapOptions.fileName=fileName;
111
else
112
    showMapOptions.fileName=[];
113
end
114

  
115
%% Generate stimuli
116
switch signalType
117
    case 'tones'
118
        % Create pure tone stimulus
119
        dt=1/sampleRate; % seconds
120
        time=dt: dt: duration;
121
        inputSignal=sum(sin(2*pi*toneFrequency'*time), 1);
122
        amp=10^(leveldBSPL/20)*28e-6;   % converts to Pascals (peak)
123
        inputSignal=amp*inputSignal;
124
        % apply ramps
125
        % catch rampTime error
126
        if rampDuration>0.5*duration, rampDuration=duration/2; end
127
        rampTime=dt:dt:rampDuration;
128
        ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ...
129
            ones(1,length(time)-length(rampTime))];
130
        inputSignal=inputSignal.*ramp;
131
        ramp=fliplr(ramp);
132
        inputSignal=inputSignal.*ramp;
133
        % add silence
134
        intialSilence= zeros(1,round(beginSilence/dt));
135
        finalSilence= zeros(1,round(endSilence/dt));
136
        inputSignal= [intialSilence inputSignal finalSilence];
137

  
138
    case 'file'
139
        %% file input simple or mixed
140
        [inputSignal sampleRate]=wavread(fileName);
141
        dt=1/sampleRate;
142
        inputSignal=inputSignal(:,1);
143
        targetRMS=20e-6*10^(leveldBSPL/20);
144
        rms=(mean(inputSignal.^2))^0.5;
145
        amp=targetRMS/rms;
146
        inputSignal=inputSignal*amp;
147
        intialSilence= zeros(1,round(0.1/dt));
148
        finalSilence= zeros(1,round(0.2/dt));
149
        inputSignal= [intialSilence inputSignal' finalSilence];
150
end
151

  
152

  
153
%% run the model
154
tic
155
fprintf('\n')
156
disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)])
157
disp([num2str(numChannels) ' channel model: ' AN_spikesOrProbability])
158
disp('Computing ...')
159

  
160
MAP1_14(inputSignal, sampleRate, BFlist, ...
161
    MAPparamsName, AN_spikesOrProbability, paramChanges);
162

  
163

  
164
%% the model run is now complete. Now display the results
165
UTIL_showMAP(showMapOptions, paramChanges)
166

  
167
if strcmp(signalType,'tones')
168
    disp(['duration=' num2str(duration)])
169
    disp(['level=' num2str(leveldBSPL)])
170
    disp(['toneFrequency=' num2str(toneFrequency)])
171
    global DRNLParams
172
    disp(['attenuation factor =' ...
173
        num2str(DRNLParams.rateToAttenuationFactor, '%5.3f') ])
174
    disp(['attenuation factor (probability)=' ...
175
        num2str(DRNLParams.rateToAttenuationFactorProb, '%5.3f') ])
176
    disp(AN_spikesOrProbability)
177
end
178
disp(paramChanges)
179
toc
180
path(restorePath)
181

  
userProgramsMikaelDeroche/testACF.m
1
% function [P dt lags SACF]= testACF
2
% testACF is a *script* to demonstrate the smoothed ACF of 
3
% Balaguer-Ballestera, E. Denham, S.L. and Meddis, R. (2008). 
4
%
5
% Convert this to a *function* by uncommenting the first line
6
%  The function returns the P matrix plotted in Figure 96.
7
%  If a function is used, the following outputs are returned:
8
%   P:  smoothed SACF (lags x time matrix)
9
%   dt: time interval between successive columns of P
10
%   lags: lags used in computing P
11
%   SACF: unsmoothed SACFs
12
%  
13
% A range of options are supplied in the early part of the program
14
%
15
% #1
16
% Identify the model parameter file (in 'MAPparamsName') 
17
%
18
% #2
19
% Identify the kind of model required (in 'AN_spikesOrProbability')
20
%  'probability' is recommended for ACF work
21
%
22
% #3
23
% Choose between a harmonic complex or file input
24
%  by commenting out unwanted code
25
%
26
% #4
27
% Set the signal rms level (in leveldBSPL)
28
%
29
% #5
30
% Identify the model channel BFs in the vector 'BFlist'.
31
%
32
% #6
33
% Last minute changes to the model parameters can be made using
34
%  the cell array of strings 'paramChanges'.
35
%  This is used here to control the details of the ACF computations
36
%  Read the notes in this section for more information
37
%
38
% displays:
39
% Figure 97 shows the AN response to the stimulus. this is a channel x time
40
%  display. The z-axis (and colour) is the AN fiber firing rate
41
%
42
% Figure 96 shows the P-matrix, the smoothed SACF.
43
%
44
% Figure 89 shows a summary of the evolution of the unsmoothed SACF 
45
%  over time. If you wish to take a snapshot of the P-matrix at a
46
%  particular time, this figure can help identify when to take it. 
47
%  The index on the y-axis, identifies the required row numbers 
48
%    of the P or SACF matrix, e.g. P(:,2000)
49
%
50
%  On request, (filteredSACFParams.plotACFs=1) Figure 89 shows the channel 
51
%   by channel ACFs at intervals during the computation as a movie.
52
%  The number of ACF displays is controlled by 'plotACFsInterval'
53
%   and the movie can be slowed or speeded up using 'plotMoviePauses' 
54
%   (see paramChanges section below).
55

  
56
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
57
% This global will find results from MAP1_14
58
global savedInputSignal ANprobRateOutput ANoutput dt dtSpikes savedBFlist 
59
 % This global,from model parameter file
60
global filteredSACFParams                      
61

  
62
dbstop if error
63
restorePath=path;
64
addpath (['..' filesep 'MAP'],    ['..' filesep 'wavFileStore'], ...
65
    ['..' filesep 'utilities'])
66

  
67
% User sets up requirements
68
%%  #1 parameter file name
69
MAPparamsName='Normal';                 % recommended
70

  
71

  
72
%% #2 probability (fast) or spikes (slow) representation: select one
73
% AN_spikesOrProbability='spikes';
74
%   or
75
AN_spikesOrProbability='probability';   % recommended
76

  
77
%% #3 A. harmonic sequence or B. speech file input
78
% Comment out unwanted code
79
% A. harmonic tone (Hz) - useful to demonstrate a broadband sound
80
sampleRate= 44100;              % recommended 44100
81
signalType= 'tones';
82
duration=0.100;                 % seconds
83
beginSilence=0.020;
84
endSilence=0.020;
85
rampDuration=.005;              % raised cosine ramp (seconds)
86

  
87
% toneFrequency is a vector of component frequencies
88
F0=120;
89
toneFrequency= [3*F0 4*F0 5*F0];
90

  
91
%   or
92
% B. file input
93
signalType= 'file';
94
fileName='Oh No';
95

  
96
%% #4 rms level
97
leveldBSPL= 60;                  % dB SPL (80 for Lieberman)
98

  
99
%% #5 number of channels in the model
100
%   21-channel model (log spacing of BFs)
101
numChannels=21;
102
lowestBF=250; 	highestBF= 6000;
103
BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels));
104

  
105
%% #6 change model parameters
106
% Parameter changes can be used to change one or more model parameters
107
%  *after* the MAPparams file has been read (see manual)
108

  
109
% Take control of ACF parameters
110
%  The filteredACF parameters are set in the MAPparamsNormal file
111
%  However, it is convenient to change them here leving the file intacta
112
    minPitch=	80; maxPitch=	500; numPitches=50;  
113
    maxLag=1/minPitch; minLag=1/maxPitch;
114
    lags= linspace(minLag, maxLag, numPitches);
115
    
116
paramChanges={...
117
    'filteredSACFParams.lags=lags;     % autocorrelation lags vector;',...
118
    'filteredSACFParams.acfTau=	2;     % (Wiegrebe) time constant ACF;',...
119
    'filteredSACFParams.lambda=	0.12;  % slower filter to smooth ACF;',...
120
    'filteredSACFParams.plotACFs=1;    % plot ACFs while computing;',...
121
    'filteredSACFParams.plotACFsInterval=0.01;',...
122
    'filteredSACFParams.plotMoviePauses=.1;  ',...
123
    'filteredSACFParams.usePressnitzer=0; % attenuates ACF at  long lags;',...
124
    'filteredSACFParams.lagsProcedure=  ''useAllLags'';',...
125
    };
126

  
127
% Notes:
128
% acfTau:   time constant of unsmoothed ACF
129
% lambda:   time constant of smoothed ACFS
130
% plotACFs: plot ACFs during computation (0 to switch off, for speed)
131
% plotACFsInterval: sampling interval for plots
132
% plotMoviePauses:  pause duration between frames to allow viewing
133
% usePressnitzer:   gives low weights to long lags
134
% lagsProcedure:    used to fiddle with output (ignore)
135

  
136
%% delare 'showMap' options to control graphical output
137
% see UTIL_showMAP for more options
138
showMapOptions=[];
139
% showMapOptions.showModelOutput=0;     % plot of all stages
140
showMapOptions.surfAN=1;                % surface plot of HSR response
141
showMapOptions.PSTHbinwidth=0.001;      % smoothing for PSTH
142

  
143
if exist('fileName','var')
144
    % needed for labeling plot
145
    showMapOptions.fileName=fileName;
146
end
147

  
148
%% Generate stimuli
149
switch signalType
150
    case 'tones'
151
        % Create tone stimulus
152
        dt=1/sampleRate; % seconds
153
        time=dt: dt: duration;
154
        inputSignal=sum(sin(2*pi*toneFrequency'*time), 1);
155
        amp=10^(leveldBSPL/20)*28e-6;   % converts to Pascals (peak)
156
        inputSignal=amp*inputSignal;
157
        % apply ramps
158
        % catch rampTime error
159
        if rampDuration>0.5*duration, rampDuration=duration/2; end
160
        rampTime=dt:dt:rampDuration;
161
        ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ...
162
            ones(1,length(time)-length(rampTime))];
163
        inputSignal=inputSignal.*ramp;
164
        ramp=fliplr(ramp);
165
        inputSignal=inputSignal.*ramp;
166
        % add silence
167
        intialSilence= zeros(1,round(beginSilence/dt));
168
        finalSilence= zeros(1,round(endSilence/dt));
169
        inputSignal= [intialSilence inputSignal finalSilence];
170

  
171
    case 'file'
172
        %% file input simple or mixed
173
        [inputSignal sampleRate]=wavread(fileName);
174
        dt=1/sampleRate;
175
        inputSignal=inputSignal(:,1);
176
        targetRMS=20e-6*10^(leveldBSPL/20);
177
        rms=(mean(inputSignal.^2))^0.5;
178
        amp=targetRMS/rms;
179
        inputSignal=inputSignal*amp;
180
end
181

  
182
wavplay(inputSignal, sampleRate)
183

  
184
%% run the model
185

  
186
fprintf('\n')
187
disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)])
188
disp([num2str(numChannels) ' channel model: ' AN_spikesOrProbability])
189
disp('Computing ...')
190

  
191
MAP1_14(inputSignal, sampleRate, BFlist, ...
192
    MAPparamsName, AN_spikesOrProbability, paramChanges);
193

  
194

  
195
%% The model run is now complete. Now display the results
196
% display the AN response
197
UTIL_showMAP(showMapOptions)
198

  
199
% compute ACF
200
switch AN_spikesOrProbability
201
    case 'probability'
202
        % use only HSR fibers
203
        inputToACF=ANprobRateOutput(end-length(savedBFlist)+1:end,:);
204
    otherwise
205
        inputToACF=ANoutput;
206
        dt=dtSpikes;
207
end
208

  
209
disp ('computing ACF...')
210

  
211
% read paramChanges to get new filteredSACFParams
212
for i=1:length(paramChanges)
213
eval(paramChanges{i});
214
end
215

  
216
[P BFlist SACF]= filteredSACF(inputToACF, dt, savedBFlist, filteredSACFParams);
217
disp(' ACF done.')
218

  
219
%% plot original waveform on summary/smoothed ACF plot
220
figure(96), clf
221
subplot(3,1,3)
222
t=dt*(1:length(savedInputSignal));
223
plot(t,savedInputSignal, 'k')
224
xlim([0 t(end)])
225
title(['stimulus: ' num2str(leveldBSPL, '%4.0f') ' dB SPL']);
226

  
227
% plot SACF
228
figure(96)
229
subplot(2,1,1)
230
imagesc(P)
231
colormap bone
232
ylabel('periodicities (Hz)'), xlabel('time (s)')
233
title(['smoothed SACF. (periodicity x time)'])
234
% y-axis specifies pitches (1/lags)
235
% Force MATLAB to show the lowest pitch
236
postedYvalues=[1 get(gca,'ytick')]; set(gca,'ytick',postedYvalues)
237
pitches=1./filteredSACFParams.lags;
238
set(gca,'ytickLabel', round(pitches(postedYvalues)))
239
% x-axis is time at which P is samples
240
[nCH nTimes]=size(P);
241
t=dt:dt:dt*nTimes;
242
tt=get(gca,'xtick');
243
set(gca,'xtickLabel', round(100*t(tt))/100)
244

  
245
%% On a new figure show a cascade of SACFs
246
figure(89), clf
247
% select 100 samples;
248
[r c]=size(SACF);
249
step=round(c/100);
250
idx=step:step:c;
251

  
252
UTIL_cascadePlot(SACF(:,idx)', 1./pitches)
253

  
254
xlabel('lag (s)'), ylabel('time pointer -->')
255
title(' SACF summary over time')
256
yValues=get(gca,'yTick');
257
set(gca,'yTickLabel', num2str(yValues'*100))
258

  
259
path(restorePath)
260

  

Also available in: Unified diff