Generate Sound for a range of frequencies in MATLAB individually

96 ビュー (過去 30 日間)
Varun Kumar
Varun Kumar 2015 年 9 月 16 日
編集済み: Walter Roberson 2015 年 9 月 16 日
I wanted to generate sound from MATLAB for frequencies between 1Hz and30kHz. Technically, I shouldn't be able to hear sounds which are 30kHz but the code I'm using- I can hear those too. Don't know what I'm doing wrong. Here's what I used:
amp=10
fs=20500 % sampling frequency
duration=10
freq=30000
values=0:1/fs:duration;
a=amp*sin(2*pi* freq*values)
sound(a)
The duration has to be 1 second which is not the case either.
Any help is appreciated.
Thanks.

回答 (1 件)

Kirby Fears
Kirby Fears 2015 年 9 月 16 日
Hi Varun,
To fix the duration problem, include the sampling frequency "fs" as the second argument to sound(). I can still hear some of the very high frequency range, though that might be due to imperfect hardware.
amp=10;
fs=20500; % sampling frequency
duration=1;
freq=30000;
values=0:1/fs:duration;
a=amp*sin(2*pi*freq*values);
sound(a,fs)
  3 件のコメント
Kirby Fears
Kirby Fears 2015 年 9 月 16 日
編集済み: Kirby Fears 2015 年 9 月 16 日
Okay, mystery solved.
Your sampling frequency must be above the frequency you put into the signal. Previously any frequency above the sampling frequency was impossible to represent because the oscillations are faster than the sampling rate, creating a deeper (audible) sound. 20kHz is inaudible (for me at least) if you have a sampling rate of 80kHz, for example.
amp=1;
fs=80000; % sampling frequency
duration=1;
freq=20000;
values=0:1/fs:duration;
a=amp*sin(2*pi*freq*values);
sound(a,fs)
Star Strider
Star Strider 2015 年 9 月 16 日
Most computer sound cards have an upper limit for the sampling frequency of 44.1 kHz, and the upper frequency reproduction limit for that is about 21 kHz. You can query the sound card information with the audiodevinfo function.
Higher frequencies generally require special driver circuitry and transducers.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by