I will have a binary array or boolean array (easy to convert so either works). Ideally, the result would be 0000011111100000 and I would count the number of 1's and that's my output. That situation is really easy with a case structure inside a for loop. However, if the result is 000011110000111110000 I want to display an error since there are two chunks of 1's sandwiched between zeros (I guess could also be 001010101011 and need to display an error). Not sure how to do this part, I was thinking maybe a while loop but not sure. Using LabVIEW 2021
Solved! Go to Solution.
I think you almost "solved it yourself". Here's a hint: think of it as an array of Booleans, and how this might be related to the sort of Digital Signal that uses 0's and 1's, for example TTL signals, where a "High" (or 1, or "on") is conventionally 5 V, and a "Low" (or 0, or "off") is 0 V. Look at your two (or three) example "signals" and characterize them. How would you describe the "good" signal from, shall we say, the "noisy" signal?
You can also consider converting it to a string "00000111110000011111000000" for example and looping over a RegEx match of +
This will find any length of ones.... 111 or 111111111 are both found in a single loop iteration
Make sure to set the starting position after each loop. number of matches != 1, generate your error message.
I would just count the number of rising edges (0 to 1) and if it is more than 1, you have an error.
Assuming your "binary array" is a byte array where all 8 bits of each element counts, all you need is index into a LUT that contains the number of bits for each combination of 8 bits. Then sum the output. Make sure that the LUT datatype is sufficient to contain the final sum. (This will be very efficient. Almost no computations and 8x less memory than a boolean array.)
Edit: sorry, I misread the question, so read on ... 🙂
To ensure that you only have a consecutive stretch of ones flanked by zeroes, the LUT can be even simpler. The first nonzero value must be a sorted binary, the (optional) middle elements can only be 255, and the tail must be a reverse sorted binary. All zeroes (if any) before and after.
Thank you everyone! I wasn't sure if there was an easier way with a search pattern vi or similar, but it seems like nested structures and a counter is the way to go. Thanks!
It would really help to define the problem better. What exactly is a "binary array" vs. a "boolean array"? How long can it possibly be? Is the length in e.g. integer multiples of eight?
What is the desired output? I would suggest a I32 count of the consecutive ones (a nonnegative number: 0..N) and -1 for an error. (unless zero ones is also an error?).
Done right, the code can be very simple.
The input is a digital waveform of size 496 (1D). I convert it to a boolean array(T/F) and binary array(0/1) for other reasons. From the input I want to count how many ones are sandwiched between zeros, but if there are more than 1 sandwich I want to have a string indicator that there is an error. If there are no 1's found, I would like the string indicator to say none found.
000111111000 Count= 6
000000000000 "None found"