Home > voicebox > overlapadd.m

overlapadd

PURPOSE ^

OVERLAPADD join overlapping frames together X=(F,WIN,INC)

SYNOPSIS ^

function [x,zo]=overlapadd(f,win,inc)

DESCRIPTION ^

OVERLAPADD join overlapping frames together X=(F,WIN,INC)

 Inputs:  F(NR,NW) contains the frames to be added together, one
                   frame per row.
          WIN(NW)  contains a window function to multiply each frame.
                   WIN may be omitted to use a default rectangular window
                   If processing the input in chunks, WIN should be replaced by
                   ZI on the second and subsequent calls where ZI is the saved
                   output state from the previous call.
          INC      gives the time increment (in samples) between
                   succesive frames [default = NW].

 Outputs: X(N,1) is the output signal. The number of output samples is N=NW+(NR-1)*INC.   
          ZO     Contains the saved state to allow a long signal
                 to be processed in chunks. In this case X will contain only N=NR*INC
                 output samples. 

 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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [x,zo]=overlapadd(f,win,inc)
0002 %OVERLAPADD join overlapping frames together X=(F,WIN,INC)
0003 %
0004 % Inputs:  F(NR,NW) contains the frames to be added together, one
0005 %                   frame per row.
0006 %          WIN(NW)  contains a window function to multiply each frame.
0007 %                   WIN may be omitted to use a default rectangular window
0008 %                   If processing the input in chunks, WIN should be replaced by
0009 %                   ZI on the second and subsequent calls where ZI is the saved
0010 %                   output state from the previous call.
0011 %          INC      gives the time increment (in samples) between
0012 %                   succesive frames [default = NW].
0013 %
0014 % Outputs: X(N,1) is the output signal. The number of output samples is N=NW+(NR-1)*INC.
0015 %          ZO     Contains the saved state to allow a long signal
0016 %                 to be processed in chunks. In this case X will contain only N=NR*INC
0017 %                 output samples.
0018 %
0019 % Example of frame-based processing:
0020 %          INC=20                                                           % set frame increment
0021 %          NW=INC*2                                                         % oversample by a factor of 2 (4 is also often used)
0022 %          S=cos((0:NW*7)*6*pi/NW);                                % example input signal
0023 %          W=sqrt(hamming(NW+1)); W(end)=[];      % sqrt hamming window of period NW
0024 %          F=enframe(S,W,INC);                           % split into frames
0025 %          ... process frames ...
0026 %          X=overlapadd(F,W,INC);                       % reconstitute the time waveform (omit "X=" to plot waveform)
0027 
0028 %       Copyright (C) Mike Brookes 2009
0029 %      Version: $Id: overlapadd.m 713 2011-10-16 14:45:43Z dmb $
0030 %
0031 %   VOICEBOX is a MATLAB toolbox for speech processing.
0032 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0033 %
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 %   This program is free software; you can redistribute it and/or modify
0036 %   it under the terms of the GNU General Public License as published by
0037 %   the Free Software Foundation; either version 2 of the License, or
0038 %   (at your option) any later version.
0039 %
0040 %   This program is distributed in the hope that it will be useful,
0041 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0042 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0043 %   GNU General Public License for more details.
0044 %
0045 %   You can obtain a copy of the GNU General Public License from
0046 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0047 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0049 [nr,nf]=size(f);            % number of frames and frame length
0050 if nargin<2
0051     win=nf;                 % default increment
0052 end
0053 if isstruct(win)
0054     w=win.w;
0055     if ~numel(w) && length(w)~=nf
0056         error('window length does not match frames size');
0057     end
0058     inc=win.inc;
0059     xx=win.xx;
0060 else
0061     if nargin<3
0062         inc=nf;
0063     end
0064     if numel(win)==1 && win==fix(win) && nargin<3       % win has been omitted
0065         inc=win;
0066         w=[];
0067     else
0068         w=win(:).';
0069         if length(w)~=nf
0070             error('window length does not match frames size');
0071         end
0072         if all(w==1)
0073             w=[];
0074         end
0075     end
0076     xx=[];      % partial output from previous call is null
0077 end
0078 nb=ceil(nf/inc);        % number of overlap buffers
0079 no=nf+(nr-1)*inc;       % buffer length
0080 z=zeros(no,nb);                      % space for overlapped output speech
0081 if numel(w)
0082     z(repmat(1:nf,nr,1)+repmat((0:nr-1)'*inc+rem((0:nr-1)',nb)*no,1,nf))=f.*repmat(w,nr,1);
0083 else
0084     z(repmat(1:nf,nr,1)+repmat((0:nr-1)'*inc+rem((0:nr-1)',nb)*no,1,nf))=f;
0085 end
0086 x=sum(z,2);
0087 if ~isempty(xx)
0088     x(1:length(xx))=x(1:length(xx))+xx;     % add on leftovers from previous call
0089 end
0090 if nargout>1            % check if we want to preserve the state
0091     mo=inc*nr;          % completed output samples
0092     if no<mo
0093         x(mo,1)=0;
0094         zo.xx=[];
0095     else
0096         zo.xx=x(mo+1:end);
0097         zo.w=w;
0098         zo.inc=inc;
0099         x=x(1:mo);
0100     end
0101 elseif ~nargout
0102     if isempty(xx)
0103         k1=nf-inc;  % dubious samples at start
0104     else
0105         k1=0;
0106     end
0107     k2=nf-inc;      % dubious samples at end
0108     plot(1+(0:nr-1)*inc,x(1+(0:nr-1)*inc),'>r',nf+(0:nr-1)*inc,x(nf+(0:nr-1)*inc),'<r', ...
0109         1:k1+1,x(1:k1+1),':b',k1+1:no-k2,x(k1+1:end-k2),'-b',no-k2:no,x(no-k2:no),':b');
0110     xlabel('Sample Number');
0111     title(sprintf('%d frames of %d samples with %.0f%% overlap = %d samples',nr,nf,100*(1-inc/nf),no));
0112 end

Generated on Thu 02-Feb-2012 09:15:04 by m2html © 2003