Integration


goldfronts1

Recommended Posts

  • Replies 86
  • Created
  • Last Reply

Sure. But if you want to plot it, you'll need some sort of timescale to integrate over, a sort of boxcar. If you make the assumption that your data is coming in at constant intervals and you miss no data point you can simply use the boxcarsum() function. For example, if myChannel is taking data once a second:

boxcarsum(myChannel, 10) * 10

will create an array with the integrals of myChannel over ten seconds, the result in units of secs * units of myChannel. This is a squared integral, not a polygon integral.

If, however, you don't want to make that assumption, you'll have to manually calculate it in the channel event, probably putting the result in another channel. That is slightly more complicated, but this will get you started: to calculate the instant integral of the last reading using a polygon integral it would be:

(myChannel[0] + myChannel[1]) / 2 * (myChannel.time[0] - myChannel.time[1])

Again the units are secs times whatever units myChannel is.

Link to comment
Share on other sites

So do I put the following (myChannel[0] + myChannel[1]) / 2 * (myChannel.time[0] - myChannel.time[1])

into the conversions tab or into the coordinate expression for the axis I want in my plot?

Also, if my x axis is time and I want the y axis to be the integrated value, then I put the above expression into the Y expression field?

I have attached my file for you to look at. It is the graph on the right. I would like to take the integral of Voltage2 channel which has a conversion to become current and then this will give me Charge. Then I want to plot the Charge vs the time.

Thanks

Setup4.ctl

Link to comment
Share on other sites

It depends. Do you want to plot the integral between successive points? This isn't a particular accurate integral and will amplify any noise in your signal (or quantization due to the resolution of the input).

If this is what you want, you would put this in your Y expression, as the expression I first gave you gives you a scalar.

(myChannel[0,100000] + myChannel[1,100000]) / 2 * (myChannel.time[0,100000] - myChannel.time[1,100000])

Link to comment
Share on other sites

Basically what I want to do is record my data for the plot on the right, which is current vs time. then I would like to take that data from that plot and then integrate the recorded current over the time and plot that integration vs time.

So I start with current, then integrate it to get charge, then plot charge vs time.

Thanks

Link to comment
Share on other sites

I'm not sure what you mean. I would like to plot the integral over the range of time that I recorded for the current vs time. For example if I recorded from 1 minute to 5 minutes worth of data. I want to integrate over this time. Does that make sense??? Sorry for the confusion.

Thanks

Link to comment
Share on other sites

So by adding this expression (myChannel[0,100000] + myChannel[1,100000]) / 2 * (myChannel.time[0,100000] - myChannel.time[1,100000]) to my Y expression in my plot and plotting this versus time of mychannel, will give me the integral of the recorded channel?

Also, what do the numbers mean in "myChannel[0,100000]" ???

Thanks for your help

Link to comment
Share on other sites

[0,100000] means give me all the data points in myChannel starting at the most recent and going back 100,001 data points. Its actually probably not needed since just doing myChannel will give you the entire array. It is needed to get the next most recent value, so [1,100000] does the same thing but starts one data point back. 100000 is just an arbitrary high number. If your history is bigger, you'll need to make this number bigger too.

Note that a trapezoidal integral is simply the average of two consecutive points times dt. A square integral is simply a point times dt from the previous point. It is not as accurate as trapezoidal (draw it out on graph paper and you'll see why).

Link to comment
Share on other sites

First, I had a typo when I posted the expression. The /2 needs to be outside the parenthesis. I've corrected it on most of the posts. But this isn't your issue. Hit F6 when in the expression box and see what the error message is. Do you have data in these channels?

And yes, you can do trapezoidal integrals in Express, it is just math and that's what the formula I've given is for.

Link to comment
Share on other sites

Yes, I have data in the channels but it is not correct. Adding the /2 outside the parenthesis solved the error issue. So what is happening is that I am simultaneously plotting Voltage2 vs the start time of voltage2.

Then at the same time I want to take the integral of that plot from the starting time to the end time and then plot that against time.

Link to comment
Share on other sites

Yes. This plot should record the intergral vs time (limit of time from the first plot). of the other plot while it is recording data. I would like to see this integral plot in real time.

The first plot is a decreasing plot. So the voltage2 value goes from a positive value to almost zero. (never negative. The time axis goes from 0 to 5 minutes.

Thanks

Link to comment
Share on other sites

OK, then the result is going to be a steadily increasing plot where the slope slowly decreases towards 0.

To do this you are going to need a Test channel, with Timing = 0. Call it "Int_v2". Then in the voltage2 channel event, put:

private newInt = int_v2[0] + (Voltage2[0] + Voltage2[1] / 2) * (Voltage2.time[0] - Voltage2.time[1])

newInt.time = voltage2.time[0]

int_v2.addvalue(newInt)

You'll need to initialize int_v2 to 0 whenever you want to reset the plot. Just do:

int_v2.addvalue(0)

Then plot int_v2 vs time.

Link to comment
Share on other sites

That is what I said, it will climb from 0, then reach a point where the slope is 0 (which is steady state). This is where the voltage is 0. Note that in order to get the plot you posted, you would have to have negative voltage starting at time 100msec.

You can plot it against integral time by setting a variable with the start time and subtracting it from the absolute time. There are a number of recent posts on this forum about doing graphs against dt instead of absolute t.

Link to comment
Share on other sites

So you can see from this image that the blue charge current line is what I already am able to plot. It is this data that I want to integrate with respect to time, in order to get the black dotted line which is the charge capacity.

Notice that it is an increasing plot.

Hope this helps

Thanks

Link to comment
Share on other sites

1) the image you sent doesn't show a blue line or dotted line, just a single red one

2) the posts I was talking about are the first two posts in the DAQFactory and LabJack forum

3) the error tells you the problem. There's a ) missing at the end of the line, probably from when I cut/pasted the script

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.