[net.audio] Gibbs effect, Square waves, etc.

muller@inmet.UUCP (06/27/84)

#N:inmet:2600088:000:6070
inmet!muller    Jun 25 14:07:00 1984

From a:muller Mon Jun 25 13:50:32 1984
***
Several previous notes have mentioned the matters of square waves, the
Gibbs phenomenon, and (in one humorous but pointed response) megahertz
sampling with 32+ bit data.  Someone also posted a set of rough graphs 
prepared by superimposing the Fourier components for a square wave.  The
comments on megahertz closed by saying something about the square waves
being so nice then.  I was tempted to respond to that by pointing out
that megahertz sampling would still not prevent ringing in square waves, 
rather it would just compress it into a shorter time interval.  (Of course 
the author of the comment did not intend it to be serious...)   Then I
realized that this was a complex subject that deserved serious discussion.

The Gibbs effect is essentially a phenomenon that acts on continuous time
functions (expressed as a Fourier series).  This implies the conditions that
the time function is continuous (not sampled) and repeating, with a fundamental
finite waveform which repeats exactly at the fundamental frequency.  The
frequency space representation therefore has the properties that it is NON-
replicating (since the time function is continuous) and composed of integer
multiples of the fundamental (the harmonics - i.e. the Fourier series).  
The Gibbs effect is the result of taking (only!) a finite number of the terms
from the Fourier series.  If those terms are taken at the correct amplitudes
(which for a square wave will be 1/n), and no contribution is taken for those
terms above some truncation frequency, the result is as if the frequency-space
function were multiplied by a rectangular window.  This produces a convolution
of the time function with the corresponding sinc function [ i.e. (sin x)/x ],
thus producing the ringing.  No matter how many more terms are added to the
Fourier series, the sinc function convolution persists, with the same amplitude
(about 9%) but increasing shorter time duration (higher frequency).  If we want
to minimize the ringing we must truncate the frequency components with some
function other than the sharp cutoff of a rectangle, e.g., a Hamming window.
This will reduce the side lobe effects in the time domain convolution, BUT note
that it requires a diddling with the frequency response, precisely what you
DON'T want in the frequency response of a stereo (unless it occurrs at higher-
than-audible frequencies only).  

Now for the fun part.  When you construct and plot square waves on your Apple
by superimposing the odd harmonics (or when you do it digitally at all, even
with CD's) you also introduce SAMPLING to the time function, and thus you
force replication and potential aliasing of the frequency components.  In other
words, you now produce a sampling of the ringing!!  If you superinpose terms
up to the Nyquist frequency you are using for your plots (or whatever other
representation) you will not get rid of the ringing.  But if you go beyond,
you will see all manner of deceptive results as the still present ringing gets
aliased.  At 3/2 Nf it may appear as if it has gone away, but just add more
terms and things will get gronky again as the ringing gets sampled at other
points in the function.  Moral:  don't get too fancy with your summation, 
since the DIGITAL behavior will become significant at higher frequencies.

Well, so what?...  This has some SIGNIFICANT implications for the output of
any digital system (including CD's) trying to produce square waves.  If all
frequencies are reproduced perfectly (with amplitudes of 1/n) up to the
truncation limit, ringing MUST be observed.  If any system (digital or not)
produces GOOD square waves, even though it is bandlimited at the top, it must
do so by introducing a frequency response corresponding to some type of
reduced-side-lobe window, rather than with a "flat" response.  "But," you say,
"can't you just create a square wave by postulating every byte to be some
pre-determined amplitude, with the sign changing at the your fundamental
frequency -- just make your CD have values that go +,+,+,-,-,-,+,+,+,-,-,- etc.
or even +,+,+,0,0,0,+,+,+,0,0,0, or maybe +,+,+,0,-,-,-,0,+,+,+,0 -- won't
this be a perfect square wave?"  Definitely not!!  In fact, it will instead
have a frequency response (if, say, you padded it by x8 and FFT'ed it) that
deviates from the expected 1/n by that of a reduced-side-lobe windowing 
function (choice of function is ambiguous at this point and must only meet
the requirement that it's FFT-1 produces the apparent effect on the time
function at the sampled points).  If it DOES come out with the (un)expected 1/n
shape, then your playback system is introducing some correction for that window
function, and it therefore is less than ideal for music.  If you do try
summing the Fourier series for square waves, you cannot REALLY make the
ringing go away, but the aliasing introduced by calculating higher-than-Nf
components will make the resulting waveform have all manner of "better"
shapes as terms are added.  CD's of course are not supposed to have any
components above 22.1kHz, and therefore will not demonstrate this aliasing.
They should produce a good square wave if the data on the disk is postulted
to be so as above, but this data should not have the spectrum of "real" 
infinite-extent, continuous square waves.  In other words, "perfect" square
waves composed of Fourier terms CANNOT look square, while "perfect" square
waves from postulated time domain data cannot have the expected 1/n amplitude
components!!! 

Don't you just love that string section?  *** This has turned out to be longer
than I expected.  Sorry, but enough had been said or suggested about these
matters that some clarification was in order before someone went off 
half-cocked about why his summation experiment did or didn't produce an 
expected result.  The potential for noisy discussion was just too great a
risk.  And megahertz sampling STILL won't produce AUDIBLE ringing...but
... oh never mind...     
    Jim Muller,  Intermetrics, Inc.,  Cambridge, Mass.