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?

 채택된 답변

Star Strider
Star Strider 2015년 1월 27일

2 개 추천

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

Kelsey S.
Kelsey S. 2015년 1월 27일
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 2015년 1월 27일
편집: Star Strider 2015년 1월 27일
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. 2015년 1월 27일
It worked! I'm working off of 2014a (Student version) , that must have been the issue. Thanks again!
Star Strider
Star Strider 2015년 1월 27일
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 2015년 1월 27일
편집: Star Strider 2015년 1월 27일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2015년 1월 26일

편집:

2015년 1월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by