function [fwhm, absorption_min, contrast_left, contrast_right, features] = getPeak(detunings, absorptions) eit_data = [detunings, absorptions]; %Get local extrema values and indexes and sort them [maxima, max_index, minima, min_index] = extrema(eit_data(:,2)); minima = [min_index, minima]; maxima = [max_index, maxima]; peaks = sortrows([maxima; minima], 1); % Find the set of extrema closest to being centered on 0 center_index = find(eit_data(:,1) == 0); differences = abs(peaks(:,1) - center_index); [detuning_index_offset, peak_center_index] = min(differences); peak_center = peaks(peak_center_index, :); left_max = peaks(peak_center_index - 1, :); right_max = peaks(peak_center_index + 1, :); %Define each point of interest absorption_min = peak_center(2); left_range = left_max(1):peak_center(1); right_range = peak_center(1):right_max(1); %Calculate the width absorption_max = min([right_max(2), left_max(2)]); % use the smallest of the maximums absorption_mid = (absorption_max + absorption_min) / 2; half_width_right = interp1(eit_data(right_range,2), eit_data(right_range,1), absorption_mid) - eit_data(peak_center(1),1); half_width_left = eit_data(peak_center(1),1) - interp1(eit_data(left_range,2), eit_data(left_range,1), absorption_mid); fwhm = half_width_right + half_width_left; linewidth = [eit_data(peak_center(1),1)-half_width_left, absorption_mid; eit_data(peak_center(1),1)+half_width_right, absorption_mid]; left_max = [detunings(left_max(1)), left_max(2)]; right_max = [detunings(right_max(1)), right_max(2)]; peak_center = [detunings(peak_center(1)), peak_center(2)]; features = [left_max; peak_center; right_max; linewidth]; contrast_left = (left_max(2) - peak_center(2))/left_max(2); contrast_right = (right_max(2) - peak_center(2))/right_max(2); %Plot extrema over existing plot % features = figure('visible', 'off'); % plot( % eit_data(:,1), eit_data(:,2), % detunings(left_max(1)), left_max(2), 'r*', % detunings(right_max(1)), right_max(2), 'r*', % detunings(peak_center(1)), peak_center(2), 'g*', % linewidth(:,1), linewidth(:,2) % ); end