Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (29 sloc) 804 Bytes
% Disktrete Fouriertransformation
function [kp, Ak, Bk] = DFT(t,f)
% Calculate the discrete fourier transformation
n = floor(length(f)/2);
T = t(2*n)-t(1);
dt = T/(2*n-1);
omega = 2*pi/T;
% Initialize output variables
kp = [0:n];
Ak = zeros(1,n+1);
Bk = zeros(1,n+1);
% Calculate A_0 and A_n
Ak(1) = sum(f(1:2*n))/(2*n);
for i = 1:2*n
Ak(n+1) = Ak(n+1)+f(i)*cos(n*omega*t(i));
end
Ak(n+1) = Ak(n+1)/(2*n);
% Calculate all the other coefficients
for k=2:n
Ak(k) = 0;
Bk(k) = 0;
for i=1:2*n
Ak(k) = Ak(k)+f(i)*cos((k-1)*omega*t(i));
Bk(k) = Bk(k)+f(i)*sin((k-1)*omega*t(i));
end
Ak(k) = Ak(k)/n;
Bk(k) = Bk(k)/n;
end
end
You can’t perform that action at this time.