LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Calculate a rate of change for DAQ reading

Hi all,

 

I have an application where I need to calculate the change rates of numerous weigh scales and flow meters.  I would like to know what the rate is for the last 10 minutes.  My sample rate is 1 second.  I could build a subvi where I have an array and use the linear fit to calculate the slope.

 

But I was reading the forum and found a reference to using the ptbypt linear fit.  I have never used these ptbypt functions before and was hoping someone could have a look at the vi I have attached and let me know if I am on the right track.  

0 Kudos
Message 1 of 2
(1,667 Views)

Hi Terry,

 

TL:DR; Yes - you can use your attached VI to do probably what you want (with a little care).

 

Longer version:

 

Spoiler

Do you want your returned value (i.e. the 'rate') to be per second, or over some longer time period, or a sliding scale etc?

 

A simple method is to take two adjacent points, subtract the first from the second, and divide by the time between them (1s) and so you then get the slope. But if you have noise in your measurements or a changing rate of change, then this will probably be very unreliable as a predictor of anything.

 

If you take over a longer time period, you can perhaps somewhat ameliorate that, but at that point you'd be better using something like the linear fit function (not necessarily pt-by-pt) that you describe.

 

If you'd like a value every second, but you want to have it 'averaged' over a longer period (e.g. 10s or something) then you can use a rotating array to buffer 10s of data and output one new point per new point added (either Delete from Array the first point and Build Array a new point, or Rotate 1D Array and then Replace Array Subset on the last element (which becomes the oldest when you rotate). Note that in either case you need to keep your points in order because you want a trendline, not just e.g. a mean. 

This is effectively what is happening in your example, 'averaging' over the "Period (min)", provided the time value and the value value are appropriate.

 


GCentral
0 Kudos
Message 2 of 2
(1,594 Views)