Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to demonstrate the aliasing effect using sound, that is, when the sample rate is fixed and the sound frequency is increased, we would hear the sound pitch go down when we pass the Nyquist frequency.

Here is what I tried so far:

  Play[Sin[ω* t], {t, 0, 0.2}, SampleRate -> 900]], {ω, 200, 6000, 10}]

  Play[Sin[ω* t], {t, 0, 0.2}, SampleRate -> 8000]], {ω,200, 6000, 10}]

Question: The sound is a little bit lag to the slider. Is it possible to create a more responsive one like this

Manipulate[EmitSound[Sound[SoundNote[n, 3]]], {n, 1, 10, 1}]
share|improve this question
This question is very closely related, if not a duplicate (re: the choppy and disconnected notes with Play). There's also this answer, although I have not tried it. – R. M. Aug 21 '13 at 18:01
up vote 6 down vote accepted

Here's one way to explore aliasing in audio using a "chirp" signal (thus avoiding the problems of real-time sound generation). A chirp is a sinusoid-like signal with frequency that constantly increases. Using the formula from the Wikipedia page, the chirp can be generated using

chirp[t_] := Sin[2 Pi (f0 t + (k/2) t^2)];

which is a sinusoid-like signal with instantaneous frequency f0 + kt. Hence the frequency increases as time progresses. If the sampling was done very quickly, then this is what we would hear. However, if the sampling frequency is low (such as 1000 Hz), the frequency will increase only up to the Nyquist frequency (in this case 1000/2 = 500 Hz.).

Select some nominal values and create a sampled version of the signal (using Table).

f0 = 200; k = 100; 
Sound[SampledSoundList[Table[chirp[t], {t, 0, 10, 0.001}], 1000]]

enter image description here

With these values, the "instantaneous frequency" is 200+100*t Hz. If you press the play button, you can hear the sound starting at 200 Hz and increasing. When it gets to the Nyquist frequency 500 (at about 3 seconds in), it starts to descend. The small upper figure shows (a rough version of) the spectrogram (a plot with time on the horizontal axis and frequency on the vertical axis). This agrees quite nicely with what you hear -- the sine wave sweeping up, then down, then up again over the course of 10 seconds.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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