annotate lappedwindow.m @ 17:0da5eb32e49d tip

minor changes
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Thu, 10 Nov 2011 15:53:06 +0000
parents 88af68016e8a
children
rev   line source
danieleb@0 1 function g = lappedwindow(wLength,tailLength,tailFunc,special)
danieleb@15 2 %LAPPEDWINDOW lapped window for lapped orthogonal transform
danieleb@0 3 %
danieleb@14 4 % Example
danieleb@0 5 % g = lappedwindow(wLength,tailLength,tailFunc,special)
danieleb@0 6 %
danieleb@14 7 % Input:
danieleb@0 8 % - wLength: length of the window
danieleb@4 9 % - tailLength: (optional, default=floor(wLength/2))length of the tail of
danieleb@4 10 % the overlapping window.
danieleb@0 11 %
danieleb@0 12 % ......................
danieleb@0 13 % |. .|
danieleb@0 14 % . .
danieleb@0 15 % .| |.
danieleb@0 16 % . |---------wLength--------| .
danieleb@0 17 % |-|
danieleb@0 18 % tailLength
danieleb@0 19 %
danieleb@0 20 % The maximum tailLength cannot exceed half the window length.
danieleb@4 21 % - tailFunc: (optional, default='sin2') either a string or a function
danieleb@4 22 % handle used to define the tails of the overlapping windows. The default
danieleb@4 23 % is 'sin2' (twicely differentiable sinusoidal).
danieleb@0 24 %
danieleb@14 25 % Output:
danieleb@0 26 % - g: vector containing the window
danieleb@0 27 %
danieleb@14 28 % Reference:
danieleb@0 29 % S. Mallat, A Wavelet Tour of Signal Processing
danieleb@0 30 %
danieleb@14 31 % See also lot, ilot
danieleb@4 32
danieleb@4 33 % Author(s): Daniele Barchiesi
danieleb@14 34 % Copyright 2011-2011
danieleb@0 35
danieleb@0 36 %% Check inputs
danieleb@4 37 error(nargchk(1, 4, nargin, 'struct'));
danieleb@0 38 if ~exist('special','var') || isempty(special), special = []; end
danieleb@4 39 if ~exist('tailFunc','var') || isempty(tailFunc), tailFunc = 'sin2'; end
danieleb@4 40 if ~exist('tailLength','var') || isempty(tailLength), tailLength = floor(wLength/2); end
danieleb@0 41
danieleb@0 42 %check that the window is not too short
danieleb@0 43 if wLength<2*tailLength
danieleb@0 44 error('the window length must be at least twice as long as the tail length');
danieleb@0 45 end
danieleb@0 46
danieleb@0 47 %manage tail function
danieleb@0 48 if ischar(tailFunc)
danieleb@0 49 [fname iter] = parsefunctionname(tailFunc);
danieleb@0 50 switch lower(fname)
danieleb@0 51 case 'sin'
danieleb@0 52 tailFunc = @(x)sin((pi/4)*(x+1));
danieleb@0 53 otherwise
danieleb@0 54 error('invalid tail function');
danieleb@0 55 end
danieleb@0 56 if iter
danieleb@0 57 for i=1:iter
danieleb@0 58 tailFun = @(x)tailFun(sin(pi*x/2));
danieleb@0 59 end
danieleb@0 60 end
danieleb@0 61 else %if a function handler, check that it corresponds to a valid tail.
danieleb@0 62 t = linspace(-1,1,1000);
danieleb@0 63 test = norm((tailFunc(t).^2)+(tailFunc(fliplr(t)).^2)-ones(1,length(t)));
danieleb@0 64 if test>1e-8
danieleb@0 65 error('invalid tail function');
danieleb@0 66 end
danieleb@0 67 end
danieleb@0 68
danieleb@0 69 %% construct the window
danieleb@0 70 if ~isempty(special)
danieleb@0 71 g = ones(wLength+tailLength,1);
danieleb@0 72 g(1:2*tailLength) = tailFunc((-tailLength+0.5:tailLength-0.5)'/tailLength);
danieleb@0 73 if strcmpi(special,'first')
danieleb@0 74 g = flipud(g);
danieleb@0 75 end
danieleb@0 76 else
danieleb@0 77 g = ones(wLength+2*tailLength,1);
danieleb@0 78 g(1:2*tailLength) = tailFunc((-tailLength+0.5:tailLength-0.5)'/tailLength);
danieleb@0 79 g(wLength+1:wLength+2*tailLength) = ...
danieleb@0 80 flipud(tailFunc((-tailLength+0.5:tailLength-0.5)'/tailLength));
danieleb@0 81 end
danieleb@0 82
danieleb@0 83 function [fname iter] = parsefunctionname(tailFunc)
danieleb@0 84 nameLen = length(tailFunc);
danieleb@0 85 for i=1:nameLen
danieleb@0 86 if real(str2double(tailFunc(i)))>0
danieleb@0 87 fname = tailFunc(1:i-1);
danieleb@0 88 iter = uint16(str2double(tailFunc(i:end)));
danieleb@0 89 return
danieleb@0 90 end
danieleb@0 91 end
danieleb@0 92 fname = tailFunc;
danieleb@0 93 iter = [];