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 / userProgramsRM / pitchModel_RM.m

History | View | Annotate | Download (5.83 KB)

1 38:c2204b18f4a2 rmeddis
function pitchModel_RM
2
% Modification of testMAP_14 to replicate the pitch model published
3
%  in JASA 2006.
4
%
5
% A range of options are supplied in the early part of the program
6
%
7
% One use of the function is to create demonstrations; filenames <demoxx>
8
%  to illustrate particular features
9
%
10
% #1
11
% Identify the file (in 'MAPparamsName') containing the model parameters
12
%
13
% #2
14
% Identify the kind of model required (in 'AN_spikesOrProbability').
15
%  A full brainstem model (spikes) can be computed or a shorter model
16
%  (probability) that computes only so far as the auditory nerve
17
%
18
% #3
19
% Choose between a tone signal or file input (in 'signalType')
20
%
21
% #4
22
% Set the signal rms level (in leveldBSPL)
23
%
24
% #5
25
% Identify the channels in terms of their best frequencies in the vector
26
%  BFlist.
27
%
28
% Last minute changes to the parameters fetched earlier can be made using
29
%  the cell array of strings 'paramChanges'.
30
%  Each string must have the same format as the corresponding line in the
31
%  file identified in 'MAPparamsName'
32
%
33
% When the demonstration is satisfactory, freeze it by renaming it <demoxx>
34
35
dbstop if error
36
restorePath=path;
37
addpath (['..' filesep 'MAP'],    ['..' filesep 'wavFileStore'], ...
38
    ['..' filesep 'utilities'])
39
40
41
42
% Pitch model modification here
43
global ICrate           % used to collect rate profile from showMAP temporary
44
rates=[]; F0count=0;
45
46
% F0s=[150 200 250];          % fundamental frequency
47
% harmonics= 3:5;
48
49
% F0s=[3000];          % fundamental frequency
50
F0s=50:5:1000;
51
harmonics= 1;
52
% F0s=150;
53
for F0=F0s
54
    F0count=F0count+1;
55
56
57
%%  #1 parameter file name
58
MAPparamsName='Normal';
59
60
61
%% #2 probability (fast) or spikes (slow) representation
62
AN_spikesOrProbability='spikes';
63
64
% or
65
% NB probabilities are not corrected for refractory effects
66
% AN_spikesOrProbability='probability';
67
68
69
%% #3 pure tone, harmonic sequence or speech file input
70
signalType= 'tones';
71
sampleRate= 50000;
72
duration=0.50;                 % seconds
73
% toneFrequency= 1000;            % or a pure tone (Hz8
74
75
% F0=210;
76
toneFrequency= F0*harmonics;  % harmonic sequence (Hz)
77
78
rampDuration=.005;              % raised cosine ramp (seconds)
79
80
% or
81
82
% signalType= 'file';
83
% fileName='twister_44kHz';
84
85
86
%% #4 rms level
87
% signal details
88
leveldBSPL= 50;                  % dB SPL
89
90
91
%% #5 number of channels in the model
92
%   21-channel model (log spacing)
93
numChannels=21;
94
lowestBF=250; 	highestBF= 8000;
95
BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels));
96
97
%   or specify your own channel BFs
98
% numChannels=1;
99
BFlist=toneFrequency;
100
% BFlist=500;
101
102
103
%% #6 change model parameters
104
paramChanges={...
105
    'MacGregorMultiParams.currentPerSpike=25e-9;'...
106
    'MacGregorMultiParams.tauGk=	[0.1e-3:.00005 : 1e-3];'...
107
'MacGregorParams.currentPerSpike=40e-9;'...
108
};
109
110
%% delare 'showMap' options to control graphical output
111
112
showMapOptions.printModelParameters=0;   % prints all parameters
113
showMapOptions.showModelOutput=1;       % plot of all stages
114
showMapOptions.printFiringRates=1;      % prints stage activity levels
115
showMapOptions.showACF=0;               % shows SACF (probability only)
116
showMapOptions.showEfferent=0;          % tracks of AR and MOC
117
showMapOptions.surfProbability=0;       % 2D plot of HSR response
118
showMapOptions.surfSpikes=0;            % 2D plot of spikes histogram
119
showMapOptions.ICrates=1;               % IC rates by CNtauGk
120
121
% disable certain silly options
122
if strcmp(AN_spikesOrProbability, 'spikes')
123
    % avoid nonsensical options
124
    showMapOptions.surfProbability=0;
125
    showMapOptions.showACF=0;
126
else
127
    showMapOptions.surfSpikes=0;
128
end
129
if strcmp(signalType, 'file')
130
    % needed for labeling plot
131
    showMapOptions.fileName=fileName;
132
else
133
    showMapOptions.fileName=[];
134
end
135
136
%% Generate stimuli
137
138
switch signalType
139
    case 'tones'
140
        inputSignal=createMultiTone(sampleRate, toneFrequency, ...
141
            leveldBSPL, duration, rampDuration);
142
143
    case 'file'
144
        %% file input simple or mixed
145
        [inputSignal sampleRate]=wavread(fileName);
146
        dt=1/sampleRate;
147
        inputSignal=inputSignal(:,1);
148
        targetRMS=20e-6*10^(leveldBSPL/20);
149
        rms=(mean(inputSignal.^2))^0.5;
150
        amp=targetRMS/rms;
151
        inputSignal=inputSignal*amp;
152
        silence= zeros(1,round(0.1/dt));
153
        inputSignal= [silence inputSignal' silence];
154
end
155
156
157
%% run the model
158
tic
159
160
fprintf('\n')
161
disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)])
162
disp([num2str(numChannels) ' channel model'])
163
disp([num2str(F0) ' F0'])
164
disp('Computing ...')
165
166
MAP1_14(inputSignal, sampleRate, BFlist, ...
167
    MAPparamsName, AN_spikesOrProbability, paramChanges);
168
169
170
% the model run is now complete. Now display the results
171
UTIL_showMAP(showMapOptions, paramChanges)
172
173
%% pitch model Collect and analyse data
174
% ICrate is global and computed in showMAP
175
%  a vector of 'stage4' rates; one value for each tauCNGk
176
rates=[rates; ICrate];
177
figure(92), imagesc(rates)
178
ylabel ('F0 no'), xlabel('tauGk')
179
% figure(92), plot(rates), ylim([0 inf])
180
181
h=figure(99); CNmovie(F0count)=getframe(h);
182
figure(91), plot(rates'),ylim([0 inf])
183
pause (0.1)
184
185
end
186
%% show results
187
toc
188
figure(91), plot(F0s,rates'), xlabel('F0'), ylabel('rate'),ylim([0 inf])
189
% figure(99),clf,movie(CNmovie,1,4)
190
path(restorePath)
191
192
193
function inputSignal=createMultiTone(sampleRate, toneFrequency, ...
194
    leveldBSPL, duration, rampDuration)
195
% Create pure tone stimulus
196
dt=1/sampleRate; % seconds
197
time=dt: dt: duration;
198
inputSignal=sum(sin(2*pi*toneFrequency'*time), 1);
199
amp=10^(leveldBSPL/20)*28e-6;   % converts to Pascals (peak)
200
inputSignal=amp*inputSignal;
201
202
% apply ramps
203
% catch rampTime error
204
if rampDuration>0.5*duration, rampDuration=duration/2; end
205
rampTime=dt:dt:rampDuration;
206
ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ...
207
    ones(1,length(time)-length(rampTime))];
208
inputSignal=inputSignal.*ramp;
209
ramp=fliplr(ramp);
210
inputSignal=inputSignal.*ramp;
211
212
% add 10 ms silence
213
silence= zeros(1,round(0.005/dt));
214
inputSignal= [silence inputSignal silence];