function [a, b, c, f0] = dfs(x,dt,N)

L = length(x);
T0 = L*dt;
f0 = 1/T0;
time = (0:(L-1))'*dt;

n = 1:N;
C0 = ones(L,1);
C = cos(2*pi*(time)*n*f0);
S = sin(2*pi*(time)*n*f0);

a0 = dt*C0'*x/T0;
a = 2*dt*C'*x/T0;
b = 2*dt*S'*x/T0;

c = [a0; sqrt(a.^2 + b.^2)];

xhat = a0 + C*a + S*b;

figure
plot(time,x)
hold
plot(time,xhat,'ro')

figure
stem((0:N)*f0,abs(c))





