Integration


goldfronts1

Recommended Posts

  • Replies 86
  • Created
  • Last Reply

Its lucky you didn't crash DAQFactory. You put the script that calcs the integral into the event for the channel that is to contain the result. You thus have Int_v2.addValue() inside of the event for Int_v2. This creates an infinite loop as the addValue() will trigger the event again, which will call addValue(), etc. etc.

Also, you never mentioned you were streaming, which makes it so Events won't work the way you want. (see: http://www.azeotech.com/board/index.php?showtopic=4728. Also, you are averaging in the channel which creates other sync problems as well. However, you might be able to get it to work by putting the event code you have in the Int_v2 channel into the event for Voltage2. You still have to initialize Int_v2 to 0 somewhere. I'd put it in the startStream sequence probably. Right at the top: Int_v2.addValue(0)

Another way to do this though is to simply do the integration in the graph. If you want to log the integration too, use an export set and put the same function there. Better yet, use a V channel and put the expression in the V. channel, then reference the V channel from the graph and the export set. You won't be able to use the logging set.

I've attached a sample showing the Event method.

integral.ctl

Link to comment
Share on other sites

By putting the expression I indicated earlier directly in the expression for the graph:

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

That gives you instant integral though. For cumulative you'll probably need to use the Event method.

Link to comment
Share on other sites

This is not working either. I tried doing it without streaming as well. I have attached images of the data from the plot. Also images of the plots. The integral plot is the bottom left plot. The plot on the top right is the plot I am trying to take the integral of.

Thanks

post-8150-1330993160_thumb.jpg

post-8150-1330993168_thumb.jpg

post-8150-1330993179_thumb.jpg

Link to comment
Share on other sites

OK, several problems:

1) int_v2 and Voltage are the exact same channel (LabJack channel 0) and since you are streaming channel 0, the result is getting put into Int_v2 along with your calculation

2) your plot scaling is only 0 to 3, while new_time in your screen shot shows 82, way out of range

3) It's important for you to actually understand the math behind calculating an integral when taking discrete measurements. Its math that applies no matter what hardware or software you are using. I'd like to be perfect all the time, but as you would expect, I reply to a lot of different forum threads, direct emails and telephone calls so don't necessarily proof everything I type and have typos, but I expect the person I'm talking with to take time to understand the concept, not simply cut/paste. As indicated in post #12, I had a typo in my formula in earlier posts, which was then corrected. However, it appears that you have not understood the math and reintroduced the typo into your expression. The /2 needs to be outside the sum of the voltage because the formula is the average of the two readings times the difference in time. Think of it like the area of a trapazoid where the bottom is square.

Link to comment
Share on other sites

OK, several problems:

1) int_v2 and Voltage are the exact same channel (LabJack channel 0) and since you are streaming channel 0, the result is getting put into Int_v2 along with your calculation

Since int_v2 is actually the the integral values, what would giving it an empty LabJack channel do? I have the code for doing the integral in my Voltage_2 channel event.

2) your plot scaling is only 0 to 3, while new_time in your screen shot shows 82, way out of range

The plot scaling is in minutes and I'm not sure what the new_time is in because 82 makes no sense.

3) It's important for you to actually understand the math behind calculating an integral when taking discrete measurements. Its math that applies no matter what hardware or software you are using. I'd like to be perfect all the time, but as you would expect, I reply to a lot of different forum threads, direct emails and telephone calls so don't necessarily proof everything I type and have typos, but I expect the person I'm talking with to take time to understand the concept, not simply cut/paste. As indicated in post #12, I had a typo in my formula in earlier posts, which was then corrected. However, it appears that you have not understood the math and reintroduced the typo into your expression. The /2 needs to be outside the sum of the voltage because the formula is the average of the two readings times the difference in time. Think of it like the area of a trapazoid where the bottom is square.

This was an error on my part not just a copy paste. I am new to this and really appreciate your help with this issue.

Thanks

Link to comment
Share on other sites

1) you can't use a real channel because you are getting real data into that channel. You have to use a channel that isn't wired to anything real (or that you've instructed to stream). Int_v2 isn't a real channel, its a calculated one

2) new_time, like all DAQFactory time is in seconds.

3) sorry to get on your case. I just want to encourage you to take the time to understand the concepts.

4) yes, doing /60 will convert seconds to minutes, your desired units.

Link to comment
Share on other sites

I don't see anywhere where you are populating the new_time channel. Are you trying to do elapsed time from the start of streaming? If so, add this line to your startStream Sequence:

global starttime = systime()

and change "new_time" your y expression to int_v2:

(int_v2.time - starttime) / 60

You can delete the new_time channel.

Link to comment
Share on other sites

I'm trying to plot the time range of the integral itself. So from the other graph I have voltage2 plotted against the elapsed time. So whatever this time range is then I am taking the integral of the data over that time range.

Hope this is not too confusing.

Thanks for your help

Link to comment
Share on other sites

Archived

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