%%%%%%%%DTFS MATRIX%%%%%%%%%%
close all;
clear all;

fvz=40;  
t=0:1/fvz:1; 
f=5;  
x=sin(2*pi*f*t);
figure(1);
stem(t,x);

 
vektorx=x';
X=vektorx(1:8,1);


N=8;
W=exp(-j*2*pi/N);
for k=0:N-1
  for n=0:N-1
  
  T(k+1,n+1)=W^(n*k);
  end
end

T;
DTFS=T*X;
rekonstrukcia=ifft(DTFS);
figure(2);
stem(0:1/40:7/40,rekonstrukcia);


%%%%%%%%%IFFT%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%
for n=0:N-1
  for k=0:N-1
  
  TI(k+1,n+1)=W^-(n*k);
  end
end
%%%%%%%%%%%%%%%%

IFFTmarix=(1/N)*TI*DTFS;
rekonstrukcia=ifft(DTFS);

Matica=[abs(IFFTmarix) abs(rekonstrukcia)]

Upravena=T*T';
Jednotkova=Upravena*1/8
BB=T(1:8,2)
figure(3);
stem(real(BB));

figure(4);
stem(abs(BB));

figure(5);
stem(imag(BB));

figure(6);
stem(angle(BB));

energia_cas=sum(sum(x*x'))
energia_spektrum=sum(sum(DTFS*DTFS'))