function [SIGMAT] = sig2frames(SIG, FRAMELEN, STEP)
% [SIGMAT] = sig2frames(SIG, FRAMELEN, STEP)
% 
% Chop the signal SIG up into frames of length FRAMELEN, 
% with the frame-start position shifted STEP samples between frames.
% (Default: STEP=FRAMELEN, i.e. no overlap).
%
% SIGMAT [NFRAMES x FRAMELEN] 
%   Each row of SIGMAT contains one frame taken from the signal SIG:
%
%   SIGMAT(i,:) = SIG((i-1)*STEP + [1:FRAMELEN])';
% 
%

if nargin<3, STEP=FRAMELEN; end;

NFRAMES = ceil((length(SIG)-FRAMELEN)/STEP) + 1;

SIG = [SIG(:); zeros(STEP, 1)];

SIGMAT = zeros(NFRAMES, FRAMELEN);

for i = 1:NFRAMES,
  SIGMAT(i,:) = SIG((i-1)*STEP + [1:FRAMELEN])';
end;
