I have function of two variables which was calculated numerically for grid {x,y}. Then I calculate numerical Fourier trasform of my function and obtain array of Fourier transform values. How can I find the array {u,v,f[u,v]}, where u and v Fourier coordinates and f[u,v] is obtained values of Fourier transform, i.e. how can I create frequency array {u,v}?


1 Answer 1


You need your data in a 2D array form, but I've also shown how to convert a flat list to this form. You can use ImagePeriodogram to get the image, or use Fourier directly, or use ImagePeriodogramArray to get the image 2D array data:

(* make up some fake data in 2D grid form *)
f[x_, y_] := Sin[4 π x y^2] - y*Cos[6 π x]
data = Table[f[x, y], {y, 0, 1, .01}, {x, 0, 1, 0.01}];


ft = Fourier[data]; (* note you may want to look into FourierParameters *)
(* to get ft in a flat list of {u,v,ft} where u,v are integers we can do: *)
ftflat = Flatten[MapIndexed[Append[#2,#1],ft,{2}],1];

(* see also ImagePeriodogramArray *)

(* if your data are in a flat list of the form {{x,y,f[x,y]}, {x,y,f[x,y]}, ... } *)
(* make up some fake data first *)
dataFlat = Flatten[Table[{x, y, f[x, y]}, {y, 0, 1, .01}, {x, 0, 1, 0.01}], 1];
(* convert dataFlat to the appropriate 2D array form  *)
dataConverted = Map[Last, GatherBy[dataFlat, #[[2]] &], {2}];

fourier image

See also FourierDCT if you want a discrete cosine transform:

MatrixPlot[FourierDCT[data], ImageSize -> Medium]

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.