
Untitled
By: a guest on
May 25th, 2012 | syntax:
None | size: 2.46 KB | hits: 15 | expires: Never
MATLAB: Adjusting the dynamic range of a plot of logarithmic values
%% Constants
fnum = 1;
Fc = 1/16;
taup = 128;
taumin = 1;
taumax = 512;
taux = taumin:taumax;
%% Signal
l = 1:16; %Signal length
s = sin(2*pi*Fc*l); %Original Signal
sig = zeros([1 taup+512]);
sig(taup:taup+size(l,2)-1) = s;
[mfr,fdy] = MatchedFilterResponse(sig,taup,l);
Z = mfr;
slices = true;
%full dynamic range
name = 'Short Tone Ping results with 0dB range';
Zmag = abs(Z).^2;
Zn = normalizeMat(Zmag);
Zdb = 10*log10(1+Zn);
fnum = plotSurfaces(taux,fdy,Zdb,fnum,name,slices);
slices = false;
%40dB dynamic range
name = 'Short Tone Ping results with 40dB range';
Z40mag = Zmag;
Z40n = normalizeMat(Z40mag);
Z40n(Z40n<0.0001) = 0.0001;
Z40db = 10*log10(1+Z40n);
fnum = plotSurfaces(taux,fdy,Z40db,fnum,name,slices);
function [mfr,fdy] = MatchedFilterResponse(sig,taup,l)
Fdmin = -1/16;
Fdmax = 1/16;
Fdinc = (0.125)/(255);
fdy = linspace(Fdmin,Fdmax,256);
i = 0;
for tau = 1:512
i = i+1;
j = 0;
for Fd = Fdmin:Fdinc:Fdmax
j = j+1;
a = sig(l+taup-1);
b = sig(l+tau).*exp(1i*2*pi*Fd*l);
mfr(j,i) = sum(a.*b);
end
end
return
end
function [fnum] = plotSurfaces(taux,fdy,z,fnum,name,slices)
fid = figure(fnum);
axes1 = axes('Parent',fid);
grid(axes1,'on');
hold(axes1,'all');
msh = mesh(taux,fdy,z,'Parent',axes1);
xlabel ('Delay - seconds');
ylabel ('Frequency offset from center frequency - Cycles/sample');
zlabel ('Ambiguity function (Normalized Magnitude-Squared)','Visible','off');
fname = strcat(name,' (Ambiguity Function z(tau;F_d))');
title(fname);
ax = axis;
axis([50 200 ax(3) ax(4)])
cb = colorbar('peer',axes1);
set(get(cb,'ylabel'),'String','Magnitude-Squared (dB)');
hold off;
fnum = fnum + 1;
return
end
data = 10 .^ randn(100,100); % large dynamic range data
ncols = 128; % number of colors in the colormap
R1 = [linspace(0,1, 10)'; ones(ncols - 10, 1); ]; % colormap for the small values
R2 = [zeros(ncols - 10, 1); linspace(0,1,10)']; % colormap for the large values
G = zeros(ncols, 1);
B = zeros(ncols, 1);
cmap1 = [R1, G, B];
cmap2 = [R2, G, B];
figure
subplot(1,2,1)
rgbplot(cmap1) % plot the colormap values
subplot(1,2,2)
imagesc (data) % plot the data
colormap(cmap1)
colorbar
figure
subplot(1,2,1)
rgbplot(cmap2)
subplot(1,2,2)
imagesc (data)
colormap(cmap2)
colorbar