6
$\begingroup$

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.

$\endgroup$
8
  • 32
    $\begingroup$ I was similarly disappointed when GrayLevel[10^50] failed to produce a gigawatt laser cannon. $\endgroup$ Commented Nov 6, 2013 at 10:09
  • 6
    $\begingroup$ @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. $\endgroup$
    – gpap
    Commented Nov 6, 2013 at 10:24
  • 3
    $\begingroup$ @gpap Probably an experimental setup problem. You've to stuff the processor inside the poultry, not the other way around $\endgroup$ Commented Nov 6, 2013 at 11:30
  • 4
    $\begingroup$ @gpap On the other hand, you could easily do it with Inverse[RandomInteger[1000, {1000, 1000}]] :P $\endgroup$
    – rm -rf
    Commented Nov 6, 2013 at 13:18
  • 3
    $\begingroup$ Funny, my son's dog asked me this very question the other day. $\endgroup$ Commented Jan 30, 2021 at 16:06

4 Answers 4

15
$\begingroup$

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).

$\endgroup$
3
  • $\begingroup$ how do i determine a rate supported by my hardware? $\endgroup$
    – Michael
    Commented Aug 30, 2021 at 0:29
  • $\begingroup$ @Michael AFAICS this is not possible from within Mathematica. All built-in sound devices support 48 kHz. $\endgroup$
    – CL.
    Commented Aug 30, 2021 at 7:15
  • $\begingroup$ Hmm, ok. The reason I ask is I can hear a steadily increasing frequency sound from Play[Sin[100*2^(t/1.9)*2 Pi*t], {t, 0, 10}, SampleRate -> 48000] all the way to the end which if I understand the formula should be impossible as it should peak at around 40kHz. $\endgroup$
    – Michael
    Commented Aug 30, 2021 at 14:41
8
$\begingroup$

Along with the fact that the hardware is incapable of very high sampling rates (as described by 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 Stack Exchange question that addresses the issue.

$\endgroup$
6
$\begingroup$

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.

$\endgroup$
3
  • 1
    $\begingroup$ I can hear these two, but these are not that kind of sound I mentioned in the question, the sound of the high-frequency code in my question is much lower than these two. $\endgroup$
    – xzczd
    Commented Nov 6, 2013 at 10:02
  • $\begingroup$ It's funny that you mention teenagers… $\endgroup$ Commented Dec 12, 2015 at 14:21
  • $\begingroup$ Ouch! That second one hurts my ears and I'm much older than a teenager... $\endgroup$
    – Michael
    Commented Aug 30, 2021 at 0:18
4
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.