# Using timestamps to integrate data at specific values

## Recommended Posts

I'm trying to integrate data from one waveform graph that depends on the timestamps of another. What I have setup is digital waveform and an analog waveform and I would like to integrate over data from the analog waveform whenever the digital goes high.

My idea on how to approach this was to check when the digital input goes high and then low, and at the those timestamps as my limits of integration, however, I'm not sure how to go about this.

What I have tried to do was to take the digital input data and AND it with 1 to see if it is high, and then take that data and store its timestamp in an array and then input those values when integrate, but this is not the correct approach because it will not give me the right intervals for integration. I think what I am having trouble with is getting the timestamps of when the digital input goes high and then back to low.

Does anyone have any idea on how to approach this problem? I would appreciate any suggestions.

Thank you!

Are the Analog and Digital samples driven from the same clock?  Are they sampled at the same rate?  Are they started at the same time?  If you answer yes to any of these your life can get a little easier.  Saying no to all of these questions means lots of manual code searching for times that match up and will likely take much more time but still do able.

Are you having trouble finding the array index where the transition occurs or the timestamp of that index?

If the array index for the transition, a search 1D array for a true/false would give you the index. You 'd need to use the results for the search for the true as the start index for the false.

For finding the timestamp... If the analog and digital data acquisitions are synchronized, you don't need to find the timestamp; just use the index. If the data acquisitions are not synchonized, then the timestamp would be the (index * dt) + t0, and then (timestamp - t0) / dt on the analog side to get back to an index.

Currently each input has its own sample clock and the waveforms are synchronized. I am confused as to how I would go about extracting the intervals to integrate the analog input data.

I thought I would first have to do some sort of check to see if the digital input is high and if it is then continue to get the timestamp, but how would I get the time at which it goes back to low? You are saying I can use an array index to get the right intervals if they are synchronized but I'm not completely understanding.

I've attached an image of what I have so far along with another image of what I've tried to do to get the right timestamps..

This is all good as it makes what you're looking to do easier.

Looking at your code, are you looking to perform the integration on "live" data (as you collect it) or are you going to post-process the data (after you've collected all the data)? I would recommend something different for live versus post-processing.

I am looking to perform integration on live data. I've setup an index search to find the index for the transition to high and the transition to low as you were saying (attached image), but can I use the indices as my intervals of integration or do I have to use the time stamps? Or do you suggest something else because I want to do it live?

Using the transitions output would probably be easier but for my test I created the analog and digital data.  I think it works but you'll want to check my work of course.  I don't have 8.0 (which your profile says you use) so I attached an image as well as the VI saved in 2011.

Integrate Analog Digital Values.vi

hooovahh has a good example. I think you'll need to monitor state between loop iterations as well. For example, the integration would start when the digital goes high in one read of your data and then continue into the next read until the digital goes low in a read N iterations later. You'll need a shift register to hold the state (don't forget to initialize the shift register), which might be as simple as a boolean for this. If you need more than two state (integrate/don't integrate), then my preference would be to use an enum made into a type def.

Very true I was thinking this would be used in a finite sample type of situation but yes if you are doing this continuously you'll need some extra work.  It was just meant as an example anyway.

Thanks! I will try all of the suggestions and update if it works or not. I really appreciate all of the help!

• ### Similar Content

• #### Selecting signals by user - Waveform chart

By nagesh,

• 6 replies
• 3,600 views
• #### Slow Waveform Concanenation

By ctr26,

• 2,626 views
×