# [ncl-talk] ezfftf (NCL vs. Matlab)

Maria Gehne - NOAA Affiliate maria.gehne at noaa.gov
Wed Apr 15 10:20:15 MDT 2015

```Hi Thomas,

It is actually the imaginary part of the FFT in matlab that has opposite
sign. If you compute example 1 on the NCL ezfftf page
https://www.ncl.ucar.edu/Document/Functions/Built-in/ezfftf.shtml
in Matlab you can see that. I attached a Matlab script that shows this.

Unlike NCL Matlab returns the same number of coefficients as input data N (
NCL only returns half N/2). The first coefficient in the Matlab FFT is the
sum of all elements, divide by N and you get the mean. The next N/2-1
entries are the same as the N/2-1 last entries, except that they are
complex conjugates. So depending on which direction you read from you will
either get the same sign for the imaginary part as you get in NCL or the
opposite.

Also the magnitudes returned by Matlab are not the same automatically. You
need to divide the results by N/2 to match the NCL result.

Hope this helps,
Maria

On Tue, Apr 14, 2015 at 9:47 AM, Thomas Tobian <thomastobian at gmail.com>
wrote:

> Dear NCL developers,
>
> I recently worked a lot with Fourier analysis. Once, I compared the
> results of forward fft function in ncl and matlab. Please find attached, an
> example of FFT product for the meridional wind (V).  So in general, the
> amplitudes and imaginary coefs produced by NCL and MATLAB are the same but
> the real part is of opposite sign. Any idea why? What is the process to use
> for the complex parts in NCL to convert back to longitude projection ? is
> there any big differences if the data has longitude -180 to 180 VS. 0-360?
>
> Cheers,
> Thomas
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150415/0c29e073/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fft_ex1.m
Type: application/octet-stream
Size: 1098 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150415/0c29e073/attachment.obj
```