clear; close all
figure('units','pixels','position',[0 0 1920 1080],'ToolBar','none');
vid = VideoWriter('FTs_explained6.mp4','MPEG-4');
vid.FrameRate = 30;    % Default 30
vid.Quality = 100;    % Default 75
open(vid);
set(0,'defaultfigurecolor',[1 1 1]);
myBlue = [0.5 0.55 0.88];
myBlue2 = [0.61 0.67 0.92];
pos1 = [0.1 0.7 0.8 0.28];
pos2 = [0.1 0.1 0.4 0.5];
pos3 = [0.55 0.1 0.4 0.5];

omegamax = 8*2*pi; 
omega = -omegamax:0.00126:omegamax;  
y = (sin(omega/2))./(omega/2);

jj = 0; 

timeFacMax = 50; 
for timeFac = 0.05:0.1:timeFacMax % Change Euler circle rotation frequency 
    jj = jj+1; 
    hold off
    subplot('position',pos1); % Plot of g(x) 
    plot(omega,y,'b','LineWidth', 2.0)
    hold on

    xlim([-omegamax-0.00001 omegamax+0.00001]);
    ylim([-0.25 1.1]*max(y(:)));
    set(gca,'fontsize',18);
    set(gca,'linewidth',2);
    set(gca,'box','off')
    ax = gca;

    ax.XAxisLocation = 'origin';
    ax.YAxisLocation = 'origin';
    ax.YTickLabel = ' '; 
    xlabel('Angular frequency [rad]','Position',[8*pi -0.25*max(y(:))],'HorizontalAlignment','center'); 
    ylabel('Amplitude'); 
    xticks(-16*pi:4*pi:16*pi);
    xticklabels({'-16\pi','-12\pi','-8\pi','-4\pi',' ','4\pi','8\pi','12\pi','16\pi'});
    hold off
    
    subplot('position',pos2); % Plot of g(x) on Euler circle 
    time = linspace(0,2,size(omega,2)); 
    time2 = timeFac*time; 
    rho = y;
%   Only show intensity = |Re|^2 + |Im|^2  
    absIntegral(jj) = ((sum(cos(time2).*rho)).^2 + (sum(sin(time2).*rho)).^2); 
    timeRatio(jj) = timeFac; 
    polarplot(time2,rho,'b','LineWidth', 2.0)
    hold on 
    rlim([0 1.1]*max(y(:)))
    thetaticks(0:45:315);
    thetaticklabels({'1',' ','i',' ','-1',' ','-i',' '});
    rticks(0:0.25:1);
    rticklabels({' ',' ',' ',' ',' '});
    set(gca,'fontsize',18);
    set(gca,'linewidth',2);
    set(gca,'box','off')
    hold off
    
    subplot('position',pos3); % Plot of integrals as a function of frequency ratios 
    hold on 
    plot(timeRatio,absIntegral,'g','LineWidth', 2.0)
    xlim([0 timeFacMax]);
    ylim([-0 4e7]);
    set(gca,'fontsize',18);
    set(gca,'linewidth',2);
    set(gca,'box','off')
    ax = gca;
    ax.XAxisLocation = 'origin';
    ax.YAxisLocation = 'origin';
    ax.YTickLabel = ' '; 
    ax.XTickLabel = ' '; 
    xlabel('Time [s]','Position',[timeFacMax/2 -0.5e5],'HorizontalAlignment','center'); 
    ylabel('Intensity [|Re|^2 + |Im|^2]'); 

    frame = getframe(gcf);
    writeVideo(vid,frame);
end
% Output the movie as an mp4 file and close it
close(vid);