Mercurial > repos > public > sbplib
changeset 598:f6ada1719420 feature/grids
Add functions for calculating fourier transforms
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 14 Sep 2017 14:30:57 +0200 |
parents | 97b9a0023d38 |
children | 489bea7fc33f |
files | four.m fourInv.m |
diffstat | 2 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r 97b9a0023d38 -r f6ada1719420 four.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/four.m Thu Sep 14 14:30:57 2017 +0200 @@ -0,0 +1,19 @@ +% four returns the fourier transform u_hat of the function u and the frequencies w +function [w, u_hat] = four(x, u) + u_hat = fft(u); + + N = length(x); + L = x(end) - x(1); + + k = shift_k(0:N-1); + + u_hat = fftshift(u_hat); + + dw = 2*pi/L; + w = dw*k; +end + +function k_shifted = shift_k(k) + N = length(k); + k_shifted = [-floor(N/2):-1, 0, 1:ceil(N/2)-1]; +end