Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by