% Test script for ao/ifft
% 
% L. Ferraioli 02-12-08
% 
% $Id: test_ifft.m,v 1.5 2009/09/21 14:10:58 luigi Exp $
% 
% Description:
% 
%   Generate odd and even sets of data, do fft with all possible options
%   and test that ifft works correctly.
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Get odd and even sets of data

a1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 10));
a2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 10.1));

%% fft plain

% do standard matlab fft - frequency range from 0 Hz to sampling frequency
b1 = fft(a1,plist('type','plain'));
b2 = fft(a2,plist('type','plain'));

% ifft
c1 = ifft(b1);
c2 = ifft(b2);

% compare with original data
iplot(a1,c1, plist('LineStyles', {'-', '--'}));
iplot(a2,c2, plist('LineStyles', {'-', '--'}));
iplot(c1./a1,c2./a2,plist('LineStyles', {'-', '--'}))


%% fft onesided

% do one-sided fft - frequency range from 0 Hz to Nyquist frequency
b1 = fft(a1,plist('type','one'));
b2 = fft(a2,plist('type','one'));

% ifft
c1 = ifft(b1);
c2 = ifft(b2);

% compare with original data
iplot(a1,c1, plist('LineStyles', {'-', '--'}));
iplot(a2,c2, plist('LineStyles', {'-', '--'}));
iplot(c1./a1,c2./a2,plist('LineStyles', {'-', '--'}))

%% fft twosided

% do two-sided fft - frequency range from -Nyquist to Nyquist
b1 = fft(a1,plist('type','two'));
b2 = fft(a2,plist('type','two'));

% ifft
c1 = ifft(b1);
c2 = ifft(b2);

% compare with original data
iplot(a1,c1, plist('LineStyles', {'-', '--'}));
iplot(a2,c2, plist('LineStyles', {'-', '--'}));
iplot(c1./a1,c2./a2,plist('LineStyles', {'-', '--'}))
