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

9 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Audio I/O and Waveform Generation in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by