Multiply Two Channels With Different Time Steps

Recommended Posts

I have 2 channels:

- A with a gas concentration, read from a LabJack every 5 seconds.

- B with a flow rate, getting a new data point each time 20 ml have passed the flow meter, which can be more than an hour.


What I want to do is displaying both the raw gas flow (channel B ) and the flow of my gas (i.e. channel A multiplied with channel B ). However, if I just do "A*B", then the program will multiply the channels as arrays, without taking care of the different time scales.

Is there a more elegant way to do this than by creating a help channel which is filled with "A[0]*B[0]" every time a new data point is recorded in B?

Share this post

Link to post
Share on other sites

Yup, use the align() function (section 14.12.11 in the help) and filter():


filter(align(A, B, 1) != nan()) * B


align() will then make any value in A that isn't within 1 second of a point in B into NaN().  The filter then removes the NaN() and you can then multiply by B.  


Personally I think you are better off making a helper channel, that way you can log the result and do other things.  Its also more efficient.  Finally, align will only remove points.  If you want to have the multiple for every reading of A, you have to use a helper channel.  Just put:


helperChannel = a[0] * b[0]


in A's Event.

Share this post

Link to post
Share on other sites

Thanks a lot! If I understand the align function right, there may however be a risk that 2 neighbour data points in A which ly around a data point in B "survive" and somehow compete, so I am not really sure this would lead to exactly aligned data. Also, I get the point regarding efficiency and logging, so I probably will go the helper channel way.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now