Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

searching a 1D array of booleans for a start pattern

I am using an NI Digital I/O to capture data that my Unit under test is spitting out data to and I need to look for a sequence of boolean data that signifies my start bit. I have all the data in an array but now I need to be able to search for this start bits and only look at the data that follows it. Any Idea how to do this??
0 Kudos
Message 1 of 4
(3,533 Views)

Phil,

I would first create a VI that finds the index of the pattern you are searching for. Then using this index, you can use the array subset VI to get the data after that position.

There are a coupld of ways to find the pattern in the array. An easy way is to use a while loop and for each iteration get a subset of your data array where index = iteration and length = pattern match length.  Then just compare the two arrays and stop parsing on the first match. This could require alot of memory allocations, and therefore would be slow. Alternatively, you could parse earch element of the data array and try to match it to the first element of your search pattern. When a match is found then you try to match the remaining search elements. I've included a VI that shows how I implemented this.

-Jared

0 Kudos
Message 2 of 4
(3,520 Views)
Here's another way that I've used. The Boolean arrays are converted to strings and then a Match Pattern is used to find the desired pattern. I haven't done any testing to see which method might be faster than the other. I think it might depend on the length of the data and search patterns.
0 Kudos
Message 3 of 4
(3,515 Views)
Guys, both VI's worked very well and are exactly what I needed. Many thanks to both of you for your help.
Phil
0 Kudos
Message 4 of 4
(3,506 Views)