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 / userProgramsRM / test_toneInNoise.m
History | View | Annotate | Download (7.22 KB)
| 1 | 38:c2204b18f4a2 | rmeddis | function test_toneInNoise |
|---|---|---|---|
| 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 | global dt dtSpikes savedBFlist saveAN_spikesOrProbability saveMAPparamsName... |
||
| 36 | savedInputSignal OMEextEarPressure TMoutput OMEoutput ARattenuation ... |
||
| 37 | DRNLoutput IHC_cilia_output IHCrestingCiliaCond IHCrestingV... |
||
| 38 | IHCoutput ANprobRateOutput ANoutput savePavailable ANtauCas ... |
||
| 39 | CNtauGk CNoutput ICoutput ICmembraneOutput ICfiberTypeRates ... |
||
| 40 | MOCattenuation |
||
| 41 | global OMEParams DRNLParams IHC_cilia_RPParams IHCpreSynapseParams |
||
| 42 | global AN_IHCsynapseParams MacGregorParams MacGregorMultiParams |
||
| 43 | global ICrate |
||
| 44 | |||
| 45 | |||
| 46 | dbstop if error |
||
| 47 | restorePath=path; |
||
| 48 | addpath (['..' filesep 'MAP'], ['..' filesep 'wavFileStore'], ... |
||
| 49 | ['..' filesep 'utilities']) |
||
| 50 | |||
| 51 | %% #1 parameter file name |
||
| 52 | MAPparamsName='Normal'; |
||
| 53 | |||
| 54 | |||
| 55 | %% #2 probability (fast) or spikes (slow) representation |
||
| 56 | AN_spikesOrProbability='spikes'; |
||
| 57 | % or |
||
| 58 | AN_spikesOrProbability='probability'; |
||
| 59 | |||
| 60 | |||
| 61 | %% #3 pure tone, harmonic sequence or speech file input |
||
| 62 | signalType= 'tones'; |
||
| 63 | sampleRate= 44100; % must agree with noise |
||
| 64 | duration=0.010; % seconds |
||
| 65 | rampDuration=.001; % raised cosine ramp (seconds) |
||
| 66 | beginSilence=0.010; |
||
| 67 | endSilence=0.010; |
||
| 68 | toneFrequency= 2000; % or a pure tone (Hz) |
||
| 69 | |||
| 70 | % or |
||
| 71 | % harmonic sequence (Hz) |
||
| 72 | % F0=210; |
||
| 73 | % toneFrequency= F0:F0:8000; |
||
| 74 | |||
| 75 | % or |
||
| 76 | % signalType= 'file'; |
||
| 77 | % fileName='twister_44kHz'; |
||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | %% #4 rms level |
||
| 82 | % signal details |
||
| 83 | leveldBSPL= 70; % dB SPL (80 for Lieberman) |
||
| 84 | leveldBSPLNoise=30; |
||
| 85 | |||
| 86 | %% #5 number of channels in the model |
||
| 87 | % 21-channel model (log spacing) |
||
| 88 | numChannels=21; |
||
| 89 | lowestBF=250; highestBF= 8000; |
||
| 90 | BFlist=round(logspace(log10(lowestBF), log10(highestBF), numChannels)); |
||
| 91 | |||
| 92 | % % or specify your own channel BFs |
||
| 93 | % numChannels=1; |
||
| 94 | % BFlist=toneFrequency; |
||
| 95 | |||
| 96 | |||
| 97 | %% #6 change model parameters |
||
| 98 | |||
| 99 | paramChanges={};
|
||
| 100 | |||
| 101 | % Parameter changes can be used to change one or more model parameters |
||
| 102 | % *after* the MAPparams file has been read |
||
| 103 | % This example declares only one fiber type with a calcium clearance time |
||
| 104 | % constant of 80e-6 s (HSR fiber) when the probability option is selected. |
||
| 105 | % paramChanges={'AN_IHCsynapseParams.ANspeedUpFactor=5;', ...
|
||
| 106 | % 'IHCpreSynapseParams.tauCa=86e-6; '}; |
||
| 107 | paramChanges={'DRNLParams.MOCtauProb =.25;', ...
|
||
| 108 | 'DRNLParams.rateToAttenuationFactorProb = 0.02; '}; |
||
| 109 | % paramChanges={'DRNLParams.MOCtauProb =.15;', ...
|
||
| 110 | % 'DRNLParams.rateToAttenuationFactorProb = 0.00; '}; |
||
| 111 | |||
| 112 | |||
| 113 | %% delare 'showMap' options to control graphical output |
||
| 114 | showMapOptions.printModelParameters=1; % prints all parameters |
||
| 115 | showMapOptions.showModelOutput=1; % plot of all stages |
||
| 116 | showMapOptions.printFiringRates=1; % prints stage activity levels |
||
| 117 | showMapOptions.showACF=0; % shows SACF (probability only) |
||
| 118 | showMapOptions.showEfferent=1; % tracks of AR and MOC |
||
| 119 | showMapOptions.surfProbability=1; % 2D plot of HSR response |
||
| 120 | showMapOptions.surfSpikes=1; % 2D plot of spikes histogram |
||
| 121 | showMapOptions.ICrates=0; % IC rates by CNtauGk |
||
| 122 | |||
| 123 | % disable certain silly options |
||
| 124 | if strcmp(AN_spikesOrProbability, 'spikes') |
||
| 125 | % avoid nonsensical options |
||
| 126 | showMapOptions.surfProbability=0; |
||
| 127 | showMapOptions.showACF=0; |
||
| 128 | end |
||
| 129 | |||
| 130 | if strcmp(signalType, 'file') |
||
| 131 | % needed for labeling plot |
||
| 132 | showMapOptions.fileName=fileName; |
||
| 133 | else |
||
| 134 | showMapOptions.fileName=[]; |
||
| 135 | end |
||
| 136 | |||
| 137 | %% Generate stimuli |
||
| 138 | |||
| 139 | switch signalType |
||
| 140 | case 'tones' |
||
| 141 | % Create pure tone stimulus |
||
| 142 | dt=1/sampleRate; % seconds |
||
| 143 | time=dt: dt: duration; |
||
| 144 | inputSignal=sum(sin(2*pi*toneFrequency'*time), 1); |
||
| 145 | amp=10^(leveldBSPL/20)*28e-6; % converts to Pascals (peak) |
||
| 146 | inputSignal=amp*inputSignal; |
||
| 147 | % apply ramps |
||
| 148 | % catch rampTime error |
||
| 149 | if rampDuration>0.5*duration, rampDuration=duration/2; end |
||
| 150 | rampTime=dt:dt:rampDuration; |
||
| 151 | ramp=[0.5*(1+cos(2*pi*rampTime/(2*rampDuration)+pi)) ... |
||
| 152 | ones(1,length(time)-length(rampTime))]; |
||
| 153 | inputSignal=inputSignal.*ramp; |
||
| 154 | ramp=fliplr(ramp); |
||
| 155 | inputSignal=inputSignal.*ramp; |
||
| 156 | % add silence |
||
| 157 | intialSilence= zeros(1,round(beginSilence/dt)); |
||
| 158 | finalSilence= zeros(1,round(endSilence/dt)); |
||
| 159 | inputSignal= [intialSilence inputSignal finalSilence]; |
||
| 160 | |||
| 161 | % [inputNoise sampleRateN]=wavread('babble');
|
||
| 162 | [inputNoise sampleRateN]=wavread('white noise');
|
||
| 163 | inputNoise=inputNoise(1:length(inputSignal)); |
||
| 164 | inputNoise=inputNoise(:,1); |
||
| 165 | targetRMS=20e-6*10^(leveldBSPLNoise/20); |
||
| 166 | rms=(mean(inputNoise.^2))^0.5; |
||
| 167 | amp=targetRMS/rms; |
||
| 168 | inputNoise=inputNoise*amp; |
||
| 169 | inputSignal=inputSignal+inputNoise'; |
||
| 170 | figure(2), subplot(2,1,1) |
||
| 171 | time=dt:dt:dt*length(inputSignal); |
||
| 172 | plot(time,inputSignal,'k') |
||
| 173 | |||
| 174 | |||
| 175 | case 'file' |
||
| 176 | %% file input simple or mixed |
||
| 177 | [inputSignal sampleRate]=wavread(fileName); |
||
| 178 | dt=1/sampleRate; |
||
| 179 | inputSignal=inputSignal(:,1); |
||
| 180 | targetRMS=20e-6*10^(leveldBSPL/20); |
||
| 181 | rms=(mean(inputSignal.^2))^0.5; |
||
| 182 | amp=targetRMS/rms; |
||
| 183 | inputSignal=inputSignal*amp; |
||
| 184 | intialSilence= zeros(1,round(0.1/dt)); |
||
| 185 | finalSilence= zeros(1,round(0.2/dt)); |
||
| 186 | inputSignal= [intialSilence inputSignal' finalSilence]; |
||
| 187 | |||
| 188 | end |
||
| 189 | |||
| 190 | |||
| 191 | %% run the model |
||
| 192 | tic |
||
| 193 | fprintf('\n')
|
||
| 194 | disp(['Signal duration= ' num2str(length(inputSignal)/sampleRate)]) |
||
| 195 | disp([num2str(numChannels) ' channel model: ' AN_spikesOrProbability]) |
||
| 196 | disp('Computing ...')
|
||
| 197 | |||
| 198 | MAP1_14(inputSignal, sampleRate, BFlist, ... |
||
| 199 | MAPparamsName, AN_spikesOrProbability, paramChanges); |
||
| 200 | |||
| 201 | |||
| 202 | %% the model run is now complete. Now display the results |
||
| 203 | UTIL_showMAP(showMapOptions, paramChanges) |
||
| 204 | |||
| 205 | if strcmp(signalType,'tones') |
||
| 206 | disp(['duration=' num2str(duration)]) |
||
| 207 | disp(['level=' num2str(leveldBSPL)]) |
||
| 208 | disp(['toneFrequency=' num2str(toneFrequency)]) |
||
| 209 | global DRNLParams |
||
| 210 | disp(['attenuation factor =' ... |
||
| 211 | num2str(DRNLParams.rateToAttenuationFactor, '%5.3f') ]) |
||
| 212 | disp(['attenuation factor (probability)=' ... |
||
| 213 | num2str(DRNLParams.rateToAttenuationFactorProb, '%5.3f') ]) |
||
| 214 | disp(AN_spikesOrProbability) |
||
| 215 | end |
||
| 216 | |||
| 217 | figure(2), subplot(2,1,2), plot(ANprobRateOutput(13+21,:)) |
||
| 218 | disp([ 'peak channel 13: ' num2str(max(ANprobRateOutput(13+21,:)))]) |
||
| 219 | |||
| 220 | for i=1:length(paramChanges) |
||
| 221 | disp(paramChanges{i})
|
||
| 222 | end |
||
| 223 | |||
| 224 | path(restorePath) |