MATLAB: Sound generation using MATLAB

sound

clc;
clear all;
close all;
fs=24000; %sampling frequency
f=100000; %frequency of the sound wave
t=0:1/fs:10;
y=sin(2*pi*f*t);
sound(y);
I generated a sound wave using the above code. Why is it audible? I set its frequency to more than 20kHz which is the limit of the human ear.
what's wrong here? Does it have to do with the speakers? or the code?

Best Answer

It's called aliasing. Sampling at rate lower than the Nyquist frequency will give signals that look like they are oscillating at a lower frequency. See the Wikipedia article on it: Wikpedia on Aliasing
Aliasing_between_a_positive_and_a_negative_frequency.png