# Nyquist FFT Tutorial Help Classic List Threaded 3 messages Reply | Threaded
Open this post in threaded view
|

## Nyquist FFT Tutorial Help

 I'm following the Nyquist FFT Tutorial. But I'm getting a slightly different result than expected. The output from `(fft-test)` should have -1 in the 9th array element, but I'm getting -16:     > (fft-test)     fft-test : (SEND FFT-ITER :NEXT) = #(3.28013e-15 2.79029e-15 1.15578e-15 2.79029e 15 2.79029e-15 2.79029e-15 6.73636e-15 1.68587e-07 -16 2.79029e-15 -6.73636e-15 2.79029e-15 -2.79029e-15 2.79029e-15 -1.15578e-15 3.28013e-15 -0 2.79029e-15 1.15578e-15 2.79029e-15 2.79029e-15 2.79029e-15 6.73636e-15 -1.68587e-07 3.4366e-07 2.79029e-15 -6.73636e-15 2.79029e-15 -2.79029e-15 2.79029e-15 -1.15578e-15 3.28013e-15) I copied and pasted the code from the tutorial, so I doubt there's a mistake on my part. Is -16 the correct result? Also, the tutorial describes the FFT array as:  -  the DC component goes in array element 0  -  the Cosine part is in elements 2i - 1  -  the Sine part is in elements 2i  -  the Nyquist frequency component is in the last element I'm not clear what the meaning of "cosine part" and "sine part" are. The array as shown above doesn't seem like it could be the coefficients for SUM(Asin(2πnt) + Bcos(2πnt)) where n is the frequency.  Can anyone please clarify this for me? Thanks for your assistance!
Reply | Threaded
Open this post in threaded view
|

## Re: Nyquist FFT Tutorial Help

 Hi Mark, You are right. I don't know how the -1 got in there (maybe a typo) because I get -16 as well. I added some text to my copy of the Nyquist FFT Tutorial as follows, which might answer other questions: Running this prints an array of nearly-zero values except for the 9th element (index 8), which is -16. (In an ideal world, all other values would be exactly zero, but because numerical computation has limited precision, you may see some ugly values like -1.15578e-15. The "e-15" part means 10-to-the-minus-15 power, or 0.000000000000001, which is at least pretty close to zero.) The layout is as follows (remember that the Fourier Transform analyzes a signal as the sum of sines and cosines): the DC component goes in array element 0. The DC component is just the coefficient for the zero-frequency cosine component. Since cosine at zero frequency is equal to 1 everywhere, this is just the sum of all the samples. In electrical terms, alternating current (AC) averages to zero, and any non-zero average is the direct current (DC) part. Note that sine of zero is zero, so there is no zero-frequency sine term. the Cosine part is in elements 2i - 1. Cosine part means the real coefficients of the cosines at various frequencies. the Sine part is in elements 2i. Sine part means the real coefficients of the sines at various frequencies. the Nyquist frequency component is in the last element. The Nyquist frequency component is the coefficient for the cosine component at half the sampling rate (which is also called the Nyquist frequency). Note that at the Nyquist frequency, samples of sine would be taken at the angles of 0 and PI, where sine is zero, so there is no Nyquist frequency sine term. The output should look like this: ```> (load "fft1.lsp") ;loading "fft1.lsp" ;fft-test : (SEND FFT-ITER :NEXT) = ; #(4.89859e-16 0 0 0 0 0 0 2.38419e-07 ; -16 0 0 0 0 0 0 4.89859e-16 ; -0 0 0 0 0 0 0 -2.38419e-07 ; 0 0 0 0 0 0 0 4.89859e-16) ;T ;> ``` Thus, the element at index 8 is the 4th Sine component, indicating a 4th harmonic as expected. Why is the number -16 rather than -32 or -1? This is just how the FFT is defined. And why -16 rather than +16. Again, if you look closely at the definition, you'll find a minus sign either in front of the sine term or in the complex exponential. While these may not seem to be exactly coefficients of sines and cosines, the FFT and IFFT are carefully defined to be inverses of one another.
Reply | Threaded
Open this post in threaded view
|

## Re: Nyquist FFT Tutorial Help

 Thank you, it's much clearer now.