How to handle a large binary vector?

I need to handle a frame which incluses 230400 bits. If I use an array to include element of 0 or 1 in unit8 type then I need memory of about 225 Mb. If I use an element of int64 then I need about 3.5 Mb. What is the best practice to handle this large binary vector. In either ways I mentions, it needs almost Mbs to store a frame.
Update: Actually I will process further with 230400 bits. There few blocks where this 230400 bits frame will go through. It is convenient for me to process as a vector of 230400 bits. But I am not sure how normally this problem to be handled in Simulink. Do we need to divide it and process each byte or a portion of 230400 bits each time.

4 comentarios

Rik
Rik el 26 de Jul. de 2021
The best way to store it depends on what you need to do next. You probably don't just want to hold it in memory and then close Matlab. What do you want to do next?
Phan Dang Thoai
Phan Dang Thoai el 26 de Jul. de 2021
Thanks for your question Rik. Actually I will process further with 230400 bits. There few blocks where this 230400 bits frame will go through. It is convenient for me to process as a vector of 230400 bits. But I am not sure how normally this problem to be handled in Simulink. Do we need to divide it and process each byte or a portion of 230400 bits each time.
James Tursa
James Tursa el 26 de Jul. de 2021
You still haven't told us how you intend to process this downstream in your code. What exact computations are you doing with this?
Phan Dang Thoai
Phan Dang Thoai el 7 de Ag. de 2021
Sorry James for the late reply/ I just want to know how do you process each bit as a single element? My block gets input as a vecor of 230400 bits, then arranged in a matrix of 75*3072 bits, then each couple of two bits are transfromed to a comlex number [(1-2*bit1)+j(1-2*bit2)]/sqrt(2). Bit1 is element (l,n) and bit2 is element (l,n+K), l: from 1 to 75, n: from 1 to 3072/2, K=3072/2.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 26 de Jul. de 2021
UINT8 oder Logical use 1 byte per value. 225 MB are usually fine. You can store the bits packed in UINT8 also, but this is harder to access. So it depends on what you want to do with the data.
How do you import the data of the "frame"?
Maybe this helps:
Bit = PackBits([1,0,1,0,1,0,1,1, 1,1,1,0,1,1,1,0])
Bit = 1×2
213 119
UnpackBits(Bit)
ans = 1×16
1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 0
function Byte = PackBits(Bit)
% Byte = PackBits(Bit)
% Input: Numerical vector which is 1 for a set bit and 0 otherwise.
% Treated as vector. NUMEL(Bit) must be a multiple of 8.
% Output: UINT8 using all 8 bits per Byte. LSB order.
% Failing in R2021a: bitshift(uint8(1), 0:7) * reshape(uint8(Bit), 8, [])
Byte = sum(bitshift(uint8(1), 0:7).' .* reshape(uint8(Bit), 8, []), 1);
end
function Bit = UnpackBits(Byte)
% Bits = UnpackBits(Byte)
% Input: UINT8 using all 8 bits per Byte. LSB order. Treated as vector.
% Output: UINT8, 1 for set bits, 0 otherwise. NUMEL(Bit) = 8*NUMEL(Byte)
% Failing in R2021a: bitshift(uint8(1), 0:7) * reshape(uint8(Bit), 8, [])
Byte = Byte(:).';
Bit = [bitget(Byte, 1); bitget(Byte, 2); bitget(Byte, 3); bitget(Byte, 4); ...
bitget(Byte, 5); bitget(Byte, 6); bitget(Byte, 7); bitget(Byte, 8)];
Bit = reshape(Bit, 1, []);
end
% License: Jan-DWYW: Do what you want with this code.
% Don't blame me and don't mention my name, if your code contains bugs.
@all readers: Do oyu have a more efficient idea for UnpackBits?

4 comentarios

Phan Dang Thoai
Phan Dang Thoai el 26 de Jul. de 2021
Thanks for the nice answer Jan. The frame is provided as a vector of 230400 bits. I am not sure that should we hanlde in this format or should we ask to change, such as handling in multiple of smaller vectors.
Jan
Jan el 26 de Jul. de 2021
Editada: Jan el 26 de Jul. de 2021
Providing "bits" in a vector is a rare case. In which format do you get them? There is no "bits" type in Matlab and many other programming languages.
Phan Dang Thoai
Phan Dang Thoai el 7 de Ag. de 2021
Editada: Phan Dang Thoai el 7 de Ag. de 2021
Yah, I know but how do you process each bit as a single element? My block gets input as a vecor of 230400 bits, then arranged in a matrix of 75*3072 bits, then each couple of two bits are transfromed to a comlex number [(1-2*bit1)+j(1-2*bit2)]/sqrt(2). Bit1 is element (l,n) and bit2 is element (l,n+K), l: from 1 to 75, n: from 1 to 3072/2, K=3072/2.
Jan
Jan el 8 de Ag. de 2021
@Phan Dang Thoai: I cannot follow your descriptions.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Functions en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Preguntada:

el 26 de Jul. de 2021

Comentada:

Jan
el 8 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by