diff four.m @ 704:111fcbcff2e9 feature/optim

merg with featuew grids
author Ylva Rydin <ylva.rydin@telia.com>
date Fri, 03 Nov 2017 10:53:15 +0100
parents f6ada1719420
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/four.m	Fri Nov 03 10:53:15 2017 +0100
@@ -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