averaging captured values

Peter West

Posted on 26.03.2026 09:36

I want to capture values with a 'basic statistics' math channel using 'start-stop blocks'.

I then want to average those values.in such a way that the result is not influenced by the number of samples over which the channel is at any given value.

For instance, if the channel value is 2 for 100 samples, 4 for 50 samples and 6 for 25 samples, how do I make the average equal to 4 (average of 2, 4 & 6), and not 3.143 (550/175 which is the sum of values/no of samples at each value)?


Pika Kreča Šmid

Posted on 30.03.2026 08:36

Dear Peter,


thank you for reaching out to us.

We understand that you are looking to calculate an Arithmetic mean of distinct values rather than a sample-count weighted average.


We do not believe this is possible to calculate using built-in DewesoftX mathematics, but it should be possible to implement using our C++ script plugin.

In the attached script, we defined a values vector that contains all unique values of a selected signal. The script then looks at the current value and loops through the entire values vector to see if this specific value is already recorded. If the number is new (if (cnt == 0)), the script saves this number to the values vector, if not, the value is skipped.

After checking for uniqueness of the current value, the script will sum up every unique value stored in the vector, divide the sum by the number of unique entries (values.size()), and output the result to a new channel called out1.


Here's an example of the final result:


I have attached a setup file that includes the previously mentioned C++ script.


I do have to note that our C++ script requires a license with a C++ option in order to work. If you do not have this license, you can test out the functionality with a Trial license, as this should allow you to load a setup file that includes C++ scripts. Here is a link to our online form for acquiring a DewesoftX Evaluation (Trial) License.


Best regards,

Pika

Peter West

Posted on 03.04.2026 09:06

@Pika Kreča Šmid


Thanks Pika for looking at this problem for me, and for your proposed solution.

 

Is it possible that in the future there could be a ‘built-in’ method of removing the sample-count weighting to captured values?

Perhaps a tick box option?

And could that also be applied to any other method (Latch value math etc?) of capturing and holding data for subsequent use in other math channels?

Pika Kreča Šmid

Posted on 07.04.2026 07:28

Dear Peter,


thank you for your message.


The Unique value average isn't as widely used as the Sample‑based average, so we don't currently plan to add it as a built‑in feature in DewesoftX. For this type of specialized calculation, we provide a C++ script plugin and, for more advanced needs, the option to create Custom Extensions (plugins). Those tools let you implement whichever algorithm you need.


Best regards,

Pika



Login to reply to this topic. If you don't have account yet, you can signup for free account .