Jump to content

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!

Link to comment

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.

Link to comment

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.

Link to comment

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..

 

 

post-51848-0-33162300-1401226613_thumb.p

post-51848-0-01489400-1401226799_thumb.p

Link to comment

OK, the way you've set up the data acquisition it will use the sample clock from the analog input to also acquire the digital input. In other words, a digital input sample will be taken every time and at the same time that an analog input sample is taken. You've also started the digital and analog input tasks such that the two will start together. This means the analog input and digital input are synchronized in time (e.g., the 1000th sample taken for the analog input was taken at the same time as the 1000th sample of the digital input -- this is the array index referenced).

 

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.

Link to comment

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? 

 

 

post-51848-0-33553600-1401233551_thumb.p

Link to comment

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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.