function h = cor_pltf(z, sv, paras, M0)
% COR_PLTF features of static cortical representation 
%	cor_pltf(z, sv, paras);
%	cor_pltf(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

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 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 = 2: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 = 3;
K2 = K-1;
z = z(:, K1:K2);
mdx = 1-dM:M0+dM;
kdx = K1:K2;
a = abs(z);
p = angle(z);
zt = a .* (abs(p) < (pi/8));
%image(mdx, kdx, cplx_col(zt')); 
%axis xy;
hold on;
contour(mdx, kdx, a', 8, 'c--');
hold on;
contour(mdx, kdx, p', 8, 'y');
zij = cor2sing(z);
h = plot(mdx(zij(:, 1)), kdx(zij(:, 2)), 'k*');
set(h, 'markersi', 10);
if dM,
	plot([0 M0+1; 0 M0+1], [K+1 K+1; 1 1], 'k--');
end;
hold off; 
set(gca, 'xtick', xtic, ['x' TICKLABEL], xtlabel, ...
	'ytick', ytic, ['y' TICKLABEL], ytlabel, 'box', 'on');
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;

axis tight
