view testing/utp_1.1/utps/ao/utp_ao_lpsd.m @ 49:0bcdf74587d1 database-connection-manager

Cleanup
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:24:36 +0100
parents 409a22968d5e
children
line wrap: on
line source

% UTP_AO_LPSD a set of UTPs for the ao/lpsd method
%
% M Hewitson 06-08-08
%
% $Id: utp_ao_lpsd.m,v 1.30 2011/05/22 21:21:30 mauro Exp $
%

% <MethodDescription>
%
% The lpsd method of the ao class computes the spectral density of
% time-series AOs on a log-frequency axis.
%
% </MethodDescription>

function results = utp_ao_lpsd(varargin)
  
  % Check the inputs
  if nargin == 0
    
    % Some keywords
    class   = 'ao';
    mthd    = 'lpsd';
    
    results = [];
    disp('******************************************************');
    disp(['****  Running UTPs for ' class '/' mthd]);
    disp('******************************************************');
    
    % Test AOs
    [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]);
    
    % Exception list for the UTPs:
    [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
    
    % Get default window from the preferences
    prefs = getappdata(0, 'LTPDApreferences');
    defaultWinType = char(prefs.getMiscPrefs.getDefaultWindow);
    
    % Run the tests
    results = [results utp_01];    % getInfo call
    results = [results utp_02];    % Vector input
    results = [results utp_03];    % Matrix input
    results = [results utp_04];    % List input
    results = [results utp_05];    % Test with mixed input
    results = [results utp_06];    % Test history is working
    results = [results utp_07];    % Test output of the data
    results = [results utp_08];    % Test against MATLAB's fft
    results = [results utp_11(mthd, at1, ple1)];    % Test plotinfo doesn't disappear
    results = [results utp_17];    % Test units handling: PSD
    results = [results utp_18];    % Test units handling: ASD
    results = [results utp_19];    % Test units handling: PS
    results = [results utp_20];    % Test units handling: AS
    results = [results utp_41];    % Test different windows: Rectangular
    results = [results utp_42];    % Test different windows: BH92
    results = [results utp_43];    % Test different windows: Hamming
    results = [results utp_44];    % Test different windows: Hanning
    results = [results utp_45];    % Test different windows: Bartlett
    results = [results utp_46];    % Test different windows: Nuttall3
    results = [results utp_47];    % Test different windows: Kaiser psll = [random]
    results = [results utp_48];    % Test different windows: Kaiser psll = [default]
    results = [results utp_49];    % Test different windows: Nuttall4
    results = [results utp_50];    % Test different windows: SFT3F
  
    disp('Done.');
    disp('******************************************************');
    
  elseif nargin == 1 % Check for UTP functions
    if strcmp(varargin{1}, 'isutp')
      results = 1;
    else
      results = 0;
    end
  else
    error('### Incorrect inputs')
  end
  
  %% UTP_01
  
  % <TestDescription>
  %
  % Tests that the getInfo call works for this method.
  %
  % </TestDescription>
  function result = utp_01
    
    
    % <SyntaxDescription>
    %
    % Test that the getInfo call works for no sets, all sets, and each set
    % individually.
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      % Call for no sets
      io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
      % Call for all sets
      io(2) = eval([class '.getInfo(''' mthd ''')']);
      % Call for each set
      for kk=1:numel(io(2).sets)
        io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
      end
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that getInfo call returned an minfo object in all cases.
    % 2) Check that all plists have the correct parameters.
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    if stest
      % check we have minfo objects
      if isa(io, 'minfo')

        %%% SET 'None'
        if ~isempty(io(1).sets), atest = false; end
        if ~isempty(io(1).plists), atest = false; end
        %%% Check all Sets
        if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
        if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
        %%%%%%%%%%   SET 'Default'
        if io(3).plists.nparams ~= 10, atest = false; end
        % Check key
        if ~io(3).plists.isparam('kdes'), atest = false; end
        if ~io(3).plists.isparam('jdes'), atest = false; end
        if ~io(3).plists.isparam('lmin'), atest = false; end
        if ~io(3).plists.isparam('win'), atest = false; end
        if ~io(3).plists.isparam('olap'), atest = false; end
        if ~io(3).plists.isparam('scale'), atest = false; end
        if ~io(3).plists.isparam('order'), atest = false; end
        if ~io(3).plists.isparam('psll'), atest = false; end
        if ~io(3).plists.isparam('times'), atest = false; end
        if ~io(3).plists.isparam('split'), atest = false; end
        % Check default value
        if ~isequal(io(3).plists.find('kdes'), 100), atest = false; end
        if ~isequal(io(3).plists.find('jdes'), 1000), atest = false; end
        if ~isequal(io(3).plists.find('lmin'), 0), atest = false; end
        if ~strcmpi(io(3).plists.find('win'), defaultWinType), atest = false; end
        if ~isequal(io(3).plists.find('olap'), -1), atest = false; end
        if ~isequal(io(3).plists.find('scale'), 'PSD'), atest = false; end
        if ~isequal(io(3).plists.find('order'), 0), atest = false; end
        if ~isequal(io(3).plists.find('psll'), 200), atest = false; end
        if ~isEmptyDouble(io(3).plists.find('times')), atest = false; end
        if ~isEmptyDouble(io(3).plists.find('split')), atest = false; end
        % Check options
        if ~isequal(io(3).plists.getOptionsForParam('kdes'), {100}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('jdes'), {1000}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('lmin'), {0}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('win'), specwin.getTypes), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('olap'), {-1}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('scale'), {'PSD', 'ASD', 'PS', 'AS'}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('order'), {-1 0 1 2 3 4 5 6 7 8 9}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('psll'), {200}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('times'), {[]}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('split'), {[]}), atest = false; end
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_01
  
  %% UTP_02
  
  % <TestDescription>
  %
  % Tests that the lpsd method works with a vector of AOs as input.
  %
  % </TestDescription>
  function result = utp_02
    
    % <SyntaxDescription>
    %
    % Test that the lpsd method works for a vector of AOs as input.
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      avec = [at1 at5 at6];
      % Vector output
      out  = lpsd(avec);
      % List output
      [out1, out2, out3] = lpsd(avec);
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that the number of elements in 'out' is the same as in the input.
    % 2) Check that each output object contains the correct values.
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    if stest
      % Check we have the correct number of outputs
      if numel(out) ~= numel(avec), atest = false; end
      % Check we have the correct values in the outputs
      % Vector output
      for kk = 1:numel(out)
        if ~eq(out(kk), lpsd(avec(kk)), ple1), atest = false; end
      end
      % List output
      if ~eq(out1, lpsd(avec(1)), ple1), atest = false; end
      if ~eq(out2, lpsd(avec(2)), ple1), atest = false; end
      if ~eq(out3, lpsd(avec(3)), ple1), atest = false; end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_02
  
  %% UTP_03
  
  % <TestDescription>
  %
  % Tests that the lpsd method works with a matrix of AOs as input.
  %
  % </TestDescription>
  function result = utp_03
    
    % <SyntaxDescription>
    %
    % Test that the lpsd method works for a matrix of AOs as input.
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      amat = [at1 at5 at6; at5 at6 at1];
      % Vector output
      out  = lpsd(amat);
      % List output
      [out1, out2, out3, out4, out5, out6] = lpsd(amat);
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that the number of elements in 'out' is the same as in the input.
    % 2) Check that each output object contains the correct values.
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    if stest
      % Check we have the correct number of outputs
      if numel(out) ~= numel(amat), atest = false; end
      % Check we have the correct values in the outputs
      % Vector output
      for kk = 1:numel(out)
        if ~eq(out(kk), lpsd(amat(kk)), ple1), atest = false; end
      end
      % List output
      if ~eq(out1, lpsd(amat(1)), ple1), atest = false; end
      if ~eq(out2, lpsd(amat(2)), ple1), atest = false; end
      if ~eq(out3, lpsd(amat(3)), ple1), atest = false; end
      if ~eq(out4, lpsd(amat(4)), ple1), atest = false; end
      if ~eq(out5, lpsd(amat(5)), ple1), atest = false; end
      if ~eq(out6, lpsd(amat(6)), ple1), atest = false; end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_03
  
  %% UTP_04
  
  % <TestDescription>
  %
  % Tests that the lpsd method works with a list of AOs as input.
  %
  % </TestDescription>
  function result = utp_04
    
    % <SyntaxDescription>
    %
    % Test that the lpsd method works for a list of AOs as input.
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      % Vector output
      out                = lpsd(at1,at5,at6);
      % List output
      [out1, out2, out3] = lpsd(at1,at5,at6);
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that the number of elements in 'out' is the same as in the input.
    % 2) Check that each output AO contains the correct data.
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    if stest
      % Check we have the correct number of outputs
      if numel(out) ~= 3, atest = false; end
      % Check we have the correct values in the outputs
      % Vector output      
      if ~eq(out(1), lpsd(at1), ple1), atest = false; end
      if ~eq(out(2), lpsd(at5), ple1), atest = false; end
      if ~eq(out(3), lpsd(at6), ple1), atest = false; end
      % List output
      if ~eq(out1, lpsd(at1), ple1), atest = false; end
      if ~eq(out2, lpsd(at5), ple1), atest = false; end
      if ~eq(out3, lpsd(at6), ple1), atest = false; end

    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_04
  
  %% UTP_05
  
  % <TestDescription>
  %
  % Tests that the lpsd method works with a mix of different shaped AOs as
  % input.
  %
  % </TestDescription>
  function result = utp_05
    
    % <SyntaxDescription>
    %
    % Test that the lpsd method works with an input of matrices and vectors
    % and single AOs.
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      % Vector output
      out = lpsd(at1,[at5 at6],at5,[at5 at1; at6 at1],at6);
      % List output
      [out1, out2, out3, out4, out5, out6, out7, out8, out9] = ...
        lpsd(at1,[at5 at6],at5,[at5 at1; at6 at1],at6);
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that the number of elements in 'out' is the same as in
    %    input.
    % 2) Check that each output AO contains the correct data.
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    if stest
      % Check we have the correct number of outputs
      if numel(out) ~= 9, atest = false; end
      % Check we have the correct values in the outputs
      % Vector output      
      if ~eq(out(1), lpsd(at1), ple1), atest = false; end
      if ~eq(out(2), lpsd(at5), ple1), atest = false; end
      if ~eq(out(3), lpsd(at6), ple1), atest = false; end
      if ~eq(out(4), lpsd(at5), ple1), atest = false; end
      if ~eq(out(5), lpsd(at5), ple1), atest = false; end
      if ~eq(out(6), lpsd(at6), ple1), atest = false; end
      if ~eq(out(7), lpsd(at1), ple1), atest = false; end
      if ~eq(out(8), lpsd(at1), ple1), atest = false; end
      if ~eq(out(9), lpsd(at6), ple1), atest = false; end
      % List output
      if ~eq(out1, lpsd(at1), ple1), atest = false; end
      if ~eq(out2, lpsd(at5), ple1), atest = false; end
      if ~eq(out3, lpsd(at6), ple1), atest = false; end
      if ~eq(out4, lpsd(at5), ple1), atest = false; end
      if ~eq(out5, lpsd(at5), ple1), atest = false; end
      if ~eq(out6, lpsd(at6), ple1), atest = false; end
      if ~eq(out7, lpsd(at1), ple1), atest = false; end
      if ~eq(out8, lpsd(at1), ple1), atest = false; end
      if ~eq(out9, lpsd(at6), ple1), atest = false; end
      
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_05
  
  %% UTP_06
  
  % <TestDescription>
  %
  % Tests that the lpsd method properly applies history.
  %
  % </TestDescription>
  function result = utp_06
    
    % <SyntaxDescription>
    %
    % Test that the result of applying the lpsd method can be processed back
    % to an m-file.
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      out  = lpsd(at5);
      mout = rebuild(out);
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that the last entry in the history of 'out' corresponds to
    %    'lpsd'.
    % 2) Check that the re-built object is the same object as 'out'.
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    if stest
      % Check the last step in the history of 'out'
      if ~strcmp(out.hist.methodInfo.mname, 'lpsd'), atest = false; end
      % Check the re-built object
      if ~eq(mout, out, ple2), atest = false; end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_06
  
  %% UTP_07
  
  % <TestDescription>
  %
  % Check that the lpsd method pass back the output objects to a list of
  % output variables or to a single variable.
  %
  % </TestDescription>
  function result = utp_07
    
    % <SyntaxDescription>
    %
    % Call the method with a list of output variables and with a single output
    % variable. Additionaly check that the rebuild method works on the output.
    %
    % </SyntaxDescription>
    
    try
      % <SyntaxCode>
      [o1, o2] = lpsd(at5, at6);
      o3  = lpsd(at5, at6);
      mout1 = rebuild(o1);
      mout2 = rebuild(o2);
      mout3 = rebuild(o3);
      % </SyntaxCode>
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    
    % <AlgoDescription>
    %
    % 1) Check that the output contains the right number of objects
    % 2) Check that the 'rebuild' method produces the same object as 'out'.
    %
    % </AlgoDescription>
    
    atest = true;
    if stest
      % <AlgoCode>
      % Check the number of outputs
      if numel(o1) ~=1, atest = false; end
      if numel(o2) ~=1, atest = false; end
      if numel(o3) ~=2, atest = false; end
      % Check the rebuilding of the object
      if ~eq(o1, mout1, ple2), atest = false; end
      if ~eq(o2, mout2, ple2), atest = false; end
      if ~eq(o3, mout3, ple2), atest = false; end
      % </AlgoCode>
    else
      atest = false;
    end
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_07
  %% UTP_08
  
  % <TestDescription>
  %
  % Tests that the lpsd method agrees with MATLAB's pwelch if the frequency
  % resolution of the latter is changed to match those used in lpsd
  %
  %
  %   % </TestDescription>
  function result = utp_08
    
    % <SyntaxDescription>
    %
    % Test that the applying psd works on a single AO.
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      % Construct test AO
      nsecs = 10;
      fs    = 1000;
      Nfft = 2*fs;
      pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'randn(size(t))');
      a1 = ao(pl);
      % parameter list for lpsd
      win  = specwin('Hanning', Nfft);
      pl = plist('Kdes', 10, 'Lmin', 2, 'Jdes', 100, 'Win', win.type, 'Olap', 50, 'Order', -1);
      % compute lpsd
      a2 = lpsd(a1, pl);
      % </SyntaxCode>
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    
    % <AlgoDescription>
    %
    % 1) Check that the DFT equations (eq. (3) and (4) in [1]) are fulfilled.
    % 2) Check that we get the same outputs for each frequency bin when
    %    computing the psd using matlab's fft with the frequency resolution
    %    values retrieved by lpsd (and already tested in (1))
    %
    % [1] G. Heinzel, lpsd revisited: ltf, S2-AEI-TN-3052
    %
    % </AlgoDescription>
    atest = true;
    if stest
      % <AlgoCode>
      % get freq. resolution, bin number and seg. length from procinfo
      b = find(a2.procinfo,'m');
      r = find(a2.procinfo,'r');
      L = find(a2.procinfo,'L');
      % test eq.(3): f = r*b up to numerical accuracy
      if all(abs(a2.data.x - r.*b) > max(eps(a2.data.x),eps(r.*b)))
        atest = false;
      end
      % test eq.(4): fs = r*L up to numerical accuracy
      if all(abs(a2.data.fs - r.*L) > max(eps(a2.data.fs),eps(r.*L)))
        atest = false;
      end      
      
      % </AlgoCode>
    else
      atest = false;
    end
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_08
  
  %% UTP_17
  
  % <TestDescription>
  %
  % Tests handling of units:
  % 1) white noise produced from normal pdf, with a given mean value and
  % sigma (distribution's 1st and 2nd orders)
  % 2) LPSD of the white noise
  % 3) compares the units of the input and output
  %
  % </TestDescription>
  function result = utp_17
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Assign a random unit
    % 3) LPSD of the white noise
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      win_type = 'BH92';
      scale = 'PSD';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, plist);
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that (calculated LPSD yunits) equals (input units)^2 / Hz
    % 2) Check that (calculated LPSD xunits) equals Hz
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      if ne(S.yunits, (a.yunits).^2 * unit('Hz^-1')) || ne(S.xunits, unit('Hz'))
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_17
  
  %% UTP_18
  
  % <TestDescription>
  %
  % Tests handling of units:
  % 1) white noise produced from uniform pdf, with a given mean value and
  % sigma (distribution's 1st and 2nd orders)
  % 2) LASD of the white noise
  % 3) compares the units of the input and output
  %
  
  % </TestDescription>
  function result = utp_18
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from uniform distribution + offset
    % 2) Assign a random unit
    % 3) LASD of the white noise
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Uniform';
      win_type = 'Hamming';
      scale = 'ASD';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, plist);
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that (calculated LASD yunits) equals (input units) / Hz^(1/2)
    % 2) Check that (calculated LASD xunits) equals Hz
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      if ne(S.yunits, (a.yunits) * unit('Hz^-1/2')) || ne(S.xunits, unit('Hz'))
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_18
  
  %% UTP_19
  
  % <TestDescription>
  %
  % Tests handling of units:
  % 1) white noise produced from normal pdf, with a given mean value and
  % sigma (distribution's 1st and 2nd orders)
  % 2) LPS of the white noise
  % 3) compares the units of the input and output
  %
  
  % </TestDescription>
  function result = utp_19
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Assign a random unit
    % 3) LPS of the white noise
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      win_type = 'Hanning';
      scale = 'PS';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, plist);
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that (calculated LPS yunits) equals (input units)^2
    % 2) Check that (calculated LPS xunits) equals Hz
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      if ne(S.yunits, (a.yunits).^2)  || ne(S.xunits, unit('Hz'))
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_19
  
  %% UTP_20
  
  % <TestDescription>
  %
  % Tests handling of units:
  % 1) white noise produced from uniform distribution, with a given mean value and
  % sigma (distribution's 1st and 2nd orders)
  % 2) LAS of the white noise
  % 3) compares the units of the input and output
  %
  
  % </TestDescription>
  function result = utp_20
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from uniform distribution + offset
    % 2) Assign a random unit
    % 3) LAS of the white noise
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Uniform';
      win_type = 'Rectangular';
      scale = 'AS';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, plist);
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that (calculated LAS yunits) equals (input units)
    % 2) Check that (calculated LAS xunits) equals Hz
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      if ne(S.yunits, a.yunits)  || ne(S.xunits, unit('Hz'))
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_20
  
  %% UTP_41
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (Rectangular)
  % 3) lpsd passing the window object (Rectangular type)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_41
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, Rectangular window (name)
    % 4) Estimate the psd without detrending, Rectangular window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'Rectangular';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_41
  
  %% UTP_42
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (BH92)
  % 3) lpsd passing the window object (BH92 type)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_42
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, BH92 window (name)
    % 4) Estimate the psd without detrending, BH92 window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'BH92';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_42
  
  
  %% UTP_43
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (Hamming)
  % 3) lpsd passing the window object (Hamming type)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_43
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, Hamming window (name)
    % 4) Estimate the psd without detrending, Hamming window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'Hamming';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_43
  
  %% UTP_44
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (Hanning)
  % 3) lpsd passing the window object (Hanning type)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_44
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, Hanning window (name)
    % 4) Estimate the psd without detrending, Hanning window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'Hanning';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_44
  
  %% UTP_43
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (Bartlett)
  % 3) lpsd passing the window object (Bartlett type)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_45
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, Bartlett window (name)
    % 4) Estimate the psd without detrending, Bartlett window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'Bartlett';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_45
  
  %% UTP_46
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (Nuttall3)
  % 3) lpsd passing the window object (Nuttall3 type)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_46
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, Nuttall3 window (name)
    % 4) Estimate the psd without detrending, Nuttall3 window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'Nuttall3';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_46
  
  %% UTP_47
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (Kaiser, psll = 150)
  % 3) lpsd passing the window object (Kaiser type, psll = 150)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_47
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, Kaiser window (name)
    % 4) Estimate the psd without detrending, Kaiser window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'Kaiser';
      psll =        utils.math.randelement([10:10:200],1);
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_47
  
  %% UTP_48
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (Kaiser, psll = default)
  % 3) lpsd passing the window object (Kaiser type, psll = default)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_48
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, Kaiser window (name)
    % 4) Estimate the psd without detrending, Kaiser window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'Kaiser';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_48
  
  
  %% UTP_49
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (Nuttall4)
  % 3) lpsd passing the window object (Nuttall4 type)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_49
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, Nuttall4 window (name)
    % 4) Estimate the psd without detrending, Nuttall4 window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'Nuttall4';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_49
  
  %% UTP_50
  
  % <TestDescription>
  %
  % Tests the effect of windowing:
  % 1) white noise produced from normal pdf, with:
  %   a given mean value and sigma (distribution's 1st and 2nd order)
  % 2) lpsd passing the window name (SFT3F)
  % 3) lpsd passing the window object (SFT3F type)
  % 4) compares the two psds
  %
  
  % </TestDescription>
  function result = utp_50
    
    % <SyntaxDescription>
    %
    % 1) Prepare the test tsdata:
    %   white noise from normal distribution + offset
    % 2) Calculate the statistical parameters
    % 3) Estimate the psd without detrending, SFT3F window (name)
    % 4) Estimate the psd without detrending, SFT3F window (object)
    % 5) Compare results
    %
    % </SyntaxDescription>
    
    % <SyntaxCode>
    try
      
      noise_type = 'Normal';
      scale =      'PSD';
      win_type =   'SFT3F';
      
      [a, S, S1] = prepare_analyze_noise(win_type, noise_type, scale, ...
        plist('win_test', true));
      
      stest = true;
      
    catch err
      disp(err.message)
      stest = false;
    end
    % </SyntaxCode>
    
    % <AlgoDescription>
    %
    % 1) Check that calculated psds are identical
    %
    % </AlgoDescription>
    
    % <AlgoCode>
    atest = true;
    
    if stest
      % Compare the psd evaluated with the window name / object
      if ~eq(S, S1, ple1)
        atest = false;
      end
    else
      atest = false;
    end
    % </AlgoCode>
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_50
  
  
  %% Helper function for window call construction
  
  function [a, S_name, S_obj] = prepare_analyze_noise(win_type, noise_type, scale, pli)
    % Array of parameters to pick from
    fs_list =             [0.1;1;2;5;10];
    nsecs_list =          [20 100 1000:1000:10000]';
    sigma_distr_list =    [1e-6 2e-3 0.25 1:0.1:10]';
    trend_0_list =        [1e-6 2e-3 0.25 1:0.1:10]';
    
    
    % Build time-series test data
    
    % Picks the values at random from the list
    fs = utils.math.randelement(fs_list, 1);
    nsecs = utils.math.randelement(nsecs_list, 1);
    sigma_distr = utils.math.randelement(sigma_distr_list, 1);
    trend_0 = utils.math.randelement(trend_0_list, 1);
    
    % Pick units and prefix from those supported
    unit_list = unit.supportedUnits;
    % remove the first empty unit '' from the list, because then is it
    % possible that we add a prefix to an empty unit
    unit_list = unit_list(2:end);
    prefix_list = unit.supportedPrefixes;
    
    % White noise
    a_n = ao(plist('waveform', 'noise', ...
      'type', noise_type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
    
    % Constant signal
    a_c = ao(trend_0);
    
    % Total signal
    a = a_n + a_c;
    
    % Set units
    a.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
    
    % Evaluate the lpsd of the white noise time-series data
    olap = find(pli, 'olap');
    if isempty(olap)
      olap = 0; %% Should we take the rov instead?
    end
    detrend_order = 0;
    
    switch lower(win_type)
      case 'kaiser'
        psll = find(pli, 'psll');
        if isempty(psll)
          psll = find(ao.getInfo('lpsd').plists, 'psll');
        end
        pl_spec = plist('Win', win_type, 'psll', psll, 'olap', olap, ...
          'order', detrend_order, 'scale', scale);
      otherwise
        pl_spec = plist('Win', win_type, 'olap', olap, ...
          'order', detrend_order, 'scale', scale);
    end
    
    if find(pli, 'win_test')
      % Calls the lpsd applying the detrend and window internally
      % (passig window object)
      S_obj = a.lpsd(pl_spec);
    else
      S_obj = ao;
    end
    
    % Calls the lpsd applying the detrend and window internally
    % (passig window name)
    pl_spec.pset('Win', win_type);
    S_name = a.lpsd(pl_spec);
    
  end
  
  
end