DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract First Zero Crossing After Peak

Solved!
Go to solution

I have a signal that approximates a noisy sine wave which I want to broadly break down into segments of negative and positive slope. As peak detection on the original trace is messy and the section of positive slope is complex, I plan to extract these features by working with the differential (the maximum velocity of the principle waveform is largely invariant and can be easily thresholded from the lower amplitude waveforms). I can easily detect the MIN peaks in the differential and now want to walk forward in the dataset to the first transition across the zero line and extract this timepoint to a new dataset. Does anyone have a script that I can modify for this purpose? Essentially, I want to trigger with an existing timepoint, iterate to the first timepoint where ti times ti+1 is negative and then write ti+1 to a new waveform.  I also want to walk backwards to the the first transition across the zero line and extract this timepoint to a new dataset but this is secondary.

 

Thanks!

 

Matt

0 Kudos
Message 1 of 7
(5,836 Views)

What aspect of an example algorithm are you specifically looking for?  From the sound of it, you seem to know how to create the search algorithm which locates at which time value your differential data set values change from positive to negative or vice versa.  

 

I think it would be a matter of traversing your data using a loop, searching for sign-change transitions, and adding the time value at those transitions to an array.  

 

Are you looking for an algorithm to do this, or is there some other level of automation you were looking for?

 

Warm Regards,

Daniel Dorroh
National Instruments
0 Kudos
Message 2 of 7
(5,815 Views)

Daniel,

 

I very much appreciate your response. Allow me to clarify where my problem lies.

 

I know how to design the algorithm in theory (and have successfully implemented it using excel) but have difficulty implementing it in vbs script. I therefore was looking for some sample code fragments that highlight each of the steps you've mentioned. Barring that, is there a good resource for learning the basics of this scripting language? I think this is actually my principle question.

 

To further clarify the strategy, this implementation generates a zero crossings array (time and value), merges this array with my existing peaks array, then writes to new arrays only the zero crossings that immediately precede (array1) and follow (array2) the peak.

 

Of course, being able to do this in a more direct fashion would be preferable (ie. iterate to a zero crossing, if it is followed by a peak exceeeding the threshold, write the zero crossing, peak and next zero crossing to three independent arrays. Otherwise, proceed to next zero crossing and repeat.

 

FYI - I am using my adaptation of thresholdpeaks.vbs to detect the peaks but don't fully understand the code. Again, if there is a resource for learning the basics of vbs, I would very much appreciate the recommendation.

 

Matt

0 Kudos
Message 3 of 7
(5,801 Views)

Hello Matt,

 

Here is a good starter on VB Script.

 

Regards,

 

Jeff L.

0 Kudos
Message 4 of 7
(5,774 Views)

Hey matt,

 

You could try looking at this peak finding script for tips.  This method uses an absolute threshold value excursion to trigger the local peak finding.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 5 of 7
(5,710 Views)

Sorry for not responding earlier about my progess.

 

I was able to extract the timepoints using your advice but now want to go back to the original data and extract the y-values. For some reason, my for loop below completes but only writes no-values? Extracting the x and y values in parallel won't work because I generated by x-value subset using the differential of the original dataset.

 

The general question is as follows:

 

Given a common timepoint, find the y-value associated with that timepoint in another channel.

 

FOR i=1 TO InitContrLength

   ChDx(i, InitContrY) = ChDx(ChDx(i,InitContr)/Interval, Filtered)

   Next

 

InitContr is an array of discontinuous time values which represent a subset of the original time series. My for loop is designed to iterate through the InitContr, converting them to an integer representing the appropriate row in my original dataset (Filtered) by dividing the time value by the step interval, and then writing the value from Filtered (which is an array of y-values) that corresponds to that row to InitContrY.

 

Definitions in case the above is confusing

 

InitContr = Channel containing a subset of time values

Filtered = Channel containing all y-values from the original waveform

Interval = step width of the original waveform

InitContrY = New Channel that I want to write y-values to that correspond to InitContr x-Values

 

Any ideas or links to a debugging primer would be greatly appreciated. If I could iterate through my for loop and visualize the variables in real time, I think I could figure this out myself.

 

Matt

0 Kudos
Message 6 of 7
(5,554 Views)
Solution
Accepted by topic author MKlassen

I downloaded windows script debugger and figured out my problem. Because I extracted my initial timepoints from the differential, I was not returning integers of the original timepoints. I have it working now.

 

Matt

0 Kudos
Message 7 of 7
(5,550 Views)