Create rapid beeping tone in matlab

30 ビュー (過去 30 日間)
Michael Boyle
Michael Boyle 2021 年 11 月 27 日
編集済み: DGM 2021 年 11 月 27 日
I am trying to use sound( ) or some other function to create a rapid beeping tone at a specified frequency. The sound( ) function only seems to let me create a continuous smooth tone, is there a way to create a discontinious tone that beeps rapidly?

回答 (1 件)

DGM
DGM 2021 年 11 月 27 日
編集済み: DGM 2021 年 11 月 27 日
Depends how you want to do it. I bet there's lots of ways.
I just made a piecewise signal and played it.
fs = 8192;
toneduration = 0.1;
spaceduration = 0.05;
tonefreq = 800;
nbeeps = 15;
t = linspace(0,toneduration,round(toneduration*fs));
y = 0.8*sin(2*pi*tonefreq*t); % tone
ys = zeros(1,round(spaceduration*fs)); % space
Y = [repmat([y ys],[1 nbeeps-1]) y]; % the whole signal
sound(Y,fs);
If you didn't want to have to generate the entire vector, maybe you could just use the y vector by itself and then play it in a loop, pausing afterwards each time. That would allow beeping indefinitely without needing a giant precalculated vector, but you'll have to wrangle the audio tools such that they behave as needed.
Something like this:
fs = 8192;
toneduration = 0.1;
spaceduration = 0.05;
tonefreq = 800;
nbeeps = 15;
t = linspace(0,toneduration,round(toneduration*fs));
y = 0.8*sin(2*pi*tonefreq*t);
a = audioplayer(y,fs);
for k = 1:nbeeps
play(a)
pause(spaceduration)
end
I couldn't get this to work using sound(). Audioplayer seems to work, but it's glitchy.

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by