-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetFWHM.m
More file actions
48 lines (35 loc) · 1 KB
/
getFWHM.m
File metadata and controls
48 lines (35 loc) · 1 KB
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
function sx = getFWHM(dat,display)
if nargin < 2; display = 0; end
% return the exact FWHM of dat using local linear interpolation
% dat has to be a vector of any arbitrary focus
try
dat = linmap(dat,min(dat),max(dat),0,1);
% substract background
dat = dat - min(dat);
M = max(dat);
y = M*0.5;
map = abs(diff(dat > y));
temp = find(map == 1);
xa1 = temp(1);xb1 = temp(2);
xa2 = xa1+1; xb2 = xb1+1;
ya1 = dat(xa1); ya2=dat(xa2);
yb1=dat(xb1); yb2=dat(xb2);
ma = ya2-ya1;mb = yb2-yb1;
ca = ya1-ma*xa1;cb = yb1-mb*xb1;
sx = abs((y-ca)/ma - (y-cb)/mb);
% check the analysis by plot
if display
figure(display)
plot(dat)
hold on
plot(dat,'*')
plot([1 length(dat)],[y y])
plot(xa1,ya1,'g*');plot(xa2,ya2,'g*','linewidth',2)
plot(xb1,yb1,'g*');plot(xb2,yb2,'g*','linewidth',2)
plot((y-ca)/ma,y,'r*');plot((y-cb)/mb,y,'r*')
% xlim([length(dat)/2-40 length(dat)/2+40]);ylim([0.4 0.6])
hold off
end
catch
sx = length(dat);
end