summaryrefslogtreecommitdiff
path: root/getPeak.m
blob: 088a9ca88a9326bcd486bb7e1b2ff1f1fe9e4a3d (plain)
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
function [fwhm, absorption_min] = 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;
    
    
    %Plot extrema over existing plot
    % plot(eit_data(:,1), eit_data(:,2));
    % hold all
    % grid on
    % plot(detuning_1(left_max(1)), left_max(2), 'r*')
    % plot(detuning_1(right_max(1)), right_max(2), 'r*')
    % plot(detuning_1(peak_center(1)), peak_center(2), 'g*')
    

end