Integrator Posted August 6, 2021 Share Posted August 6, 2021 Hello, 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? Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted August 6, 2021 Share Posted August 6, 2021 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. Quote Link to comment Share on other sites More sharing options...
Integrator Posted August 7, 2021 Author Share Posted August 7, 2021 (edited) 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 August 7, 2021 by Integrator insert brackets Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted August 7, 2021 Share Posted August 7, 2021 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? Quote Link to comment Share on other sites More sharing options...
Integrator Posted August 7, 2021 Author Share Posted August 7, 2021 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. test.ctl Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted August 8, 2021 Share Posted August 8, 2021 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. Quote Link to comment Share on other sites More sharing options...
Integrator Posted August 15, 2021 Author Share Posted August 15, 2021 I got it now. Thank you. Just one more thing, how I can get the time difference since start? Voltage.Time[0] - Voltage.Time[max] ? Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted August 16, 2021 Share Posted August 16, 2021 Yes, but to get [max] you have to use numrows(), and then [] is zero indexed, so you have to subtract 1: voltage.time[0] - voltage.time[numrows(voltage)-1] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.