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 / userPrograms / Pavel_MAP1_14.m @ 23:6cce421531e2

History | View | Annotate | Download (5.46 KB)

1
function Pavel_MAP1_14
2
% test_MAP1_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
% 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

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

    
39

    
40
%% #2 probability (fast) or spikes (slow) representation
41
AN_spikesOrProbability='spikes';
42

    
43
% or
44
% AN_spikesOrProbability='probability';
45
% NB probabilities are not corrected for refractory effects
46

    
47

    
48
%% #3 pure tone, harmonic sequence or speech file input
49
signalType= 'tones';
50
sampleRate= 100000;
51
duration=0.1;                 % seconds
52
% toneFrequency= 250:250:8000;    % harmonic sequence (Hz)
53
toneFrequency= 1000;            % or a pure tone (Hz8
54
rampDuration=.005;              % seconds
55

    
56
% or
57
% signalType= 'file';
58
% fileName='twister_44kHz';
59

    
60

    
61
%% #4 rms level
62
% signal details
63
leveldBSPL= 30;                  % dB SPL
64

    
65

    
66
%% #5 number of channels in the model
67
%   21-channel model (log spacing)
68
% numChannels=21;
69
% lowestBF=250; 	highestBF= 8000;
70
% BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels));
71

    
72
%   or specify your own channel BFs
73
numChannels=1;
74
BFlist=toneFrequency;
75

    
76

    
77
%% #6 change model parameters
78
paramChanges=[];
79

    
80
% or
81
% Parameter changes can be used to change one or more model parameters
82
%  *after* the MAPparams file has been read
83
% This example declares only one fiber type with a calcium clearance time
84
% constant of 80e-6 s (HSR fiber) when the probability option is selected.
85
% It also removes the speed up that normally takes place for AN spikes
86
% It also increases the number of AN fibers computed to 500.
87
paramChanges={...
88
    'AN_IHCsynapseParams.ANspeedUpFactor=1;', ...
89
    'IHCpreSynapseParams.tauCa=86e-6;',...
90
    'AN_IHCsynapseParams.numFibers=	500;' };
91

    
92

    
93
%% delare 'showMap' options to control graphical output
94
global showMapOptions
95

    
96
% or (example: show everything including an smoothed SACF output
97
showMapOptions.printModelParameters=1;   % prints all parameters
98
showMapOptions.showModelOutput=1;       % plot of all stages
99
showMapOptions.printFiringRates=1;      % prints stage activity levels
100
showMapOptions.showACF=0;               % shows SACF (probability only)
101
showMapOptions.showEfferent=0;          % tracks of AR and MOC
102
showMapOptions.surfProbability=0;       % 2D plot of HSR response 
103
if strcmp(AN_spikesOrProbability, 'spikes')
104
    % avoid nonsensical options
105
    showMapOptions.surfProbability=0;
106
    showMapOptions.showACF=0;
107
end
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

    
117
dbstop if error
118
restorePath=path;
119
addpath (['..' filesep 'MAP'],    ['..' filesep 'wavFileStore'])
120
switch signalType
121
    case 'tones'
122
        inputSignal=createMultiTone(sampleRate, toneFrequency, ...
123
            leveldBSPL, duration, rampDuration);
124

    
125
    case 'file'
126
        %% file input simple or mixed
127
        [inputSignal sampleRate]=wavread(fileName);
128
        dt=1/sampleRate;
129
        inputSignal=inputSignal(:,1);
130
        targetRMS=20e-6*10^(leveldBSPL/20);
131
        rms=(mean(inputSignal.^2))^0.5;
132
        amp=targetRMS/rms;
133
        inputSignal=inputSignal*amp;
134
        silence= zeros(1,round(0.1/dt));
135
        inputSignal= [silence inputSignal' silence];
136
end
137

    
138

    
139
%% run the model
140
tic
141

    
142
fprintf('\n')
143
disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)])
144
disp([num2str(numChannels) ' channel model'])
145
disp('Computing ...')
146

    
147
restorePath=path;
148
addpath (['..' filesep 'MAP'])
149

    
150
MAP1_14(inputSignal, sampleRate, BFlist, ...
151
    MAPparamsName, AN_spikesOrProbability, paramChanges);
152
path(restorePath)
153
toc
154

    
155
% the model run is now complete. Now display the results
156
% the model run is now complete. Now display the results
157
disp(' param changes to list of parameters below')
158
for i=1:length(paramChanges)
159
    disp(paramChanges{i})
160
end
161
UTIL_showMAP(showMapOptions)
162

    
163
toc
164
path(restorePath)
165

    
166

    
167
function inputSignal=createMultiTone(sampleRate, toneFrequency, ...
168
    leveldBSPL, duration, rampDuration)
169
% Create pure tone stimulus
170
dt=1/sampleRate; % seconds
171
time=dt: dt: duration;
172
inputSignal=sum(sin(2*pi*toneFrequency'*time), 1);
173
amp=10^(leveldBSPL/20)*28e-6;   % converts to Pascals (peak)
174
inputSignal=amp*inputSignal;
175

    
176
% apply ramps
177
% catch rampTime error
178
if rampDuration>0.5*duration, rampDuration=duration/2; end
179
rampTime=dt:dt:rampDuration;
180
ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ...
181
    ones(1,length(time)-length(rampTime))];
182
inputSignal=inputSignal.*ramp;
183
ramp=fliplr(ramp);
184
inputSignal=inputSignal.*ramp;
185

    
186
% add 10 ms silence
187
silence= zeros(1,round(0.03/dt));
188
inputSignal= [silence inputSignal silence];
189