[comp.dsp] how oversampling works

d88-jwa@nada.kth.se (Jon W{tte) (09/22/89)

In article <REED.89Sep21130447@intelob.intel.com> reed@intelob.intel.com (Robert Reed) writes:
>If anyone out there has an on-line document that explains how oversampling
>works in CD players, could you please e-mail it to me?  I know this subject

I thought I'd post this reply as well as mail it, since there's sure to be
other people out there wondering the same thing. FOLLOWUPS DIRECTED TO
COMP.DSP, which is where these things belong.



Oversampling's very simple. To get good sound quality, you have to
filter out everything from and above half the sampling frequency.
I.e.  the waveform out of a CD player looks like this:

____
   !
   !        ____
   !       !
   !____   !
       !   !
       !___!

This cases the use of VERY steep filters ( > 100 dB / octave) which
causes BAD phase distortion ( ~ 180 degrees :-( )

The solution is to "fake" a higher sample pitch, causing the CD to
interpolate the samples between the actual samples. The waveform
now looks like this: (4-fold oversampling)

_   
!_  
 !_         ____
  !_      _!
   !__   _! 
     !___!  
       !!   

And requres much less steep filters (typically 30 dB/octave) which means
no phase shifting. Good CD players use more bits in the output stage
than is recorded on the CD (i.e. 18 or 20 instead of 16) to get better
resolution in the oversampling if the variation between each sample is
small (i.e. low output) so that they don't have to interpolate 47 -> 48
as 47 47 47 48 48 but could use 47 47.25 47.5 47.75 48 and thus get a
smoother, cleaner output.

Simple as that !

h+@nada.kth.se
-- 
Have a nice day!
-- 
Trapezoid, n. -- A device for catching zoids.

ingoldsb@ctycal.COM (Terry Ingoldsby) (09/26/89)

In article <1737@draken.nada.kth.se>, d88-jwa@nada.kth.se (Jon W{tte) writes:
...
> Oversampling's very simple. To get good sound quality, you have to
> filter out everything from and above half the sampling frequency.
...
> This cases the use of VERY steep filters ( > 100 dB / octave) which
> causes BAD phase distortion ( ~ 180 degrees :-( )
> 
> The solution is to "fake" a higher sample pitch, causing the CD to
> interpolate the samples between the actual samples. The waveform
> now looks like this: (4-fold oversampling)
...
> And requres much less steep filters (typically 30 dB/octave) which means
> no phase shifting. Good CD players use more bits in the output stage
> than is recorded on the CD (i.e. 18 or 20 instead of 16) to get better
> resolution in the oversampling if the variation between each sample is
> small (i.e. low output) so that they don't have to interpolate 47 -> 48
> as 47 47 47 48 48 but could use 47 47.25 47.5 47.75 48 and thus get a
> smoother, cleaner output.

Something I've always wondered is what distortion this introduces.  If I
weren't so lazy I'd test it out in the frequency domain (if I don't get
any satisfactory answers maybe I will).  I understand that this is
practically the best way of doing the filtering, but what I want to
know is the difference between the output using oversampling (with
30 dB/octave filters) vs no oversampling and perfect (non-existent)
filters that have no phase shift.

I note that Philips recently went the other direction and used a
single bit output with a *very* high sampling frequency.  They claim
that although there is lots of noise, it all occurs at very high
frequencies (>50 KHz) where it can be filtered out easily.  ie.
filters that have appreciable phase shift at 100 KHz don't have
much at 20 KHz.

Comments?

Hooray for comp.dsp.  (Finally, someone who understands me :^)
-- 
  Terry Ingoldsby                       ctycal!ingoldsb@calgary.UUCP
  Land Information Systems                           or
  The City of Calgary         ...{alberta,ubc-cs,utai}!calgary!ctycal!ingoldsb

d88-jwa@nada.kth.se (Jon W{tte) (09/27/89)

>In article <1737@draken.nada.kth.se>, d88-jwa@nada.kth.se (Jon W{tte) writes:

-- Oversampling's very simple. To get good sound quality, you have to
-- filter out everything from and above half the sampling frequency.

-- This cases the use of VERY steep filters ( - 100 dB / octave) which
-- causes BAD phase distortion ( ~ 180 degrees :-( )

-- The solution is to "fake" a higher sample pitch, causing the CD to
-- interpolate the samples between the actual samples. The waveform
-- now looks like this: (4-fold oversampling)

-- And requres much less steep filters (typically 30 dB/octave) which means

In article <472@ctycal.UUCP- ingoldsb@ctycal.COM (Terry Ingoldsby) writes:

- Something I've always wondered is what distortion this introduces.  If I

- know is the difference between the output using oversampling (with
- 30 dB/octave filters) vs no oversampling and perfect (non-existent)
- filters that have no phase shift.


Oversampling really introduces no new distortion (that's the real thing
about it...) but instead spreads (shifts) the spectra of the distortion
upwards proportional to the oversampling rate, and also softens it, also
proportional to the oversampling rate.

This is as compared to the STEEP 100 db/octave filters...

Compared to non-existant phase linear cut-completely-after-n-Hz filters,
of course there is the phase shift from the 30 db/octave filters (24 ?
48 ? depends, I think) and the possibility that, after all, a little of
the distortion from the "transients" between levels in the D/A leaks.

And, me too, says HOORAY for comp.dsp, although I am merely a young
student in computer science who happens to have stumbled over some
intuitive knowledge about sound from being into the new-wave era in
'82 :')

h+@nada.kth.se
-- 
All that glitters has a high refractive index.

jefft@phred.UUCP (Jeff Taylor) (09/28/89)

In article <1737@draken.nada.kth.se> d88-jwa@nada.kth.se (Jon W{tte) writes:
>In article <REED.89Sep21130447@intelob.intel.com> reed@intelob.intel.com (Robert Reed) writes:
>>If anyone out there has an on-line document that explains how oversampling
>>works in CD players, could you please e-mail it to me?  I know this subject
>
>
>
>Oversampling's very simple. To get good sound quality, you have to
>filter out everything from and above half the sampling frequency.

>
>The solution is to "fake" a higher sample pitch, causing the CD to
>interpolate the samples between the actual samples. The waveform
>now looks like this: (4-fold oversampling)
>

>
>Simple as that !


For every problem there is a simple, wrong,  solution. (sorry)

The problem is not to get a signal that looks like what the original signal
*might* have looked like, but to regenerate the original signal as though it
was sampled at a higher frequency.

Linear Interpolation introduces disortion (changes the spectrum).
[which can be componsated for in a digital filter].  Adding zeros does not.
(plus the calculations are so simple).  

What follows is a hand waving (no math) justification on why this is logical
(although it defies common sense). (posted about 3 years ago to rec.audio)

---- OVERSAMPLING AND ZERO FILLING ----------------------------------

Back up to the basics about sampling (talk about the signals, and leave
out A/D's for the moment).  Everyone *knows* that the
sampling must be done at twice the bandwidth of the signal.  This is because

	1) The fourier transform of a periodic impulse (time domain) is
	a periodic impulse train (freq domain).

	2) The Multiplication of two signals in the time domain is
	equivalant to convolution in the frequency domain.

                time                            freq

	|   **         **                 |   *
	|  *   *      *   *               |**
Signal	|  *    *     *    *              |    *
	|-*-------*--*-------*            |     *
	*          *          *           |     *
	|*          *                     |--------------------


Sample  |                                 |
impulse ^   ^   ^   ^   ^   ^             ^               ^             ^
train   |   |   |   |   |   |             |               |             |
        +---------------------            +-------------------------------
        |<T>|                             |<---- 1/T ---->|

If we multiply the two time domain signals together (sample the signal) we
get:

	|                                 |   *       *       *      *
	|   ^           ^                 |**           *****          *****
	|   |           |                 |    *     *         *    *
	|   |   ^       |   ^             |     *   *           *  * 
	+----------------------           |     *   *           *  *
	v           |                     +---------------------------------
	|           v                             ^
                                                  |
						 1/2T

Looking at the freq plot, if we filter everything to the right of 1/2T,
we get the original signal back.  Therefore this impulse train (time domain)
contains all the information in the original signal.

A couple of important points about this time domain signal. 1) it is a
different signal then the original 'analog' signal, but contains all
the information that the original signal had.  2) It is a periodic sequence
of impulses, and *zero* everywhere else (the definitive digital signal,
only two values, 0 and infinity :-)). 3) It can be completely described
with a finite number of terms (the area under the impulses) so it is 
well suited for digital systems.

The disadvantage of this signal is that it is hard to realize (infinite
bandwidth, infinite amplitude).  However it is easy to get the weighting of
(area under) the impulses.  The area under each impulse is the value of the
original waveform at the instant it is sampled.  (Sample/Hold -> A/D).

[Key point coming up]

If you think of the 'digital' signal as completely describing the impulse
train signal, instead of an approximation of the original analog signal, it
is easy to accept zero filling as not introducing any errors.


	|                                 |   *       *       *      *
	|   ^           ^                 |**           *****          *****
	|   |           |                 |    *     *         *    *
	|   |   ^       |   ^             |     *   *           *  * 
	+-o---o---o---o---o---o           |     *   *           *  *
	v           |                     +---------------------------------
	|           v                                     ^
                                                          |
						         1/2T

By adding redundant information (the "o"'s above) of impulses with zero
area, we have not changed the spectrum of the signal, or it's ability
to represent the original analog signal.  Granted, this signal will not
look much like the original analog signal if plotted. So what. [try
sampling a 99 hz sine wave (which we know is bandlimited < 100hz) at
200 samples/sec.  It won't look like a sine wave either].  The other
two approaches, linear interpolation and sample duplication change the
impulse train, and the spectrum.  [ sin(f)/f ** 2  *I think*  and sin(f)/f ]


[Draw out a couple of cycles of 99hz and sample it at 200 S/sec, then
upsample to 400 by 1) zero filling, 2) linear interpolation 3) sample
duplication. None of them will be very accurate representation of the
original signal (if they are, change the phase 90 deg)]

Why bother oversampling?  Twice the sample rate, twice the processing
required (or more (or less)).  In the case of CD's which have a signal
BW of 20Khz, and a sample rate of ~44 khz, that means any signal at
20khz gets mirrored at 24khz.  To get rid of it you either need a
*very* sharp analog filter (with phase distortion/ringing), or lower
the BW of the filter (and lose some of the high freq).  If you
oversample by zero filling, it is possible to remove the
aliased signal with a digital filter.

A digital FIR filter has some good properties for removing the aliased
signal.  It is easy to make mulit-stage (90+) filters.  They are
noncausal (for proper reconstruction in the time domain, each of the
'zero' samples should be influenced by next impulse (not easily achieved
in an analog design :-) )).

		IMPULSE RESPONSE FIR INTERPOLATION FILTER

                                 |
                                _-_
                               - | -
                      _-_     _  |  _     _-_
                -*---*---*---*-------*---*---*---*
                   -      -_-         -_-      -


An important thing to notice about this filter is, it is zero at every
other sample (original sample rate), so running the oversampled signal
through this filter does not change any of the original samples (also
hard to do with an analog filter :-) ).  Adding more stages to the
filter moves the added zeros closer to the values of the original
waveform (by removing the aliased frequencies).  If the filter was
perfect, and the analog signal was bandlimited, they would become
identical to what would have been sampled at 88Khz.

The signal, and it's spectrum after running through this filter is:


	|                                 |   *                      *
	|   ^           ^                 |**                          *****
	|   | ^         | ^               |    *                    *
	|   | | ^       | | ^             |     *                  * 
	+----------------------           |     *                  *
	v           |                     +---------------------------------
	|           v                                     ^
                                                          |
						         1/2T

This is then fed to a D/A converter (at the 88 Khz rate), and the analog
output filter has a much simpler job. The signal at 20Khz is aliased at
68khz.

[side note on this FIR filter - half of the coefficents are zero,  half
of the signal samples are zero,  and the coefficents that are left are
duplicated.  But IIR filters have the reputation of being more efficent?
(but then I often use IIR filters when I want less ripple disortion,  and the
traditional rational for FIR filters is low disortion due to linear
phase delay).  Such is dsp, it often doesn't make sense, until you remember
the reason for your prejudice.]

jt

-- 
-----------------------------------------------------------------------------
No Opinions,				| Jeff Taylor
Just Facts.				| Physio Control Corp.
-----------------------------------------------------------------------------

d88-jwa@nada.kth.se (Jon W{tte) (09/28/89)

In article <2757@phred.UUCP> jefft@phred.UUCP (Jeff Taylor) writes:
>In article <1737@draken.nada.kth.se> d88-jwa@nada.kth.se (Jon W{tte) writes:

>>The solution is to "fake" a higher sample pitch, causing the CD to
>>interpolate the samples between the actual samples. The waveform

>For every problem there is a simple, wrong,  solution. (sorry)

>Linear Interpolation introduces disortion (changes the spectrum).
>[which can be componsated for in a digital filter].  Adding zeros does not.
>(plus the calculations are so simple).  

[ Long description of bandwidth inverting/shifting and adding zeros ]

Ahem.. Yes, you might be right. Or the CD players use a curve-fitting
algorythm. Your method is, of course, theoretically correct, but do you
KNOW that this is the way it's done in a CD ? I remember hearing something
else...

h+@nada.kth.se
-- 
Say, kids, what time is it ? -It's time for a house !

brianw@microsoft.UUCP (Brian Willoughby) (09/30/89)

In article <2757@phred.UUCP> jefft@phred.UUCP (Jeff Taylor) writes:
>
>Linear Interpolation introduces disortion (changes the spectrum).
>[which can be componsated for in a digital filter].  Adding zeros does not.
>(plus the calculations are so simple).  

This explains how digital mixing works.  My first musings on digital
mixing involved using addition to mimic analog op-amp mixers.  This
method has the same drawbacks as analog mixing, because you must now be
concerned with signal overload due to wave peaks coinciding.  In the
analog world the voltage sum reaches the supply limits, and in the
digital realm the values overflow the arithmetic unit.

But the first digital sampler circuitry I examined utilized time
multiplexing of the signals.  My first reaction was that this was a cheap
solution full of distortion from unwanted high frequencies.  But
reviewing your post, I see that time multiplexing N signals is equivalent
to oversampling each channel by N times and then adding them (where
adding zero is a no-op).  The only difference is that each channel is
shifted in time.  This method of digital mixing of multiple sample
channels obviously requires that you have a constant sampling rate for
all channels, and that you follow the combined output with an appropriate
digital filter.

I hope I wasn't too far off on that, since I don't practice DSP math.

>What follows is a hand waving (no math) justification on why this is logical
>(although it defies common sense). (posted about 3 years ago to rec.audio)

Thanks for a very informative (and surprisingly understandable) post.
Your explaination might defy common sense, but I still can't help but
examine the results of zero-filling intuitively.  I.e. following the
zero-filled, over-sampled data with a digital filtering algorithm tends
to smooth out the data so that ideally you have a wave which looks very
similar to a linearly interpolated wave (to the eye), but has less
distortion from errors in approximation.

Brian Willoughby
UUCP:           ...!{tikal, sun, uunet, elwood}!microsoft!brianw
InterNet:       microsoft!brianw@uunet.UU.NET
  or:           microsoft!brianw@Sun.COM
Bitnet          brianw@microsoft.UUCP