Create a time delayed cosine function

1 view (last 30 days)
Wes Madere
Wes Madere on 8 Feb 2018
Commented: Wes Madere on 22 Feb 2018
I have a signal that I'm trying to output as sound that looks like this
ts=0.0001; %sampling rate
n=[0:1057]; %number of samples
t7=4.26:ts:5; %time in seconds to play
c4=261.626; %note frequencey
ynote7=cos(2*pi*c4*t7); %cosine function
sound(ynote4,1/ts,16) %plays the sound from 4.26 sec to 5 sec
but the note plays immediately with no time delay, and I have no clue what I'm doing wrong with this

Answers (1)

Kai Domhardt
Kai Domhardt on 8 Feb 2018
Edited: Kai Domhardt on 8 Feb 2018
Your signal starts with the cosine wave, you will need to define the signal for 0 sec to 4.26 sec.
ts=0.0001;
freq = 261.626;
amp = 0.1; %in case somebody tries this without checking their speakers.
empty_signal = zeros(1,5/ts)
sound_signal = cos( linspace( 0, 2*pi*freq, (5-4.26)/ts ));
delayed_signal( end-length(signal)+1 : end ) = sound_signal;
sound(delayed_signal * amp, 1/ts)
  1 Comment
Wes Madere
Wes Madere on 22 Feb 2018
Can you tell me what's going on with
empty_signal = zeros(1,5/ts)
sound_signal = cos( linspace( 0, 2*pi*freq, (5-4.26)/ts ));
delayed_signal( end-length(signal)+1 : end ) = sound_signal;

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!