Exploring The FFT - GF4 As an Educational Tool (Part 3)#

In FFT Part 1, we created a damped sine wave and ran a Fast Fourier Transform on it. We looked at a few basic features of the FFT. In FFT Part 2, we learned about the frequency steps in the FFT and a bit about zero-padding, which can be used to increase the apparent precision of the FFT display.

As a reminder, GF4’s FFT routine produces only the magnitude of the FFT, not the phase or the complex values. For the type of exploratory and educational activities that GF4 is strong at, this is hardly ever a practical limitation.

Windowing The Waveform#

To Window a waveform means to multiply it by another that falls off at one or both ends. A rectangular step that is non-zero only within a particular span is a simple window.

../../_images/rect_windows_sine.png

A continuous sine wave windowed by a rectangular step. All points outside the window are forced to zero.#

Note

Here is how this graph was made. Each step uses a button on the Button Window.

  1. Set number of points to 1000.

  2. Create Sine wave with 10 cycles across the screen.

  3. Push the sine wave to the Y position.

  4. Create a Step of width 500.

  5. Shift the step right by 250 points.

  6. Multiply the X and Y waveforms together.

GF4 has several specific windowing functions, as shown in this screen shot:

../../_images/windowing_functions.png

GF4’s built-in Windowing Functions.#

The ones starting with Half start at a value of one at the left hand of the waveform, the others are symmetrical and fall off to near zero at either end of the waveform.

GF4’s Standard Windows#

The two figures below depict the five built-in windows. Pressing one of these Window buttons applies the window to the waveform in the X position.

../../_images/windows-1.png

Built-in window functions: Cosine, Half-Cosine, and Gaussian#

../../_images/windows-2.png

Built-in window functions: Gaussian, Super Gaussian, and Half Super Gaussian#

To display these windows, a line of constant height was created by multiplying the X waveform by zero, then adding one to it. Applying a window to this constant line results in the windowing waveform.

The super gaussian window is a member of a family of functions that differ in the power to which the exponent is raised. The basic equation (except for a normalizing factor) is

\[e^{-(x/s*\sqrt2) ^ n}\]

The familiar Gaussian function has \(n = 2\). Values of \(n > 2\) give rise to Supergaussian functions. GF4’s Supergaussian uses \(n = 6\).

Windows And The FFT#

The main reasons windows are sometimes applied to data are

  1. To try to improve the signal-to-noise ratio, at least in some part of the FFT’s frequency range;

  2. To try to improve the resolution of frequency features that are close to each other.

When a window is applied to a waveform, its own frequency characteristics become included in the FFT, but not quite as one might expect. To be specific, the window is a mathematical function that multiplies the data waveform. When the FFT operation transforms the data to the frequency domain, the multiplication operation in the time domain becomes a convolution operation in the frequency domain:

\[f \times g \rightarrow F \ast G\]

where \(f, g\) are time domain waveforms and \(F, G\) are their frequency-domain equivalents (that is, the FFTs of the time domain waveforms), and the \(\ast\) operator is the convolution operator. In words, the FFT of two multiplied functions is the convolution of the FFTs of those functions.

This is not the place to get into properties of convolutions. For this exploration of GF4’s FFT and windowing features, it is enough to say that any windowing function that has sudden changes will cause ripples or waves in the FFT. The sharper those features are, the more and larger the ripples will be. Here’s an example. We will window a sine wave with square wave, then run an FFT on the result.

Notes#

Resolve two sinusoidal signals#

10000 pts

  1. damped sine 50/8

  2. damped sine 53/8

This gives a barely resolved twin peak.

FFT, cosine windowed FFT, supergussian windowed FFT

The cosine window clearly improves resolution.

Window with step starting at 200: FFT has less resolution, only one peak can be seen.

Half-x windows don’t change the FFT, or just barely. Full-x windows do.

A right-shifted half-cosine and a right-shifted step also increase the peak resolution, though not by as much as the full-cosine window.

Set the number of points to 10000. Conventional FFTs must have a number of points to be an exact power of two using the NumPts button. The FFT routine used by GF4 can handle any number of points, although powers of two will run faster.

Create a step function that has a magnitude of 1 and a width of 2000:

  1. Press the Step button and fill in the value of 2000 in the dialog.

  2. Shift this step to the right by using the Shift button and filling in the value of 2500.

Copy this step to the Y postion by pressing the Copy2Y button, or by pressing the Push button.

Next create a sine wave using the Sine button and entering a value of 50 in the dialog. Then multiply the sine by the step using the Y*X button. The result will be plotted in the plot display. It will look like this:

../../_images/step-windowed-sine.png

Sine wave windowed by a step function#

Now press the FFT button to generate the FFT of this waveform. The result looks like this after you press the Loglog button:

../../_images/fft_step-windowed-sine.png

FFT of the step-windowed sine wave. The FFT is plotted with a log-log scale.#

Notice the ripples extending out to either side of the central peak. These ripples are the result of the sharp-featured rectangular step. In fact, the rectangular step by itself has a strong ripple pattern as well, also caused by the sharp edges:

../../_images/fft-step.png

FFT of a rectangular step, plotted using a log-log scale.#

For comparison, the FFT of the underlying sine wave is clean, very narrow, and ripple-free:

../../_images/fft-sine-50cycles.png

FFT of unwindowed sine wave, plotted using a log-log scale.#

Finally, here is an overlaid comparison of the FFT of the unwindowed sine wave with two different windows:

../../_images/sine_fft_var_windows.png

FFTs of sine wave with no window, step window, and supergaussian (SG) window. The SG has a more gradual shape than the rectangular step, and this difference shows up in the FFTs as smaller and fewer ripples for the SG curve.#

As a reminder, we repeat how to understand the location of the frequency peak, which was covered in FFT Part 1 of this series. This time, we generated a sine wave that has 10,000 points. The minimum frequency of the FFT, which is the distance between two frequency points, is the inverse of this. Our sine wave has 50 cycles across the entire span, so its frequency is 50 times the minimum, or \(50/10000 = 0.005\). If you zoom into the FFT, you will see that the peak is indeed at that frequency.

../../_images/expanded_50-cycle-sine.png

A zoomed-in view of the FFT peak of the sine wave, plotted on linear axes.#

To zoom in or out, click on the crossed arrows icon, the one boxed with a heavy line at the toolbar at the bottom. Then hold the right mouse button down while you drag the mouse right to zoom in or left to zoom out. Dragging with the left mouse button pans the graph.

W1: sine1 + sine2 + noise W2: W1 + step