04-09-2010 05:38 AM - edited 04-09-2010 05:39 AM
Hey guys,
Before I start, I am being intentionally vague, and I apologise for that, but this is the best I can do.
The situation - a piece of equipment outputs numeric values which in the example below are delivered by Local Variable (this is necessary - different loops).
I want to take the values from a user defined period of time (defined by the cut off blue wire at the top of the diagram (in seconds)) and average them for that period.
What I want to know is, will the code below provide me with an array of values sampled from the Mean Values Array Local Variable at a sampling rate of 1 per second (intentional gaps of 1 second at the start and end - hence the -2)
I've written the code, but truth be told, I don't trust it! :manvery-happy:
04-09-2010 05:52 AM
Several things:
1. Do not wait for 1s. This will introduce unwanted behavior to the software ("Stuck-experience" for the user).
2. Do not use local variables. If the data origins from another, parallel running loop, take a look into design pattern "Producer/Consumer".
3. Do not build up arrays like this. Most often, it's a waste of memory and may introduce issues like "out of memory" or speed issues.....
So you should build your average on the fly in the loop in order to keep the amount of data low. So you need to create a weighted averaging algorithm in order to keep an unweighted averaging.
hope this helps,
Norbert