Ocean FFT in Matlab

I was always amazed how fantastic was the Ocean simulation from nVidia (Its a part of the CUDA toolkit). I did not understand how was it working, so I searched and in fact found many examples on the internet. All of the ocean wave animations use the statistics model with philips spectrum and IFFT. Everything is described in Jerry Tessendorf’s work  –Simulating Ocean Waterfrom 2002.

Since this topic can be found everywhere on the web, I willl not talk about it much. An interested reader can always open the pdf and look for details there. The main reason I decided to write about this topic is in fact the lack of code available for begginers (Who are not familiar with CUDA/C++ …). Thus I have created a small script in Matlab that can be used to generate a moving ocean surface.

The script works just fine. Depending on your machine, you will have to change the FFT resolution to a suitable level (128 would be fine for most situations – a default size of 256 is defined in the code ). Since the animation uses a different colormap, a “cold” script is included (Not written by myself). Feel free to play with anything.  I would love to add the “Choppy wave effect” someday, but I am not sure how to do it right now in matlab, so I may come back later with a diffent script :)

PS: You can try to create the choppy efect by combining more spectrums  (It will never have sharp edges, but it may look more realistic anyway :) ). Matlab users can try to accelerate speed of the code by using Matlab “GPU Array” functions ;)