% Returns the array of FFT wavenumbers for a 2D array. The
% units of k are radians per pixel. This assumes that the
% pixels are square in coordinate space.
function [kx, ky, k] = k2d(arraysize)
% Inputs;
%  arraysize = result of size(array), that is an array [Nx, Ny].
% Outputs:
%  kx = An Nx by Ny array of x-components of the wavenumber.
%  ky = An Nx by Ny array of x-components of the wavenumber.
%  k = An Nx by Ny array of magnitudes of the wavenumber.

Nx = arraysize(1)
Ny = arraysize(2)

% construct the wavenumber array
kx = 2 * pi * [0:Nx/2, -ceil(Nx/2-1):-1]' * ones(1,Ny) / Nx;
ky = 2 * pi * ones(Nx,1) * [0:Ny/2, -ceil(Ny/2-1):-1] / Ny;
k = sqrt(kx.^2 + ky.^2);
