Is there a function or a way to write/read bit by bit to/from a buffer in MATLAB?

조회 수: 10 (최근 30일)
Hi everyone, I am testing an audio compression in Matlab, and I am searching a way to write/read bit by bit to/from a buffer in MATLAB.
For example, I have a sequence of bits: 100, so I need to write in order bit 0, bit 0 and then bit 1 to the buffer. For the next sequence for example 1011, I need to write in order bit 1, bit 1, bit 0 and then bit 1 next to the first sequence into the buffer.
My goal is to write many sequences of bits to a buffer and read those sequences back for process, and they need to be in bit by bit.
Thank you so much for your help and support,
Best regards,
Le An.

채택된 답변

jibrahim
jibrahim 2021년 12월 13일
Hi An,
Maybe dsp.AsyncBuffer works for you?
b = dsp.AsyncBuffer;
write(b,1); % write the number 1 to the buffer
write(b,2); % write 2 to buffer
write(b,3); % write 3 to buffer
read(b,1) % read one element --> 1
write(b,4); % write 4 to buffer
read(b,1) % read one element --> 2
read(b,1) % read one element --> 3
b = dsp.AsyncBuffer;
write(b,1); % write the number 1 to the buffer
write(b,2); % write 2 to buffer
write(b,3); % write 3 to buffer
read(b) % read everything [1 2 3].'
  댓글 수: 2
An Vo
An Vo 2021년 12월 13일
Thanks Jibrahim for the answer,
It helps me understand how to write and read samples to samples to buffer, and I can use it for bit-to-bit.
One more thing I would like to ask is that does MATLAB support checking the buffer memory ( the number of bits written into the buffer after writing many bit sequences)?
Thanks again,
An.
jibrahim
jibrahim 2021년 12월 14일
Hi An,
To check how many samples are available in the buffer, you can execute:
b.NumUnreadSamples

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by