Clear questions and runnable code
get the best and fastest answer
Nyquist's Theorem in Action with Audio::Wavby jeffa (Chancellor)
|on Nov 11, 2001 at 23:12 UTC||Need Help??|
So, how long have CD's been around now? Since the early eighties, right? Right, in 1982 the first digital audio 5-inch CD discs were marketed - Philips/Sony finalized their standard in 1980, they had begun work in 1969.
So, how long has digital audio been around? Shortly before that, right? Nope, digital audio was born in the early 20th century when Alec H. Reeves invented pulse-code modulation PCM at the International Telephone and Telegraph Co. in France. PCM wouldn't be used until 1962 after the first practical integrated circuits were developed. The first analog sound wave was digitized at 8000 hertz.
But, the notion of digital audio and the notion of 'digitizing' and analog wave has been around since the early 1830's, when Samual Morse was expermenting with telegraph relays.
So, who is Nyquist and what does he have to do with all of this ob-trivia?
Henry Nyquist was a chap that worked at Bell Telephone Laboratories in the early 20th century. In 1928, he discovered that to acurately represent an analog wave digitally, that analog wave needs to be sampled by at least TWICE the amount of the highest perceived frequency that is desired for playback. I mentioned above that the first analog wave was digitized at 8KHz, this means that highest perceived frequency would only be half of that, 4KHz - but this perfect for the human voice, which is contained in the range of roughly 90 to 1200 Hz.
So, what happens when you break Nyquist's Theorem? Frequency aliasing - new frequecies appear and distort the original signal. The same phenoma appears when you watch the blades of a helicopter rotate - you seem to see new 'blades' which rotate the other direction at a much slower frequency.
According to Nyquist's Theorem, if S is the sampling rate, F is a frequency greater than 2S, and N is some integer, then a new sampled frequency is also created at:
Where Perl Comes InSo, let's demonstrate Nyquist's Theorem with the CPAN module Audio::Wav. Our sampling rate will be 44.1KHz at 16 bits - the CD standard. According to the formula above, if we try to sample a 36KHz wave, we should hear an 8KHz aliased wave:
44 - 36 = 8
I updated the code with jryan's suggestion, he also told me to remind you folks to turn down your volume before you listen, as an 8KHz sine wave is not a rather pleasing tone. :)