-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatm_Gaussian_single_peak.m
59 lines (50 loc) · 2.97 KB
/
atm_Gaussian_single_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
function f = atm_gaussian_single_peak(pars,t)
% ------------------------------------------------------------------------------------------------------------------------------------------------------------------
% SUMMARY: The atm_gaussian_single_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_single_peak
% use as a function: atm_gaussian_single_peak(pars,t)
%
% ------------------------------------------------------------------------------------------------------------------------------------------------------------------
% INPUT PARAMETERS
%
% pars Array with 4 input parameters for a Gaussian function with a single peak 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
%
% 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_single_peak:nargin', ['\n\tERROR: Number of input arguments must be 2:\n', ...
'\tSYNTAX: atm_gaussian_single_peak(pars,t);\n'])
end
% check pars array
if (any(~isfinite(pars)) || ~isvector(pars) || numel(pars) ~= 4)
error('atm_gaussian_single_peak:pars', '\n\tERROR: pars input values must be finite and a 4 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
e_g = pars(1); % signal baseline
A_g = pars(2); % Amplitude
t_g = pars(3); % peak location
s_g = pars(4); % 1-sigma peak with = standard deviation
%% set Gaussian function with a single peaks and baseline
f = e_g + A_g.* exp(-0.5.*(t - t_g).^2./(s_g^2));
end