% Test specwin/specwin normalized equivalent noise bandwidth definition.
%
% M Hueller 06-03-09
%
% $Id: test_specwin_nenbw_definition.m,v 1.1 2009/03/06 09:26:28 mauro Exp $
%
win_names = {'Rectangular', ...
  'Welch', ...
  'Bartlett', ...
  'Hanning', ...
  'Hamming', ...
  'Nuttall3', ...
  'Nuttall4', ...
  'Nuttall3a', ...
  'Nuttall3b', ...
  'Nuttall4a', ...
  'Nuttall4b', ...
  'Nuttall4c', ...
  'BH92', ...
  'SFT3F', ...
  'SFT3M', ...
  'FTNI', ...
  'SFT4F', ...
  'SFT5F', ...
  'SFT4M', ...
  'FTHP', ...
  'HFT70', ...
  'FTSRS', ...
  'SFT5M', ...
  'HFT90D', ...
  'HFT95', ...
  'HFT116D', ...
  'HFT144D', ...
  'HFT169D', ...
  'HFT196D', ...
  'HFT223D', ...
  'HFT248D'};

% Different parameters for the Kaiser window family
psll = [50:50:300];
% Lenght of the window
npts = 100;

N = length(win_names);
M = length(psll);
def_dif = zeros(N+M,1);

% All windows but Kaiser
for jj = 1:N
  w = specwin(win_names{jj},npts);
  % Definition from the specwin constructor (included in a helper dedicated 
  % to each window)
  d1 = w.nenbw;
  % Definition from the "theory" 
  d2 = w.ws2/(w.ws)^2/fs*length(w.win);
  % Relative difference
  def_dif(jj) = (d1-d2)/mean([d1,d2]);
  disp([win_names{jj} ' ' num2str(def_dif(jj))]);
end

% Kaiser windows
for jj = N+1:N+M
  w = specwin('Kaiser',psll(jj-N),npts);
  % Definition from the specwin constructor (included in a helper dedicated 
  % to each window)
  d1 = w.nenbw;
  % Definition from the "theory" 
  d2 = w.ws2/(w.ws)^2/fs*length(w.win);
  % Relative difference
  def_dif(jj) = (d1-d2)/mean([d1,d2]);
  disp(['Kaiser' num2str(psll(jj-N)) ' ' num2str(def_dif(jj))]);
end