Mercurial > hg > lots
changeset 5:084000643ad1
changed names
author | danieleb@code.soundsoftware.ac.uk |
---|---|
date | Thu, 16 Jun 2011 13:33:43 +0100 |
parents | e23a23349e31 |
children | e2a029a70df3 |
files | ilot.m lappedorthobasis.m lappedorthoplot.m lotbasis.m lotplot.m |
diffstat | 5 files changed, 173 insertions(+), 168 deletions(-) [+] |
line wrap: on
line diff
--- a/ilot.m Thu Jun 16 13:16:29 2011 +0100 +++ b/ilot.m Thu Jun 16 13:33:43 2011 +0100 @@ -81,13 +81,18 @@ nWindows = length(wLength); sigLength = sum(wLength); x = zeros(sigLength,1); +p = 1; % first frame g = lappedwindow(wLength(1),tailLength,tailFunc,'first'); h = invOrthoFun(y(1:wLength(1))); % folded ilot C = 1:wLength(1)-tailLength; % central interval Om = wLength(1)-tailLength+(1:tailLength); %overlapping interval (end) -hp = invOrthoFun(y(wLength(1)+(1:wLength(2)))); % next folded ilot +if strcmpi(orthoBasis,'mdct') && p==nWindows-1 % if mdct use idct I + hp = idcti(y(sum(wLength(1:end-1))+(1:wLength(end))),'I'); +else + hp = invOrthoFun(y(sum(wLength(1:end-1))+(1:wLength(end)))); +end x(C) = h(C); % unfold x(Om) = g(Om).*h(Om) + g(end:-1:end-tailLength+1).*hp(tailLength:-1:1); @@ -127,5 +132,5 @@ C = sum(wLength(1:end-1))+(tailLength+1:wLength(end)); % unfold x(Op) = g(tailLength+(1:tailLength)).*h(1:tailLength) - ... - g(tailLength:-1:1).*hm(end:-1:end-tailLength+1); + g(tailLength:-1:1).*hm(end:-1:end-tailLength+1); x(C) = h(tailLength+1:end);
--- a/lappedorthobasis.m Thu Jun 16 13:16:29 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -function phi = lappedorthobasis(wLength,orthobasis,tailLength,tailFunc) -%LAPPEDORTHOBASIS Lapped orthogonal basis matrix -% -% phi = lappedorthobasis(wLength,orthobasis,tailLength,tailFunc) -% -% returns a matrix whose columns contain the atoms of a lapped orhogonal -% basis function. -% -% INPUT: -% - wLength: vector containing the lengths of the overlapping windows -% - orthobasis: either a string or a function handle corresponding to an -% orhogonal transform to be used in each overlapping window. The default -% is DCT-IV (which is globally referred as MDCT) -% - tailLength: length of the tail of the overlapping windows. Two -% consecutive windows overlap in a portion of dimension 2*tailLength. -% The maximum tailLength cannot exceed half the length of the smallest -% window. -% - tailFunc: either a string or a function handle used to define the tails -% of the overlapping windows. The default is 'sin2' (twicely differentiable -% sinusoidal). -% -% OUTPUT: -% - phi: matrix containing the lapped orthogonal dictionary. -% -% REFERENCE: -% S. Mallat, A Wavelet Tour of Signal Processing -% -% SEE ALSO -% lappedorthotransform, lappedwindow -% -% ----------------------------------------------------------- % -% Daniele Barchiesi, daniele.barchiesi@eecs.qmul.ac.uk % -% Centre for Digital Music, Queen Mary University of London % -% Apr. 2011 % -% ----------------------------------------------------------- % -%% check inputs & defaults -error(nargchk(1, 4, nargin, 'struct')); -if ~exist('tailFunc','var') || isempty(tailFunc), tailFunc = 'sin2'; end -if ~exist('tailLength','var') || isempty(tailLength), tailLength = floor(min(wLength)/2); end -if ~exist('orthobasis','var') || isempty(orthobasis), orthobasis = 'mdct'; end - -% select local orthonormal transform -if ischar(orthobasis) - switch orthobasis - case 'mdct' - basisFun = @(x) dcti(x,'IV'); - otherwise - error('invalid basis function'); - end -elseif isa(orthobasis,'function_handle') - basisFun = orthobasis; -else - error('invalid basis function'); -end - -%% calculate dictionary -nWindows = length(wLength); -sigLength = sum(wLength); -phi = zeros(sigLength); -suppLen = @(p) wLength(p)+2*tailLength; - -% first frame -% generate window -g = lappedwindow(wLength(1),tailLength,tailFunc,'first'); -% generate local orthogonal matrix -orthoMat = basisFun(eye(wLength(1))); -% periodically extend length of basis functions to overlapping regions -orthoMatExtended = orthomatextend(orthoMat,tailLength,'first'); -% multiply local orthogonal matrix by windowing function -phi(1:wLength(1)+tailLength,1:wLength(1)) = diag(sparse(g))*orthoMatExtended; - -% central frames -for p=2:nWindows-1 - % generate window - g = lappedwindow(wLength(p),tailLength,tailFunc); - % generate local orthogonal matrix - orthoMat = basisFun(eye(wLength(p))); - % periodically extend length of basis functions to overlapping regions - orthoMatExtended = orthomatextend(orthoMat,tailLength); - % multiply local orthogonal matrix by windowing function - phi(sum(wLength(1:p-1))-tailLength+(1:suppLen(p)),sum(wLength(1:p-1))+(1:wLength(p)))... - = diag(sparse(g))*orthoMatExtended; -end - -%last frame -% generate window -g = lappedwindow(wLength(end),tailLength,tailFunc,'last'); -% generate local orthogonal matrix -if strcmpi(orthobasis,'mdct') %if mdct use dct I at last block to avoid artefacts - orthoMat = dcti(eye(wLength(end)),'I'); -else - orthoMat = basisFun(eye(wLength(end))); -end -% periodically extend length of basis functions to overlapping regions -orthoMatExtended = orthomatextend(orthoMat,tailLength,'last'); -% multiply local orthogonal matrix by windowing function -phi(sum(wLength(1:end-1))-tailLength+(1:wLength(end)+tailLength),sum(wLength(1:end-1))+(1:wLength(end)))... - = diag(sparse(g))*orthoMatExtended; - -function orthomatextended = orthomatextend(orthomat,tailLength,special) -% Periodic extension of local orthonormal basis -if ~exist('special','var') || isempty(special), special = []; end - -if strcmpi(special,'first') - % odd symmetry at the end of basis functions - orthomatextended = [orthomat; -orthomat(end:-1:end-tailLength+1,:)]; -elseif strcmpi(special,'last') - % even symmetry at the beginning of basis functions - orthomatextended = [flipud(orthomat(1:tailLength,:)); orthomat]; -else - % even symmetry at the beginning and odd symmetry at the end of basis - % functions - orthomatextended = [flipud(orthomat(1:tailLength,:)); orthomat; ... - -orthomat(end:-1:end-tailLength+1,:)]; -end \ No newline at end of file
--- a/lappedorthoplot.m Thu Jun 16 13:16:29 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -function varargout = lappedorthoplot(y,wLength,Fs) -%LAPPEDORTHOPLOT plot of the lapped orthogonal transform -% -% varargout = lappedorthoplot(y,wLength,timeVec) -% -% plots a spectrogram-like visualisation of the lapped orthogonal -% transform coefficients contained in y -% -% INPUT: -% - y: vector containing the lapped orthogonal transform coefficients -% - wLength: vector containing the lengths of the overlapping windows -% - Fs: sampling frequency (default 44100) -% -% OUTPUT: -% - varargout{1}: optionally, the function outputs the matrix containing -% the spectrogram-like representation. -% -% SEE ALSO -% lappedorthotransform -% -% ----------------------------------------------------------- % -% Daniele Barchiesi, daniele.barchiesi@eecs.qmul.ac.uk % -% Centre for Digital Music, Queen Mary University of London % -% Apr. 2011 % -% ----------------------------------------------------------- % -nWindows = length(wLength); -maxLength = max(wLength); -sigLength = sum(wLength); - -if ~exist('Fs','var') || isempty(Fs), Fs = 44100; end - -timeVec = linspace(0,sigLength/Fs,10*ceil(sigLength/min(wLength))); - -S = zeros(maxLength,length(timeVec)); -timeSupp = @(p) floor(wLength(p)*length(timeVec)/sigLength); -interpFun = @(p,v) interp1(1:wLength(p),abs(v),linspace(1,wLength(p),maxLength))'; -S(:,1:timeSupp(1)) = repmat(interpFun(1,y(1:wLength(1))),1,timeSupp(1)); -for i=2:nWindows - S(:,sum(timeSupp(1:i-1))+(1:timeSupp(i))) = ... - repmat(interpFun(i,y(sum(wLength(1:i-1))+(1:wLength(i)))),1,timeSupp(i)); -end - -SmagdB = mag2db(S); -if nargout, varargout{1} = SmagdB; end - -surf(timeVec,1:maxLength,SmagdB,'EdgeColor','none'); -axis xy; axis tight; -colormap(jet); -view(0,90); -set(gca,'YScale','log'); -title(['l1/l2 = ' num2str(l1overl2(y))]) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lotbasis.m Thu Jun 16 13:33:43 2011 +0100 @@ -0,0 +1,115 @@ +function phi = lotbasis(wLength,orthobasis,tailLength,tailFunc) +%LAPPEDORTHOBASIS Lapped orthogonal basis matrix +% +% phi = lappedorthobasis(wLength,orthobasis,tailLength,tailFunc) +% +% returns a matrix whose columns contain the atoms of a lapped orhogonal +% basis function. +% +% INPUT: +% - wLength: vector containing the lengths of the overlapping windows +% - orthobasis: either a string or a function handle corresponding to an +% orhogonal transform to be used in each overlapping window. The default +% is DCT-IV (which is globally referred as MDCT) +% - tailLength: length of the tail of the overlapping windows. Two +% consecutive windows overlap in a portion of dimension 2*tailLength. +% The maximum tailLength cannot exceed half the length of the smallest +% window. +% - tailFunc: either a string or a function handle used to define the tails +% of the overlapping windows. The default is 'sin2' (twicely differentiable +% sinusoidal). +% +% OUTPUT: +% - phi: matrix containing the lapped orthogonal dictionary. +% +% REFERENCE: +% S. Mallat, A Wavelet Tour of Signal Processing +% +% SEE ALSO +% lappedorthotransform, lappedwindow +% + +% Author(s): Daniele Barchiesi +% Copyright QMUL +% $Revision: 1 + +%% check inputs & defaults +error(nargchk(1, 4, nargin, 'struct')); +if ~exist('tailFunc','var') || isempty(tailFunc), tailFunc = 'sin2'; end +if ~exist('tailLength','var') || isempty(tailLength), tailLength = floor(min(wLength)/2); end +if ~exist('orthobasis','var') || isempty(orthobasis), orthobasis = 'mdct'; end + +% select local orthonormal transform +if ischar(orthobasis) + switch orthobasis + case 'mdct' + basisFun = @(x) dcti(x,'IV'); + otherwise + error('invalid basis function'); + end +elseif isa(orthobasis,'function_handle') + basisFun = orthobasis; +else + error('invalid basis function'); +end + +%% calculate dictionary +nWindows = length(wLength); +sigLength = sum(wLength); +phi = zeros(sigLength); +suppLen = @(p) wLength(p)+2*tailLength; + +% first frame +% generate window +g = lappedwindow(wLength(1),tailLength,tailFunc,'first'); +% generate local orthogonal matrix +orthoMat = basisFun(eye(wLength(1))); +% periodically extend length of basis functions to overlapping regions +orthoMatExtended = orthomatextend(orthoMat,tailLength,'first'); +% multiply local orthogonal matrix by windowing function +phi(1:wLength(1)+tailLength,1:wLength(1)) = diag(sparse(g))*orthoMatExtended; + +% central frames +for p=2:nWindows-1 + % generate window + g = lappedwindow(wLength(p),tailLength,tailFunc); + % generate local orthogonal matrix + orthoMat = basisFun(eye(wLength(p))); + % periodically extend length of basis functions to overlapping regions + orthoMatExtended = orthomatextend(orthoMat,tailLength); + % multiply local orthogonal matrix by windowing function + phi(sum(wLength(1:p-1))-tailLength+(1:suppLen(p)),sum(wLength(1:p-1))+(1:wLength(p)))... + = diag(sparse(g))*orthoMatExtended; +end + +%last frame +% generate window +g = lappedwindow(wLength(end),tailLength,tailFunc,'last'); +% generate local orthogonal matrix +if strcmpi(orthobasis,'mdct') %if mdct use dct I at last block to avoid artefacts + orthoMat = dcti(eye(wLength(end)),'I'); +else + orthoMat = basisFun(eye(wLength(end))); +end +% periodically extend length of basis functions to overlapping regions +orthoMatExtended = orthomatextend(orthoMat,tailLength,'last'); +% multiply local orthogonal matrix by windowing function +phi(sum(wLength(1:end-1))-tailLength+(1:wLength(end)+tailLength),sum(wLength(1:end-1))+(1:wLength(end)))... + = diag(sparse(g))*orthoMatExtended; + +function orthomatextended = orthomatextend(orthomat,tailLength,special) +% Periodic extension of local orthonormal basis +if ~exist('special','var') || isempty(special), special = []; end + +if strcmpi(special,'first') + % odd symmetry at the end of basis functions + orthomatextended = [orthomat; -orthomat(end:-1:end-tailLength+1,:)]; +elseif strcmpi(special,'last') + % even symmetry at the beginning of basis functions + orthomatextended = [flipud(orthomat(1:tailLength,:)); orthomat]; +else + % even symmetry at the beginning and odd symmetry at the end of basis + % functions + orthomatextended = [flipud(orthomat(1:tailLength,:)); orthomat; ... + -orthomat(end:-1:end-tailLength+1,:)]; +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lotplot.m Thu Jun 16 13:33:43 2011 +0100 @@ -0,0 +1,51 @@ +function varargout = lappedorthoplot(y,wLength,Fs) +%LAPPEDORTHOPLOT plot of the lapped orthogonal transform +% +% varargout = lappedorthoplot(y,wLength,timeVec) +% +% plots a spectrogram-like visualisation of the lapped orthogonal +% transform coefficients contained in y +% +% INPUT: +% - y: vector containing the lapped orthogonal transform coefficients +% - wLength: vector containing the lengths of the overlapping windows +% - Fs: sampling frequency (default 44100) +% +% OUTPUT: +% - varargout{1}: optionally, the function outputs the matrix containing +% the spectrogram-like representation. +% +% SEE ALSO +% lappedorthotransform +% +% ----------------------------------------------------------- % +% Daniele Barchiesi, daniele.barchiesi@eecs.qmul.ac.uk % +% Centre for Digital Music, Queen Mary University of London % +% Apr. 2011 % +% ----------------------------------------------------------- % +nWindows = length(wLength); +maxLength = max(wLength); +sigLength = sum(wLength); + +if ~exist('Fs','var') || isempty(Fs), Fs = 44100; end + +timeVec = linspace(0,sigLength/Fs,10*ceil(sigLength/min(wLength))); + +S = zeros(maxLength,length(timeVec)); +timeSupp = @(p) floor(wLength(p)*length(timeVec)/sigLength); +interpFun = @(p,v) interp1(1:wLength(p),abs(v),linspace(1,wLength(p),maxLength))'; +S(:,1:timeSupp(1)) = repmat(interpFun(1,y(1:wLength(1))),1,timeSupp(1)); +for i=2:nWindows + S(:,sum(timeSupp(1:i-1))+(1:timeSupp(i))) = ... + repmat(interpFun(i,y(sum(wLength(1:i-1))+(1:wLength(i)))),1,timeSupp(i)); +end + +SmagdB = mag2db(S); +if nargout, varargout{1} = SmagdB; end + +surf(timeVec,1:maxLength,SmagdB,'EdgeColor','none'); +axis xy; axis tight; +colormap(jet); +view(0,90); +set(gca,'YScale','log'); +title(['l1/l2 = ' num2str(l1overl2(y))]) \ No newline at end of file