LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

log search

Hello,
Where can I find a VI that utilizaes a log search algorithm (in order to shorten the time to find the best value).
Thank you,
Gaby
0 Kudos
Message 1 of 4
(2,362 Views)
This example is designed to be nearly a drop-in replacement for the Search 1D Array function, which comes with LabVIEW. This VI is polymorphic and accepts most numeric data types as well as strings.

There are a few things to note about a binary search that make it different from the linear search performed by LabVIEW's Search 1D Array function.
1. Your input array must be sorted before using this function. If it is not, this function will not return the desired output.
2. There is no start index input due to the nature of this search algorithm.
3. If your input array has duplicate elements, a match will be found, but the index returned is not guaranteed to be the index of the match with the lowest array element number, as it would be with the standard Search 1D Array function. This binary search is typically used to see if the element exists in the input array at all, and people are often not concerned with the actual index. However, if each element in your input array is unique, then the index returned will be accurate and the only possible answer.

If you understand these items, the benefit to using this search algorithm is performance. A linear search on a very large array can take a long time. If your linear search takes time 'N' to execute (worst case), the binary search will take at worst log2(N) to execute. (That is the base-2 log of N).

To put this in more concrete terms, if you're searching a very large 1D array linearly and it takes 1024 seconds (~17 minutes) for the search to complete, a binary search on the same array (as long as it is sorted) will take approximately log2(1024) = 10 seconds!

ADDITIONAL NOTES: Be sure to extract the ZIP file and run the VI rather than running the VI from within the ZIP file. You will need to extract it for LabVIEW to have access to the included dictionary.txt file. The VI included to demonstrate this search routine uses some Windows-only libraries for execution time measurement. However, the Binary Search routine itself is written completely in LabVIEW, and can be used on any platform that LabVIEW supports.

Is this what you are looking for?
Robert Mortensen
Software Engineer
National Instruments
0 Kudos
Message 2 of 4
(2,331 Views)
Hi Robert,
Thank you for your reply. I probably did not explain myself very well. I need to incorporate the log search algorithm in an experimental optical system, where I have a photomultiplier(PMT) (on which I can set the desired voltage) and read the input of light that is reaching it. I need to find the optimal value of voltage so that PMT will not saturate the signal on the one hand, and on the other will not be to low to detect. I used a simple algorithm of adding or substracting small increments untill I reached the desired value. As you can probably guess this is very time consuming, i was wondering wether there is a shorter way of doing that.
Thanks,
Gaby
0 Kudos
Message 3 of 4
(2,309 Views)
It sounds like you are looking for something more along the lines of a PID control system. There are a few examples that ship with LabVIEW that do exactly this. Open the Example Finder and search for PID. Is that closer to what you are looking for?
Robert Mortensen
Software Engineer
National Instruments
0 Kudos
Message 4 of 4
(2,288 Views)