How to improve bit reading process in Matlab?
古いコメントを表示
I need to read a binary file and the Matlab coding is:
a = uint8(fread(fid,'ubit1')');
This is inefficient so I added a line below:
a = uint16(swapbytes(a));
But it doesn't help. Any other method to improve the bit reading process in Matlab?
14 件のコメント
Walter Roberson
2019 年 9 月 6 日
Is there any reason that you are not reading uint8? And possibly extracting bits afterwards? Either with bitget() or with a lookup table ?
Star Rats
2019 年 9 月 6 日
Walter Roberson
2019 年 9 月 6 日
bittable = (dec2bin(0:255, 8) - '0').';
a8 = fread(fid, 'uint8');
a = reshape( bittable(a8, :), [], 1);
Star Rats
2019 年 9 月 6 日
Walter Roberson
2019 年 9 月 6 日
編集済み: Walter Roberson
2019 年 9 月 6 日
a = reshape( bittable(double(a8)+1, :), [], 1);
Star Rats
2019 年 9 月 6 日
Walter Roberson
2019 年 9 月 6 日
a = reshape( bittable(:,double(a8)+1), [], 1);
Star Rats
2019 年 9 月 6 日
Walter Roberson
2019 年 9 月 6 日
Your sync_word is wrong. It should be
syn = ones(1,12);
isMP2 = 1; %0 for MP4
layer = zeros(1,2);
sync_word = [syn, isMP2, layer];
Same total number of bits, but you had 0 1 for layer instead of 0 0.
Star Rats
2019 年 9 月 6 日
Walter Roberson
2019 年 9 月 6 日
It is reading byte by byte and translating to bits.
There is a theoretical possibility that the order of bits within a byte is reversed but it seems unlikely.
Star Rats
2019 年 9 月 12 日
Walter Roberson
2019 年 9 月 12 日
編集済み: Walter Roberson
2019 年 9 月 12 日
Yes, you can use gpu array. However it will slow down your code.
Star Rats
2020 年 7 月 18 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!