Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A high-pitched square wave absolutely will have aliasing when played without interpolation. In Audacity, try creating a 30 second square chirp from 6000 to 16000 Hz, and listen to the weird and wacky frequencies far away from the intended frequency.


Because a square wave is actually infinitely many sine waves (at odd harmonic frequencies) added together. So, almost all of these will lie outside the Nyquist frequency, which is half the sampling rate for real sampling.

In practice, only the first few odd harmonics are strong enough to really matter, but with a high-pitched square wave you still need oversampling and lowpass filtering to get rid of those in the general case without aliasing[1].

However, if you choose the frequency of your square wave right (to make the sample rate an integer multiple), the aliasing products will just be reflected back to be exactly on top of the "actual" harmonics, neatly sounding like a perfect square wave again (in theory). Matching well with our intuition of what happens with the actual signal, if you do the "skipping" for such a square wave.

[1] Or maybe not if your goal is really only generating square waves: Just don’t generate these harmonics. Your 16kHz square wave without aliasing will just sound like a sine wave anyway, because your ear cannot hear its harmonics.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: