-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfwhm.m
61 lines (58 loc) · 1.48 KB
/
fwhm.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
function [width,tlead,ttrail] = fwhm(x,y)
% function width = fwhm(x,y)
%
% Full-Width at Half-Maximum (FWHM) of the waveform y(x)
% and its polarity.
% The FWHM result in 'width' will be in units of 'x'
%
%
% Rev 1.2, April 2006 (Patrick Egan)
y = y / max(y);
N = length(y);
lev50 = 0.5;
if y(1) < lev50 % find index of center (max or min) of pulse
[garbage,centerindex]=max(y);
% if centerindex>N-3
% centerindex=centerindex-4;
% end
Pol = +1;
disp('Pulse Polarity = Positive')
else
[garbage,centerindex]=min(y);
Pol = -1;
disp('Pulse Polarity = Negative')
end
i = 2;
while sign(y(i)-lev50) == sign(y(i-1)-lev50)
i = i+1;
if i>=N; break
end
end %first crossing is between v(i-1) & v(i)
interp = (lev50-y(i-1)) / (y(i)-y(i-1));
tlead = x(i-1) + interp*(x(i)-x(i-1));
i = centerindex+1;
if i >= N
disp('No found')
ttrail = NaN;
width = NaN;
tlead=NaN;
i=round(N/2);
end
%start search for next crossing at center
while ((sign(y(i)-lev50) == sign(y(i-1)-lev50)) && (i <= N-1))
i = i+1;
if i>=N; break
end
end
if i ~= N
Ptype = 1;
disp('Pulse is Impulse or Rectangular with 2 edges')
interp = (lev50-y(i-1)) / (y(i)-y(i-1));
ttrail = x(i-1) + interp*(x(i)-x(i-1));
width = ttrail - tlead;
else
Ptype = 2;
disp('Step-Like Pulse, no second edge')
ttrail = NaN;
width = NaN;
end