% Lösung DFT - SINUS

fs  = 1000;
k   = 0:1:15;
x_k = [1 , 0.707 , 0 , -0.707 , -1 , -0.707 , 0 , 0.707 , 1 , 0.707 , 0 , -0.707 , -1 , -0.707 ,0, 0.707];
N   = length(x_k); 

subplot(2,1,1);
stem(k, x_k);
xlabel('k'); ylabel('x(k)'); grid on;

Xcomp = zeros(1,16);
Xmag  = zeros(1,16);

for m=0:1:15
    for n=1:1:16
        Xcomp(m+1) = Xcomp(m+1) + x_k(n) * (cos(2*pi*n*m/N) - i*sin(2*pi*n*m/N));
    end
    
    Xmag(m+1) = abs(Xcomp(m+1));
end

f = (0:1:(N-1))/N*fs;

k = (0:1:(N-1));

subplot(2,1,2);
stem(k, Xmag);
xlabel('k'); ylabel('X(k)'); grid on;