[ncl-talk] a classic (slow) Fourier transform function

Dennis Shea shea at ucar.edu
Mon Sep 9 09:12:30 MDT 2019


[1] You should put 'print' statements in your code when testing.

[2] You did not initialize the a(k) and b(k) values for each 'k'

[3]
f = new((/ k,t /), typeof(in),getVarFillValue(in))

the 'k' and 't' are index values for the previous do loops. They are not
dimension sizes.

---
Attached is an old test code that should help you.
It produces results from '*ezfftf*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/ezfftf.shtml>'
You can comment the fortran section.
Please note, it is **your responsibility** to think about what is is being
done.

Please talk to a local person is knows the  Fourier Transform

On Mon, Sep 9, 2019 at 4:02 AM Md. Jalal Uddin via ncl-talk <
ncl-talk at ucar.edu> wrote:

> Hi all,
>
> The following Fourier Transformation Function gives me constant 0 value.
> Is there anyone who can guide me to solve this issue?
>
> undef ("fftwavenumber")
> function fftwavenumber (in[*]:numeric)
>
> local in,p,a,b,f,output
>
> begin
>     N=dimsizes(in)
>
>    if mod(N,2).eq.0 then
>          p=N/2     ; N even
>    else
>          p=(N-1)/2 ; N odd
>    end if
>
> pi=3.1416
>
> a = new((/ p /), typeof(in),getVarFillValue(in))
> b = new((/ p /), typeof(in),getVarFillValue(in))
>
> do k=0,p-1
>   do t=0,N-1
>       a(k) = (2/N)*( in(t)*cos(2*pi*k*t/N) )
>       b(k) = (2/N)*( in(t)*sin(2*pi*k*t/N) )
>   end do
> end do
>
> f = new((/ k,t /), typeof(in),getVarFillValue(in))
> output = new((/ t /), typeof(in),getVarFillValue(in))
>
> do t=0,N-1
>    do k=0,p-1
>         f(k,t) = a(k)*cos(2*pi*k*t/N)+ b(k)*sin(2*pi*k*t/N)
>    end do
>    output(t)=(sum(f(0,t)))  ; 0 used for Fourier Decomposition (wave
> number 1)
>    return(output)
> end do
> end
>
>
> --
> *Md. Jalal Uddin*
> MSc in Applied Meteorology
> Nanjing University of Information, Science and Technology, China
> B.Sc. in Disaster Management (Hons.)
> Patuakhali Science and Technology University, Bangladesh.
> Cell: +8613260859092, +8801792052662
> Web: www.dmjalal90.weebly.com
> Facebook: jalal.hossen.39
> LinkedIn: https://bd.linkedin.com/in/md-jalal-uddin-80a026b0
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> 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/20190909/2e0b168d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst_ezfftfb_so.ncl
Type: application/octet-stream
Size: 3699 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190909/2e0b168d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ftslow.f
Type: application/octet-stream
Size: 760 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190909/2e0b168d/attachment-0001.obj>


More information about the ncl-talk mailing list