
% provede derivaci Gauss. fce

function sfa2_2


L=10, N=32
del=L/N;
delf=1/N/del;
x=(-N/2:N/2-1)*del; 
f=(-N/2:N/2-1)/N/del;


% fce exp(-x^2)
g=exp(-x.*x);
figure(1)
plot(x,g,"*")
xlim([-6,6])
ylim([-0.1,1.1])

% derivace vyssiho radu

% pomoci FT
g2=derivace(g,del,8);

%standardni
g3=diff(g,8)/del^8;
%vraceni na puvodni delku
g3=[zeros(1,4),g3,zeros(1,4)]; 

%analyticka
xx=linspace(x(1),x(end),512);
g4=16*exp(-xx.^2).*(16*xx.^8-224*xx.^6+840*xx.^4-840*xx.^2+105);

figure(2)
plot(xx,g4,"-b",x,g3,"*b")
axis('tight')
xlim([-6,6])
ylim([-1500,2000])
title("diference")


figure(3)
plot(xx,g4,"-b",x,real(g2),"*b")
axis('tight')
xlim([-6,6])
ylim([-1500,2000])
title("FT")




endfunction



function G=ft(g,del)
 G=fftshift(fft(ifftshift(g)))*del;
end


function g=ift(G,delf)
 g=fftshift(ifft(ifftshift(G)))*delf*length(G);
end


function der=derivace(g,del,n)
N=length(g); 
delf=1/(N*del);
f=(-N/2:N/2-1)*delf; 
der=ift((i*2*pi*f).^n.*ft(g,del),delf);
endfunction
