# Coefficient of Variation

## Recommended Posts

Hello

I am using a LabJack U6 to read four pressure transducers and a EI1050 thermohygrometer. I am almost done with my project, the only piece missing is that I need to plot the Coefficient of Variation in Krough (which is calculated based on the pressure values) for the last 5 minutes of measurements. That is my first time using DAQFactory, and I am not sure how can I write a function for that.

If I use

StdDev(((pressure0- pressure1 )/2.745)/pressure1)/ Avg (((pressure0 - pressure1)/2.745)/pressure1)

I will not get the last 5 minutes of measurements...

Thank you very much in advance

Best

Ilaine Matos ##### Share on other sites

What is the actual formula (not in DAQFactory)?

It looks like your graph is actually showing the last 25 minutes.  Are you just looking to get it based on the last five minutes?  In that case, you need to subset:

StdDev(((pressure0[systime(), systime() - 300]- pressure1[systime(), systime() - 300] )/2.745)/pressure1[systime(), systime() - 300])/ Avg (((pressure0[systime(), systime() - 300] - pressure1[systime(), systime() - 300])/2.745)/pressure1[systime(), systime() - 300])

It kind of gets hard to read this way, so you might consider creating a calculated V channel, so V.pressure0_5min might be pressure0[systime(),systime()-300], and the same for pressure1.  Then I'd create another calcuated V channel with the division, say v.kroughPreCalc

((v.pressure0_5min - v.pressure1_5min)/2.745)/v.pressure1_5min

Then the final expression just becomes:

stdDev(v.kroughPreCalc) / avg(v.kroughPreCalc)

Remember, when naming the V channel you don't put the V. in front.  That is just for accessing the data.

That all said, I would, in fact, if I was doing this, do it in a sequence that runs all the time and calculates this at the same interval as data comes in:

```global Krough
private timeFrame = 300 // seconds
delay(timeframe) // wait 5 minutes for data to accumulate
while(1)
private p0 = pressure0[systime(), systime() - timeframe]
private p1 = pressure1[systime(), systime() - timeframe]
private precalc = (p0 - p1) / 2.745 / p1
Krough = stdDev(precalc) / avg(precalc)
delay(1) // gives an update rate of once a second...
endwhile```

##### Share on other sites

Hello

Thank you very much for your quick and detailed response!!

I ran the sequence code that you provided and I was able to display the CV Krough values for the last 5 minutes.

However, I am still not able to plot such values. If I try to plot Krough (Y expression) versus Time (X expression), my graph is blank...

I really need to plot the CV Krough, because for my measurements the CV Krough (for the last 5min) must be below 0.05 during at least 5 consecutive minutes. When that condition is met I can consider that my measurements are stable enough, so I can log the data and conduct some further calculations.

Any insight of why the plot is not working?

Thank you very much

##### Share on other sites

That is because the Krough value is the result of an average of 5 minutes of data and you haven't created a history.  So, I would create a Test channel called KroughData, with Timing = 0.  Then replace this line:

Krough = stdDev(precalc) / avg(precalc)

with these:

private tKr = stdDev(precalc) / avg(precalc)
tKr.time = systime()

Also you can get rid of the line that says "global Krough"

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible. Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.