Generate Sound for a range of frequencies in MATLAB individually
98 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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
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
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 Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!