# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## detect where a threshold crosses a peak

I want to be able to detect the point at which a threshold crosses a peak as shown in the figure, I know that the threshold VI will give me the point A but I also want to be able to get the point B, any ideas?

Message 1 of 13
(3,934 Views)

## Re: detect where a threshold crosses a peak

Hi cconormac,

so you want to compare a waveform with a fixed value?

Such a comparison will give you a boolean signal (aka array) and now you need to detect rising and falling edges in this boolean signal. Sounds like a good example to actually learn to code in LabVIEW…

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 13
(3,922 Views)

## Re: detect where a threshold crosses a peak

You could also make some Rube Goldberg code to reverse the the 1D array, find the threshold there and subtract it from the array size to figure out B if you really wanted to use the threshold function again.

GerdW's suggestion is infinitely better though.

Matt J | National Instruments | CLA
Message 3 of 13
(3,905 Views)

## Re: detect where a threshold crosses a peak

You don't need to reverse the 1D array, just negate it.  Then falling becomes rising and vice versa but the indexes don't change.

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
Message 4 of 13
(3,900 Views)

## Re: detect where a threshold crosses a peak

Good point, although you then would need to round the first threshold's index towards positive infinity and use that as the starting index for the threshold of the negated array.  If you didn't do that then it would always return 0 as the first element is already above the threshold.

Matt J | National Instruments | CLA
Message 5 of 13
(3,893 Views)
Solution
Accepted by cconormac

## Re: detect where a threshold crosses a peak

I would use two arrays, the original and the negated.  Search (or threshold) the original array for the threshold value until the threshold is found then search (or thershold) the negated array for the negated fhreshold value starting from the index where the first threshold was found.  Both indexes will be correct and the values are correct except that the value of the second one will need to be negated to give the correct value.

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
Message 6 of 13
(3,890 Views)

## Re: detect where a threshold crosses a peak

And here we have arrived at a solution way more complicated than it needs to be that will only solve this one particular problem but will, in fact, work.  Well done team.

Matt J | National Instruments | CLA
Message 7 of 13
(3,877 Views)

## Re: detect where a threshold crosses a peak

Thanks for all the help

Message 8 of 13
(3,850 Views)

## Re: detect where a threshold crosses a peak

you could use the "threshold point-by-point.vi" instead of the "threshold.vi"

Regards,
Alex

Message 9 of 13
(3,835 Views)

## Re: detect where a threshold crosses a peak

@cconormac wrote:

Thanks for all the help

Please do not do what you marked as a solution in your program.  If you do this it will only work for a continuous function that starts below the threshold, goes above it and then dips back down. This will also only return you the first and last time it crosses that threshold.

I would STRONGLY suggest you take GerdW or Alex's approach.  They are both much better, I wish sarcasm showed through the internet better.

Matt J | National Instruments | CLA
Message 10 of 13
(3,816 Views)