diff testing/utp_1.1/utp_fcns/get_test_objects_ao.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testing/utp_1.1/utp_fcns/get_test_objects_ao.m	Tue Dec 06 18:42:11 2011 +0100
@@ -0,0 +1,90 @@
+% GET_TEST_OBJECTS_AO returns a set of AOs suitable for many of the UTPs
+%
+% CALL:   [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao();
+%
+% OUTPUTS:
+%         at1   - a tsdata AO containing 2 seconds of a 1.23Hz sine wave sampled at 10Hz.
+%         at2   - an fsdata AO containing 1000 samples of white noise
+%         at3   - an xydata AO containing 100 data samples
+%         at4   - a cdata AO containing a 3x3 matrix
+%         at5   - a tsdata AO containing 30s of noise at 10Hz           (data-vector = row vector)
+%         at6   - a tsdata AO containing 30s of different noise at 10Hz (data-vector = column vector)
+%         atvec - a vector of AOs containing [at1 at3 at3]
+%         atmat - a matrix of AOs containing [at1 at2 at3; at4 at5 at6]
+%
+% M Hewitson 06-08-08
+%
+% $Id: get_test_objects_ao.m,v 1.8 2011/04/01 08:07:25 mauro Exp $
+%
+function [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao
+
+  %% Single AO containing a sine wave
+  fs  = 10;
+  pl1 = plist();
+  pl1.append('fs', fs);
+  pl1.append('nsecs', 30);
+  pl1.append('waveform', 'sine wave');
+  pl1.append('f', 1.23);
+  pl1.append('phi', 30);
+  at1 = ao(pl1);
+
+
+  % Single AO containing an xydata object
+  x = 1:100;
+  y = exp(x.^.5/2);
+  at3 = ao(x,y, plist('type', 'xydata'));
+
+  %% Single AO with a matrix
+  at4 = ao([1 -2 3; 4  5 -6; -7 8  9]);
+
+  %% Single AO with 30s of noise
+  at5 = ao(plist('tsfcn', 'randn(size(t))', 'nsecs', 30, 'fs', fs));
+  at5.setDy(at5.y*.1);
+
+  %% Single AO with 30s of noise
+  at6 = ao(plist('tsfcn', 'randn(size(t)).''', 'nsecs', 30, 'fs', fs));
+
+  %% Single AO containing some fsdata
+  at2 = psd(at5);
+  at2.setDy(at2.y*.1);
+
+  %% Set AOs yunits
+  
+  % 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;
+  
+  % Set units by choosing a random prefix and a random unit
+  at1.setYunits(...
+    unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
+  at2.setYunits(...
+    unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
+  at3.setYunits(...
+    unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
+  at4.setYunits(...
+    unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
+  at5.setYunits(...
+    unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
+  at6.setYunits(...
+    unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
+  
+  %% Vector of AOs
+  atvec = [at2 at5 at6];
+
+  %% Matrix of AOs
+  atmat = [at1 at2 at3; at4 at5 at6];
+
+  %% Set AO names.
+  %  Don't remove the setting of the AO names and it must be at the last position.
+  at1.setName;
+  at2.setName;
+  at3.setName;
+  at4.setName;
+  at5.setName;
+  at6.setName;
+
+end
+