function leakage=joe
% 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)  % 1 sec hann*1 (89 sec flat)
    frac = 89/90;
  elseif (i == 2) % 1 sec hann*8 (89 sec flat)
    frac = 89/90;
  elseif (i == 3) % rectangular*8 (90 sec flat)
    frac = 1;
  end;

  w = splicedhann(N_tot, N_tot*frac);
  if i > 1,
    w = [w ; z];
  end  

  L_w=length(w);
  dft_w = fft(w);
  leakage(1:floor(L_w/2 + 1),i) = abs( dft_w(1:floor(L_w/2 + 1)) );

end;

% display leakage of windows
deltaF = 1/(M*deltaT);
f = deltaF*[0:floor(M/2 + 1)-1];
deltaf = 1/(N_tot*deltaT);
f8 = deltaf*[0:floor(N_tot/2 + 1)-1];
figure(1);
loglog(f, leakage(:,2)/N_tot, 'green', ...
       f8, leakage(1:length(f8),1)/N_tot, 'red', ...
       f, leakage(:,3)/N_tot, 'black');
xlabel('Frequency (Hz)','FontSize',14);
ylabel('Amplitude of Leakage','FontSize',14);
legend('1 s Hann*8', '1 s Hann*1', 'Rect\_win*8   ');
title('Leakage function for spliced Hann windows (T=90 s)','FontSize',16);
xlim([1e-3 1e+3])
ylim([1e-12 1e+1])
print -depsc2 -f1 flattopLeakage_hann.eps

return;

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