function imgdb(a1,a2,a3)
% imgdb(X)                 Show matrix as an image, but convert it to dB first.
if(nargin>=3)  % 3-arg version
  X = a3;
else
  X = a1;
end
[nr,nc]=size(X);

dbx = 8.68588963806504*log(max(0.0000101,1000*abs(X)));
maxdbx = max(max(dbx));
% limit to 50 dB range black to white
mdbx = max(dbx, maxdbx-50.0);

if(nargin<3)
  a1 = [1 nc];
  a2 = [1 nr];
end

v = version;
if(v([1 2 3])=='4.1')
  OLDVERS = 1;
else
  OLDVERS = 0;
end
if(v([1 2])=='5.' | v([1 2])=='6.')
  MAT5 = 1;
else
  MAT5 = 0;
end

% Matlab 4 only
if (MAT5 == 0) 
	a2 = fliplr(a2);
end

imagesc(a1, a2, mdbx);

if (MAT5)
	axis xy
end
