annotate userProgramsTim/enframe.m @ 38:c2204b18f4a2 tip

End nov big change
author Ray Meddis <rmeddis@essex.ac.uk>
date Mon, 28 Nov 2011 13:34:28 +0000
parents
children
rev   line source
rmeddis@38 1 function [f,t]=enframe(x,win,inc)
rmeddis@38 2 %ENFRAME split signal up into (overlapping) frames: one per row. [F,T]=(X,WIN,INC)
rmeddis@38 3 %
rmeddis@38 4 % F = ENFRAME(X,LEN) splits the vector X(:) up into
rmeddis@38 5 % frames. Each frame is of length LEN and occupies
rmeddis@38 6 % one row of the output matrix. The last few frames of X
rmeddis@38 7 % will be ignored if its length is not divisible by LEN.
rmeddis@38 8 % It is an error if X is shorter than LEN.
rmeddis@38 9 %
rmeddis@38 10 % F = ENFRAME(X,LEN,INC) has frames beginning at increments of INC
rmeddis@38 11 % The centre of frame I is X((I-1)*INC+(LEN+1)/2) for I=1,2,...
rmeddis@38 12 % The number of frames is fix((length(X)-LEN+INC)/INC)
rmeddis@38 13 %
rmeddis@38 14 % F = ENFRAME(X,WINDOW) or ENFRAME(X,WINDOW,INC) multiplies
rmeddis@38 15 % each frame by WINDOW(:)
rmeddis@38 16 %
rmeddis@38 17 % The second output argument, T, gives the time in samples at the centre
rmeddis@38 18 % of each frame. T=i corresponds to the time of sample X(i).
rmeddis@38 19 %
rmeddis@38 20 % Example of frame-based processing:
rmeddis@38 21 % INC=20 % set frame increment
rmeddis@38 22 % NW=INC*2 % oversample by a factor of 2 (4 is also often used)
rmeddis@38 23 % S=cos((0:NW*7)*6*pi/NW); % example input signal
rmeddis@38 24 % W=sqrt(hamming(NW+1)); W(end)=[]; % sqrt hamming window of period NW
rmeddis@38 25 % F=enframe(S,W,INC); % split into frames
rmeddis@38 26 % ... process frames ...
rmeddis@38 27 % X=overlapadd(F,W,INC); % reconstitute the time waveform (omit "X=" to plot waveform)
rmeddis@38 28
rmeddis@38 29 % Copyright (C) Mike Brookes 1997
rmeddis@38 30 % Version: $Id: enframe.m,v 1.7 2009/11/01 21:08:21 dmb Exp $
rmeddis@38 31 %
rmeddis@38 32 % VOICEBOX is a MATLAB toolbox for speech processing.
rmeddis@38 33 % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
rmeddis@38 34 %
rmeddis@38 35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rmeddis@38 36 % This program is free software; you can redistribute it and/or modify
rmeddis@38 37 % it under the terms of the GNU General Public License as published by
rmeddis@38 38 % the Free Software Foundation; either version 2 of the License, or
rmeddis@38 39 % (at your option) any later version.
rmeddis@38 40 %
rmeddis@38 41 % This program is distributed in the hope that it will be useful,
rmeddis@38 42 % but WITHOUT ANY WARRANTY; without even the implied warranty of
rmeddis@38 43 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
rmeddis@38 44 % GNU General Public License for more details.
rmeddis@38 45 %
rmeddis@38 46 % You can obtain a copy of the GNU General Public License from
rmeddis@38 47 % http://www.gnu.org/copyleft/gpl.html or by writing to
rmeddis@38 48 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
rmeddis@38 49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rmeddis@38 50
rmeddis@38 51 nx=length(x(:));
rmeddis@38 52 nwin=length(win);
rmeddis@38 53 if (nwin == 1)
rmeddis@38 54 len = win;
rmeddis@38 55 else
rmeddis@38 56 len = nwin;
rmeddis@38 57 end
rmeddis@38 58 if (nargin < 3)
rmeddis@38 59 inc = len;
rmeddis@38 60 end
rmeddis@38 61 nf = fix((nx-len+inc)/inc);
rmeddis@38 62 f=zeros(nf,len);
rmeddis@38 63 indf= inc*(0:(nf-1)).';
rmeddis@38 64 inds = (1:len);
rmeddis@38 65 f(:) = x(indf(:,ones(1,len))+inds(ones(nf,1),:));
rmeddis@38 66 if (nwin > 1)
rmeddis@38 67 w = win(:)';
rmeddis@38 68 f = f .* w(ones(nf,1),:);
rmeddis@38 69 end
rmeddis@38 70 if nargout>1
rmeddis@38 71 t=(1+len)/2+indf;
rmeddis@38 72 end
rmeddis@38 73
rmeddis@38 74