Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!polya!rokicki From: rokicki@polya.STANFORD.EDU (Tomas G. Rokicki) Newsgroups: comp.sys.amiga Subject: Sampling at 29KHz Message-ID: <2845@polya.STANFORD.EDU> Date: 18 May 88 17:42:18 GMT Organization: Stanford University Lines: 81 [ Sample *this*, you soundless hulk! ] Why Sampling At 29K Is Usually Sufficient First, I'm not sure I know what I'm talking about here, as I'm not a musician and know very little about sound, but let's pretend I do know what I'm talking about for a second or two. Some people have been bitching lately about having to provide waveforms for each octave of a sound sample. I won't go into issues here about how the relative frequency distribution changes as a function of frequency for musical instruments, other than to note that it does, so actually sampling the different octaves will give you more realistic sound, but rather I will explain how using separate samples for the higher frequencies works better than undersampling higher resolution samples, by stepping through them at a faster rate. First, any infinite periodic waveform of period t with n samples can be represented as a sum of n sine waves with periods of t/1, t/2, t/3...t/n. The discrete fourier transform can do (and undo) this transformation. If you undersample such a waveform, aliasing will cause some strange effects. Let us say our sampling rate that we are undersampling at is m (samples per second.) According to Nyquist, our sampling rate should be at least twice the frequency of the highest component sine wave. Any components that have a frequency greater than 2/m will have some portion of their energy aliased or mirrored down to a lower frequency. To demonstrate this, let us look at a 10KHz sine wave. We'll sample it at 20KHz, exactly the Nyquist rate. If our samples happen to fall exactly at the zero crossings of the sine wave, we will have a zero amplitude output. If they fall on the peaks, we will have a maximum amplitude output. Depending on the random position of our first sample. Now let's sample our 10KHz sine wave at 20.2KHz. We are now slightly off our frequency, and we will see a 10KHz tone modulated by a 200 Hz carrier; this will sound like two narrowly separated frequencies beating against one another. Ugly as sin. Let's now sample a 16KHz sine wave at 20KHz. In this case, we will get as output approximately a 4KHz tone at almost the full amplitude as the original sine wave. (Draw it out on graph paper to see what happens.) So, by undersampling our highly accurate waveform, we map the frequencies which are normally unheard (if they are really there at all) into frequencies which can be heard and which will greatly diminish the quality of the output. How do we fix this? Easy. We generate sound samples at the higher frequencies that do not contain the unheard higher frequency components of the original sound, and sample this newer sample at the correct rate. This is exactly the way it is recommended you do it on the Amiga, and for good reason. Someone recently complained that they had to go all the way down to a 32 samples to get the high frequencies they needed. I claim that that 32 sample sound, if properly created from the filtered original, would sound superior to an undersampled larger sample size. The final point is, because you know *each* sample will be used, you can adjust the energy of any of the harmonics essentially independently, and be assured that the output signal will have that much energy. Undersampling does not give you this ability. Any further comments? Oh, so you want to know how to create the smaller samples from the larger ones. I'll leave that to the experts out there. -- /-- Tomas Rokicki /// Box 2081 Stanford, CA 94309 / o Radical Eye Software /// (415) 326-5312 \ / | . . . or I \\\/// Gig 'em, Aggies! (TAMU EE '85) V | won't get dressed \XX/ Bay area Amiga Developer's GroupE