Integrating an analog signal

Recommended Posts


I would like to integrate my analog input signal from the U3 Labjack. I have successfully generated my channel to display the input voltage correct. I have also found the post with the integration equations, but they don't work for me. I would like to get the following:

In addition to my voltage signal I would like to display the integration over time for this signal. Life, same as for the voltage. I am logging one value every 1s. I am thinking the time format is making it difficult for me.

Let's say my voltage is constant at 3V. Then I would expect a graph which rises 45 degree. So at 1s -> 3, 2s -> 6, 3s -> 9 ...Basically input*time(since start), value by value.

Is this possible somehow?

Link to comment
Share on other sites

Yes, create a second channel, let's say you call it "Integration", device type "Test", D to A.  I'll assume your first channel is just called Input.  Go to the Event for the Input channel.  In it do:

Integration = input[0] * (input.time[0] - input.time[1]) + integration[0]

This will do an accumulated,  integral with units of V-sec assuming input is in units of V.  Note that this is a stair-step integral, so is assuming that the value just read existed at that value since the last reading.  You can make it slightly more accurate by doing a trapezoidal integral by changing the math slightly.

Also, note that since you are doing accumulated, you need to initialize the Integration channel to 0, which you can do just by:

Integration = 0

DAQFactory will give you an error until you do that because your event code relies on Integration having some value.  Note you can also reset the integral the same way.

Link to comment
Share on other sites

Hmm, it does not work in my case. I just getting a triangle wave.

What I need is this:

Voltage: 3, 3, 1, 2, 3 (5 readings, one every second from Labjack channel, unit[V])

Int1: 3, 6, 7, 9, 11 ( 5 calculations from channel Voltage, one every second, unit [Vs])

I think it have something to do with the time format and that the latest values always are the index 0, and the other will be shifted in the array with every new reading.

In my understanding I need something like this:

Int1[newest] = Voltage[newest] * (Voltage.Time[newest] - Voltage.Time[oldest])

Edited by Integrator
insert brackets
Link to comment
Share on other sites

Your formula is wrong as it is not accumulated integration, just a normalized Vs reading.  You need to add that to the previous integration total as I did.  If mine does work, you have a typo.  Can you attach your .ctl document for review?  Did you remember to set the Timing of your Integration channel to 0?

Link to comment
Share on other sites

Here is my file.

Maybe there is a typo, not sure. I am new to this software.

My final goal is to log the voltage from a battery which will be drained by a Resistor.

Then also calculate the drained Capacity, where P=U^2*R. And P*time is the capacity in maybe Wh. So I would like to have it life, or 1 or 2 samples delay. Not a post calculation.


Link to comment
Share on other sites

Your issue is that you are setting Integration to 0 in the Event.  Every time a new data point arrives on the Voltage channel, the Event script is called.  You first set Integration to 0, then you set it to the correct value.  This is causing the triangle shape.  The Integration = 0 needs to be in an autostart sequence, or in a button press to reset the integration.

Link to comment
Share on other sites

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.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.