% Tests the fngen method of the AO class.
% 
% M Hewitson 18-04-08
% 
% $Id: test_ao_fngen.m,v 1.3 2008/09/19 14:03:50 ingo Exp $
% 

clear

fs    = 12;
nsecs = 1e3;

% Make a sine-wave
s = ao(plist('tsfcn', 'randn(size(t)) + sin(2*pi*1e-1*t)', 'fs', fs, 'nsecs', nsecs));

% Add noise and signal
pl = plist('type', 'highpass', ...
  'order', 1,         ...
  'gain',  2.0,       ...
  'fs',    10,        ...
  'fc',    0.2);
a = filter(s, miir(pl));

% Compute target PSD
Nfft = fs*100;
axx = pwelch(a, plist('Nfft', Nfft, 'Scale', 'PSD', 'win', specwin('Hanning', 10)));

% Compute new time-series
Nsecs = 1e4;  % Number of seconds to produce
swin  = specwin('Kaiser', 10, 150); % Window for blending
b = fngen(axx, plist('Win', swin, 'Nsecs', Nsecs));


%% Output from noise generator
iplot(b)

sxx = pwelch(a,b, plist('Nfft', 100*fs, 'Scale', 'AS'));
% iplot(sxx(1)./sxx(2), plist('YScales', {'All', 'lin'}))
iplot(sxx)
