Generating a sequence of tones

90 views (last 30 days)
Kelsey S.
Kelsey S. on 26 Jan 2015
Edited: Star Strider on 27 Jan 2015
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?

Accepted Answer

Star Strider
Star Strider on 27 Jan 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 Comments
Image Analyst
Image Analyst on 27 Jan 2015
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 on 27 Jan 2015
Edited: Star Strider on 27 Jan 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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!