-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatm_Gaussian_two_peak.m
67 lines (57 loc) · 3.31 KB
/
atm_Gaussian_two_peak.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
function f = atm_gaussian_two_peak(pars,t)
% ------------------------------------------------------------------------------------------------------------------------------------------------------------------
% SUMMARY: The atm_gaussian_two_peak function can be used as a function or a function handle for input into a nonlinear regression.
%
% SYNTAX: use as a function handle: @atm_gaussian_two_peak
% use as a function: atm_gaussian_two_peak(pars,t)
%
% ------------------------------------------------------------------------------------------------------------------------------------------------------------------
% INPUT PARAMETERS
%
% pars Array with 7 input parameters for a Gaussian function with two peaks as follows:
% e_g1 = pars(1); % signal baseline 1
% a_g1 = pars(2); % amplitude 1
% t_g1 = pars(3); % peak location 1
% s_g1 = pars(4); % 1-sigma peak width = standard deviation
%
% a_g2 = pars(5); % amplitude 2
% t_g2 = pars(6); % peak location 2
% s_g2 = pars(7); % 1-sigma peak width = standard deviation
%
% t Array of ATM waveform time tags with laser trigger time in nano seconds (e.g., atm_wvfm.shots(shot_nr).wf(rcv_gate).t)
%
% ------------------------------------------------------------------------------------------------------------------------------------------------------------------
% OUTPUT PARAMETERS
% function f when used as function handle or
% result of nonlinear regression when used as a function
%
% ------------------------------------------------------------------------------------------------------------------------------------------------------------------
% Author: Michael Studinger, NASA Goddard Space Flight Center, Greenbelt MD, USA.
% Version: 1.02 - August 19, 2015
% See also:
% ------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% check input parameters
% check number of input arguments
if (nargin ~= 2)
error('atm_gaussian_two_peak:nargin', ['\n\tERROR: Number of input arguments must be 2:\n', ...
'\tSYNTAX: atm_gaussian_two_peak(pars,t);\n'])
end
% check pars array
if (any(~isfinite(pars)) || ~isvector(pars) || numel(pars) ~= 7)
error('atm_gaussian_two_peak:pars', '\n\tERROR: pars input values must be finite and a 7 element vector.\n');
end
if (isvector(t) == 1) % means is a not column vector (dimension 1 x n)
t = double(t);
elseif (isvector(t) == 0) % is a column vector (dimension n x 1) that needs to be transformed into a vector
t = double(t)';
end
%% set Gaussian function with two peaks and one baseline
e_g1 = pars(1); % signal baseline 1
a_g1 = pars(2); % amplitude 1
t_g1 = pars(3); % peak location 1
s_g1 = pars(4); % 1-sigma peak width = standard deviation
a_g2 = pars(5); % amplitude 2
t_g2 = pars(6); % peak location 2
s_g2 = pars(7); % 1-sigma peak width = standard deviation
f = e_g1 + a_g1.* exp(-0.5.*(t - t_g1).^2/(s_g1^2)) + a_g2.* exp(-0.5.*(t - t_g2).^2/(s_g2^2));
end