# FFT of Sinusoid, Square and Triangle, Range and Resolution.

Cuthbert Nyack
There are 2 properties of the FFT which must be understood for the FFT to be used effectively. These are the relation between the sampling interval and the spectrum and how to control the range and resolution of the spectrum produced. The applet below attempts to illustrate both by calculating the FFT of a sinusoid.
Relation between spectrum and sampling interval.
eg parameters (8.0, 1, 0.778, 1.56, 256, 0, 5, 150.0, 15.0, 0.2)
1 period is sampled, the sampling frequency is ~ 2048rad/s, the spectrum contains 1 line at 8 rad/s corresponding to m = 1. The magnitude is ~128 and when multiplied by 2/N it is ~1.
eg parameters (8.0, 10, 0.797, 8.62, 256, 0, 50, 150.0, 15.0, 0.2)
10 periods are sampled starting and ending at the zeros, the sampling frequency is ~ 204.8rad/s, the spectrum contains 1 line at 8 rad/s corresponding to m = 10. The magnitude is ~128 and when multiplied by 2/N it is ~1.
eg parameters (8.0, 10, 0.986, 8.81, 256, 0, 50, 150.0, 15.0, 0.2)
10 periods are sampled starting and ending at the peaks, the sampling frequency is ~ 204.7rad/s, the spectrum contains 1 line at 8 rad/s corresponding to m = 10. The magnitude is ~128 and when multiplied by 2/N it is ~1.
eg parameters (8.0, 10, 0.777, 9.0, 256, 0, 50, 150.0, 15.0, 0.3)
10.5 periods are sampled, the sampling frequency is ~ 194.8rad/s, the spectrum now contains several lines separated by 0.761rad/s. The 2 largest components are :- mag 81.6 at 7.611rad/s corresponding to m = 10 and mag 81.4 at 8.372rad/s corresponding to m = 11. Note that these 2 are approximately equally spaced about 8rad/s.
If w1 is increased to 8.37rad/s or reduced to 7.61rad/s then the spectrum again consists of 1 line at w1.
If instead T2 is increased to 9.38s or reduced to 8.6s the spectrum again becomes 1 line at 8rad/s.
Range and Resolution.
The range of the spectrum produced is half the sampling frequency and depends on the sampling interval (T2 - T1) and the number of samples N.
The Range = ws/2 = p(N - 1)/(T2 - T1) rad/s.
With the FFT N must be a power of 2 so it may not always be convenient to change N. Instead it may be easier to adjust the Range by changing the sampling interval.
eg parameters (10.0, 100, 0.814, 63.4, 256, 0, 256, 293.0, 65.5, 0.18)
eg parameters (10.0, 50, 0.688, 31.98, 256, 0, 256, 147.0, 65.5, 0.18)
A small sampling interval tends to produce a large range and a low resolution.
eg parameters (10.0, 4, 0.647, 3.15, 256, 0, 256, 12.0, 6.0, 0.18)
The range is ~320rad/s and the resolution is 2.5rad/s. Reducing the number of samples reduces the range but keeps the resolution the same (10.0, 4, 0.646, 3.12, 64, 0, 64, 47.0, 6.0, 0.8)

Changing Fn to 1 calculates the FFT of a square wave and Fn = 2 calculates the FFT of a triangle wave.
Because of the wide bandwidth of the square wave, a high range can be used. eg(6.66, 5, 0.016, 4.71, 256, 1, 256, 14.0, 10.0, 0.15)
Several aliased frequencies occur in the spectrum, eg 147.9rad/s = 341.3 - 29 * 6.66(193.4).
The magnitude of the lines in the spectrum occur at m = 5, 15, 25 etc. The magnitude of the fundamental *2/N = 1.2732 ~ 4/p as expected.

eg parameters (5.0, 21, 0.034, 26.32, 256, 2, 256, 319.0, 38.0, 0.24) show the spectrum of the triangle. Lines occur at freq 5.0rad/s, mag 0.81059 ~ 8/p2, freq 15.0rad/s, mag 0.0090073 ~ 8/9p2 etc. An aliased frequency occurs at ~ 25.92rad/s ~ (60.95 - 35.0)rad/s