The Frame Vector Library (Frv)

Version v3r20
March 20, 2002
By D. Buskulic, I. Ferrante, F. Marion, B. Mours


Summary


Introduction

This document describes a utility library dedicated to vector manipulation. The vectors used in this packages are the Frame Library vectors (FrVect) described in the frame specification. The only part frame library part used in this library is the vector definition frome the FrameL.h. This library is intend to simplify the access of date for the various vector. It provide most of the basic tools to do vector algebra and basic signal processing. This code is written in C. It is thread safe and could be easily used in C or C++ software.

The FrVect Structure

The FrVect srtucture defined in the Frame Format specification and  in the file FrameL.h contains many fields. We list here the fields that a non expert user may access in a read mode. Some fields reserved for internal managemend have been omitted

struct FrVect {

  char  *name;            /* vector name                              */
  unsigned short compress;/* 0 = no compression; 1 = gzip, ...        */
  unsigned short type;    /* vector type  (see bellow)                */
  unsigned int  nData;    /* number of elements=nx[0].nx[1]..nx[nDim] */
  unsigned int  nBytes;   /* number of bytes                          */
  char  *data;            /* pointer to the data area.                */
  unsigned int  nDim;     /* number of dimension                      */
  unsigned int *nx;       /* number of element for this dimension     */
  double *dx;             /* step size value (express in above unit)  */
  double *startX;         /* offset for the first x value             */
  char   **unitX;         /* unit name for (used for printout)        */
  char    *unitY;         /* unit name for (used for printout)        */
  FrVect *next;           /* hook for additional data                 */
  short  *dataS;          /* pointer to the data area (same as *data) */
  int    *dataI;          /* pointer to the data area (same as *data) */
  FRLONG *dataL;          /* pointer to the data area (same as *data) */
  float  *dataF;          /* pointer to the data area (same as *data) */
  double *dataD;          /* pointer to the data area (same as *data) */
  unsigned char  *dataU;  /* pointer to the data area (same as *data) */
  unsigned short *dataUS; /* pointer to the data area (same as *data) */
  unsigned int   *dataUI; /* pointer to the data area (same as *data) */
  FRULONG        *dataUL; /* pointer to the data area (same as *data) */
  char  **dataQ;          /* pointer to the data area (same as *data) */
  int  wSize;             /* size of one data element                 */

The following fields are filled only when a vector have been extract from a Frame. They may not been always available.

  unsigned int GTimeS;    /* vector time origin(GPS:s)                */
  unsigned int GTimeN;    /* vector time origin(nsec modulo 1 sec)    */
  unsigned short ULeapS;  /* leap seconds between GPS and UTC         */
  int localTime;          /* Time offset = Local time - UTC (sec)     */
};

The vector type is one of the following:

       FR_VECT_C,     /* vector of char                           */
       FR_VECT_2S,    /* vector of short                          */
       FR_VECT_8R,    /* vector of double                         */
       FR_VECT_4R,    /* vector of float                          */
       FR_VECT_4S,    /* vector of int                            */
       FR_VECT_8S,    /* vector of long                           */
       FR_VECT_C8,    /* vector of complex float                  */
       FR_VECT_C16,   /* vector of complex double                 */
       FR_VECT_STRING,/* vector of string                         */
       FR_VECT_2U,    /* vector of unsigned short                 */
       FR_VECT_4U,    /* vector of unsigned int                   */
       FR_VECT_8U,    /* vector of unsigned long                  */
       FR_VECT_1U,    /* vector of unsigned char                  */

Additional field s exist but are used only for management purpose


Usefull FrameLib vector functions


Vector Copy and type Conversion and Decimation (file FrvCopy.c)

Go to: FrvClone,  FrvCopy,FrvCopyToX, FrvCopyTo,Back to summary

FrvClone(vect, newName)

FrVectCopy(vect)

  • Syntax:    FrVect *=FrVectCopy(FrVect, char *newName)
  • This is a full vector copy from the FrameLib (FrVectHeader + data part). It does not change the vector type. This function returns null in case of problems like malloc failed.
  • Supported types: all types.
  • FrvCopyToF, FrvCopyToD, FrvCopyToI, FrvCopyToS FrvCopyTo FrvDecimateF, FrvDecimateD, FrvDecimateI, FrvDecimateS FrvDecimate
    Vector arithmetic (file FrvMath.c)

    FrvBias

  • Syntax: FrVect *FrvBias(FrVect *vect1, double bias, FrVect *vectOut)
  • This function adds bias to vector vect1 .

  • The output is stored in vector vectOut, which should have the same size and type of vect1.
    If vectOut==NULL, vect1 is modified.
  • Supported types: only signed  data types.
  • FrvAdd

  • Syntax:  FrVect* = FrvAdd(FrVect* vect1, FrVect*  vect2, FrVect* vectOut, char *newName)
  • This function computed vectOut= vect1+vect2. The vector vectOut could be vect1 or vect2. If vectOut = NULL, a new one is created named newName. It returns, the output vector or NULL in case of error. If vectOut != NULL, the newName argument is ignored.
  • Supported types: all.
  • Examples:

  •     v3 = FrvAdd(v1, v2, NULL,"vector3");   Create and fill a new vector called vector3.
        FrVectAdd(v1, v2, v1, NULL);             Put in v1 the sum of v1 and V2

    FrvCombine2

    FrvCombine FrvDelta

    FrvDivide

  • Syntax: FrVect* = FrvDivide(FrVect* vect1, FrVect* vect2, FrVect* vectOut, char* newName)
  • This function computed vectOut= vect1/vect2 elements by elements after checking the division by 0. ( if the denominator is zero then the result is set also to 0. The vector vectOut could be vect1 or vect2. If vectOut = NULL, a new one is created called newName. This function returns, the vector result or NULL in case of error.
  • Supported types: all.
  • FrvFlatten

  • Syntax: FrVect *FrvFlatten(FrVect *vect1, FrVect *vectOut)
  • This function puts vector extrema equal to zero, subtracting a straigth  line.

  • The output is stored in vector vectOut, which should have the same size and type of vect1.
    If vectOut==NULL, vect1 is modified.
  • Supported types: only signed  data types.
  • FrvMean

  • Syntax: double Int = FrvMean(FrVect* vect, double *mean)
  • This function computes the mean value of the input vector vect. The result is put in mean. It returns 1 in case of failure (vector not found), or 0 in case of success.
  • Supported types: all non complex types
  • FrvModulus

  • Function prototype: FrVect* = FrvModulus(FrVect *vectIn, FrVect* vectOut, char *newName)
  • This function computes the modulus of a complex vector vectIn. The result is stored in vectOut, a real vector (Float or Double according to the complex type of vectIn).
  • If vectOut = NULL, a new one is created. Its name is  newName or 'module(vectIn->name)' if newName = NULL.
  • It returns, the vector result or NULL in case of error.
  • Supported types: works only for complex.
  • FrvMult

  • Syntax: FrVect* = FrvMult(FrVect* vect1, FrVect* vect2, FrVect* vectOut, char *newName)
  • This function computes vectOut= vect1*vect2 elements by elements. ( this is not a matrix multiplication); The vector vectOut could be vect1 or vect2. If vectOut = NULL, a new one is created. Its name is then newName. It returns, the vector result or NULL in case of error. If vectOut = NULL, the newName argument is ignored.
  • Supported types: all.
  • FrvMultConj

  • Syntax: FrVect* = FrvMult(FrVect* vect1, FrVect* vect2, FrVect* vectOut, char *newName)
  • This function computes vectOut= vect1*cc(vect2) elements by elements. ( this is not a matrix multiplication); The vector vectOut could be vect1 or vect2. If vectOut = NULL, a new one is created. Its name is then newName. It returns, the vector result or NULL in case of error. If vectOut = NULL, the newName argument is ignored.
  • Supported types: FR_VECT_C8 and FR_VECT_C16.
  • FrvPhase

  • Function prototype: FrVect* = FrvPhase(FrVect *vectIn, FrVect* vectOut, char *newName)
  • This function computes the phase of a complex vector vectIn. The result is stored in vectOut, a real vector (Float or Double according to the complex type of vectIn).
  • If vectOut = NULL, a new one is created. Its name is build as "phase(vectIn->name)"
  • It returns, the vector result or NULL in case of error.
  • Supported types: works only for complex.
  • FrvRms

  • Syntax: double Int = FrvRms(FrVect* vect, double *mean, double *rms)
  • This function computes the rms and mean value of the input vector vect. The result is put in mean and rms. It returns 1 in case of failure (vector not found), or 0 in case of success.
  • Supported types: all non complex types
  • FrvScale

  • Syntax: FrVect* = FrvScale(double scale, FrVect* vect1, FrVect* vectOut, newName)
  • This function computes vectOut= scale*vect1 elements by elements. ( this is not a matrix multiplication);
  • The vector vectOut could be vect1 or vect2.
  • If vectOut = NULL, a new one is created. Its name is then newName.
  • It returns, the vector result or NULL in case of error.
  • Supported types: all.
  • FrvSub

  • Syntax: FrVect* = FrvSub(FrVect* vect1, FrVect*  vect2, FrVect* vectOut)
  • This function computes vectOut= vect1- vect2.
  • The vector vectOut could be vect1 or vect2.
  • If vectOut = NULL, a new one is created. Its name is then newName.
  • It returns, the vector result or NULL in case of error.
  • Supported types: all.
  • FrvZeroMean

  • Syntax: FrVect *FrvZeroMean(FrVect *vect1, FrVect *vectOut)
  • This function subtracts the mean to  vect1.

  • The output is stored in vector vectOut, which should have the same size and type of vect1.
    If vectOut==NULL vect1 data are modified.
  • Supported types: only signed  data types.

  • The Vector Buffering (FrvBuf)

    The purpose of this object is to resize vector actracted from frame. It can provides vector concatenation and support vector overlap, decimation and type changes. The suported vector type are all types excpet when decimation is requested.

    Go to:   Using FrvBuf,FrvBufFree,FrvBufFeed,FrvBufGetNext, FrvBufInit,FrvBufNew,Back to Summary

    Using FrvBuf

    In this example, the input vectors are  extract from a frame file. New vectors are build .  See FrvBufNew for the definition of the FrvBuf parameters.

     buffer = FrvBufNew(outSize, outSize, -1, 0);  // create a buffer object
     while((frame = FrameRead(iFile)) != NULL)     // loop on all frame from one file
       {vect = FrameGetV(frame,"adc1");            // find the vector for ADC 'adc1'
        FrvBufFeed(buffer, vect);                  // feed the buffer
        while(FrvBufGetNext(buffer) == 0)          // is there a vector in the buffer?
          {FrVectDump(buffer->output, stdout, 2);} // use the output vector

    An other example could be found in the file FrvBufTest.c.

    FrvBufFree

    FrvBufFeed

    FrvBufGetNext

    FrvBufInit

    FrvBufNew


    The vector correlation: FrvCorr
    This object computes the correlation among  two vectors. The type of of the input vector could be any non complex type, but the output vector (named filter->output) is of type FR_VECT_8R (double).

    FrvCorrNew

    FrvCorrFree

    FrvCorrInit

    FrvCorrProc

    FrvCorrSetPast


    The linear filter: FrvLinFilt

    This object filters the data for one vector. The type of of the input vector could be any non complex type, but the output vector (named filter->output) is of type FR_VECT_8R (double).

    FrvLinFiltFree

  • Syntax: void FrvLinFiltFree(FrvLinFilt* filter)
  • Comment:This function frees all the memory associate to the FrvLinFilt object.
  • FrvLinFiltInit

    FrvLinFiltSetIni

    FrvLinFiltSetGain

    FrvLinFiltNew

    FrvLinFiltMult

    FrvLinFiltCopy

    FrvLinFiltAddZP

    FrvLinFiltProc


    The second order filter: FrvFilter2

    This object filter the data for one vector. The type of of the input vector could be any non complex type, but the output vector (named filter->output) is of type FR_VECT_8R (double).

    FrvFilter2Free

  • Syntax:    void FrvFilter2Free(FrvFilter2* filter)
  • Comment:This function free all the memory associate to the FrvFilter2 object.
  • FrvFilter2Init

    FrvFilter2New

    FrvFilter2Proc


    The Fast Fourrier Transform (FFT) for Real Vector (FrvRFFT)

    This Fast Fourrier Transform FFT object use FFTW. It works with real vector for the direct FFT, the Fourrier Tranform in this case is 'halfcomplex' (the negative-frequency amplitudes for real data are
    the complex conjugate of the positive-frequency amplitudes) but the result is stored has a standard complex vector. All internal compuation are done in double precision. The results are also stored in double precision.

    Remark: The FFTW  is no more included in the Frv distribution.  You need first to install FFTW.

    FrvRFFTFree

  • Syntax:    void FrvRFFT (FrvFFT* fft)
  • Comment:This function free all the memory associate to the FFT object.
  • FrvRFFTFor

    FrvRFFTInit

    FrvRFFTNew

    FrvRFFTSetDecay


    The Transfer function computation (FrvTF)

    This object compute a transfer function, assuming the the input signal has wide band noise.The useful FrVect members are:

    FrvTFError

  • Syntax:    void FrvTFError(FrvTF* tf)
  • Comment:This function compute the transer function errors. It is automatically called by FrvTFProc is the option 'E' has been used when creating the TF object.
  • FrvTFFree

  • Syntax:    void FrvTFFree(FrvTF* tf)
  • Comment:This function free all the memory associate to the FrvTF object.
  • FrvTFInit

    FrvTFNew

    FrvTFProc

    FrvTFSetDecay


    Library installation

    Before installing Frv, you need first to install FFTW.

    The latest version of the Frv library could be found in wwwlapp.in2p.fr/virgo/frameL. Assuming that you have downloaded the gzip tar file for the library, you need to:

    For any question, e-mail to mours@lapp.in2p3.fr

    The ROOT interface

    Like for the frame library, a ROOT compatible shared library is available. To use it, you need to you need to update the PATH and  LD_LIBRARY_PATH to include the FrvROOT.so binary directory (named by your system). Then if you start root from the Frv/vXX/root subdirectory, it will execute the FrvLogon.C which load everything you need.

    Example of ROOT macros are available in the root subdirectory. Play with them to get an idea of what you could do.


    History

    Version v3r20 (May 2, 2002) Version v3r10 (March 20, 2002) Version v3r00 (November 22, 2001) Version v2r10 (April 22, 2001) Version v2r02 (Jan 16, 2001) Version v2r01 (Jan 11, 2001) Version v2r0 (Jan 10, 2001)