Generating a sequence of tones

I am trying to generate a sequences of tones (of a standard frequency and duration) separated by a standard interval. For example, a series of 5 tones (1000 Hz, 1 sec.) with an interval of 2 seconds between the onset of each tone. What is the best way to go about this?

 Respuesta aceptada

Star Strider
Star Strider el 27 de En. de 2015
This works:
Fs = 8192; % Default Sampling Frequency (Hz)
Ts = 1/Fs; % Sampling Interval (s)
T = 0:Ts:(Fs*Ts); % One Second
Frq = 1000; % Tone Frequency
Y = sin(2*pi*Frq*T); % Tone
Y0 = zeros(1, Fs*2); % Silent Interval
Ys = [repmat([Y Y0], 1, 4) Y]; % Full Tone With Silent Intervals
soundsc(Ys,Fs); % Play Sound

6 comentarios

Kelsey S.
Kelsey S. el 27 de En. de 2015
Thanks for your response! I'm getting an error message after: Ys=[repmat([Y Y0],1,4)Y]; It says "Unexpected Matlab expression". Any idea what I might be doing wrong here?
Star Strider
Star Strider el 27 de En. de 2015
Editada: Star Strider el 27 de En. de 2015
My pleasure!
It could be version problems, since it worked perfectly for me in R2014b. I don’t remember when repmat was introduced.
If all else fails, just brute-force it:
Ys = [Y Y0 Y Y0 Y Y0 Y Y0 Y];
Kelsey S.
Kelsey S. el 27 de En. de 2015
It worked! I'm working off of 2014a (Student version) , that must have been the issue. Thanks again!
Star Strider
Star Strider el 27 de En. de 2015
My pleasure!
I’m glad it worked. The repmat glitch still mystifies me.
repmat() has been around for hundreds of years, if not millennia. He's missing a space or comma after the right parenthesis in
Ys=[repmat([Y Y0],1,4)Y];
Star Strider
Star Strider el 27 de En. de 2015
Editada: Star Strider el 27 de En. de 2015
I would agree, except that my original code (as posted, with the space, and correctly formatted in my Answer) worked without error when I ran it. I always test my code if possible before I post it, or clearly label it as untested. Perhaps a comma would have made it more robust, but it works as posted. Copy, paste, run.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 26 de En. de 2015

Editada:

el 27 de En. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by