# 2D DFFT: wrong order along the second dimension

**URL:** <https://discourse.julialang.org/t/2d-dfft-wrong-order-along-the-second-dimension/74869>\
**Category:** Numerics\
**Tags:** fftw\
**Created:** [January 19, 2022, 3:28pm UTC](https://discourse.julialang.org/t/2d-dfft-wrong-order-along-the-second-dimension/74869 "2022-01-19T15:28:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [January 19, 2022, 3:28pm UTC](https://discourse.julialang.org/t/2d-dfft-wrong-order-along-the-second-dimension/74869/1 "2022-01-19T15:28:24Z")

</div>

Let us consider a 2D discrete fast Fourier transform of a separable function:

```julia
using FFTW
xs = collect(0.0:0.1:0.9)
ys = xs
zs = cos.(xs).^2*sin.(ys')
fzs = fft(zs)

```

The result of 2D DFF transform of `zs` is

 ![fzs](https://global.discourse-cdn.com/julialang/original/3X/4/0/407af96ee754b9765fcc74073d8f0d4b73e4c446.png)

On the other hand, since the function is separable, we can compute 2D Fourier transform as a product of two 1D Fourier transforms:

```julia
fzs2 = fft(cos.(xs).^2)*fft(sin.(ys))'

```

This gives us

 ![fzs2](https://global.discourse-cdn.com/julialang/original/3X/4/e/4eaa9083ccd0c4220feefe1caa151025b3431df2.png)

As we see, the two results do not exactly coincide. However, if we permute the columns of `fzs2`, we actually obtain `fzs`: we need to permute columns 2 and 10, 3 and 9, etc. If one does fft shift, it corresponds to exchanging columns corresponding to ky and -ky.

**Can anyone explain why this happens?**

---

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [January 19, 2022, 4:14pm UTC](https://discourse.julialang.org/t/2d-dfft-wrong-order-along-the-second-dimension/74869/2 "2022-01-19T16:14:36Z")

</div>

> [@Gregstrq](#):
>
> `fzs2 = fft(cos.(xs).^2)*fft(sin.(ys))'`

you need `transpose(fft(sin.(ys)))`, what you are doing is the `adjoint` which is the transpose, complex conjugated. You don’t see the effect on `ys` since it was real.
