Newer
Older
Yves Gouriou
committed
function [] = tsg_moveaverage(hTsgGUI)
% Perform a moving average of a time series.
% The average is made over a period equal to 'tsg.cst.TSG_DT_SMOOTH'
% Data exceeding the average over that period by 'tsg.cst.TSG_STDMAX'
% are not taken into account.
%
% Input

jacques.grelet_ird.fr
committed
% hTsgGUI ............ Handle to the main user interface
Yves Gouriou
committed
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
%
% No computation : NaN
%
% Get the tsg structure from the application
% ------------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
% Memory allocation
% -----------------
%tsg.ssps.smooth = zeros( size(tsg.SSPS) );
%tsg.ssps.smooth.nval = zeros( size(tsg.SSPS) );
smooth = zeros( size(tsg.SSPS) );
nval = zeros( size(tsg.SSPS) );
% Loop over the tsg.SSPS time series
% -----------------------------------
for i = 1:length(tsg.SSPS)
% Select the param data over 'tsg.cst.TSG_DT_SMOOTH' time interval
% ind1 : indices of tsg.SSPS in the 'tsg.cst.TSG_DT_SMOOTH' time interval
% ind2 : indices of 'good' tsg.SSPS in the 'tsg.cst.TSG_DT_SMOOTH' time
% interval
% --------------------------------------------------
ind1 = find( tsg.DAYD >= tsg.DAYD(i) - tsg.cst.TSG_DT_SMOOTH/2 & ...
tsg.DAYD <= tsg.DAYD(i) + tsg.cst.TSG_DT_SMOOTH/2 );
ind2 = ind1;
if ~isempty(ind2)
currentStd = Inf;
previousStd = 0;
% Compare Standard Deviation to the MAX acceptable STD
% ------------------------------------------------
while currentStd > tsg.cst.TSG_STDMAX && currentStd ~= previousStd
previousStd = currentStd;
% Standard deviation and average over timeInterval
% ------------------------------------------------
currentStd = nanstd( tsg.SSPS(ind2) );
meanParam = nanmean( tsg.SSPS(ind2) );
% Indices of 'good' values of Param
% ---------------------------------
ind2 = find( tsg.SSPS(ind1) >= meanParam - currentStd & ...
tsg.SSPS(ind1) <= meanParam + currentStd);
ind2 = ind1( ind2 );
end
smooth(i) = nanmean( tsg.SSPS(ind2) );
else
smooth(i) = NaN;
end
nval( i ) = length( ind2 );
end
tsg.ssps.smooth.val = smooth;
tsg.ssps.smooth.nval = nval;
% Update the tsg structure in the application
% --------------------------------------------
setappdata( hTsgGUI, 'tsg_data', tsg);