LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Overwrite array in loop

Solved!
Go to solution
Solution
Accepted by eeeeeeeeeeehelp

@eeeeeeeeeeehelp wrote:
but I think it would be easier to break the loop and count the ones from the start, since you get the same result anyway.

 

Now that I'm writing this, I might be confusing loops with iterations, well I won't know until I try to make the actual code.


Here's a quick draft. All you need is one loop and keep track of the running odd/even state. Modify as needed.

 

(If you start over from the beginning, you are processing the early parts N times, leading to a O(N²) complexity that will slow you down significantly for large inputs)

 

altenbach_0-1700589373311.png

 

Message 11 of 16
(602 Views)

@altenbach wrote:

@eeeeeeeeeeehelp wrote:
but I think it would be easier to break the loop and count the ones from the start, since you get the same result anyway.

 

Now that I'm writing this, I might be confusing loops with iterations, well I won't know until I try to make the actual code.


Here's a quick draft. All you need is one loop and keep track of the running odd/even state. Modify as needed.

 

(If you start over from the beginning, you are processing the early parts N times, leading to a O(N²) complexity that will slow you down significantly for large inputs)

 

altenbach_0-1700589373311.png

 


Thank you, this is exactly what I needed! It is much simpler than anything I could come up with.

 

There was a very minor issue with the code, where the odd case would invert the odd/even case conditions, but it was very easy to fix by simply resetting the comparison input back to 0.

 

eeeeeeeeeeehelp_0-1700677624626.png

 

0 Kudos
Message 12 of 16
(577 Views)

You are correct. With the "even" replacement we are actually changing history data, so the toggle on the first replaced element is missed on the next iteration. Did you test your solution for all possible scenarios?

 

If the solution is correct, the main problem is that you added a zero constant that is probably I32, leading to several coercions and carrying four times too many bits for the odd/even state.

 

Instead, you should just configure the output tunnel to "use default if unwired" as follows. This way you get a zero in the existing U8 representation and the code is cleaner overall.

 

altenbach_0-1700680707583.png

 

Message 13 of 16
(569 Views)
The OP mentioned that he is "trying to do HDB3 encoding". This is a bit more complicated algorithm than just substituting 0001 or 1001 in a sequence of 4 or more zeros. The HDB3 encoding converts data bits (0,1) into a bipolar code format (-1, 0 +1).
 
The conversion from bits to bipolar code must be done first. In short, a "1" bit toggles the polarity of the previous bipolar pulse, and a "0" bit is 0 pulse.  This resulting bipolar code is then modified to insert deliberate violations in long sequences of 0's to help in maintaining clock synchronization, and the choice of the inserted pattern is chosen to prevent a dc voltage from being introduced.
 
The choice of 0001 or 1001 is also not correct. It's actually a bipolar pulse train dependent on the polarity of the Preceding Pulse. It should be as follows:
 
           Polarity of                                   Number of Pulses since last substitution
      Preceding Pulse                                         Odd                    Even           
                 "-"                                                     000-                   +00+
                 "+"                                                    000+                   -00-

 

Message 14 of 16
(541 Views)

@jamiva wrote:
The OP mentioned that he is "trying to do HDB3 encoding". This is a bit more complicated algorithm than just substituting 0001 or 1001 in a sequence of 4 or more zeros. The HDB3 encoding converts data bits (0,1) into a bipolar code format (-1, 0 +1).
 
The conversion from bits to bipolar code must be done first. In short, a "1" bit toggles the polarity of the previous bipolar pulse, and a "0" bit is 0 pulse.  This resulting bipolar code is then modified to insert deliberate violations in long sequences of 0's to help in maintaining clock synchronization, and the choice of the inserted pattern is chosen to prevent a dc voltage from being introduced.
 
The choice of 0001 or 1001 is also not correct. It's actually a bipolar pulse train dependent on the polarity of the Preceding Pulse. It should be as follows:
 
           Polarity of                                   Number of Pulses since last substitution
      Preceding Pulse                                         Odd                    Even           
                 "-"                                                     000-                   +00+
                 "+"                                                    000+                   -00-

 


I know, but I was able to do that part myself and didn't need help with it. The code provided above helped me a lot already.

0 Kudos
Message 15 of 16
(527 Views)

Yes, I only tried to solve the question as posed. I guess we need to change the datatype to I8 to allow -1, 0, +1 but the bulk of the code can be reused and modified. Apparently the OP was able to do all that. 😄

 

Message 16 of 16
(522 Views)