function tfp4(basis,Y)

%EXTENDED TFPLOT FUNCTION:
%
%TFP4   Plots the time-frequency plane tiling of a wavelet or
%	   wavelet packet transform.
%
%	   TFP4(B,Y) plots the TF plane for the basis B.
%          L is the length of the original signal, and Y the
%          vector of coefficients. 
%          The B and Y must be filter bank ordered.
%          Modified by Arne Jensen 2003
%
%          See also: PRUNEADD

%--------------------------------------------------------
% 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
%--------------------------------------------------------


%if length(basis)==1		% Wavelet transform: a wavelet packet basis
	%for i=basis:-1:1	% vector is built.
		%basis=[basis i];
	%end
%end

l=length(basis);
k = floor(log2(length(Y)));

[basis,Y2]=chformat(basis,0,Y,length(Y));

clf
axis([0 1 0 1])
hold on			% This freezes the axes

y2=0;			% Initial position for the boxes of this band
cnt = 1;
%map= colormap;
colormap(gray);
Y2 = log(abs(Y2)+1);
%size(Y)
for i=1:l
	dt=2^(basis(i)-k);	% Time width of the 'Heisenberg box'	
	df=2^(-basis(i));	% Frequency height
	nb=1/dt;		% Number of boxes per frequency band
	x1=0;
	x2=dt;
	y1=y2;
	y2=y2+df;

	for j=1:nb			% Plot the boxes of each band, from left to right 
                col=abs(Y2(cnt)/max(Y2));
		
patch([x1 x2 x2 x1 x1],[y1 y1 y2 y2 y1],64-floor((col^2)*63),'EdgeColor','none')
		cnt = cnt + 1;
		x1=x1+dt;
		x2=x2+dt;		% Renew the positions
	end
end
%cnt
g=gca;
set(g,'XTickLabel','','XTick',[0 1])	% Removing tick marks ... 
set(g,'YTickLabel','','YTick',[0 1])
xlabel('Time')				% ... but not axis labels
ylabel('Frequency')
set(g,'Box','on');
axis equal;
axis tight;
hold off				% Unfreezes the axes
