-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathEr_PL_in_YSO.m
76 lines (61 loc) · 2.12 KB
/
Er_PL_in_YSO.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
%% PeakFit Example #1: Er PL in YSO
%
% Copyright: Herianto Lim (https://heriantolim.com)
% Licensing: GNU General Public License v3.0
% First created: 28/10/2018
% Last modified: 28/10/2018
% Add the required packages using MatVerCon.
% addpackage('MatCommon','MatGraphics','PeakFit');
% Clear workspace variables.
clear;
% Load data. If fails, adjust the file path supplied to the argument.
S = load('Er_PL_in_YSO.mat');
% Perform Lorentzian peak fitting with default values.
% The algorithm will attempt to find all the peaks in the spectrum.
S.Fit = PeakFit(S.Data, 'PeakShape', 'Lorentzian');
%% Plotting
% Settings.
Groot.usedefault();
Groot.usedefault('latex', 8, .6);
RESOLUTION = 300;
AXES_SIZE = [12, 4];
TICK_LENGTH = .2;
% Plot data.
xData = S.Fit.XData;
yData = S.Fit.YData;
xLim = S.Fit.Window;
xModel = linspace(xLim(1), xLim(2), ceil(RESOLUTION / 2.54 * AXES_SIZE(1)));
[yModel, yPeak, yBaseline] = S.Fit.model(xModel);
yLim = [min(min(yData), min(yBaseline)), max(max(yData), max(yModel))];
% Figure.
fig = docfigure(AXES_SIZE);
% Axes.
pos = [0, 0, AXES_SIZE];
ax = axes('Position', pos, 'XLim', xLim, 'YLim', yLim, 'YTickLabel', '');
xlabel('Wavenumber (cm$^{-1}$)');
ylabel('Intensity (arb. unit)');
fixticklength(.2);
% Plots.
N = S.Fit.NumPeaks;
h = plot(xData, yData, 'Color', 'b');
for j = 1:N
plot(xModel, yBaseline + yPeak{j}, 'Color', 'r', 'LineWidth', .3);
end
h(2) = plot(xModel, yModel, 'Color', 'g', 'LineWidth', .3);
% Peak labels.
h = Label.peak(S.Fit.Center(1, :), 'StringFormat', '%.1f', ...
'FontColor', [.3, .3, .3], 'LineWidth', 0, ...
'MinYPos', .1, 'MinYDist', .01, 'PlotLine', h);
% Reconfigure the axes.
extent = vertcat(h.Extent);
yLim(2) = max(extent(:, 2) + extent(:, 4));
yLim(2) = yLim(1) + diff(yLim) / (1 - TICK_LENGTH / AXES_SIZE(2));
ax.YLim = yLim;
% Reconfigure the layout.
margin = ax.TightInset + .1;
ax.Position = pos + [margin(1), margin(2), 0, 0];
pos = pos + [0, 0, margin(1) + margin(3), margin(2) + margin(4)];
set(fig, {'Position', 'PaperPosition', 'PaperSize'}, {pos, pos, pos(3:4)});
% Saving.
print(fig, 'Er_PL_in_YSO.png', '-dpng', sprintf('-r%d', RESOLUTION));
close(fig);