function fwhm = sta_fwhm(sta, dt)
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here

% Subtract offset
sta = sta - min(sta);
n = 1:numel(sta);

% Find peak location
[p, pi] = max(sta);

% Find local minima around peak
[m1, m1i] = min(sta(n < pi));
[m2, m2i] = min(sta(n > pi));
m2i = m2i + pi;

% Find the FWHM between the maximum and local minima
[~, h1i] = min(abs(sta(n < pi & n > m1i) - p/2));
h1i = h1i + m1i;
[~, h2i] = min(abs(sta(n > pi & n < m2i) - p/2));
h2i = h2i + pi;

% % Sanity check
% figure;
% hold on
% plot(sta)
% plot(pi,p,'r*')
% plot(m2i,m2,'r*')
% plot(m1i,m1,'r*')
% plot(h2i,p/2,'r*')
% plot(h1i,p/2,'r*')
% plot([h1i h2i],[p/2 p/2],'r')
% close gcf

fwhm = dt*(h2i - h1i);


end

