MicFFT v1.0 - January 27, 1993 The PC Fourier Spectrum Analyzer by Craig M. Walsh CIS 70701-1614 walsh@biovx1.dnet.nasa.gov MicFFT is a program that allows PCs equipped with 8-bit analog to digital converters (ADCs) on sound cards to perform spectral analysis on pulse-code modulated (PCM) signals. With operation similar to octave spectrum analyzers found on certain audio equalizers, MicFFT can be used to view the frequency components of musical and vocal signals, as well as a number of other types of signals that can be input thru the ADC. Requirements: MicFFT requires a fast computer equipped with an EGA or VGA graphics adapter, a properly configured sound card with an 8-bit ADC, and a curious computer user with an interest in sound. This program has been developed on a 33Mhz 486 computer equipped with SVGA and a Covox SoundMaster II sound card with a default ADC port address of 22f (hex), but I believe other configurations should work if the proper options are set. For example, Sound Blaster cards, etc. should also work, if the associated ADC port address is known. MicFFT v1.0 is freeware with a catch. Anyone who uses the program must advise me by sending a note via CompuServe mail or over the Internet to the appropriate address listed above. I'd love to know what you think about the program and what you are using it for, or perhaps to tell me what a bunch of crap I'm shoveling in this document. I uploaded the program FileScop about a month ago to CompuServe (MIDIFORUM) and nobody has written a single note about it, although plenty have downloaded it. I cannot improve on these programs unless people give me ideas about them. I need information about problems, ideas etc. Depending on the response, I may not release programs into the public domain in the future. It just isn't worth it, unless... Oi! The source code for this is not available without fee however. Contact me if you are interested in the methods used and we can make arrangements. MicFFT is written almost entirely in Microsoft C (save the timer routines which are written in assembly). I may provide a Windows version of the program, if I can get the performance up to par. What it does: MicFFT takes PCM data sampled at a defined rate and transforms the data using the Fast Fourier Transform (FFT) from a time domain to frequency domain representation. When the program is running with the proper setup, a plot window is presented that displays 128 frequency bands. Below the plot window is a ruler that displays 128 "ticks" representing each of the bands. To determine the frequency of each band, multiply the value of the ruler tick (tens are shown in red, fives in orange and ones in blue) by the Fundamental frequency listed at the bottom of the screen. For example, if the fundamental frequency is 30Hz and the band of interest is tick 32, then the frequency of that band is 960Hz. Note that the fundamental frequency is equal to the sampling frequency divided by the number of points (256 in MicFFT). Thus, if the sampling frequency is 7680Hz, the fundamental will be 30Hz. This is also referred to as the "resolution" of the spectrum, since values between this are not directly calculated. Note that the frequency bands plotted are multiples of the fundamental and are thus scaled linearly. Octave spectrum analyzers (of the type mentioned above) scale the frequency data by powers of two. Also note the bandwidth (i.e. the lowest to highest frequencies) that can be attained using any particular sampling frequency value. You will notice that the highest frequency that MicFFT displays is half the sampling frequency. In fact, all PCM recording systems are limited to bandwidths of one-half the sampling frequency. The Nyquist sampling theorem dictates that it is not possible to surpass this limit without inducing "aliasing." Aliasing is a sampling error that can be likened to the common observation in the movie house of wagon wheels that appear to rotate backwards in "Westerns." Of course, the wheels are not turning backwards, but the sampling rate of the projection system (24 frames/second) is not fast enough to keep up with the movement of those spokes, so we observe this backwards movement. Aliasing is a problem for PCM-sampled sound as well. To ensure that aliasing does not introduce problems in this arena, PCM- sampled sound always passes thru "anti-aliasing filters" (which are very high slope low-pass filters) before the Nyquist limit. Thus, in CD-quality sound applications (where sound is sampled at 44.1 kHz), these low-pass filters begin attenuating sound at about 20 kHz, and have attenuated most sound at the Nyquist limit of 22.05 kHz. Since MicFFT does not have these sorts of anti-aliasing filters built in, you will observe aliasing if you surpass the Nyquist limit. This will be seen when a signal of increasing frequency moves toward the right end of the plot and then begins to move toward the left again. You should thus be aware that complex waveforms with components that surpass this limit will not be accurately represented in the frequency plot. To avoid such problems, it is wise to choose the appropriate bandwidth for a particular signal, assuming that the ADC can keep up with the chosen sampling rate. For speech, it is usually sufficient to choose a sampling rate of about 10 kHz, but musical signals will require higher rates (perhaps as high as 32 kHz before any degradation resulting from the ADC speed becomes a problem). Of course, aliasing can be an interesting phenomenon unto itself, and you should consider experimenting a bit with the sampling frequency on various signals to see what is going on here. Amplitude plotting modes: It is possible to view amplitude data in two ways with MicFFT. The default is to represent data logarithmically. That is, the amplitudes plotted (i.e. the y-axis) are scaled by a factor of log base 10. This is most useful for sound applications and results in a plot similar to that observed on the octave-type spectrum analyzer discussed above. However, it is also possible to view the data scaled linearly. In this mode (using the flag -m1 at the command line), the data will be scaled to the maximum value returned by the FFT routine. When the signal data is zero or very low level, you will observe that the fundamental frequency band is the highest. This is due to the fact that the FFT is returning a value here representing a DC signal (i.e. not time-varying). Maximum amplitude scaling is perhaps more interesting to watch than log scaling since it appears to be more sensitive to ambient signals. I'm not sure yet why this is (hey, I'm a molecular biologist, not a math hack) just yet. Anyway, if you have an idea, just let me know. Suffice it to say that low-level signals will have amplitudes scaled appropriately by this method for analysis, so long as background spectral components do not overtake them. Usage: MicFFT is designed to be run at the DOS prompt and does not require additional parameters if the default setup is appropriate for your system. However, you may change the following parameters by using command line flags that tell MicFFT what defaults to change. You can list these flags by typing: MicFFT -? Most likely, you will need to change the address of the ADC port, if you are not using a Covox SoundMaster II with factory defaults. You will need to know the value of the port address for your 8-bit ADC. This can be supplied to MicFFT in hexadecimal or decimal format using the -p flag. If you use the hexadecimal address, be sure to follow this number with an 'h' as this tells MicFFT to use a hexadecimal port address. Note that all flags (except the video mode flags) require that values be entered after the flag with no spaces (e.g. MicFFT -p24fh tells MicFFT to use hexadecimal address 24f for the ADC port). The sampling frequency can be changed with the -f flag. You should use a reasonable value here (i.e. greater than zero, less than the maximum sampling rate of the ADC on your sound card) otherwise the program will produce garbage and may crash with a zero-divide error (I'm not sure why this happens just yet). Also, you must type all zeros (sorry about that), so don't enter -f15kHz when you mean -f15000. The video mode is set to use the maximum resolution mode of your monitor. This means that if you have a graphics card, you should be able to use the program. However, the program was designed to run on EGA or VGA monitors, and the justification of windows, etc. will not be correct for monitors other than these. The program may very well work on Hercules compatible systems, although I've not tested this. On CGA systems, the screen is definitely not justified properly, so it won't work well. You can override the default screen environment by typing -e or -v for EGA or VGA mode. You can use this on VGA monitors to force EGA mode, which may increase the plot speed. The EGA mode will also increase the relative size of the plotting window and may be more suited to your taste. Experiment with this in your environment to get the best performance. Plotting modes are set by the -m flag as discussed above. The default mode is -m0 (log base 10 scaling of the amplitudes). Applications: Although I'm sure a number of you can think of other things to do with MicFFT, I've used the program for the following analyses with interesting results. With a sine-wave generator connected to the input port, I was able to test the accuracy of the program. To my knowledge, the timing routines are fairly accurate, and the program's accuracy was verified (at least in the audio spectrum) at a number of discrete frequencies using this method. Thus, MicFFT's accuracy makes it useful for analysis of real world signals. The program would be useful for analysis of musical signals. It should be possible to analyze samples of a particular musical instrument to observe the various frequency components generated. For those interested in speech recognition, the program is able to display frequency components of various formant sounds. On a fast computer, it can even act as a sort of octave-spectrum analyzer (although not currently scaled in octaves) for musical signals. Have fun and let me know what you think. Craig Walsh