fix: non_sys_stream_2 in turbo_encode is twice the expected size #122
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using the
turbo_encode
function from thechannelcoding
module, I noticed that thenon_sys_stream_2
was twice the expected length. The extra bits were all 0s. Looking a little deeper in the code, I notice that this changed fixed my issue for 1/3 encoding.The issue seems to be related to the part where the puncturing is applied. The puncturing is supposed to drop bits according to the puncture matrix, but it seems like the function is not correctly applying the puncturing.
Here is the related code block:
This block is intended to iterate through the encoded bits in outbits, and copy each bit to
p_outbits
only if the corresponding bit in the puncture matrix is 1. Thej
variable keeps track of the current position in thep_outbits
array.However, the length of
p_outbits
is set earlier in the function to be equal to the length ofoutbits
:Since puncturing is supposed to reduce the length of the output, it seems incorrect to set the length of
p_outbits
to be the same asoutbits
. If the puncture matrix has a lot of zeros (indicating a lot of bits to drop), thenp_outbits
could end up being much larger than the actual number of bits that are copied fromoutbits
. This could be whynon_sys_stream_2
is longer than expected.The length of
p_outbits
should be set to the number of 1s in the puncture matrix, multiplied by the number of blocks of bits that are being encoded. In the case when this function is called from theturbo.py
file to calculate thenon_sys_stream_2
, the puncture matrix has size (1, 2), so you would expect to keep half of the bits from outbits. Therefore, we should initializep_outbits
to have half the length ofoutbits
.One possible fix could be to calculate the correct size for
p_outbits
before initializing it:Then, you can apply the puncturing as before:
With these changes,
p_outbits
should end up being the correct length, andnon_sys_stream_2
should also end up being the correct length.