function h = cor_plts(z, sv, paras, M0, BP)
% COR_PLTS static cortical representation 
%	cor_plts(z, sv, paras);
%	cor_plts(z, sv, paras, M0);
%	z	: static cortical representation, M-by-K, M = 128.
%   sv      : scale vector in cyc/oct, e.g., 2.^(-2:.5:3).
%	paras	: parameter set. (see WAV2AUD).
%	M0	: # of frequency channel
%
%	COR_PLTS plots the static cortical representation generated by AUD2CORS.
%	See also: AUD2CORS

% Auther: Powen Ru (powen@isr.umd.edu), NSL, UMD
% v1.00: 17-Jun-97
% v1.01: 30-Jul-97, make it executable in Matlab4
% v1.02: 19-Aug-97, new: M0, dM for non-truncation
% v1.03: 16-Sep-97, colormap auto-detection
% v1.04: 12-Apr-98, make quiver density flexible

if isglobal('TICKLABEL'),
	global TICKLABEL;
else,
	TICKLABEL = 'ticklabel';
end;

% target cortical representaion
[M, K] = size(z);
if nargin < 4, M0 = M; end;
dM = max((M-M0)/2, 0);
if nargin < 5, BP = 0; end;
if length(sv) ~= K, error('Size not matched'); end;

% xtick labels
xtic = (11:24:128);
xtlabel = [];
for fdx = 5:-1:1,
	R1 = sprintf('%5d', round(1000*2^(fdx-3+paras(4))));
        xtlabel = [R1; xtlabel];
end;

% ytick labels
ytic = []; ytlabel = [];
for k = 1:K,
        R1 = log2(sv(k));
        if abs(R1-round(R1)) < .001,
                ytic = [ytic k];
                ytlabel = [ytlabel; sprintf('%3.1f', sv(k))];
        end;
end;

% image
K1 = 2-BP;
K2 = K;
z = z(:, K1:K2);

if isa1map,
	image(1-dM:M0+dM, K1:K2, cplx_col(z')); 
else,
	za = abs(z);
	zp = angle(z);
	imagesc(1-dM:M0+dM, K1:K2, za', [0 max(za(:))]);
	
	z = z * i;				% rotation 90 deg

	fdx = 1:ceil(M/128):M;
	sdx = 1:ceil(K/64):K2-1;
	%size(z), M, K
	hold on;
	h = quiver(fdx-dM, sdx+1, real(z(fdx, sdx))', ...
		imag(z(fdx, sdx))', .5, 'w-');
	set(h, 'linew', 1);
	hold off;
end;

axis xy;
if dM, hold on;
	plot([0 M0+1; 0 M0+1], [K+1 K+1; 1 1], 'k--');
hold off; end;

set(gca, 'xtick', xtic, ['x' TICKLABEL], xtlabel, ...
	'ytick', ytic, ['y' TICKLABEL], ytlabel);
if size(sv, 1) > 1,
	for xi = 11:12:128,
		text('position', [xi, .1*k], 'str', ['#' num2str(xi)], ...
			'ho', 'ce', 'fontwe', 'bo', 'fontsi', 10, 'fontna', 'times');
	end;
	for yi = ytic,
		text('position', [.02*M yi], 'str', ['#' num2str(yi)], ...
        	'ho', 'le', 'fontwe', 'bo', 'fontsi', 10, 'fontna', 'times');
	end;
end;
