function f=enframe(x,win,inc)
% 0002 %ENFRAME split signal up into (overlapping) frames: one per row. F=(X,WIN,INC)
% 0003 %
% 0004 %    F = ENFRAME(X,LEN) splits the vector X(:) up into
% 0005 %    frames. Each frame is of length LEN and occupies
% 0006 %    one row of the output matrix. The last few frames of X
% 0007 %    will be ignored if its length is not divisible by LEN.
% 0008 %    It is an error if X is shorter than LEN.
% 0009 %
% 0010 %    F = ENFRAME(X,LEN,INC) has frames beginning at increments of INC
% 0011 %    The centre of frame I is X((I-1)*INC+(LEN+1)/2) for I=1,2,...
% 0012 %    The number of frames is fix((length(X)-LEN+INC)/INC)
% 0013 %
% 0014 %    F = ENFRAME(X,WINDOW) or ENFRAME(X,WINDOW,INC) multiplies
% 0015 %    each frame by WINDOW(:)
% 0016 
% 0017 %       Copyright (C) Mike Brookes 1997
% 0018 %      Version: $Id: enframe.m,v 1.5 2007/05/04 07:01:38 dmb Exp $
% 0019 %
% 0020 %   VOICEBOX is a MATLAB toolbox for speech processing.
% 0021 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
% 0022 %
% 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 0024 %   This program is free software; you can redistribute it and/or modify
% 0025 %   it under the terms of the GNU General Public License as published by
% 0026 %   the Free Software Foundation; either version 2 of the License, or
% 0027 %   (at your option) any later version.
% 0028 %
% 0029 %   This program is distributed in the hope that it will be useful,
% 0030 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
% 0031 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% 0032 %   GNU General Public License for more details.
% 0033 %
% 0034 %   You can obtain a copy of the GNU General Public License from
% 0035 %   http://www.gnu.org/copyleft/gpl.html or by writing to
% 0036 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
% 0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 nx=length(x(:));
 nwin=length(win);
 if (nwin == 1)
    len = win;
 else
    len = nwin;
 end
 if (nargin < 3)
    inc = len;
 end
 nf = fix((nx-len+inc)/inc);
 f=zeros(nf,len);
 indf= inc*(0:(nf-1)).';
 inds = (1:len);
 f(:) = x(indf(:,ones(1,len))+inds(ones(nf,1),:));
 if (nwin > 1)
     w = win(:)';
     f = f .* w(ones(nf,1),:);
 end
