Re: fft different results by ezzfft and cfft

From: Sergio Abarca <abarcas_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 22 2010 - 12:50:52 MDT

Hi Dennis,

Thank you very much for your answers. I understand the positive/negative frequency difference between ezfft and cfftf.

However I am still puzzled by the normalization. While the ezfftf coefficient of wavenumber 0 (the average) differs by a factor of "N" (number of elements in the original array) with the coefficient of cfftf, the rest of the coefficients (wave number 1 and larger) differ by a factor of "N/2". Shouldn't the normalization be the same for all wavenumbers?

Sergio

On Mar 22, 2010, at 11:29 AM, Dennis Shea wrote:

> I think the documentation covers this. See the "Description" section
> and Example 1.
>
> ==
> The cfftf function returns the same information as the forward real discrete fourier transform, ezfftf. The returned information is in a different form, in particular, the representation of frequency. The real forward transform pertains to the positive frequency portion of the spectrum while the complex forward transform includes positive and negative frequencies. The following is a slightly edited excerpt from the Smith reference.
> [snip] ...
>
> Also, see:
> http://www.ncl.ucar.edu/Document/Functions/Built-in/cfftf_frq_reorder.shtml
>
> This further explains some information.
>
> ===
>
> Which to use ... it depends on what it is
> you want to do:
> traveling waves ... cfftf
> power ... ezfft
>
> Good luck
>
>
> On 03/22/2010 09:56 AM, Sergio Abarca wrote:
>>
>> Hi all,
>>
>> I am doing a fft and I am puzzled about the output of ezzfft and cfftf.
>> I use the NCL example (given in the ezfft function) of a sequence "x"
>> (below) and do the fourier transform using both ezzfft and cfftf. When
>> using cfftf I add an imaginary part =0. The coefficients differ from
>> each other by a factor of N (the number of elements in the "x" array, in
>> this case 24), for the wave number "0" coefficient and a factor of N/2,
>> for the rest of the coefficients.
>>
>> Any idea of why? And, which one should I use? I got into this because in
>> using ezzfft the difference in magnitude between wavenumber 0 and
>> wavenumber 1 in the (hurricane) data I am using seemed abnormally high,
>> between 2 and 3 orders of magnitude, when I expected it to be between a
>> factor of 2 and an order of magnitude.
>>
>> Thanks,
>> Sergio
>>
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> begin
>> x = (/ 1002, 1017, 1018, 1020, 1018, 1027, \
>> 1028, 1030, 1012, 1012, 982, 1012, \
>> 1001, 996, 995, 1011, 1027, 1025, \
>> 1030, 1016, 996, 1006, 1002, 982 /)
>> cfReal = ezfftf (x)
>> cfComplex = cfftf (x,0,0)
>> print(cfReal)
>> print(cfComplex)
>> end
>>
>>
>> Here is the output:
>>
>> Variable: cfReal
>> Type: float
>> Total Size: 96 bytes
>> 24 values
>> Number of Dimensions: 2
>> Dimensions and sizes: [2] x [12]
>> Coordinates:
>> Number Of Attributes: 2
>> npts : 24
>> xbar : 1011.042
>> (0,0) 1.338438
>> (0,1) -13.48403
>> (0,2) 2.166667
>> (0,3) 3.291667
>> (0,4) -5.398408
>> (0,5) 0.08333334
>> (0,6) -2.724774
>> (0,7) 2.708333
>> (0,8) 2.166667
>> (0,9) -0.3493074
>> (0,10) 2.951411
>> (0,11) -1.791667
>> (1,0) 3.73528
>> (1,1) 6.88814
>> (1,2) 3.362945
>> (1,3) 0.3608439
>> (1,4) 3.019545
>> (1,5) 1
>> (1,6) 4.113242
>> (1,7) 1.515544
>> (1,8) 2.529612
>> (1,9) -2.63814
>> (1,10) 2.808251
>> (1,11) 0
>>
>>
>> Variable: cfComplex
>> Type: float
>> Total Size: 192 bytes
>> 48 values
>> Number of Dimensions: 2
>> Dimensions and sizes: [2] x [24]
>> Coordinates:
>> Number Of Attributes: 2
>> npts : 24
>> frq : <ARRAY of 24 elements>
>> (0,0) 24265
>> (0,1) 16.06125
>> (0,2) -161.8083
>> (0,3) 26
>> (0,4) 39.5
>> (0,5) -64.78089
>> (0,6) 1
>> (0,7) -32.69729
>> (0,8) 32.5
>> (0,9) 26
>> (0,10) -4.191688
>> (0,11) 35.41693
>> (0,12) -43
>> (0,13) 35.41693
>> (0,14) -4.191688
>> (0,15) 26
>> (0,16) 32.5
>> (0,17) -32.69729
>> (0,18) 1
>> (0,19) -64.78089
>> (0,20) 39.5
>> (0,21) 26
>> (0,22) -161.8083
>> (0,23) 16.06125
>> (1,0) 0
>> (1,1) -44.82336
>> (1,2) -82.65768
>> (1,3) -40.35534
>> (1,4) -4.330127
>> (1,5) -36.23454
>> (1,6) -12
>> (1,7) -49.3589
>> (1,8) -18.18653
>> (1,9) -30.35534
>> (1,10) 31.65768
>> (1,11) -33.69901
>> (1,12) 0
>> (1,13) 33.69901
>> (1,14) -31.65768
>> (1,15) 30.35534
>> (1,16) 18.18653
>> (1,17) 49.3589
>> (1,18) 12
>> (1,19) 36.23454
>> (1,20) 4.330127
>> (1,21) 40.35534
>> (1,22) 82.65768
>> (1,23) 44.82336
>>
>>
>>
>>
>>
>>
>>
>>
>> Sergio Abarca
>> Graduate Student
>> UCLA Dept of Atmospheric & Oceanic Sciences
>> 7127 Math Sciences Building
>> 405 Hilgard Avenue
>> Los Angeles, CA 90095-1565
>> (310) 206.3185
>> (310) 206.5219 fax
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> --
> ======================================================
> Dennis J. Shea tel: 303-497-1361 |
> P.O. Box 3000 fax: 303-497-1333 |
> Climate Analysis Section |
> Climate & Global Dynamics Div. |
> National Center for Atmospheric Research |
> Boulder, CO 80307 |
> USA email: shea 'at' ucar.edu |
> ======================================================

Sergio Abarca
Graduate Student
UCLA Dept of Atmospheric & Oceanic Sciences
7127 Math Sciences Building
405 Hilgard Avenue
Los Angeles, CA 90095-1565
(310) 206.3185
(310) 206.5219 fax

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 22 12:48:21 2010

This archive was generated by hypermail 2.1.8 : Sat Mar 27 2010 - 07:18:15 MDT