summaryrefslogtreecommitdiff
path: root/getPeak.m
diff options
context:
space:
mode:
Diffstat (limited to 'getPeak.m')
-rw-r--r--getPeak.m42
1 files changed, 42 insertions, 0 deletions
diff --git a/getPeak.m b/getPeak.m
new file mode 100644
index 0000000..088a9ca
--- /dev/null
+++ b/getPeak.m
@@ -0,0 +1,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