A long time ago in college, I learned a lot about signal processing. A microphone produces a signal, and a speaker processes that signal back into sound. Why is CD quality sound sampled at 44 Khz ? Because human hearing ranges from 20-20 Khz and the Nyquist theorem. Actually, older people tend to have high frequency hearing loss. A standard NTSC TV set horizontal retrace transformer emits a 15 Khz squeal that I can’t hear any more. 15Khz is less than an octave down from 20Khz so I’m not too worried: an octave is a doubling of frequency. (For more about TV and computers, see Why was the original IBM PC 4.77 Megahertz?)
I worked for a company called Bolt Beranek and Newman (BBN) in Cambridge Massachusetts right after graduation from MIT in 1980.
BBN has a couple historical computer science related accomplishments:
One of the projects I worked on at BBN in the early 80’s was detecting submarines. I created a computer system that would control a sound source underwater. This source was a vertical array of cylinders of compressed air, released under computer control to make an underwater sound. The array was steerable: firing the higher ones just a little before the lower ones caused the wavefront to be steered downward.
I also created a “target simulator”, which basically consisted of an underwater microphone and speaker. My computer system would listen to the microphone for the air gun sounds, and then echo back via the speaker as if it were a submarine (at various aspects: head-on, broadside, etc). Then it would echo back the same signal 3 times: each time being 10 times louder. Thus the number of times the “submarine” was detected indicated by how much we missed.
We’d take the machines out to sea for weeks, doing sea trials, sometimes with real submarines (which are expensive to rent!). Each computer system was a PDP-11 running RT-11. My software was written mostly in Fortran, with some Macro-11 assembly language for the crucial real time processing. I also was very seasick, and never got better til well after landfall.
You’ve probably seen “graphic equalizers” that display the spectrum of sound coming from a music system. It’s just a bar chart that shows the bars dancing with the music. The bars range from bass frequencies on the left to treble on the right. It’s basically a spectrum of the signal currently being played. Another way to think of a spectrum is each frequency corresponds to the keys on a piano. Each “bar” could be a piano key (or range of keys). Imagine watching and listening to a piano player. The keys being pushed comprise the “spectrum” of the music.
A pure tone is a sine wave. This “time domain” signal can be represented as a graph with the X axis representing time. The Fourier Transform converts the signal to a “frequency domain” signal, with the X axis now representing frequency. Thus, the Fourier Transform of a simple sine wave is very simple: it consists of just a single spike at the frequency of the sine wave (a single “piano key” (minus harmonics))
Below is a sample of code you can run. It will allow you to choose between a few kinds of signals (2 Sine waves, Square, Impulse), display them in red, display their FFT in blue and the difference between the FFT/Inverse FFT in green. A slider and spinner allow you to vary the 2 Sine waves frequency and phase shift (theta). Theta is initially zero, and the 2 frequencies are the same initially. Thus the 2 sine waves initially appear to be one. Try varying the slider and spinner to get different signal shapes.
(The green signal is the difference between the original signal and the signal after being FFT’d and inverse FFT’d. Theoretically, there should be no difference, except for mathematical rounding error.)
I have other sample code that filters sounds: it reads a WAV file, does an FFT, filters, and inverse FFT, writes the WAV file and plays back the sound. The original WAV is my voice saying “Foxpro Rocks” with a very loud high frequency sine wave in the background. The filter removes that sine wave to recover the original voice.
Filters are quite simple. Here’s the filter to remove the loud sine wave
FOR i = 1 TO np2/2
IF BETWEEN(i,nMid-nRange, nMid+nRange)
BTW, a 2 dimensional FFT can be used to sharpen the focus of a photograph or for image recognition.
*see http://www.relisoft.com/Science/Physics/fft.html and http://www.spectrumsdi.com/ch12.pdf
DEFINE CLASS signalform as form
width=2^10 && must be power of 2
ADD OBJECT spn as spinner WITH left=130,;
ADD OBJECT cboInput as Combobox WITH left=200
.SmallChange=5 && a penny
.AddItem("2 Sine Waves")
PROCEDURE keypress(nKeyCode, nShiftAltCtrl)
CASE nKeyCode=27 && escape
yOffset=thisform.Height/2 && x axis halfway down
thisform.Line(0,yOffset,thisform.Width,yOffset) && draw x axis
xMax=thisform.Width && must be power of 2
FOR x=1 TO xMax
CASE cMode="2 Sine Waves"
aInput[x]=yMax* (SIN(2*PI()*(1+nFactor)*x/100) + SIN(2*PI()*(1+nFactor*10.5)*x/100 + nTheta))
CASE cMode="Square Waves"
aInput[x]=yMax * SIGN(SIN(2*PI()*(1+nFactor)*x/100) + SIN(2*PI()*(1+nFactor*10.5)*x/100 + nTheta))
CASE cMode="DC Input"
FOR x =1 TO xMax/2
FFT(@aInput,@aOutput,.t.) && now calculate inverse FFT, display difference in green
FOR x =1 TO xMax
thisform.spn.value=0 && reset phase and freq factor to 0
DEFINE CLASS MySlider as olecontrol
PROCEDURE FFT(aRe,aIm,fInverse as Logical ) && Fast Fourier Transform
nlg2 = INT(LOG(n)/LOG(2))
n2 = n/2
FOR i = 1 TO n
FOR i = 2 TO n-2 && Bit Reversal order
DO WHILE k<j
FOR lp = 1 TO nlg2
FOR j = 1 TO le2 && each sub DFT
FOR i = j TO n STEP le && butterfly loop
tr=aRe[ip]*ur - aIm[ip]*ui
ti=aRe[ip]*ui + aIm[ip]*ur
aRe[ip] = aRe[i] - tr
aIm[ip] = aIm[i] - ti
aRe[i] = aRe[i] + tr
aIm[i] = aIm[i] + ti
tr = ur
ur = tr * sr - ui * si
ui = tr * si + ui * sr