-
Notifications
You must be signed in to change notification settings - Fork 1
/
findEchoDist.m
77 lines (66 loc) · 1.88 KB
/
findEchoDist.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function [x,y,varargout] = findEchoDist(data,varargin)
%function [xlog,nlog,xlin,nlin,hit_num] = findEchoDist(data,opt)
% Get normalized amplitude distribution
% INPUT
% data echo amp data
% varargin varargin{1}: #points on the x-axis; default=100
% varargin{2}: 0-log, 1-lin; default=0
% varargin{3}: 1-plot, 0-no plot; default=0
%
% OUTPUT
% x x-axis
% y pdf
% varargout # of hits in each x-axis bin
%
% Wu-Jung Lee | [email protected]
% 2010/05/16
% 2010/07/19 modified
% 2010/10/18 modified take out the normalization for raw distribution
% 2012/01/02 modified to use varagrout
% 2012/04/05 modified to use varargin
% 2012/11/01 simplify the code...
% 2016/08/30 Fix dimension mismatch error
if ~isempty(varargin)
if length(varargin)==3
npt = varargin{1};
ll_opt = varargin{2};
plot_opt = varargin{3};
elseif length(varargin)==2
npt = varargin{1};
ll_opt = varargin{2};
plot_opt = 0;
else
npt = varargin{1};
ll_opt = 0;
plot_opt = 0;
end
else
ll_opt = 0;
npt = 100;
plot_opt = 0;
end
if ll_opt==0
edges = logspace(log10(min(data)),log10(max(data)),npt+1);
x = sqrt(edges(1:end-1).*edges(2:end));
else
edges = linspace(min(data),max(data),npt+1);
x = mean([edges(1:end-1);edges(2:end)],1);
end
hitnum = histc(data,edges);
y = hitnum(1:end-1)./diff(edges(:)); % Fix dimension mismatch error 08/30/2016
y = y/trapz(x,y);
x = x.';
y = y.';
varargout{1} = hitnum;
if plot_opt==1
rayl = raylpdf(x,1/sqrt(2));
figure;
hr = loglog(x,rayl,'k');
hold on
hy = loglog(x,y,'rx');
legend({'Rayleigh','Data'});
xlabel('Echo amplitude','fontsize',14);
ylabel('PDF','fontsize',14);
ylim([1e-5 1e2])
xlim([1e-3 1e2])
end