Create a time delayed cosine function

4 次查看(过去 30 天)
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

回答(1 个)

Kai Domhardt
Kai Domhardt 2018-2-8
编辑:Kai Domhardt 2018-2-8
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 个评论
Wes Madere
Wes Madere 2018-2-22
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;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by