xdel(winsid())
clear;
clc

// aux
  function xlim (lo_hi)
       a = gca();
       a.tight_limits='on';
       db = a.data_bounds; 
       a.data_bounds = [lo_hi(1), db(1,2); lo_hi(2), db(2,2)]
   endfunction

// time and function
    F_sample = 1000;
    t = 0:(1/F_sample):2;
    x = 1*cos(2*%pi*t);

// calculating FFT
    n_samples = length(t);
    ff = F_sample*(0:(n_samples/2))/n_samples;
    n = size(ff,'*');   

    x_fft = abs(fft(x));   

// plotting below
   subplot(1,2,1);
       plot(t,x,'r');
       xlabel('t, s');
       ylabel('u, V');

   subplot(1,2,2)
        plot2d3(ff(1:n), x_fft(1:n)*2/n_samples);
        g = gca(); g.children(1).children(1).thickness = 4;
        xlim([0 10])
        xgrid
        xlabel('f, Hz');
        ylabel('FFT_x, V');
