LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array maximum value index

Solved!
Go to solution

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

0 Kudos
Message 1 of 8
(6,160 Views)

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

0 Kudos
Message 2 of 8
(6,144 Views)

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 

0 Kudos
Message 3 of 8
(6,133 Views)

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.

0 Kudos
Message 4 of 8
(6,128 Views)

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

0 Kudos
Message 5 of 8
(6,108 Views)
Solution
Accepted by topic author JGJ27

Keep things simple.  There are built in functions to do all of this work for you.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 8
(6,097 Views)

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

 

0 Kudos
Message 7 of 8
(112 Views)

This may be a good use case for the peakdet VI!

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 8 of 8
(63 Views)