How to convert a bitstream into groups of m-bits ?

3 ビュー (過去 30 日間)
Afaq Ahmad
Afaq Ahmad 2021 年 1 月 11 日
コメント済み: Walter Roberson 2021 年 1 月 14 日
I am trying to implement an M-ary system. I have a stream of bits which I want to group into m-bits. For example, for an 8-ARY system, I want to group it into 3 bits. For an 16-ARY system, i want to group it into 4-bits.
How could the bits be grouped in a generalized manner?

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 11 日
編集済み: Walter Roberson 2021 年 1 月 11 日
M2 = ceil(log2(M));
L = length(StreamOfBits);
eL = ceil(L/M2)*M2;
if L ~= eL
StreamOfBits(end+1:eL) = 0; %pad if need be
end
M_ary = reshape(StreamOfBits, M2, []).';
Leave off the .' if you want columns instead of rows.
This algorithm does not work in its present form if M is not a power of 2.
  4 件のコメント
Afaq Ahmad
Afaq Ahmad 2021 年 1 月 13 日
Yes thanks! but i cross checked it and it didn't make any difference. Maybe there is a difference you could point out?
Walter Roberson
Walter Roberson 2021 年 1 月 14 日
eL = ceil(L/M2)*M2;
vs
eL = floor(L/M2)*M2;
makes a difference on the case where the length of the bit stream is not an exact multiple of the number of bits at a time you want. In that case, you want to pad with extra bits, and the version with ceil() gives you the extended length whereas the version with floor() would give you the length up to the last full group.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by