Ocean Water math The fft-based representation of a wave height ﬁeld expresses the wave height $h(x, t)$ at the horizontal position $x = (x, z)$ as the sum of sinusoids with complex, time-dependent amplitudes:

where $t$ is the time and $k$ is a two-dimensional vector with components $k = (k_x, k_z)$, $k_x = 2πn/L_x$, $k_z = 2πm/Lz$, and $n$ and $m$ are integers with bounds $−N/2 ≤ n < N/2$ and $−M/2 ≤ m < M/2$. The fft process generates the height ﬁeld at discrete points $x = (nLx/N,mLz/M)$. The value at other points can also be obtained by switching to a discrete fourier transform, but under many circumstances this is unnecessary and is not
applied here. The height amplitude Fourier components, $\tilde{h}(k, t)$, determine the structure of the surface.
Another version of the same formula:

Here $X$ is a horizontal position of a point whose height we are evaluating. The wave vector $K$ is a vector pointing in the direction of travel of the given wave, with a magnitude k dependent on the length of the wave (l):
$$k = 2p /\lambda$$
And the value of $h (K,t)$ is a complex number representing both amplitude and phase of wave $K$ at time $t$. Because we are using discrete Fourier transformation, there are only a finite number of waves and positions that enters our equations. If $s$ is dimension of the heightfield we animate, and $r$ is the resolution of the grid, then we can write:
$$K = (kx,kz) = (2pn / s,2pm /s)$$
where $n$ and $m$ are integers in bounds $–r/2 < n,m < r/2$. Note that for FFT, $r$ must be power of two.
Questions:


*

*How many $k$ do I need? Does it mean, that $k$ takes all possible values (on the grid I mean)?

*And what do I get as a result - complex number that shows height and (what?) in concrete point so I need make computations for all points on the grid or the whole grid itself?

*How to apply fft to this formula?
 A: It isn't totally clear to me what you are trying to do, mostly because I am not sure what problem you are trying to solve.  I suspect you are looking for solutions to some wave / Laplacian equation, but without more specific details I can't comment very precisely.  Nonetheless, I think I can perhaps help explain some of your questions.  But first, let me recommend the following text book on spectral methods for engineers:
http://www-personal.umich.edu/~jpboyd/BOOK_Spectral2000.html
Now I will try to answer your questions in order:
1  It really depends on what you want to do, but if you have a real function on a grid of n x m numbers, then you need only n/2 x m/2 complex coefficients to represent by conjugate symmetry.  This follows from the observation that for real f,
$ \hat{f}(\omega) = \overline{ \hat{f}(-\omega) }$
I think MATLAB has a special function called rfft that will compute this for you automatically.  For a more specific answer you will probably need to analyze whatever PDE you are trying to solve and then figure out the number of coefficients you will need to get some desired accuracy.
2  In the Fourier domain, the magnitude of the kth coefficient determines the amplitude of the wave, and the arg value determines the phase.  You can compute these using the square roots and arctangents respectively.
3  How you apply the FFT once again depends on what you are trying to do.  Assuming you are trying to solve a PDE, what you basically will do is try to convert your PDE into a Fourier multiplier, then use it to solve a system of ODEs in order to get a solution to your final problem.  Constructing the multiplier is usually straightforward and makes use of the nice fact that:
$ \mathcal{F}( \partial f )(\omega) = - i \omega \hat{f}(\omega) $
Though in the discrete case you do need to be a bit careful how you do interpolation.  A common strategy is to use Shannon/Whittaker interpolation (aka sinc functions).  You should read Boyd's book since he talks about them at some length.  Once this is done, solving the system typically reduces to inverting a banded/diagonal matrix which is easy to do numerically.
Hope this helps, but I can't really be much more specific until you give me an actual problem to work with.
