rmeddis@38: function [f,t]=enframe(x,win,inc) rmeddis@38: %ENFRAME split signal up into (overlapping) frames: one per row. [F,T]=(X,WIN,INC) rmeddis@38: % rmeddis@38: % F = ENFRAME(X,LEN) splits the vector X(:) up into rmeddis@38: % frames. Each frame is of length LEN and occupies rmeddis@38: % one row of the output matrix. The last few frames of X rmeddis@38: % will be ignored if its length is not divisible by LEN. rmeddis@38: % It is an error if X is shorter than LEN. rmeddis@38: % rmeddis@38: % F = ENFRAME(X,LEN,INC) has frames beginning at increments of INC rmeddis@38: % The centre of frame I is X((I-1)*INC+(LEN+1)/2) for I=1,2,... rmeddis@38: % The number of frames is fix((length(X)-LEN+INC)/INC) rmeddis@38: % rmeddis@38: % F = ENFRAME(X,WINDOW) or ENFRAME(X,WINDOW,INC) multiplies rmeddis@38: % each frame by WINDOW(:) rmeddis@38: % rmeddis@38: % The second output argument, T, gives the time in samples at the centre rmeddis@38: % of each frame. T=i corresponds to the time of sample X(i). rmeddis@38: % rmeddis@38: % Example of frame-based processing: rmeddis@38: % INC=20 % set frame increment rmeddis@38: % NW=INC*2 % oversample by a factor of 2 (4 is also often used) rmeddis@38: % S=cos((0:NW*7)*6*pi/NW); % example input signal rmeddis@38: % W=sqrt(hamming(NW+1)); W(end)=[]; % sqrt hamming window of period NW rmeddis@38: % F=enframe(S,W,INC); % split into frames rmeddis@38: % ... process frames ... rmeddis@38: % X=overlapadd(F,W,INC); % reconstitute the time waveform (omit "X=" to plot waveform) rmeddis@38: rmeddis@38: % Copyright (C) Mike Brookes 1997 rmeddis@38: % Version: $Id: enframe.m,v 1.7 2009/11/01 21:08:21 dmb Exp $ rmeddis@38: % rmeddis@38: % VOICEBOX is a MATLAB toolbox for speech processing. rmeddis@38: % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html rmeddis@38: % rmeddis@38: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% rmeddis@38: % This program is free software; you can redistribute it and/or modify rmeddis@38: % it under the terms of the GNU General Public License as published by rmeddis@38: % the Free Software Foundation; either version 2 of the License, or rmeddis@38: % (at your option) any later version. rmeddis@38: % rmeddis@38: % This program is distributed in the hope that it will be useful, rmeddis@38: % but WITHOUT ANY WARRANTY; without even the implied warranty of rmeddis@38: % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the rmeddis@38: % GNU General Public License for more details. rmeddis@38: % rmeddis@38: % You can obtain a copy of the GNU General Public License from rmeddis@38: % http://www.gnu.org/copyleft/gpl.html or by writing to rmeddis@38: % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. rmeddis@38: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% rmeddis@38: rmeddis@38: nx=length(x(:)); rmeddis@38: nwin=length(win); rmeddis@38: if (nwin == 1) rmeddis@38: len = win; rmeddis@38: else rmeddis@38: len = nwin; rmeddis@38: end rmeddis@38: if (nargin < 3) rmeddis@38: inc = len; rmeddis@38: end rmeddis@38: nf = fix((nx-len+inc)/inc); rmeddis@38: f=zeros(nf,len); rmeddis@38: indf= inc*(0:(nf-1)).'; rmeddis@38: inds = (1:len); rmeddis@38: f(:) = x(indf(:,ones(1,len))+inds(ones(nf,1),:)); rmeddis@38: if (nwin > 1) rmeddis@38: w = win(:)'; rmeddis@38: f = f .* w(ones(nf,1),:); rmeddis@38: end rmeddis@38: if nargout>1 rmeddis@38: t=(1+len)/2+indf; rmeddis@38: end rmeddis@38: rmeddis@38: