cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

FFT dc offset question

Newbie

FFT dc offset question

When I take the FFT of cos(2*pi*0.1) + 2 using "fft" I get a 1 in the bin corresponding to 0.1Hz as expected but I get a 4 in the 0 bin and I expected a 2. Is it wrong to expect to see a value of 2 in the 0 bin (ie dc offset bin)? If so why? Thanks, Brett.

ps I attached the MC sheet...

4 REPLIES 4

Re: FFT dc offset question

It's an anomaly of the computation scheme. Using CFFT (as opposed to cfft) the amplitude of the oscillating components of the fft are multiplied by a factor of 2 (A = 2 |FFT|) except for the first term.

Because the sine waves swing both positive and negative, that factor of 2 applies to the oscillating magnitudes. But the 0 frequency (aka steady) term doesn't need that factor because it swings between value and zero. (Hewlett Packard spectrum analyzers had the same strange issue; I got burned a number of times!

Re: FFT dc offset question

Try the new algorithm for accurate fft analysis in the documents section of this Mathcad community.

See "FFT_Paradox_Improvement.xmcd"

Cheers

Re: FFT dc offset question

Brett Sandberg wrote:

When I take the FFT of cos(2*pi*0.1) + 2 using "fft" I get a 1 in the bin corresponding to 0.1Hz as expected but I get a 4 in the 0 bin and I expected a 2. Is it wrong to expect to see a value of 2 in the 0 bin (ie dc offset bin)? If so why? Thanks, Brett.

Actually, as an engineer, I would expect 2 in the f=0 bin (DC term) and 0.5 - not 1 - in the bin corresponding to f =0.1. The function x(t) = 2 + cos(2*pi*f*t) can be written as x(t) = 2 + 0.5*exp(-j*2*pi*f*t) + 0.5*exp(j*2*pi*f*t). The DC amplitude = 2, and the exponential amplitudes are both 0.5. Note that these are a factor of 4 apart, as as your results.

Fred commented that the DC term is exceptional, but this is an interpretation issue. The first term is not exceptional in any math of the various discrete Fourier transforms (DFT's) as implemented in Mathcad (at least in 11 and 14). All versions of the transforms give frequency components of the corresponding complex exponential terms, zero freq or otherwise. If you interpret nonzero frequency terms as real sinusoids, then you do need to fudge the FFT result by a factor of two, which also then scales the zero freq DC term by 2 - which is then incorrect.

The various transforms differ in the scaling factors and exponent signs used. In your sheet, you compensated for the scaling difference by adding a SQRT(Npts) term, but you also multiplied by 2, the latter being the reason that all components are 2x high based on complex exponential amplitudes. I must assume that you added tohe 2x scale to make the sinusoidal term amplitude come out correctly. IMHO, fudges like this tend to create more problems than they solve. Just use FFT (or CFFT), then no fudge to scaling is needed, and the results are the correct exponential amplitudes.

The capital case transforms FFT(power of 2 length only) and CFFT use a common transform definiton, with scaling and phase that most engineers expect.The lower case transforms fft(power of 2 length only) and cfft use a different transform definiton, but with opposite phase and scaling that is symmetric between forward and inverse transforms. This is nice mathematically, but not as useful for physical interpretation.

I use CFFT/ICFFT almost exclusively, since the speed advantage of FFT/IFFT is not worth the 2**n length and real only restriction for the array sizes I work with, and the definitions match what makes physical sense for an EE.

I added results from FFT and CFFT in the attached sheet for comparison, and changed the freq so the signal is periodic within the sample time, and has no spectral leakage.

Lou

Re: FFT dc offset question

The Mathcad Help files and linked worksheets explain the differences and details between the various types of fast Fourier transforms available in Mathcad.

I strongly suggest you read them.

FFTs can be tricky to implement correctly.

Announcements