# How to take the 3D fft of a vector?

**URL:** https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669
**Category:** Signal and Image Processing
**Tags:** fftw, 3d
**Created:** [August 12, 2022, 4:27pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669 "2022-08-12T16:27:13Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Nic\_Leblanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nic_leblanc/32/38748_2.png) [@Nic\_Leblanc](https://discourse.julialang.org/u/Nic_Leblanc)
#### Post date: [August 12, 2022, 4:27pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/1 "2022-08-12T16:27:13Z")

</div>

Hi all,

I was wondering if there were a way to take the 3D fft of a vector. I am obviously using FFTW for my direct fft calculations using plans but I’m not sure for it to calculate the 3D fft and not just a 1D fft. The dims parameter in the fft calculation in FFTW doesn’t seem to really be helpful, so any suggestion or help about how to calculate a 3D fft of a vector would be greatly appreciated.

Thanks and have a great day,  
Nic

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 12, 2022, 4:45pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/2 "2022-08-12T16:45:19Z")

</div>

> [@Nic\_Leblanc](#):
>
> my vector is stored like [x, y, z]

If you have data in a regular 3d grid, store it in a 3d array. If you have an irregular set of points in 3d, then what you want is something other than a [DFT](https://en.wikipedia.org/wiki/Discrete_Fourier_transform) (what an FFT computes), since the DFT is only defined on regular lattices.

---

<div class="post-metadata">

### Author: ![Nic\_Leblanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nic_leblanc/32/38748_2.png) [@Nic\_Leblanc](https://discourse.julialang.org/u/Nic_Leblanc)
#### Post date: [August 12, 2022, 4:50pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/3 "2022-08-12T16:50:19Z")

</div>

Firstly, thanks for the response.

Secondly, I was actually about to try and change that part because for the fft part of my program it’s actually not the case. I’m essentially trying to take the fft of a vector.  
Nic

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 12, 2022, 4:57pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/4 "2022-08-12T16:57:33Z")

</div>

> [@Nic\_Leblanc](#):
>
> I think working with vectors should mean I have regular lattices.

If you have a data on a regular 3d lattice, why can’t you store it in a 3d array `a`, with `a[i,j,k]` corresponding to the value at (x,y,z) = (i\Delta x, j\Delta y, k\Delta z)?

---

<div class="post-metadata">

### Author: ![Nic\_Leblanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nic_leblanc/32/38748_2.png) [@Nic\_Leblanc](https://discourse.julialang.org/u/Nic_Leblanc)
#### Post date: [August 12, 2022, 5:02pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/5 "2022-08-12T17:02:53Z")

</div>

Well, that’s where things kinda get weird because I’m doing these fft’s on projections of a 3D Green function, so I think everything might be stored as [x,y,z] but because of the projections (like G\_{xx} or G\_{yx}) I kinda question it. No matter what I think an fft using a plan should do the trick but I’m just not sure of the specifics because the basic one in FFTW does multidimensional fft’s with dims but I think this is different than a 3D fft.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 12, 2022, 5:55pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/6 "2022-08-12T17:55:35Z")

</div>

It sounds like you need to work out exactly what mathematical operation you want to perform before you ask how to perform it.

---

<div class="post-metadata">

### Author: ![Nic\_Leblanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nic_leblanc/32/38748_2.png) [@Nic\_Leblanc](https://discourse.julialang.org/u/Nic_Leblanc)
#### Post date: [August 12, 2022, 5:58pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/7 "2022-08-12T17:58:53Z")

</div>

Ok then… I don’t exactly understand what you mean. What more is needed than the mathematical operation is the 3D fft of a vector.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 12, 2022, 6:16pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/8 "2022-08-12T18:16:07Z")

</div>

> [@Nic\_Leblanc](#):
>
> 3D fft of a vector.

A 3d DFT is conventionally defined for a 3-index data set a\_{i,j,k} (a “3d array”) producing another 3-index result \hat{a}\_{i,j,k}. How do these inputs (and outputs) map to the contents of your “vector”? Write down a formula for what you want.

---

<div class="post-metadata">

### Author: ![Nic\_Leblanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nic_leblanc/32/38748_2.png) [@Nic\_Leblanc](https://discourse.julialang.org/u/Nic_Leblanc)
#### Post date: [August 12, 2022, 6:22pm UTC](https://discourse.julialang.org/t/how-to-take-the-3d-fft-of-a-vector/85669/9 "2022-08-12T18:22:44Z")

</div>

I’m not too sure honestly because the G\_{xx} I have been talking about is a 64x1 vector, so if we want to take the fft of it as an example, I don’t think a 3x1 element would be good. Maybe that’s where the confusion is. I was told that in my whole program things weren’t giving good results because of how my embedding code works (step 1 above) I needed to use 3D fft’s (not too sure why and I won’t be able to know until next Tuesday) and not the usual fft plan’s in FFTW.

I guess there’s no point in continuing this discussion since there’s seems to be some misunderstandings. Thanks for your time and take care,  
Nic
