clear; close all
figure('units','pixels','position',[0 0 1920 1080],'ToolBar','none');
vid = VideoWriter('FTs_explained1.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];

x = 0:0.005:4.5;
y = cos(2*pi*x/(1/3))+1;

for ii = 0:270 % 9 seconds for 4.5 cycles 
    hold off
    subplot('position',pos1);
    plot(x,y,'b','LineWidth', 2.0)
    hold on
    arrowHt = cos(2*pi*(ii/60)/(1/3))+1; 
    % Draw arrow 
    plot([ii/60 ii/60],[0 arrowHt],'r','LineWidth', 2.0);
    fill([ii/60-0.016 ii/60+0.016 ii/60],[arrowHt-0.1 arrowHt-0.1 arrowHt],'r','linestyle','none')
    xlim([0 4.5]);
    ylim([-0.1 2.1]);
    set(gca,'fontsize',18);
    set(gca,'linewidth',2);
    set(gca,'box','off')
    ax = gca;
    ax.XAxisLocation = 'origin';
    ax.YAxisLocation = 'origin';
    ax.YTickLabel = ' '; 
    xlabel('Time [s]','Position',[2.25 -0.4],'HorizontalAlignment','center'); 
    ylabel('Amplitude'); 
    
    hold off
    subplot('position',pos2);
    freqFac = 1/4.55;
    theta = 0:pi/180:2*pi*(ii/60)/(1/3); 
    theta2 = freqFac*theta; 
    rho = cos(theta)+1;
    polarplot(-theta2,rho,'b','LineWidth', 2.0)
    hold on 
    % Draw arrow 
    polarplot(-[theta2(end) theta2(end)],[0 rho(end)],'r','LineWidth', 2.0)
    polarplot(-[theta2(end)-pi/180 theta2(end)+pi/180 theta2(end) theta2(end)-pi/180],...
        [rho(end)-0.1 rho(end)-0.1 rho(end) rho(end)-0.1],'r','LineWidth', 2.0)
    rlim([0 2])
    thetaticks(0:45:315);
    thetaticklabels({'1',' ','i',' ','-1',' ','-i',' '});
    rticks(0:1:2);
    rticklabels({' ',' ',' '});

    set(gca,'fontsize',18);
    set(gca,'linewidth',2);
    set(gca,'box','off')

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