Generate Sound for a range of frequencies in MATLAB individually

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.

Antworten (1)

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 Kommentare

Hi,
For some reason, I can still listen to all the frequencies-No matter what I put.
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)
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 16 Sep. 2015

Bearbeitet:

am 16 Sep. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by