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 / userProgramsMikaelDeroche / testACF.m @ 38:c2204b18f4a2

History | View | Annotate | Download (8.43 KB)

1 38:c2204b18f4a2 rmeddis
% 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)