-
Notifications
You must be signed in to change notification settings - Fork 0
/
createStepChangeHarmonic.m
20 lines (15 loc) · 1.06 KB
/
createStepChangeHarmonic.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function [tone] = createStepChangeTone(samplingRate,dopplerInfo)
% create a tone that changes between two values
rampDuration =dopplerInfo.rampDuration; %Ramp duration is around 1 video frame 16 ms
rampSamples = round(rampDuration*samplingRate);
movingFreq = (1 + dopplerInfo.audioVelocity/dopplerInfo.speedOfSound)*dopplerInfo.stimFreq;
duration = dopplerInfo.postStimDuration+dopplerInfo.stimDuration+dopplerInfo.postStimDuration;
t=linspace(0,duration,round(samplingRate*duration));
f=ones(size(t))*dopplerInfo.stimFreq; %initialize f to hold the frequency modulation
preStimLastSamp=round(samplingRate*dopplerInfo.preStimDuration);
stimLastSamp = round(samplingRate*dopplerInfo.stimDuration)+preStimLastSamp;
f((preStimLastSamp+rampSamples): stimLastSamp) = movingFreq;
f(preStimLastSamp + (1:rampSamples)) = linspace(dopplerInfo.stimFreq,movingFreq,rampSamples);
f((stimLastSamp-rampSamples+1):stimLastSamp) = linspace(movingFreq,dopplerInfo.stimFreq,rampSamples);
tone = sin(2.*pi.*f.*t)+.5*sin(4.*pi.*f.*t)+.2*sin(6.*pi.*f.*t)+.1*sin(8.*pi.*f.*t);
tone = [tone;tone];