# Why can I still hear sound when the frequency of the periodic function inside Play is higher than the range of human ear?

We know that usually sound that is perceptible by humans has frequencies from about 20 Hz to 20,000 Hz, but as the title said, I can still hear the sound of the outputs of the following code:

(* The following sound won't cause discomfort… I think. *)
Play[Sin[1000000 2 Pi t], {t, 0, 1}, SampleRate -> 10000000]


After asking some of my friends to hear them, I'm sure I don't have clairaudience. I think it's probably not the fault of Mathematica, it might be an issue for loudspeaker, but I failed to find an answer by myself and I think it's worth posting a question for this.

• I was similarly disappointed when GrayLevel[10^50] failed to produce a gigawatt laser cannon. – Simon Woods Nov 6 '13 at 10:09
• @SimonWoods Tell me about it. I have been trying to heat my food with Plot[Sin[2 π 2.45 10^9 t], {t, 0, 60}]. Food still cold. – gpap Nov 6 '13 at 10:24
• @gpap Probably an experimental setup problem. You've to stuff the processor inside the poultry, not the other way around – Dr. belisarius Nov 6 '13 at 11:30
• @gpap On the other hand, you could easily do it with Inverse[RandomInteger[1000, {1000, 1000}]] :P – rm -rf Nov 6 '13 at 13:18
• There is something you should know, Kal El... – Peltio Nov 6 '13 at 14:34

Just saying SampleRate -> 10000000 does not mean that the hardware is capable of playing samples at that rate. (Most modern devices can do 192 kHz; but it's likely you're running at 48 kHz.)

Mathematica or the OS or the sound driver or the hardware will resample the data to something that is supported. Depending on how well the resampling is implemented, the 1 MHz signal will either vanish or be folded back to a lower frequency.

To avoid resampling, you should use SampleRate -> 48000 (or any other rate supported by your hardware).

Along with the fact that the hardware is incapable of very high sampling rates (as described CL), this is an example of a generic effect called aliasing that happens whenever the sampling frequency is less than half the frequency of the signal (this is called the Nyquist frequency). Here is a Wolfram demonstration about this effect and Wikipedia has a good article called aliasing. Here also is a previous StackExchange question that addresses the issue.

When I tried this once, I used:

Play[Sin[12000*2 Pi*t], {t, 0, 1}, SampleRate -> 44000]


which is near the top end for most adults. To annoy any teenagers in the same room, I tried:

Play[Sin[15000*2 Pi*t], {t, 0, 1}, SampleRate -> 44000]


and I know that worked, if only because I could hear the speaker starting and stopping.

The membrane may resonate on a lower frequency than what is actually played, fooling you with an audible pitch.