


ENFRAME split signal up into (overlapping) frames: one per row. [F,T]=(X,WIN,INC)
F = ENFRAME(X,LEN) splits the vector X(:) up into
frames. Each frame is of length LEN and occupies
one row of the output matrix. The last few frames of X
will be ignored if its length is not divisible by LEN.
It is an error if X is shorter than LEN.
F = ENFRAME(X,LEN,INC) has frames beginning at increments of INC
The centre of frame I is X((I-1)*INC+(LEN+1)/2) for I=1,2,...
The number of frames is fix((length(X)-LEN+INC)/INC)
F = ENFRAME(X,WINDOW) or ENFRAME(X,WINDOW,INC) multiplies
each frame by WINDOW(:)
The second output argument, T, gives the time in samples at the centre
of each frame. T=i corresponds to the time of sample X(i).
Example of frame-based processing:
INC=20 % set frame increment
NW=INC*2 % oversample by a factor of 2 (4 is also often used)
S=cos((0:NW*7)*6*pi/NW); % example input signal
W=sqrt(hamming(NW+1)); W(end)=[]; % sqrt hamming window of period NW
F=enframe(S,W,INC); % split into frames
... process frames ...
X=overlapadd(F,W,INC); % reconstitute the time waveform (omit "X=" to plot waveform)

0001 function [f,t]=enframe(x,win,inc) 0002 %ENFRAME split signal up into (overlapping) frames: one per row. [F,T]=(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 % The second output argument, T, gives the time in samples at the centre 0018 % of each frame. T=i corresponds to the time of sample X(i). 0019 % 0020 % Example of frame-based processing: 0021 % INC=20 % set frame increment 0022 % NW=INC*2 % oversample by a factor of 2 (4 is also often used) 0023 % S=cos((0:NW*7)*6*pi/NW); % example input signal 0024 % W=sqrt(hamming(NW+1)); W(end)=[]; % sqrt hamming window of period NW 0025 % F=enframe(S,W,INC); % split into frames 0026 % ... process frames ... 0027 % X=overlapadd(F,W,INC); % reconstitute the time waveform (omit "X=" to plot waveform) 0028 0029 % Copyright (C) Mike Brookes 1997 0030 % Version: $Id: enframe.m 713 2011-10-16 14:45:43Z dmb $ 0031 % 0032 % VOICEBOX is a MATLAB toolbox for speech processing. 0033 % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html 0034 % 0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0036 % This program is free software; you can redistribute it and/or modify 0037 % it under the terms of the GNU General Public License as published by 0038 % the Free Software Foundation; either version 2 of the License, or 0039 % (at your option) any later version. 0040 % 0041 % This program is distributed in the hope that it will be useful, 0042 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0043 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0044 % GNU General Public License for more details. 0045 % 0046 % You can obtain a copy of the GNU General Public License from 0047 % http://www.gnu.org/copyleft/gpl.html or by writing to 0048 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. 0049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0050 0051 nx=length(x(:)); 0052 nwin=length(win); 0053 if (nwin == 1) 0054 len = win; 0055 else 0056 len = nwin; 0057 end 0058 if (nargin < 3) 0059 inc = len; 0060 end 0061 nf = fix((nx-len+inc)/inc); 0062 f=zeros(nf,len); 0063 indf= inc*(0:(nf-1)).'; 0064 inds = (1:len); 0065 f(:) = x(indf(:,ones(1,len))+inds(ones(nf,1),:)); 0066 if (nwin > 1) 0067 w = win(:)'; 0068 f = f .* w(ones(nf,1),:); 0069 end 0070 if nargout>1 0071 t=(1+len)/2+indf; 0072 end 0073 0074