Description of the problem
Dewesoft's Basic statistics allows users to calculate statistical values of a signal based on Time or Samples.
While both options are valid, the two calculated values differ quite noticeably in the case of asynchronous channels. If we look just a little closer, we notice that Sample based statistics gives us the solution we expect, while Time based statistics yields a seemingly incorrect result.
This article will go through the mathematics behind both types of basic statistics so that we will understand exactly how each type works. To make the explanation easier, the main differences will be shown by calculating the average value of a signal’s peaks, and we will only be looking at a Single value calculation.
Description of the solution
The mathematics behind the two calculation types
- Time based Basic statistics takes the values of a signal at the specific time stamp. If the signal does not have a sample between two or more time stamps, the calculation takes the value of the previous sample until a new sample arises.
- Sample based Basic statistics takes only the values of the signal's samples. If the signal has a long period without any samples (asynchronous signal), the calculation simply waits for the new sample.
The signal
The used signal can be characterized by the following equation:
Signal = if('time'>1.240 and 'time'<1.26,3,if('time'>2.240 and 'time'<2.26,6,if('time'>5.240 and 'time'<5.26,2,'triangle')))-1,
Where
triangle = trian(1)
and time is the time elapsed from start of acquisition/storing (in seconds).
In other words, we create a signal whose value rises and falls over time as if it were a triangle. At specified times, we can additionally notice peaks in the signal.
We can now proceed with locating the peaks of the created signal.
The peaks
We firstly denote the positive edges of the signal as
positive edge = edge('signal'>=0.1,'signal'<0)
Next, we will use Basic statistis to calculate the Maximum values of Signal. These values will be calculated in Time based Start-stop blocks, with the previously set positive edge acting as a trigger for the calculations.
Additionally, we use the scnt formula, with which we can count the number of samples acquired from the start of acquisition/storing, to define the peaks:
- Peak 1:
- Samples from the start of the datafile = 125, value = 2
- Peak 2:
- Samples from the start of the datafile =225 , value = 5
- Peak 3:
- Samples from the start of the datafile = 525, value = 1
The average values
We can now use Single value, Sample based Basic statistics to calculate the Average value of the peaks:
To calculate this value, the software locates all the peaks, in our case 3 peaks, makes a sum of the peaks' values, and divides the sum by the number of samples.
Ave = ∑values /
∑peaks = (2 + 5 + 1) / 3 = 2.666
Now, let's use Single value, Time based Basic statistics to calculate the Averagevalue of the peaks:
To calculate this value, we must know the Dynamic acquisition rate of the datafile (in this case, 100 samples/s) or the amount of elapsed samples since the start of data acquisition. From this, we can calculate how many samples hold each of the values, denoting the peaks. With the help of the scnt function, we can conclude the following:
- The first 225 samples (samples from the beginning of the datafile to the second peak) hold the value 2.
- 300 samples (samples from the second peak to the third peak) hold the value 5.
- 75 samples (samples from the third peak to the end of the datafile) hold the value 1.
- The sum of all samples is 600.
The average value is then calculated as the sum of all values (based on the Dynamic acquisition rate), divided by the number of samples.
Ave = ∑values / ∑samples = (225*2 + 300*5 + 75*1) / 600 = 3.375
An alternative to Time based Basic statistics
The Time based Single value Average of an Asynchronous channel is the same as if we were to record the Peaks with the Full Dynamic sample rate, thus creating a Synchronous channel and calculating the average with Sample based statistics.
Let's demonstrate this. First, we use mathematics to change the Peaks channel from an Asnchronous channel to a Synchronous (non-interpolated) channel.
As we can see, the values of this channel do not represent the correct values yet. We should increase the signal by the value of 2 until we reach the first peak, but leave all the other values as is.
We can then use this channel in Basic statistics, to calculate a Sample based Single value average of it.
We can see from the image above that calculating a Sample based Single value Average of a Synchronous channel yields the same results as if we were to use a Time based Single value Average of the same (but Asynchronous) signal.
Additional information
Additional information regarding Basics statistics can be found in the following literature:
- What is Basic statistics? section of the Statistical Calculations on Sampled Data PRO training
- Basic statistics F1 manual
The datafile used in this link is located in this Google Drive.