LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

finding the first maximum in a 1D array

Hello evryone!!

I have a huge 1D array and It has certain values which are like peaks when plotted. For example, the array may look like:

1 0.23 0.12 0.34 0.2 1.345 0.25 0.13 0.45 0.16 1.023 ---- As you can notice, the array has maximum values  (magnitude close to 1) placed regularly. Now I need to find each of these maximum value and put them in an array. Currently I just start at iteration 0 of the array and use the array index function to get all of these peaks.

 

However,in this code, I assume that the first maximum peak occurs at element 0 (first iteration) of array. But this may not be the case and the array might look like:

0.23 0.12 1 0.24 0.34 0.15 0.19 1.023 0.45 0.51 0.21 0.3 1.345....etc. that is the first maximum value may not occur at the element 0 of the array. So the problem here is to find this first maximum peak and then as the others are placed at regular intervals, i can find them.

 

Could any one please suggest as to how i could change my code to find this first maximum/peak. thanks for the help:)  

0 Kudos
Message 1 of 10
(3,839 Views)

Have you tried the "peak detector" from the "signal processing..signal operation" palette?

 

If the peaks are truly equally spaced, you might even get the desired information from e.g. a fourier transform. The peak in the transform would give you the principal frequency and the phase of the peak would give you the shift.

 

Can you attach a VI containing some real data so we can play with it?

Message 2 of 10
(3,834 Views)

Hello again!!. I have attached my VI's.

Please note: The current issue is in the second for loop of the receiver.vi code. The peaks array output is the one which gives all the peaks found.

Thanks!!!

Download All
0 Kudos
Message 3 of 10
(3,829 Views)

Well, the VI still has missing subVIs and I see no obvious resemblance to the peak finding problem. The second loop deals with a 2D array but earlier you were talking about a simple 1D array.

 

Why don't you do the following few steps

  1. open "receiver.vi"
  2. run the VI once so all indicators contain typical data
  3. Right-click on "Non_zero_PN_Gen" indicator and select "change to constant"
  4. repeat for "output signal" indicator. (you'll get some broken wires in steps 2 and 3, simply ignore. Don't remove bad wires yet!)
  5. delete the "subVI transmitter final.vi" from the block diagram
  6. remove bad wires (ctrl+b). VI should look fine now.
  7. save VI under a new name.
  8. attach it here.
Message 4 of 10
(3,814 Views)
Hi altenbach, Sorry for not being clear enough. When I said 1D array i meant a single row of the 2D array that is input in to the 2nd for loop in the VI. And i did this becuse the same procedure needs to be repeated for each of these rows.Now if you have a look at one row of the averaged values array, you can see that there are peaks of 1. You may not have observed their regular appearance becuse the peaks are seperated by 584 values which is huge. However, the graph plots these values and the peaks are clear. One thing i forgot to mention is that there could be negative peaks as well, as can also be seen in the graph. I also went through all the steps you mentioned and attached the VI again.. thanks a lot!!!
0 Kudos
Message 5 of 10
(3,802 Views)

LSASS wrote: 
You may not have observed their regular appearance becuse the peaks are seperated by 584 values which is huge.

I could not observe anything, because the original VI had no data at all and was not executable because of missing subVIs! 😉

 

Why don't you simply get the index of the first element that is above e.g. 0.5 as in the attached quick draft (LV 8.6)? Modify as needed.

 

(I also did some general cleanup, your code was way too complicated, e.g. way too many loops! ;))

 

 

Message 6 of 10
(3,790 Views)

Take a look at this example on the Dev Zone Community, it allows you to detect all the peaks in a data set above a given (setable) threshold.

 

 

0 Kudos
Message 7 of 10
(3,739 Views)

Hi altenbach,

Thanks for the help. It works as I want it to. Also you removed may unnecessary for loops in my codde. This helped to reduce computation time....Thanks:)

0 Kudos
Message 8 of 10
(3,700 Views)

Hi hunter,

The find a frequency peak with an adjustable  peak threshold works only with inputs of signals. But my inputs are all arrays. so this will not work for me. thanks for the idea :).

0 Kudos
Message 9 of 10
(3,679 Views)

You can modify that example with this code

 

Message Edited by Huter on 05-21-2009 10:59 AM
Message 10 of 10
(3,660 Views)