function test_ltpda_lcohere()

% Test ltpda_lcohere functionality.
% 
% M Hewitson 13-02-07
% 
% $Id: test_ltpda_lcohere.m,v 1.6 2008/07/20 19:55:43 hewitson Exp $
% 

%% Make test AOs

nsecs = 100000;
fs    = 10;

pl = plist();
pl.append('nsecs', nsecs);
pl.append('fs', fs);
pl.append('tsfcn', 'randn(size(t))');

a1 = ao(pl);
a2 = ao(pl);

%% Filter one time-series


% Make a filter
pl = plist(param('type', 'bandpass'));
pl.append('fs', fs);
pl.append('order', 4);
pl.append('fc', [0.03 0.1]);
f2 = miir(pl);

% filter the input data
[a3, f2] = filter(a1,plist(param('filter', f2)));

%% make some cross-power
a4 = a1+a3;
a5 = a2+a3;

%% Make Coherence from a6 to a7

pl = plist();
pl.append('Kdes', 100);
pl.append('Kmin', 2);
pl.append('Jdes', 1000);
pl.append('Order', 0);
pl.append('Lmin', 0);
pl.append('Win', specwin('Hanning', 10));

a8 = lcohere(a1, a5, pl);
a9 = cohere(a1, a5, plist('Nfft', 10000, 'win', specwin('Hanning', 10)));


%% Plot results and history

iplot(a9(1,2), a8(1,2));

plot(a8(1,2).hist);

return

%% Reproduce from history

% Write an m-file from AO
ao2m(a8(1,2), 'test.m');

% now run it
clear all;
a_out = test;

iplot(a_out(1,2))

plot(a_out(1,2).hist)
