-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmodel.m
88 lines (75 loc) · 2.32 KB
/
model.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
77
78
79
80
81
82
83
84
85
86
87
88
function [yModel, yPeak, yBaseline] = model(obj, varargin)
%% Fit Model
% [yModel, yPeak, yBaseline] = obj.model() returns a set of fit models
% evaluated at the data points.
%
% [yModel, yPeak, yBaseline] = obj.model(x) evaluates the fit models at x
% instead.
%
% Outputs:
% yModel: The reconstructed data points from the fit results.
%
% yPeak: A cell containing the resconstructed data points of each peak.
%
% yBaseline: The reconstructed baseline points.
%
% Requires package:
% - MatCommon_v1.0.0+
%
% Tested on:
% - MATLAB R2013b
%
% Copyright: Herianto Lim (https://heriantolim.com)
% Licensing: GNU General Public License v3.0
% First created: 04/04/2013
% Last modified: 25/10/2016
yModel = [];
yPeak = [];
yBaseline = [];
numPeaks = obj.NumPeaks;
center = obj.Center;
height = obj.Height;
width = obj.Width;
if numPeaks == 0 || isempty(center) || isempty(height) || isempty(width)
return
end
%% Parse Inputs
if nargin == 1
xModel = obj.XData;
elseif nargin > 2
error('PeakfFit:model:TooManyInput', ...
'At most one input argument can be taken.');
elseif isrealvector(varargin{1})
xModel = varargin{1};
else
error('PeakFit:model:InvalidInput', ...
'Input to the domains for the model must be a vector of real numbers.');
end
%% Construct Baseline
baseline = obj.Baseline;
if obj.BaselinePolyOrder < 0 || isempty(baseline)
yBaseline = zeros(size(xModel));
else
yBaseline = polyval(baseline(1, :), xModel);
end
%% Construct Peak
yPeak = cell(1, numPeaks);
for i = 1:numPeaks
switch obj.PeakShape(i)
case 1
yPeak{i} = PeakFit.fnlorentzian(xModel, ...
center(1, i), height(1, i), width(1, i));
case 2
yPeak{i} = PeakFit.fngaussian(xModel, ...
center(1, i), height(1, i), width(1, i));
otherwise
error('PeakFit:model:UnexpectedInput', ...
'The specified peak shape is not recognized.');
end
end
%% Construct Model
yModel = yBaseline;
for i = 1:numPeaks
yModel = yModel + yPeak{i};
end
end