comparison userProgramsTim/Pavel_MAP1_14.m @ 38:c2204b18f4a2 tip

End nov big change
author Ray Meddis <rmeddis@essex.ac.uk>
date Mon, 28 Nov 2011 13:34:28 +0000
parents
children
comparison
equal deleted inserted replaced
37:771a643d5c29 38:c2204b18f4a2
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 restorePath=path;
36 addpath (['..' filesep 'MAP'], ['..' filesep 'wavFileStore'], ...
37 ['..' filesep 'utilities'])
38
39 %% #1 parameter file name
40 MAPparamsName='Normal';
41
42
43 %% #2 probability (fast) or spikes (slow) representation
44 AN_spikesOrProbability='spikes';
45
46 % or
47 % AN_spikesOrProbability='probability';
48 % NB probabilities are not corrected for refractory effects
49
50
51 %% #3 pure tone, harmonic sequence or speech file input
52 signalType= 'tones';
53 sampleRate= 100000;
54 duration=0.1; % seconds
55 % toneFrequency= 250:250:8000; % harmonic sequence (Hz)
56 toneFrequency= 1000; % or a pure tone (Hz8
57 rampDuration=.005; % seconds
58
59 % or
60 % signalType= 'file';
61 % fileName='twister_44kHz';
62
63
64 %% #4 rms level
65 % signal details
66 leveldBSPL= 30; % dB SPL
67
68
69 %% #5 number of channels in the model
70 % 21-channel model (log spacing)
71 % numChannels=21;
72 % lowestBF=250; highestBF= 8000;
73 % BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels));
74
75 % or specify your own channel BFs
76 numChannels=1;
77 BFlist=toneFrequency;
78
79
80 %% #6 change model parameters
81 paramChanges=[];
82
83 % or
84 % Parameter changes can be used to change one or more model parameters
85 % *after* the MAPparams file has been read
86 % This example declares only one fiber type with a calcium clearance time
87 % constant of 80e-6 s (HSR fiber) when the probability option is selected.
88 % It also removes the speed up that normally takes place for AN spikes
89 % It also increases the number of AN fibers computed to 500.
90 paramChanges={...
91 'AN_IHCsynapseParams.ANspeedUpFactor=1;', ...
92 'IHCpreSynapseParams.tauCa=86e-6;',...
93 'AN_IHCsynapseParams.numFibers= 500;' };
94
95
96 %% delare 'showMap' options to control graphical output
97 global showMapOptions
98
99 % or (example: show everything including an smoothed SACF output
100 showMapOptions.printModelParameters=1; % prints all parameters
101 showMapOptions.showModelOutput=1; % plot of all stages
102 showMapOptions.printFiringRates=1; % prints stage activity levels
103 showMapOptions.showACF=0; % shows SACF (probability only)
104 showMapOptions.showEfferent=0; % tracks of AR and MOC
105 showMapOptions.surfProbability=0; % 2D plot of HSR response
106 if strcmp(AN_spikesOrProbability, 'spikes')
107 % avoid nonsensical options
108 showMapOptions.surfProbability=0;
109 showMapOptions.showACF=0;
110 end
111 if strcmp(signalType, 'file')
112 % needed for labeling plot
113 showMapOptions.fileName=fileName;
114 else
115 showMapOptions.fileName=[];
116 end
117
118 %% Generate stimuli
119
120 dbstop if error
121 restorePath=path;
122 addpath (['..' filesep 'MAP'], ['..' filesep 'wavFileStore'])
123 switch signalType
124 case 'tones'
125 inputSignal=createMultiTone(sampleRate, toneFrequency, ...
126 leveldBSPL, duration, rampDuration);
127
128 case 'file'
129 %% file input simple or mixed
130 [inputSignal sampleRate]=wavread(fileName);
131 dt=1/sampleRate;
132 inputSignal=inputSignal(:,1);
133 targetRMS=20e-6*10^(leveldBSPL/20);
134 rms=(mean(inputSignal.^2))^0.5;
135 amp=targetRMS/rms;
136 inputSignal=inputSignal*amp;
137 silence= zeros(1,round(0.1/dt));
138 inputSignal= [silence inputSignal' silence];
139 end
140
141
142 %% run the model
143 tic
144
145 fprintf('\n')
146 disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)])
147 disp([num2str(numChannels) ' channel model'])
148 disp('Computing ...')
149
150
151 MAP1_14(inputSignal, sampleRate, BFlist, ...
152 MAPparamsName, AN_spikesOrProbability, paramChanges);
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