Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Constant running rate of change.


Mavada Jul 24, 2012 08:54 AM

Hi all,

i want to have a constant running rate of change for the instruction below.
With the instruction below the 10 min rate of change will only change after 10 min. but i want to have it constantly calculated, so it calculates the previous 10 min. every second. the 10 min. rate of change moves forward every second and calculates the 10 min rate of change every second over the past 10 min....


DataTable (Test10,True,-1)
DataInterval (0,10,Min,10)
Sample (1,BP_mbar,IEEE4)
EndTable

'User Entered Calculation
If Test10.Record > 0 Then

BP_mbar_Change10 = BP_mbar - Test10.BP_mbar
EndIf


Mavada Jul 31, 2012 10:53 AM

anyone?


aps Aug 1, 2012 12:09 PM

There are several ways of doing this, one of which is to use a datatable, although this is only generally used when there are multiple historical values to analyse due to the memory requirements/processing need to manage a data table.

That method would be something like:

'Define the datatable just big enough to hold 10 mins of 1 sec data
'Store every sample in the table
DataTable (Test10,True,601)
DataInterval (0,1,Sec,10)
Sample (1,BP_mbar,IEEE4)
EndTable

'User Entered Calculation
If Test10.Record > 600 Then

'Pick out the 600 oldest value out of the table for the math
BP_mbar_Change10 = BP_mbar - Test10.BP_mbar(1,600)
EndIf

--
An quicker alternative is to keep your own buffer in an array, using code something like this:

'Create a buffer array for the BP data, to oldest data in
'first element, newest in the last element
Dim BP_buffer(600)

'Original calculation using the oldest value
BP_mbar_Change10 = BP_mbar - BP_buffer(1)
'Shuffle the data down in the array
Move (BP_buffer(1),599,BP_Buffer(2),599)
'Copy the newest value into the last element for next time
BP_buffer(600)=BP_mbar

------
I should say though that I would expect you might use a more sophisticated trend algorithm than this as electronic measurements are subject to noise etc.

Log in or register to post/reply in the forum.