The av operator

The average operator average data samples.
  Usage:
    p0y = av(q0)

To see the av Dialog window mark the av with the left mouse button in the input text line in the igr calculator window.
Then press Edit->Operator. Now the av Dialog window appears.

av

The average operator average data samples.
It can average scalars (rank 0, dimension 0), vectors (rank 1, dimension 0) and spectra (rank 0, dimension 1).

This operator is used to average the original n data samples.
The user must write in the Average number of samples: line the number a samples to be averaged for each sample returned.

|<----------------    n     ------------------ >|
-------------------------------------------------
|<--  a  -->|<--  a  -->|<--  a  -->|<--  a  -->|
	    |           |
            |  average  |
	    |  interval |
none
no averaging performed (default)

average
the average of the a samples is returned. This mode works on scalars, vectors and spectra.
This (average) is the most useful mode.
The figure below shows a result of averaging the data.
The Average number of samples: is here set to 20. The black curve is the original 300 samples, and the blue curve is the result of the av operator. In this example the average option is selected. The result contains 15 samples. The user can see which option of the av operator was selected. It prints av("quantity name")[avg20smpl.] . This means the average selection in the operator was selected, and the average interval was 20 samples.
av example 1

median
the median of the a samples is returned. The samples in the input average interval are stored in a data array. This array, of length n, is then sorted. The result is the array element at index n/2.
This mode works only on scalars.
To be correct an odd number of samples should be selected in the Average number of samples:.
The maximum number of samples in the Average number of samples: is 1024, (AV_MED_MAX).
The figure below shows a result of median averaging the data.
The Average number of samples: is here set to 21. The black curve is the original samples, and the blue and magenta curves are the result of the av operator. In this example the average option is selected for the blue curve and the median is selected for the magenta curve. In the median example the operator sorts the 21 input samples to be averaged. Then the 10'th element in the sorted array is selected. As seen in this example narrow spikes are removed in the median averaging.
av example 2

min
the minimum of the a samples is returned This mode works on scalars and vectors.

max
the maximum of the a samples is returned This mode works on scalars and vectors.

min&max
the minimum and maximum of the a samples are returned. This mode works only on scalars.

skip
the first of the the a values is returned This mode works on scalars and vectors.

The figure below shows the result of all averaging modes. The black curves are the same data as in the example above.

av example 2

More about the averaging

average , median , min and max
One sample is returned for each average interval. The sample returned is time tagged to the middle of the average interval.
|<--  a  -->|<--  a  -->|<--  a  -->|<--  a -->|
      |           |           |           |
      t0          t1          t2          t3
min&max
The min&max averaging returns two samples when averaging the a samples.
|<------------------    n    ----------------- >|
-------------------------------------------------
|<--  a  -->|<--  a  -->|<--  a  -->|<--  a  -->|

      2           2           2           2<-return
The two samples returned for each average interval are the samples with maximum and minimum values. If the maximum value appears first, then the first value returned is the maximum value. If the minimum value appears first, then the first value returned is the minimum value. The two returned values are time-tagged equal to the sample 1/4 and 3/4 in the average interval.
|<--  a  -->|<--  a  -->|<--  a  -->|<--  a  -->|
   |     |     |     |     |     |     |     |           
   t0    t1    t2    t3    t4    t5    t6    t7
skip
The first sample is returned in each averaging interval. The sample returned is time tagged to the first sample in the average interval.

about median filter/average

An example contains 9 samples:
    d[0], d[1], ... d[9] 
      d[0] = 22  
      d[1] = 105
      d[2] = 31 
      d[3] = 17 
      d[4] = 25 
      d[5] = 21 
      d[6] = 44 
      d[7] = 129 
      d[8] = 21 
Then the samples are sorted, (with qsort) giving:
      d[0] = 17  
      d[1] = 21  
      d[2] = 21
      d[3] = 22 
      d[4] = 25 
      d[5] = 31 
      d[6] = 44 
      d[7] = 105 
      d[8] = 129
   The median is d[4] , 25

(The average of this example, the mean, is  
  (22+105+31+17+25+21+44+129+21)/9 = 46  )
   

about vectors and spectra

A vector sample (s) contains 3 elements: si[0], si[1] and si[2], (i is sample number).
I.e for 6 samples:
sample 0:   s0[0] s0[1] s0[2]
sample 1:   s1[0] s1[1] s1[2]
sample 2:   s2[0] s2[1] s2[2]
sample 3:   s3[0] s3[1] s3[2]
sample 4:   s4[0] s4[1] s4[2]
sample 5:   s5[0] s5[1] s5[2]
The av operator works on each element at a time.
If the user writes average 3 number of samples
the output is two samples (r)
rj[0], rj[1] and rj[2] (j is sample number).  
sample 0: r0[0] r0[1] r0[2] sample 1: r1[0] r1[1] r1[2] Where: r0[0] = (s0[0] + s1[0] + s2[0])/3 r1[0] = (s3[0] + s4[0] + s5[0])/3 r0[1] = (s0[1] + s1[1] + s2[1])/3 r1[1] = (s3[1] + s4[1] + s5[1])/3 r0[2] = (s0[2] + s1[2] + s2[2])/3 r1[2] = (s3[2] + s4[2] + s5[2])/3
The averaging of spectra works in the same manner. This time each sample contains (usually) more than 3 elements, e.g. 128, then one sample (s) contains 128 elements si[0], si[1], si[2], si[3], si[4], ... , si[127]


When the OK button is pressed the settings (in the Calculator) is updated and the av Dialog disappears.
When The Update button is pressed the settings is updated.
When the Cancel button is pressed the av Dialog disappears.


Updated Jan 03, 2007 by Bjørn Lybekk