%priklad na Suvis - FR/FT
clear all;
close all;
axis equal
subplot(5,1,1)

Tsig=2;
%Tsig=4;


A=3;
Tbox=1;


%kreslenie signalu v čase
plot_points=100;
tn=0:Tsig/plot_points:Tsig;
syms ts;
mysig_n=zeros(1,plot_points+1);
mysig_n(1:Tbox/Tsig*plot_points)=A;
mysig_s=A
plot(tn,mysig_n);
grid on;


%vykreslenie prvych N harmonickych FR
N=3
n=-N:N;
product=mysig_s*exp(-i*n*2*pi/Tsig*ts)
cn=1/Tsig*eval(int(product,ts,0,Tbox));
subplot(5,1,2);
%stem(n,abs(cn))
stem(n/Tsig,abs(cn))
grid on;
subplot(5,1,3);
stem(n/Tsig,angle(cn))
grid on;

%Fourierova transformácia vykreslime hust x hustejsie
hust=10
f1=1/Tsig/hust
NFT=N*hust
f1_nft=(-NFT:NFT)*f1
mysize=size(f1_nft,2)
x_nft=zeros(mysize,1)
for myi=1:mysize
   my_f=2*pi*f1_nft(myi)
   myprod=A*exp(-i*my_f*ts);
   x_nft(myi)=eval(int(myprod,ts,0,Tbox));
end
subplot(5,1,4);
stem(f1_nft,abs(x_nft))
grid on;
subplot(5,1,5);
stem(f1_nft,angle(x_nft))
grid on;