annotate lappedwindow.m @ 3:ee2a86d7ec07

Added support functions
author danieleb@code.soundsoftware.ac.uk
date Wed, 15 Jun 2011 11:26:03 +0100
parents 9c6ab153f1f2
children e23a23349e31
rev   line source
danieleb@0 1 function g = lappedwindow(wLength,tailLength,tailFunc,special)
danieleb@0 2 %LAPPEDWINDOW Lapped window used for lapped orthogonal transform
danieleb@0 3 %
danieleb@0 4 % g = lappedwindow(wLength,tailLength,tailFunc,special)
danieleb@0 5 %
danieleb@0 6 % returns the window g used in the lapped orthogonal transform
danieleb@0 7 %
danieleb@0 8 % INPUT:
danieleb@0 9 % - wLength: length of the window
danieleb@0 10 % - tailLength: length of the tail of 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@0 21 % - tailFunc: either a string or a function handle used to define the tails
danieleb@0 22 % of the overlapping windows. The default is 'sin2' (twicely differentiable
danieleb@0 23 % sinusoidal).
danieleb@0 24 %
danieleb@0 25 % OUTPUT:
danieleb@0 26 % - g: vector containing the window
danieleb@0 27 %
danieleb@0 28 % REFERENCE:
danieleb@0 29 % S. Mallat, A Wavelet Tour of Signal Processing
danieleb@0 30 %
danieleb@0 31 % SEE ALSO
danieleb@0 32 % lappedorthobasis, lappedorthotransform
danieleb@0 33 %
danieleb@0 34 % ----------------------------------------------------------- %
danieleb@0 35 % Daniele Barchiesi, daniele.barchiesi@eecs.qmul.ac.uk %
danieleb@0 36 % Centre for Digital Music, Queen Mary University of London %
danieleb@0 37 % Apr. 2011 %
danieleb@0 38 % ----------------------------------------------------------- %
danieleb@0 39
danieleb@0 40 %% Check inputs
danieleb@0 41 error(nargchk(2, 4, nargin, 'struct'));
danieleb@0 42 if ~exist('special','var') || isempty(special), special = []; end
danieleb@0 43 if ~exist('tailFunx','var') || isempty(tailFunc), tailFunc = 'sin2'; end
danieleb@0 44
danieleb@0 45 %check that the window is not too short
danieleb@0 46 if wLength<2*tailLength
danieleb@0 47 error('the window length must be at least twice as long as the tail length');
danieleb@0 48 end
danieleb@0 49
danieleb@0 50 %manage tail function
danieleb@0 51 if ischar(tailFunc)
danieleb@0 52 [fname iter] = parsefunctionname(tailFunc);
danieleb@0 53 switch lower(fname)
danieleb@0 54 case 'sin'
danieleb@0 55 tailFunc = @(x)sin((pi/4)*(x+1));
danieleb@0 56 otherwise
danieleb@0 57 error('invalid tail function');
danieleb@0 58 end
danieleb@0 59 if iter
danieleb@0 60 for i=1:iter
danieleb@0 61 tailFun = @(x)tailFun(sin(pi*x/2));
danieleb@0 62 end
danieleb@0 63 end
danieleb@0 64 else %if a function handler, check that it corresponds to a valid tail.
danieleb@0 65 t = linspace(-1,1,1000);
danieleb@0 66 test = norm((tailFunc(t).^2)+(tailFunc(fliplr(t)).^2)-ones(1,length(t)));
danieleb@0 67 if test>1e-8
danieleb@0 68 error('invalid tail function');
danieleb@0 69 end
danieleb@0 70 end
danieleb@0 71
danieleb@0 72 %% construct the window
danieleb@0 73 if ~isempty(special)
danieleb@0 74 g = ones(wLength+tailLength,1);
danieleb@0 75 g(1:2*tailLength) = tailFunc((-tailLength+0.5:tailLength-0.5)'/tailLength);
danieleb@0 76 if strcmpi(special,'first')
danieleb@0 77 g = flipud(g);
danieleb@0 78 end
danieleb@0 79 else
danieleb@0 80 g = ones(wLength+2*tailLength,1);
danieleb@0 81 g(1:2*tailLength) = tailFunc((-tailLength+0.5:tailLength-0.5)'/tailLength);
danieleb@0 82 g(wLength+1:wLength+2*tailLength) = ...
danieleb@0 83 flipud(tailFunc((-tailLength+0.5:tailLength-0.5)'/tailLength));
danieleb@0 84 end
danieleb@0 85
danieleb@0 86 function [fname iter] = parsefunctionname(tailFunc)
danieleb@0 87 nameLen = length(tailFunc);
danieleb@0 88 for i=1:nameLen
danieleb@0 89 if real(str2double(tailFunc(i)))>0
danieleb@0 90 fname = tailFunc(1:i-1);
danieleb@0 91 iter = uint16(str2double(tailFunc(i:end)));
danieleb@0 92 return
danieleb@0 93 end
danieleb@0 94 end
danieleb@0 95 fname = tailFunc;
danieleb@0 96 iter = [];