# Dfft not working as spected

**URL:** <https://community.freefem.org/t/dfft-not-working-as-spected/2491>\
**Category:** General Discussion\
**Created:** [May 25, 2023, 10:04am UTC](https://community.freefem.org/t/dfft-not-working-as-spected/2491 "2023-05-25T10:04:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abanderam](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/abanderam/32/1258_2.png) [@abanderam](https://community.freefem.org/u/abanderam)\
**Post date:** [May 25, 2023, 10:04am UTC](https://community.freefem.org/t/dfft-not-working-as-spected/2491/1 "2023-05-25T10:04:14Z")

</div>

I am trying to obtain the discrete fourier transform of a function in an unit square, but the results i obtain with dfft package are different with the ones that I obtain using a Vandermode matrix. I provide a minimal code

[Example.edp](https://community.freefem.org/uploads/short-url/iumR2JdyAVMLOQssR3JhY5dI4Ll.edp) (1.9 KB)

Can anyone provide me a way to compute the fourier transform with dfft so I obtain the good results?  
Please, let me know if I’m doing something the wrong way.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 25, 2023, 10:10am UTC](https://community.freefem.org/t/dfft-not-working-as-spected/2491/2 "2023-05-25T10:10:49Z")

</div>

Can you include the file as an attachment? The pasted code is missing a lot  
of characters, mostly asterisks AFAICT. Thanks.

---

<div class="post-metadata">

**Author:** ![abanderam](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/abanderam/32/1258_2.png) [@abanderam](https://community.freefem.org/u/abanderam)\
**Post date:** [May 25, 2023, 11:15am UTC](https://community.freefem.org/t/dfft-not-working-as-spected/2491/3 "2023-05-25T11:15:37Z")

</div>

You have now the minimal working example in the description. Thanks

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 25, 2023, 12:40pm UTC](https://community.freefem.org/t/dfft-not-working-as-spected/2491/4 "2023-05-25T12:40:37Z")

</div>

This looks like it is just an issue of coordinate offsets. See the attached  
with an impulse spectrum areound (0,0). Your method interprets  
this as high frequency whiile FFT apparently thinks it is DC. Your specturm  
despite apparently being singular doesn’t vary that fast and looks like  
DC in spectral domain AFAICT. Iguess I would play with the simple spectra  
and see if this makes sense.

[forum19.edp](https://community.freefem.org/uploads/short-url/rEJFxKLhCubh83N1ZxbzoDHomQU.edp) (2.1 KB)

---

<div class="post-metadata">

**Author:** ![abanderam](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/abanderam/32/1258_2.png) [@abanderam](https://community.freefem.org/u/abanderam)\
**Post date:** [May 26, 2023, 1:31pm UTC](https://community.freefem.org/t/dfft-not-working-as-spected/2491/5 "2023-05-26T13:31:09Z")

</div>

Thank you for your response.

However, that doesn’t respond my question of how making dfft command to work as I expect. Using Vandermonde matrix is a bit slower and I intend to move to 3D in a while so performing the fourier transform with dfft correctly will save a lot of time and memory.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 26, 2023, 1:42pm UTC](https://community.freefem.org/t/dfft-not-working-as-spected/2491/6 "2023-05-26T13:42:33Z")

</div>

I’m not sure offhand how to do that but you would have to dig into the ff or ffttw docs  
to see but if you really want to its just a coordinate transform. If you look at your  
matrix, the DC component appears to xform to the origin while the fftw puts  
it in the center giving you negative instead of aliased frequencies which is often  
more convienient. I guess you could come up with a transformation matrix or a simple  
loop to move th e quadrants around although it may also be worth trying to determin  
if you want negative instead of aliased frequencies.
