function leakage=joe1
% plots FFT of different spliced windows
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

T = 90;        % data length (sec)
fS = 1024;     % sampling rate (Hz)
N_tot = T*fS;  % window length
M = N_tot*2^3; % to get greater frequency resolution to see side lobes
deltaT = 1/fS; % sampling period (sec)

z = zeros(M-N_tot, 1);

% initialize matrix for leakage functions
leakage = zeros(floor(M/2 + 1),3);

for i=1:3

  if (i == 1)  % full hann (0 sec flat)
    frac = 0;
  elseif (i == 2) % 1 sec hann (89 sec flat)
    frac = 89/90;
  elseif (i == 3) % rectangular (90 sec flat)
    frac = 1;
  end;

  w = splicedhann(N_tot, N_tot*frac);
  w = [w ; z];
  dft_w = fft(w);
  leakage(:,i) = abs( dft_w(1:floor(M/2 + 1)) );
end;

% display leakage of windows
deltaF = 1/(M*deltaT);
f = deltaF*[0:floor(M/2 + 1)-1];

figure(1);
loglog(f, leakage(:,1)/sum(leakage(:,1)), 'red', ...
       f, leakage(:,2)/sum(leakage(:,2)), 'green', ...
       f, leakage(:,3)/sum(leakage(:,3)), 'black');
xlabel('Frequency (Hz)','FontSize',14);
ylabel('Amplitude of Leakage','FontSize',14);
legend('Full Hann', '1 s Hann', 'Rectangular');
title('Normalized leakage for spliced Hann windows (T=90 s)','FontSize',16);
ylim([1e-10 1e-1])
print -depsc2 -f1 flattopLeakage_joe.eps

return;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
