01-21-2015 09:16 AM
Hi Everyone,
i am a beginer in labview . first let explain the problem i am facing. i have programmed to generate sin wave with 500 points , as you can see in the attached vi i am able to genetate these points as the second task i need to find the peaks values and return the indexes but i am unable to find all the peaks for this sin wave. i used the max and min vi from the array pallette but it returns me only one value. could someone help me with this problem ?
Thanks in advance
John
Solved! Go to Solution.
01-21-2015 09:54 AM
You can do something like this:
First use Max & Min return the index of the first max, then you can use Search 1D Array.vi in a loop with the search index set to first max index +1. Stop the loop when the return index of Search 1D Array is -1. Use a shift register in the loop to set the start index to latest found +1.
Ben64
01-21-2015 10:07 AM
Hi Ben,
i have attached the code with changes as you suggested . could you have look at it and tell me what is wrong ?
the peak value for the sin happens at index 12 and so on but it shows only index 262
01-21-2015 10:18 AM
Good work on implementing a sine wave generator. If you are interested there is several built in functions that also do this. Attached is a VI that shows how it can be done a couple other ways.
Keep in mind that a real world sine wave won't have values that are exactly the same. You use the Search 1D array function looking for the maxes. This works like an Equal function looking to see if any of the array items are equal to the search. Performing floating point equal is generally a risky move, because the liklyhood of having a bit for bit equal is not very liklely. What really should be used is some kind of threshold, that finds the peak, then finds other peaks that are within so much amplitude.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
01-21-2015 10:50 AM
Your implementation is not correct, see attached (it a quick modification so it may need a bit of cleanup).
Hoovaaah is right, this won't work in the case of a real signall with added noise. You should use a threshold value and then find the local max of the areas above this threshold value.
In your case (for an "ideal" sinewave) you don't have enough x axis points to get all the maximum values, try setting the number of x- axis points to 12000. In your case If you index the output array the value at index 262 is 0.0998027 not 0.1.
Again, doing floating points equal might not produce the expected result.
Ben64
01-21-2015 11:15 AM - edited 01-21-2015 11:16 AM
Keep things simple. There are built in functions to do all of this work for you.
04-15-2025 08:43 PM
thanks a lot for making this code. However, if you use a triangular signal with minimum equal to 0 and max different of zero, and repeat this triangular function n times, you will see that the minimum 0 are not all detected, especially the first and last 0 values
See attached program
04-16-2025 01:12 PM
This may be a good use case for the peakdet VI!