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.
root / testPrograms / test_MAP1_14.m @ 21:c489ebada16e
History | View | Annotate | Download (5.45 KB)
| 1 |
function test_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 |
% Indentify 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 |
% or |
| 43 |
AN_spikesOrProbability='probability'; |
| 44 |
|
| 45 |
|
| 46 |
%% #3 pure tone, harmonic sequence or speech file input |
| 47 |
signalType= 'tones'; |
| 48 |
duration=0.100; % seconds |
| 49 |
% duration=0.020; % seconds |
| 50 |
sampleRate= 100000; |
| 51 |
% toneFrequency= 250:250:8000; % harmonic sequence (Hz) |
| 52 |
toneFrequency= 2000; % or a pure tone (Hz8 |
| 53 |
|
| 54 |
rampDuration=.005; % seconds |
| 55 |
|
| 56 |
% % or |
| 57 |
% signalType= 'file'; |
| 58 |
% fileName='twister_44kHz'; |
| 59 |
% % fileName='new-da-44khz'; |
| 60 |
|
| 61 |
% mix with an optional second file? |
| 62 |
mixerFile=[]; |
| 63 |
%or |
| 64 |
% mixerFile='babble'; |
| 65 |
% leveldBSPL2=30; |
| 66 |
|
| 67 |
%% #4 rms level |
| 68 |
% signal details |
| 69 |
leveldBSPL= 60; % dB SPL |
| 70 |
|
| 71 |
|
| 72 |
%% #5 number of channels in the model |
| 73 |
% 21-channel model (log spacing) |
| 74 |
numChannels=21; |
| 75 |
lowestBF=250; highestBF= 8000; |
| 76 |
BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels)); |
| 77 |
|
| 78 |
% or specify your own channel BFs |
| 79 |
% BFlist=toneFrequency; |
| 80 |
|
| 81 |
|
| 82 |
%% #6 change model parameters |
| 83 |
paramChanges=[]; |
| 84 |
|
| 85 |
% or |
| 86 |
% Parameter changes can be used to change one or more model parameters |
| 87 |
% *after* the MAPparams file has been read |
| 88 |
% This example declares only one fiber type with a calcium clearance time |
| 89 |
% constant of 80e-6 s (HSR fiber) when the probability option is selected. |
| 90 |
% paramChanges={'AN_IHCsynapseParams.ANspeedUpFactor=5;', ...
|
| 91 |
% 'IHCpreSynapseParams.tauCa=86e-6;'}; |
| 92 |
% paramChanges={'AN_IHCsynapseParams.ANspeedUpFactor=5;', ...
|
| 93 |
% 'DRNLParams.rateToAttenuationFactorProb = 0;'}; |
| 94 |
|
| 95 |
%% delare showMap options |
| 96 |
global showMapOptions |
| 97 |
|
| 98 |
% or (example: show everything including an smoothed SACF output |
| 99 |
showMapOptions.showModelParameters=1; |
| 100 |
showMapOptions.showModelOutput=1; |
| 101 |
showMapOptions.printFiringRates=1; |
| 102 |
showMapOptions.showACF=0; |
| 103 |
showMapOptions.showEfferent=1; |
| 104 |
if strcmp(AN_spikesOrProbability, 'probability') |
| 105 |
showMapOptions.surfProbability=1; |
| 106 |
else |
| 107 |
showMapOptions.surfProbability=0; |
| 108 |
end |
| 109 |
if strcmp(signalType, 'file') |
| 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 |
inputSignal=inputSignal(:,1); |
| 129 |
targetRMS=20e-6*10^(leveldBSPL/20); |
| 130 |
rms=(mean(inputSignal.^2))^0.5; |
| 131 |
amp=targetRMS/rms; |
| 132 |
inputSignal=inputSignal*amp; |
| 133 |
silence=zeros(10000,1); |
| 134 |
inputSignal=[silence; inputSignal]; |
| 135 |
if ~isempty(mixerFile) |
| 136 |
[inputSignal2 sampleRate]=wavread(mixerFile); |
| 137 |
inputSignal2=inputSignal2(:,1); |
| 138 |
[r c]=size(inputSignal); |
| 139 |
inputSignal2=inputSignal2(1:r); |
| 140 |
targetRMS=20e-6*10^(leveldBSPL2/20); |
| 141 |
rms=(mean(inputSignal2.^2))^0.5; |
| 142 |
amp=targetRMS/rms; |
| 143 |
inputSignal2=inputSignal2*amp; |
| 144 |
inputSignal=inputSignal+inputSignal2; |
| 145 |
end |
| 146 |
end |
| 147 |
|
| 148 |
|
| 149 |
%% run the model |
| 150 |
tic |
| 151 |
|
| 152 |
fprintf('\n')
|
| 153 |
disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)]) |
| 154 |
disp([num2str(numChannels) ' channel model']) |
| 155 |
disp('Computing ...')
|
| 156 |
|
| 157 |
restorePath=path; |
| 158 |
addpath (['..' filesep 'MAP']) |
| 159 |
|
| 160 |
MAP1_14(inputSignal, sampleRate, BFlist, ... |
| 161 |
MAPparamsName, AN_spikesOrProbability, paramChanges); |
| 162 |
path(restorePath) |
| 163 |
toc |
| 164 |
|
| 165 |
% the model run is now complete. Now display the results |
| 166 |
showMAP |
| 167 |
for i=1:length(paramChanges) |
| 168 |
disp(paramChanges{i})
|
| 169 |
end |
| 170 |
|
| 171 |
toc |
| 172 |
path(restorePath) |
| 173 |
|
| 174 |
|
| 175 |
function inputSignal=createMultiTone(sampleRate, toneFrequency, ... |
| 176 |
leveldBSPL, duration, rampDuration) |
| 177 |
% Create pure tone stimulus |
| 178 |
dt=1/sampleRate; % seconds |
| 179 |
time=dt: dt: duration; |
| 180 |
inputSignal=sum(sin(2*pi*toneFrequency'*time), 1); |
| 181 |
amp=10^(leveldBSPL/20)*28e-6; % converts to Pascals (peak) |
| 182 |
inputSignal=amp*inputSignal; |
| 183 |
|
| 184 |
% apply ramps |
| 185 |
% catch rampTime error |
| 186 |
if rampDuration>0.5*duration, rampDuration=duration/2; end |
| 187 |
rampTime=dt:dt:rampDuration; |
| 188 |
ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ... |
| 189 |
ones(1,length(time)-length(rampTime))]; |
| 190 |
inputSignal=inputSignal.*ramp; |
| 191 |
ramp=fliplr(ramp); |
| 192 |
inputSignal=inputSignal.*ramp; |
| 193 |
|
| 194 |
% add 10 ms silence |
| 195 |
silence= zeros(1,round(0.03/dt)); |
| 196 |
inputSignal= [silence inputSignal silence]; |
| 197 |
|