LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error in Mean PtByPt VI

I'm using the Mean PtByPt.vi in the NI_PtbyPt.lvlib to calculate a running average over time. My sample length is unknown, so the sample size is set to 0. I also use the initialize input to reset the running average calculation at various times as needed. I'm not getting the expected results.

 

When I set Initialize to True, I'm expecting the running average to reset to 0, and it doesn't. After looking at the block diagram (which frankly I can't believe this is allowed to ship with LabVIEW) I see that shift register is reset if an array of values is used, but not if the "Infinite horizon" approach (the one I'm using) is used.

 

Am I missing something?

"All truths are easy to understand once they are discovered; the point is to discover them." -- Galileo Galilei

0 Kudos
Message 1 of 11
(3,619 Views)

When initialize is true, the "Init" case is executed instead of the "Infinite horizon". The input x is taken as the first data, hence the output mean equals x.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 2 of 11
(3,604 Views)

I get that's what it's doing. My expectation was that the init state was more of a reset. I've created my own version with that approach, but I wanted to see if I was on island or not with my expectation of how the VI should operate.

"All truths are easy to understand once they are discovered; the point is to discover them." -- Galileo Galilei

0 Kudos
Message 3 of 11
(3,590 Views)

@B.Settles wrote:

I get that's what it's doing. My expectation was that the init state was more of a reset. I've created my own version with that approach, but I wanted to see if I was on island or not with my expectation of how the VI should operate.


Guess the init is not a reset, and that's the bottom line.

 

I agree, the VI won't win any beauty contests, but I've seen worse (also from NI).

 

My biggest objections against the hole idea of PtByPt is that it doesn't scale up. So if I use a PtByPt VI in a class method, it works on an object. Then I scale up and use the method on an array of objects, and the PtByPt method won't work properly, since the same instance is invoked on all class objects...

 

I find I have to rewrite each PtByPt VI I need to a class with an init and an execute. Sometimes that's easy, sometimes hard. But usually the code gets better.

 

 

0 Kudos
Message 4 of 11
(3,579 Views)

@B.Settles wrote:

When I set Initialize to True, I'm expecting the running average to reset to 0, and it doesn't.


So you expect the value you are passing into the VI to be completely ignored when you reset it?  It is a reset.  It is clearing out all of the previous data and performing a new mean starting with your current data point.  The average of X is X.  So it makes complete sense to me.  I would not expect a 0 output on a reset.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 11
(3,567 Views)

@crossrulz wrote:

@B.Settles wrote:

When I set Initialize to True, I'm expecting the running average to reset to 0, and it doesn't.


So you expect the value you are passing into the VI to be completely ignored when you reset it?  It is a reset.  It is clearing out all of the previous data and performing a new mean starting with your current data point.  The average of X is X.  So it makes complete sense to me.  I would not expect a 0 output on a reset.


Agreed. The only ambiguity is that "init" does not automatically imply the current iteration counts. It does for all PtByPt VI's AFAIK. And since it does, while init is true, PtByPt Mean should return the current input value. It is usually convenient that it works that way, and the other way around would almost always be inconvenient.

0 Kudos
Message 6 of 11
(3,562 Views)

This one of the few times I've found the LabVIEW help to be less than helpful.  All it says for initialize is: "initialize, when TRUE, initializes the internal state of the VI."  It should probably be more specific in what initializes.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 11
(3,557 Views)

BTW 0 would never be expected (by me). If init=true means the current cycle is not included as a valid cycle, I'd expect NaN as a result, not zero.

0 Kudos
Message 8 of 11
(3,545 Views)

In making my own version, I did find another "error" in that the size needed to be reset to 0 also, which would give the NaN. 

 

So my desire was to use the Init as a reset and ignore whatever the input value was (if I'm resetting, the value is invalid/garbage in my use case and there could be multiple resets in a row). Seeing as I'm on an island on this one, I'll move on with my own version.

"All truths are easy to understand once they are discovered; the point is to discover them." -- Galileo Galilei

0 Kudos
Message 9 of 11
(3,529 Views)

If I were writing my own API for a functional global, maybe I would break up the two operations into "Clear" (where no value is input) and "Add Point" to make it more clear what is going on. For a palette VI though, this behavior has never messed me up. At some point you will need to add your first point, this just forces you to make that coincide with your reset logic.

0 Kudos
Message 10 of 11
(3,524 Views)