This java applet demonstrates Fourier series, which is a method of expressing an arbitrary periodic function as a sum of cosine terms. In other words, Fourier series can be used to express a function in terms of the frequencies (harmonics) it is composed of.
To select a function, you may press one of the following buttons: Sine, Cosine, Triangle, Sawtooth, Square, and Noise. The function is displayed in white, with the Fourier series approximation in red. If you only see a red graph, that means the Fourier approximation is nearly the same as the original function. (The red graph is drawn on top of the white one.)
Below the function you will see a graph of the Fourier coefficients. Each one represents a frequency, or harmonic. There are two sets of terms; on top are the sine terms, and on the bottom are the cosine terms. Low frequencies are on the left and higher frequencies are on the right.
The "Number of Terms" slider will adjust the number of terms in the expansion. The more terms there are, the better the approximation. Try sliding the "Number of Terms" slider from left to right slowly to see the Fourier terms added up one by one.
If you move the mouse over one of the harmonics, it will turn yellow, and the corresponding Fourier term (frequency) will be drawn on top of the function in yellow. So if you move the mouse over all the harmonics, you can see each of the terms individually. Also, if you click with the right mouse button on one of the harmonics, the "Number of Terms" slider will be changed so that all higher-frequency terms will be taken out of the series.
You can modify the function in one of two ways. You can edit the function directly by clicking on it; in this case, the Fourier coefficients will be regenerated when you are done. Or, you can modify the Fourier coefficients, in which case the function will be changed to match. If you want to create a function from scratch, hit the "Clear" button.
The "Clip" button can be used to simulate clipping. It will increase the amplitude of the function, but will clip it if it goes out of range. Try doing this with a sine function. Using this button generally results in more jagged edges, which means more high-frequency terms will be involved in the expansion. Some functions, like the square wave, aren't affected much by clipping. Try playing the noise waveform and then hit "Clip" a few times to see if it changes.
The "Resample" button can be used to demonstrate aliasing. The function is replaced with samples at 32 points. This corresponds to a sampling frequency of 7040 Hz (at the default playing frequency of 220 Hz). In almost all cases this will cause aliasing, where new, unwanted frequencies will be introduced. Press the "Resample" button multiple times to choose a lower sampling rate.
For example a frequency of 220 Hz, when resampled, will have aliases at 6820 Hz (7040-220), 7260 Hz (7040+220), 13860 Hz (7040*2-220), and so on.
When the "Quantize" button is pressed, the values in the function are rounded off to the nearest multiple of 1/8. The resulting roundoff error causes new frequencies to be introduced; these can be heard when the function is played. This is called quantization distortion. Press "Quantize" multiple times to use a coarser quantization.
The "Rectify" button will zero out the function wherever it is negative. The "Full Rectify" button will take the absolute value of the function at all points. Try this with the sine or sawtooth function.
The "Sound" checkbox, when checked, will play the function at 220 Hz. This checkbox is only available if you have Java 2. The frequency is adjustable using the "Playing Frequency" slider. Try playing various functions to see what they sound like. Also try isolating each harmonic, or mixing two or three harmonics together. The "Number of Terms" slider will affect how many harmonics are played.
(The sampling rate used for playing is 22.05khz, so frequencies higher than 11025 Hz will be filtered out.)
There are two lines of letters at the bottom of the window which can be used to easily “hear out” harmonics (when Sound is enabled). If you click on one of the top lowercase 'm's, it capitalizes to "M", meaning "mute"; and that harmonic will not be played. If you click on one of the bottom lowercase 's's, it capitalizes to "S", meaning "solo"; only that harmonic (along with any other similarly soloed harmonics) will be played. Clicking a letter again restores its previous state.
Numeric keys (not numpad digits) 1-0 can be used as short-cuts instead of clicking the 'm's to toggle the mute attribute for each of the first ten harmonics. Similarly, shifted presses of these same numeric keys toggle the corresponding solo attributes. For instance, Shift+4, Shift+5, Shift+6 plays a major chord extracted from a complex tone.
The "Mag/Phase view" checkbox will allow you to view the Fourier terms in phase-angle form (see this page for more on this representation).
The "Log View" checkbox (which only works when "Mag/Phase View" is checked) will use a logarithmic scale to show the magnitudes of each term.
Other things to try:
Click here to go to the applet.