% function test_stuttgart_diff_acc()

% TEST_STUTTGART_DIFF_ACC
% 

%% Input AOs

pl = plist();
pl = append(pl, param('nsecs', 10));
pl = append(pl, param('fs', 100));
pl = append(pl, param('tsfcn', 'randn(size(t))'));

X1   = ao('X1.xml');
X12  = ao('X12.xml');
Fsus = ao('Fsus.xml');

%% Plot time-series

pl = plist(param('times', [10 20000]));
X1   = split(X1, pl);
X12  = split(X12, pl);
Fsus = split(Fsus, pl);

figure
plot([X1 X12 Fsus])
% ltpda_xaxis(0, 100)



%% Detrend
pl = plist(param('N', 0));

X1dt   = ltpda_polydetrend(X1, pl);
X12dt  = ltpda_polydetrend(X12, pl);
Fsusdt = ltpda_polydetrend(Fsus, pl);

figure
plot([X1dt X12dt Fsusdt])
% ltpda_xaxis(0, 100)

%% Call diff_acc

[X1, X2, X3, P] = ltpda_diff_acc(X1dt, X12dt, Fsusdt, plist());

pl = plist(param('times', [20 20000]));
X1   = split(X1, pl);
X2   = split(X2, pl);
X3   = split(X3, pl);

%% Plots

figure
plot(X3.hist)


%% Make PSD estimates

w   = specwin('Hanning', 10);
% pl  = plist(param('Nfft', 3600));
pl  = append(pl, param('Win', w));

X3xx = ltpda_pwelch(X3, pl);

figure
plot(X3xx)



% END