danieleb@4: function y = lot(x,wLength,orthoBasis,tailLength,tailFunc) danieleb@15: % LOT lapped orthogonal transform danieleb@0: % danieleb@14: % Example danieleb@0: % y = lappedorthotransform(x,wLength,orthoBasis,tailLength,tailFunc) danieleb@0: % danieleb@14: % Input danieleb@14: % - x: vector or matrix containing the input signal. If matrix, the function danieleb@4: % acts columnwise. danieleb@14: % - wLength: scalar or vector containing the lengths of the overlapping danieleb@4: % windows (if vector, the sum of wLength must equal the length of x) danieleb@14: % - orthobasis: (optional, default='mdct') either a string or a function danieleb@4: % handle corresponding to an orhogonal transform to be used in each danieleb@4: % overlapping window. danieleb@14: % - tailLength: (optional, default=floor(min(wLength)/2)) length of the tail danieleb@4: % of the overlapping windows. Two consecutive windows overlap in a portion danieleb@4: % of dimension 2*tailLength. The maximum tailLength cannot exceed half the danieleb@4: % length of the smallest window. danieleb@14: % - tailFunc: (optional, default='sin2') either a string or a function handle danieleb@4: % used to define the tails of the overlapping windows (see LAPPEDWINDOW for danieleb@4: % more details). danieleb@0: % danieleb@14: % Output danieleb@14: % - y: vector or matrix of coefficients of the lapped orthogonal transform. danieleb@0: % danieleb@14: % References: danieleb@0: % S. Mallat, A Wavelet Tour of Signal Processing danieleb@0: % danieleb@14: % See also LAPPEDWINDOW, ilot danieleb@4: danieleb@4: % Author(s): Daniele Barchiesi danieleb@14: % Copyright 2011-2011 danieleb@4: danieleb@0: %% Check input & defaults danieleb@0: error(nargchk(2, 5, nargin, 'struct')); danieleb@4: danieleb@4: if isscalar(wLength) %create vector of fixed window lengths danieleb@4: nWindows = floor(length(x)/wLength); danieleb@4: wLength = wLength*ones(nWindows,1); danieleb@4: end danieleb@4: danieleb@0: if ~exist('orthoBasis','var') || isempty(orthoBasis), orthoBasis = 'mdct'; end danieleb@0: if ~exist('tailFunc','var') || isempty(tailFunc), tailFunc = 'sin2'; end danieleb@0: if ~exist('tailLength','var') || isempty(tailLength) danieleb@0: tailLength = floor(min(wLength)/2); danieleb@0: end danieleb@4: danieleb@4: % check wLength danieleb@0: if length(x)1 danieleb@4: y = zeros(size(x)); danieleb@4: for iCol=1:size(x,2) danieleb@6: y(:,iCol) = lot(x(:,iCol),wLength,orthoBasis,... danieleb@4: tailLength,tailFunc); danieleb@4: end danieleb@4: return danieleb@4: end danieleb@4: danieleb@0: %% Compute transform danieleb@0: nWindows = length(wLength); danieleb@0: sigLength = sum(wLength); danieleb@0: y = zeros(sigLength,1); danieleb@4: % length of the support of the p-th window danieleb@0: suppLen = @(p) wLength(p)+2*tailLength; danieleb@0: danieleb@0: % first frame danieleb@4: % project input signal onto orthogonal subspace associated with the first danieleb@4: % window danieleb@0: h = lappedprojector(x(1:wLength(1)+tailLength),wLength(1),tailLength,tailFunc,'first'); danieleb@4: % transform projected signal danieleb@0: y(1:wLength(1)) = orthoFun(h(1:wLength(1))); danieleb@0: danieleb@0: % central frames danieleb@0: for p=2:nWindows-1 danieleb@4: % project input signal onto orthogonal subspace associated with the danieleb@4: % p-th window danieleb@0: h = lappedprojector(x(sum(wLength(1:p-1))-tailLength+(1:suppLen(p))),... danieleb@0: wLength(p),tailLength,tailFunc); danieleb@4: % transform projected signal danieleb@0: y(sum(wLength(1:p-1))+(1:wLength(p))) = orthoFun(h(tailLength+(1:wLength(p)))); danieleb@0: end danieleb@0: danieleb@0: %last frame danieleb@4: % project input signal onto orthogonal subspace associated with the danieleb@4: % last window danieleb@0: h = lappedprojector(x(sum(wLength(1:end-1))-tailLength+(1:wLength(end)+tailLength)),... danieleb@0: wLength(end),tailLength,tailFunc,'last'); danieleb@4: % transform projected signal danieleb@4: if strcmpi(orthoBasis,'mdct') %id mdct use DCT I at last frame to avoid artefacts danieleb@0: y(sum(wLength(1:end-1))+(1:wLength(end))) = dcti(h(tailLength+(1:wLength(end))),'I'); danieleb@0: else danieleb@0: y(sum(wLength(1:end-1))+(1:wLength(end))) = orthoFun(h(tailLength+(1:wLength(end)))); danieleb@0: end danieleb@0: danieleb@0: function h = lappedprojector(f,wLength,tailLength,tailFunc,special) danieleb@0: % Projects the input f into the space of functions with support contained danieleb@4: % in the interval defined by the lapped window. danieleb@0: danieleb@0: % check inputs danieleb@0: error(nargchk(2, 5, nargin, 'struct')); danieleb@0: if ~exist('special','var') || isempty(special), special = []; end danieleb@4: if ~exist('tailFunc','var') || isempty(tailFunc), tailFunc = 'sin2'; end danieleb@0: if ~exist('tailLength','var') || isempty(tailLength) danieleb@0: tailLength = floor(min(wLength)/2); danieleb@0: end danieleb@0: danieleb@0: % generate the window and project danieleb@0: g = lappedwindow(wLength,tailLength,tailFunc,special); danieleb@0: h = f; danieleb@0: if ~isempty(special) danieleb@0: if strcmpi(special,'first') danieleb@4: % overlapping region danieleb@0: O = wLength-tailLength+(1:2*tailLength); danieleb@4: % project danieleb@0: h(O) = g(O).*f(O) - g(fliplr(O)).*f(fliplr(O)); danieleb@0: elseif strcmpi(special,'last') danieleb@4: % overlapping portion danieleb@0: O = 1:2*tailLength; danieleb@4: % project danieleb@0: h(O) = g(O).*f(O) + g(fliplr(O)).*f(fliplr(O)); danieleb@0: end danieleb@0: else danieleb@4: % start overlapping region danieleb@0: Os = 1:2*tailLength; danieleb@4: % end overlapping region danieleb@0: Oe = wLength+(1:2*tailLength); danieleb@4: % project danieleb@0: h(Os) = g(Os).*f(Os) + g(fliplr(Os)).*f(fliplr(Os)); danieleb@0: h(Oe) = g(Oe).*f(Oe) - g(fliplr(Oe)).*f(fliplr(Oe)); danieleb@0: end