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

10 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

jibrahim
jibrahim el 13 de Dic. de 2021
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 comentarios
An Vo
An Vo el 13 de Dic. de 2021
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 el 14 de Dic. de 2021
Hi An,
To check how many samples are available in the buffer, you can execute:
b.NumUnreadSamples

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by