function [b,y]=chformat(basis,opt,w,len,flag) % CHFORMAT Changes the order of the basis or coefficient vector in the % Wavelet Packet Transform. % % B=CHFORMAT(BASIS,OPT) changes BASIS vector from the format % given in OPT to the reciprocal one. % % OPT: 0 ==> 'BASIS' is the filter bank scheme % 1 ==> 'BASIS' is the tree in frequency domain % % [B,Y]=CHFORMAT(BASIS,OPT,W,LEN) also sorts the coefficients W % obtained with BASIS and format OPT, where W is the Wavelet % Packet coefficient vector; LEN (original signal length) % is only required if it is not a power of two. % CHFORMAT returns the basis B and the coefficients Y in the % reciprocal format given in OPT. % % See also: WPK, IWPK. %-------------------------------------------------------- % Copyright (C) 1994, 1995, 1996, by Universidad de Vigo % % % Uvi_Wave is free software; you can redistribute it and/or modify it % under the terms of the GNU General Public License as published by the % Free Software Foundation; either version 2, or (at your option) any % later version. % % Uvi_Wave is distributed in the hope that it will be useful, but WITHOUT % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or % FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License % for more details. % % You should have received a copy of the GNU General Public License % along with Uvi_Wave; see the file COPYING. If not, write to the Free % Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. % % Author: Santiago Gonzalez Sanchez % e-mail: Uvi_Wave@tsc.uvigo.es %-------------------------------------------------------- N=length(basis); if (nargin==2)|(nargin==3)|(nargin==4) % we are at the root of the tree if (sum(2.^(-basis))~=1) % check that 'basis' is possible disp('Error: wrong basis specification.') return end flag=0; if (size(basis,2)~=1) % if 'basis' is a row vector basis=basis(:); % it is returned the same way fil1=1; else fil1=0; end if nargin==3 len=length(w); end if nargin==2 % initialization when working w=[]; % with basis vector only len=[]; end if (size(w,2)~=1) % if 'w' is a row vector w=w(:); % it is returned the same way fil2=1; else fil2=0; end end % cut 'basis' in 2 halves, each one of them matching the % two branches/subtrees starting from the current node tope=0.5; suma=2^(-basis(1)); i=1; while (suma