LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variance of 20 Samples At a Time....

Solved!
Go to solution

Hello,

 

I've asked a similar question before, but now the functional requirements have changed so I need to modify the vi....

This vi should calculate the variance of data points in "chunks" of 20 (or whatever the user desires), if the variance is greater than the threshold value it should start computing the difference between the data points in the "chunk." Once it encounters a difference that is larger than the allowed difference (the threshold) it time stamps it and add 1 to the loop counter. At the end, a total counter is compared with the threshold to see if it failed or not and should write the time entries to a .txt file.

 

At the moment, I see one problem-- variance is always equal to 0, and I don't know why. 

I appreciate any input regarding the obvious problem, and any other that you see.

 

Thank you, 

 

 

0 Kudos
Message 1 of 18
(3,105 Views)

In your integer division, wire to the remainder instead of the quotient and things should improve. Change the variance from an integer to a double, and you will really feel better. Replace the local variable with a wire connection so you can afford a smile...

Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
Message 2 of 18
(3,093 Views)

Haha...this reply is worth a kudo just for the wording.

I've done all the changes, but it still fails to pass the last case structure and for loop :-(.

 

 

0 Kudos
Message 3 of 18
(3,086 Views)

It's late and I have probably enjoyed too much this nice VSOP cognac in my hotel room. This is probably the reason(s) why I have difficulties understanding the idea of extracting a zero length chunk from the array in the for loop. May be you could try with some negative values ? NaN would also be a nice move.

You cheat : you didn't remove the local variable...

Kudos are welcome : they may help getting me awake before being totally drunk !...

 

Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
Message 4 of 18
(3,073 Views)

Haha...VSOP is nice without a doubt (although I prefer malt wh).

Ok, now I removed all of the local variables? Why you don't like them?

Well, I thought extracting zero size will extract only one element where size 1 for example will extract 2 elements. I just checked it and it's wrong....so I've changed it to size one.

The only problem I see now is the two counters, they are inconsistent.

Thank you very much for your help (better than just drinking 🙂

 

 

0 Kudos
Message 5 of 18
(3,065 Views)

There are 2 main reasons to avoid Locals, the first one is that a Local is a data copy. With simple data as integer that's not a big factor, but when localling arrays it can be an issue.

The second and biggest one is that Locals are very often the cause of race conditions which thus cause very hard to debug issues in programs. If you haven't yet, you will get such problems. We've all had our issues with them.

Thirdly it's considered good style to avoid them. (basically a result of the previous 2)

 

I haven't checked your code, but inconsistant indicators are typical of a race condition where they read different "age" of the data.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 18
(3,048 Views)

Hi Yamaeda,

 

Thank you for the explanation, it makes sense now. I'll try to avoid them.

I removed all of the local variables except of two T/F that I initials in the beginning.

The counters are still inconsistent though, and I think it's because some miswired terminal between the loops and the case structures.

Also, I've tried to fix this one for a couple of hours, when I try to save the time stamps to .txt the vi doesn't write anything to the file, and all I get is a a blank .txt file.

Here is the vi, I'll appreciate it if you'll take a look at it (I've added a bunch of indicators to help me debug it....)

 

Thank you,

 

 

0 Kudos
Message 7 of 18
(3,026 Views)

Run your VI with execution highlighting (the light bulb) on.  You will see that the write to file executes before the while loop completes because there is no data dependency between the loop and the file case structure.  It will always write a blank file because no data is connected to the input of the Write to Spreadsheet FIle VI.  While the initialization will probably work, there is no guarantee that the write to the local variables will occur before the while loop executes the first iteration, again because there is no data dependency.

 

Try to keep the diagram to the size of one screen.  it makes it much easier to see what is happening.

 

Lynn

0 Kudos
Message 8 of 18
(3,008 Views)

Hi Lynn,

 

I only left the "save time data?" structure unwired because when I wire the time array(from the shift register) directly to 1D terminal of the "write to spreadsheet" it doesn't work, and when I use "build array" between the two it still doesn't work. In both cases I get a blank file.

0 Kudos
Message 9 of 18
(3,003 Views)

Small correction to my reply above, the file isn't blank but it only saves the hour rather than hour:min:sec.

0 Kudos
Message 10 of 18
(2,998 Views)