Untitled

By: a guest on May 25th, 2012  |  syntax: None  |  size: 2.46 KB  |  hits: 15  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. MATLAB: Adjusting the dynamic range of a plot of logarithmic values
2. %% Constants
3. fnum = 1;
4. Fc = 1/16;
5. taup = 128;
6. taumin = 1;
7. taumax = 512;
8. taux = taumin:taumax;
9.
10. %% Signal
11. l = 1:16; %Signal length
12. s = sin(2*pi*Fc*l); %Original Signal
13. sig = zeros([1 taup+512]);
14. sig(taup:taup+size(l,2)-1) = s;
15.
16. [mfr,fdy] = MatchedFilterResponse(sig,taup,l);
17. Z = mfr;
18.
19. slices = true;
20. %full dynamic range
21. name = 'Short Tone Ping results with 0dB range';
22. Zmag = abs(Z).^2;
23. Zn = normalizeMat(Zmag);
24. Zdb = 10*log10(1+Zn);
25. fnum = plotSurfaces(taux,fdy,Zdb,fnum,name,slices);
26.
27. slices = false;
28. %40dB dynamic range
29. name = 'Short Tone Ping results with 40dB range';
30. Z40mag = Zmag;
31. Z40n = normalizeMat(Z40mag);
32. Z40n(Z40n<0.0001) = 0.0001;
33. Z40db = 10*log10(1+Z40n);
34. fnum = plotSurfaces(taux,fdy,Z40db,fnum,name,slices);
35.
36. function [mfr,fdy] = MatchedFilterResponse(sig,taup,l)
37.     Fdmin = -1/16;
38.     Fdmax = 1/16;
39.     Fdinc = (0.125)/(255);
40.     fdy = linspace(Fdmin,Fdmax,256);
41.     i = 0;
42.     for tau = 1:512
43.         i = i+1;
44.         j = 0;
45.         for Fd = Fdmin:Fdinc:Fdmax
46.             j = j+1;
47.             a = sig(l+taup-1);
48.             b = sig(l+tau).*exp(1i*2*pi*Fd*l);
49.             mfr(j,i) = sum(a.*b);
50.         end
51.     end
52. return
53. end
54.
55. function [fnum] = plotSurfaces(taux,fdy,z,fnum,name,slices)
56.     fid = figure(fnum);
57.     axes1 = axes('Parent',fid);
58.     grid(axes1,'on');
59.     hold(axes1,'all');
60.     msh = mesh(taux,fdy,z,'Parent',axes1);
61.     xlabel ('Delay - seconds');
62.     ylabel ('Frequency offset from center frequency - Cycles/sample');
63.     zlabel ('Ambiguity function (Normalized Magnitude-Squared)','Visible','off');
64.     fname = strcat(name,' (Ambiguity Function z(tau;F_d))');
65.     title(fname);
66.     ax = axis;
67.     axis([50 200 ax(3) ax(4)])
68.     cb = colorbar('peer',axes1);
69.     set(get(cb,'ylabel'),'String','Magnitude-Squared (dB)');
70.     hold off;
71.     fnum = fnum + 1;
72.     return
73. end
74.
75. data = 10 .^ randn(100,100);                      % large dynamic range data
76. ncols = 128;                                      % number of colors in the colormap
77. R1 = [linspace(0,1, 10)'; ones(ncols - 10, 1); ]; % colormap for the small values
78. R2 = [zeros(ncols - 10, 1); linspace(0,1,10)'];   % colormap for the large values
79. G = zeros(ncols, 1);
80. B = zeros(ncols, 1);
81. cmap1 = [R1, G, B];
82. cmap2 = [R2, G, B];
83.
84. figure
85. subplot(1,2,1)
86. rgbplot(cmap1) % plot the colormap values
87. subplot(1,2,2)
88. imagesc (data) % plot the data
89. colormap(cmap1)
90. colorbar
91.
92. figure
93. subplot(1,2,1)
94. rgbplot(cmap2)
95. subplot(1,2,2)
96. imagesc (data)
97. colormap(cmap2)
98. colorbar