function [w]= win(x,window);

% This function returns a window.  The window variable is acually
% a structure. Unless noted, all of the following must be specified
% before calling win
% 
% window.type is the type of window 0 for hanning, 1 for rectangular
% and 2 for exponential
%
% The window length is determined by the length of the input, x,
% and does NOT need to be specified.
%
% window.data.alpha is the fraction of the signal remaining at the end of the
% window for the exponetial window.  Alpha is between 0 and 1.
%
% window.data.totalTime is the duration of the input, x
%
% window.data.startTime is the starting time for rectangular and
% exponential windows.
%
% window.data.stopTime is the stoping time for the rectangular window


[n,m]=size(x);
window.length=m;
for i=1:n
  switch window.type
    % Hanning window construction
    case 0,
      disp('Hanning')
      w(:,i)=hanning(window.length);
  
    % Rectangular window construction
    case 1,
      disp('Rectangular')
    
      startIndex=round((window.length-1)/window.data.totalTime*...
        window.data.startTime)+1;
    
      stopIndex=round((window.length-1)/window.data.totalTime*...
        window.data.stopTime)+1;
    
      wt=(boxcar(stopIndex-startIndex+1)).';
      w(:,i)=[zeros(1,startIndex-1) wt zeros(1,window.length-stopIndex)]';
  
    % Exponential window construction
    case 2,
      disp('Exponential')
    
      t=linspace(0,window.data.totalTime,window.length);
    
      startIndex=round((window.length-1)/window.data.totalTime*...
        window.data.startTime)+1;
    
      tau=-(window.data.totalTime-window.data.startTime)/...
        log(window.data.alpha);
    
      wt(startIndex:window.length)=exp(-(t(startIndex:window.length)-...
        window.data.startTime)/tau);
      w(:,i)=wt';
 
    otherwise,
      disp('Unknown')
  end
end
    
