0
$\begingroup$

I have a [29990, 1, 512, 1] dimension list. I want to do Fourier transform over all [ -- , 1,512,1] and skip the first dimension. I appreciate it if you could help me.

$\endgroup$
5
  • $\begingroup$ so each element of your list looks like {{{x1}, {x2},.., {x512}}}...is there a specific reason the elements look like this instead of {x1,x2,...,x512} (I.e. dimension [29990,512] list)? I feel like that would make this much easier to think about, but there may be a specific reason you have it formatted like this $\endgroup$
    – ydd
    Commented Jun 23, 2023 at 15:06
  • $\begingroup$ Please can you write some Mathematica code that generates the matrix, perhaps with fewer values, and then state exactly what you are trying to do. Is this just a problem of extracting the correct data from a nested list of lists? $\endgroup$
    – Hugh
    Commented Jun 23, 2023 at 15:18
  • $\begingroup$ This should give you 29990 Fourier Transforms of each sublist. Fourier[#[[2]]] & /@ list $\endgroup$
    – OpticsMan
    Commented Jun 23, 2023 at 15:31
  • $\begingroup$ Since two of the other dimensions are 1 it might be best to Map it to the remaining dimension. $\endgroup$ Commented Jun 23, 2023 at 15:42
  • $\begingroup$ @DanielLichtblau Thanks for your help. The problem is I am confused about using the map. Can you help me in more detail about how to skip F.T with map? $\endgroup$
    – Lohrasb
    Commented Jun 23, 2023 at 15:53

1 Answer 1

1
$\begingroup$

Here is a small example that I think might do what you want. First create a random array of appropriate rank.

SeedRandom[1234];
array = RandomReal[{-1, 1}, {2, 1, 6, 1}]

(* Out[11]= {{{{0.753217}, {0.0439285}, {-0.827553}, {-0.244174}, \
{-0.976711}, {0.854532}}}, {{{0.0875135}, {-0.0413367}, {-0.509302}, \
{0.519792}, {0.969986}, {-0.56591}}}} *)

This is what you do NOT want.

ft1 = Fourier[array]

(* Out[18]= {{{{0.0184704 + 0. I}, {0.399096 - 0.40404 I}, {0.474158 + 
     0.261025 I}, {-0.30879 + 0. I}, {0.474158 - 
     0.261025 I}, {0.399096 + 0.40404 I}}}, {{{-0.24754 + 
     0. I}, {0.956957 + 0.0733171 I}, {0.081221 - 
     0.740906 I}, {-0.675784 + 0. I}, {0.081221 + 
     0.740906 I}, {0.956957 - 0.0733171 I}}}} *)

I think this gives what you want.

ft2 = Map[Fourier, array]

(* Out[19]= {{{{-0.161977 + 0. I}, {0.958875 - 0.233857 I}, {0.392712 - 
     0.339327 I}, {-0.6962 + 0. I}, {0.392712 + 
     0.339327 I}, {0.958875 + 0.233857 I}}}, {{{0.188098 + 
     0. I}, {-0.394467 - 0.337543 I}, {0.277848 + 
     0.708472 I}, {0.259504 + 0. I}, {0.277848 - 
     0.708472 I}, {-0.394467 + 0.337543 I}}}} *)

Or as I mentioned you could map it to the level at which it's needed.

ft3 = Map[Fourier, array, {2}]

(* Out[20]= {{{{-0.161977 + 0. I}, {0.958875 - 0.233857 I}, {0.392712 - 
     0.339327 I}, {-0.6962 + 0. I}, {0.392712 + 
     0.339327 I}, {0.958875 + 0.233857 I}}}, {{{0.188098 + 
     0. I}, {-0.394467 - 0.337543 I}, {0.277848 + 
     0.708472 I}, {0.259504 + 0. I}, {0.277848 - 
     0.708472 I}, {-0.394467 + 0.337543 I}}}} *)

We can recover the original array by mapping InverseFourier in the same way.

ift2 = Map[InverseFourier, ft2]

(* Out[21]= {{{{0.753217}, {0.0439285}, {-0.827553}, {-0.244174}, \
{-0.976711}, {0.854532}}}, {{{0.0875135}, {-0.0413367}, {-0.509302}, \
{0.519792}, {0.969986}, {-0.56591}}}} *)

I do not know for certain if this is what's wanted, but it's how I interpret the question. If this is wrong please follow up and someone (maybe even me, who knows?) will give a better answer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.