LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting the results of the peak detect algorithm

Hello,
 
I'm trying to find the frequencies (x-value) and the amplitudes (y-value) of the 10 largest peaks in an FFT Zoom.
 
The output of the FFT Zoom has f0, df, and a 1d array of y-values.  I think I can use the peak detect vi to find the amplitude (y-value) and the x-array-index.  Then, using f0, df, and the x-array-index, I (think) I can calculate the x-value (i.e. the frequencies of the peaks).
 
Next, I need to sort the amplitude array, but the frequency array needs to be re-ordered along with the amplitude array so that at each index in both arrays, the amplitude and frequency still "match up".  I started to design a way to do this, but it seems to be a brute force approach...I have a feeling that there's an easier way in LabVIEW and I'm confident that all you good people on this board will know how to best accomplish it.
 
Thanks in advance,
Chris
0 Kudos
Message 1 of 5
(3,040 Views)

Use a for loop to combine all the quantities of interest into a cluster, with the sorting variable as the first item in the cluster.  Autoindex the cluster out of the for loop to create a cluster array.  Sort the cluster array using sort 1D array, then retrieve the information that you need.

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 2 of 5
(3,002 Views)
Bruce,
 
Thanks for the information. 
 
You stated that I should put the desired items into a cluster "with the sorting variable as the first item in the cluster".  Can you please tell me how to set the sorting variable of a cluster?
 
Thanks,
Chris
0 Kudos
Message 3 of 5
(2,993 Views)

The sorting variable is always the first item in the cluster.  When you sort an array of clusters, it sorts by the first item in the cluster.  If there are two identical values in the first item, it sorts by the second item, and so on.

When you build your cluster, you want to put the items into the cluster in the sequence that you want to sort them by.  For example, if I was sorting names, I would put the last name as the first item in the cluster, then the first name, then any other information I want to keep with the name when I sort it, such as phone number, address, etc.

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 4 of 5
(2,980 Views)

Bruce,

Thank you very much for the assistance.  This allowed me to accomplish exactly what I needed to.

Best Regards,

Chris

0 Kudos
Message 5 of 5
(2,963 Views)