Creating Analysis Objects


Analysis objects can be created in MATLAB in many ways. Apart from being created by the many algorithms in the LTPDA Toolbox, AOs can also be created from initial data or descriptions of data. The various constructors are listed in the function help: ao help.

Examples of creating AOs

The following examples show some ways to create Analysis Objects.


Creating AOs from text files.

Analysis Objects can be created from text files containing two columns of ASCII numbers. Files ending in '.txt' or '.dat' will be handled as ASCII file inputs. The first column is taken to be the time instances; the second column is taken to be the amplitude samples. The created AO is of type tsdata with the sample rate set by the difference between the time-stamps of the first two samples in the file. The name of the resulting AO is set to the filename (without the file extension). The filename is also stored as a parameter in the history parameter list. The following code shows this in action:

        >> a = ao('data.txt')
        ----------- ao 01: data.txt_01_02 -----------
 
               name:  data.txt_01_02
               data: (0,-1.06421341288933) (0.1,1.60345729812004) (0.2,1.23467914689078) ...
                     -------- tsdata 01 ------------
              
                         fs:  10
                          x:  [100 1], double
                          y:  [100 1], double
                         dx:  [0 0], double
                         dy:  [0 0], double
                     xunits:  [s]
                     yunits:  []
                      nsecs:  10
                         t0:  1970-01-01 00:00:00.000
                     -------------------------------
              
               hist:  ao / ao / SId: fromDatafile ... $-->$Id: ao ... S
            mdlfile:  empty
        description:  
               UUID:  e6ccfcb6-da49-4f4c-8c2c-3054fe5d2762
        ---------------------------------------------
    

As with most constructor calls, an equivalent action can be achieved using an input Parameter List.

        >> a = ao(plist('filename', 'data.txt'))
    

Creating AOs from XML or .mat files

AOs can be saved as both XML and .MAT files. As such, they can also be created from these files.

        >> a = ao('a.xml')
        ----------- ao 01: a -----------
        
               name:  None
               data: (0,-0.493009815316451) (0.1,-0.180739356415037) (0.2,0.045841105713705) ...
                     -------- tsdata 01 ------------
              
                         fs:  10
                          x:  [100 1], double
                          y:  [100 1], double
                         dx:  [0 0], double
                         dy:  [0 0], double
                     xunits:  [s]
                     yunits:  []
                      nsecs:  10
                         t0:  1970-01-01 00:00:01.000
                     -------------------------------
                      
               hist:  ao / ao / SId: fromVals ... $-->$Id: ao ... S
            mdlfile:  empty
        description:  
               UUID:  2fed6155-6468-4533-88f6-e4b27bc6e1aa
        --------------------------------
    

Creating AOs from MATLAB functions

AOs can be created from any valid MATLAB function which returns a vector or matrix of values. For such calls, a parameter list is used as input. For example, the following code creates an AO containing 1000 random numbers:

        >> a = ao(plist('fcn', 'randn(1000,1)'))
        ----------- ao 01: a -----------
 
               name:  None
               data: -1.28325610460477 -2.32895451628334 0.901931466951714 -1.83563868373519 0.06675 ...
                     -------- cdata 01 ------------
                          y:  [1000x1], double
                         dy:  [0x0], double
                     yunits:  []
                     ------------------------------
              
               hist:  ao / ao / SId: fromFcn ... $-->$Id ... $
            mdlfile:  empty
        description:  
               UUID:  0072f8d0-f804-472b-a4aa-e9ec6a8de803
        --------------------------------
    

Here you can see that the AO is a cdata type and the name is set to be the function that was input.


Creating AOs from functions of time

AOs can be created from any valid MATLAB function which is a function of the variable t. For such calls, a parameter list is used as input. For example, the following code creates an AO containing sinusoidal signal at 1Hz with some additional Gaussian noise:

        pl = plist();
        pl = append(pl, 'nsecs', 100);
        pl = append(pl, 'fs', 10);
        pl = append(pl, 'tsfcn', 'sin(2*pi*1*t)+randn(size(t))');
        a = ao(pl)
        ----------- ao 01: a -----------
 
               name:  None
               data: (0,1.37694916561229) (0.1,-0.820427237640771) (0.2,1.09228819960292) ...
                     -------- tsdata 01 ------------
              
                         fs:  10
                          x:  [1000 1], double
                          y:  [1000 1], double
                         dx:  [0 0], double
                         dy:  [0 0], double
                     xunits:  [s]
                     yunits:  []
                      nsecs:  100
                         t0:  1970-01-01 00:00:00.000
                     -------------------------------
              
               hist:  ao / ao / SId: fromTSfcn ... $-->$Id: ao ... S
            mdlfile:  empty
        description:  
               UUID:  c0f481cf-4bdd-4a91-bc78-6d34f8222313
        --------------------------------
     

Here you can see that the AO is a tsdata type, as you would expect. Also note that you need to specify the sample rate (fs) and the number of seconds of data you would like to have (nsecs).


Creating AOs from window functions

The LTPDA Toolbox contains a class for designing spectral windows (see Spectral Windows). A spectral window object can also be used to create an Analysis Object as follows:

        >> w = specwin('Hanning', 1000)
        ------ specwin/1 -------
            type: Hanning
           alpha: 0
            psll: 31.5
             rov: 50
           nenbw: 1.5
            w3db: 1.4382
        flatness: -1.4236
              ws: 500
             ws2: 375.000000000001
             win: [0 9.86957193144233e-06 3.94778980919441e-05 8.88238095955174e-05 0.0001579 ...
         version: SId: specwin.m,v 1.67 2009/09/01 09:25:24 ingo Exp S
        ------------------------

        >> a = ao(w)
        ----------- ao 01: ao(Hanning) -----------
 
               name:  ao(Hanning)
               data: 0 9.86957193144233e-06 3.94778980919441e-05 8.88238095955174e-05 0.0001579 ...
                     -------- cdata 01 ------------
                          y:  [1x1000], double
                         dy:  [0x0], double
                     yunits:  []
                     ------------------------------
              
               hist:  ao / ao / SId: fromSpecWin ... $-->$Id: ao ... S
            mdlfile:  empty
        description:  
               UUID:  ea1a9036-b9f5-4bdb-b3a3-211e9d697060
        ------------------------------------------
    

It is also possible to pass the information about the window as a plist to the ao constructor.

        >> ao(plist('win', 'Hanning', 'length', 1000))
        ----------- ao 01: ao(Hanning) -----------
 
               name:  ao(Hanning)
               data: 0 9.86957193144233e-06 3.94778980919441e-05 8.88238095955174e-05 0.0001579 ...
                     -------- cdata 01 ------------
                          y:  [1x1000], double
                         dy:  [0x0], double
                     yunits:  []
                     ------------------------------
              
               hist:  ao / ao / SId: fromSpecWin ... -->$Id: ao ... S
            mdlfile:  empty
        description:  
               UUID:  5b81f67a-45b9-43f8-a74a-bc5161fd718f
        ------------------------------------------
    

The example code above creates a Hanning window object with 1000 points. The call to the AO constructor then creates a cdata type AO with 1000 points. This AO can then be multiplied against other AOs in order to window the data.


Creating AOs from waveform descriptions

MATLAB contains various functions for creating different waveforms, for example, square, sawtooth. Some of these functions can be called upon to create Analysis Objects. The following code creates an AO with a sawtooth waveform:

        pl = plist();
        pl = append(pl, 'fs', 100);
        pl = append(pl, 'nsecs', 5);
        pl = append(pl, 'waveform', 'Sawtooth');
        pl = append(pl, 'f', 1);
        pl = append(pl, 'width', 0.5);

        asaw = ao(pl)
        ----------- ao 01: Sawtooth -----------
 
               name:  Sawtooth
               data: (0,-1) (0.01,-0.96) (0.02,-0.92) (0.03,-0.88) (0.04,-0.84) ...
                     -------- tsdata 01 ------------
              
                         fs:  100
                          x:  [500 1], double
                          y:  [500 1], double
                         dx:  [0 0], double
                         dy:  [0 0], double
                     xunits:  [s]
                     yunits:  []
                      nsecs:  5
                         t0:  1970-01-01 00:00:00.000
                     -------------------------------
              
               hist:  ao / ao / SId: fromWaveform ... $-->$Id: ao ... S
            mdlfile:  empty
        description:  
               UUID:  cb76c866-ee3f-47e6-bb29-290074666e43
        ---------------------------------------
   

You can call the iplot function to view the resulting waveform:

        iplot(asaw);
    
Sawtooth waveform

Creating AOs from pole zero models

When generating an AO from a pole zero model, the noise generator function is called. This a method to generate arbitrarily long time series with a prescribed spectral density. The algorithm is based on the following paper:

Franklin, Joel N.: Numerical simulation of stationary and non-stationary gaussian random processes , SIAM review, Volume { 7}, Issue 1, page 68--80, 1965.

The Document Generation of Random time series with prescribed spectra by Gerhard Heinzel (S2-AEI-TN-3034)
corrects a mistake in the aforesaid paper and describes the practical implementation. The following code creates an AO with a time series having a prescribed spectral density, defined by the input pole zero model:

	f1    = 5;
	f2    = 10;
	f3    = 1;
	gain  = 1;
	fs    = 10;  %sampling frequancy
	nsecs = 100; %number of seconds to be generated
  
  p = [pz(f1) pz(f2)];
	z = [pz(f3)];
	pzm = pzmodel(gain, p, z);
	a = ao(pzm, nsecs, fs)
	----------- ao 01: noisegen(None) -----------
 
	       name:  noisegen(None)
	       data: (0,9.20287001568168) (0.1,-3.88425345108961) (0.2,6.31042718242658) ...
	             -------- tsdata 01 ------------
              
	                 fs:  10
	                  x:  [1000 1], double
	                  y:  [1000 1], double
	                 dx:  [0 0], double
	                 dy:  [0 0], double
	             xunits:  [s]
	             yunits:  []
	              nsecs:  100
	                 t0:  1970-01-01 00:00:00.000
	             -------------------------------
              
	       hist:  ao / ao / SId: fromPzmodel ... $-->$Id: ao ... S
	    mdlfile:  empty
	description:  
	       UUID:  4a89d910-8672-475f-91cd-4fcc4b52a6b4
	---------------------------------------------
  

You can call the iplot function to view the resulting noise.

      iplot(a);
  
Random time series



©LTP Team