What is the fastest way to get bit stream from 1D float data ?

8 visualizaciones (últimos 30 días)
nur dsc
nur dsc el 3 de Dic. de 2021
Comentada: Jan el 6 de Dic. de 2021
Hi,
I have a 5000x1 double data which returned from audio read file. I need to get bit stream(bit vector)(numeric value includes 1s and 0s) from double data.(actually the output is float but matlab says double.) I tried two ways to get bit stream.
First I used typecast to 64 bit and get 5000x64 integer value, dec2bin and str2num. But str2num is so slow for large data(for example 16000000x1 double data) and got double data back from bit stream using num2str and bin2dec, dec2hex and hex2num. When I sounded it it was perfect. The problem was about str2num and num2str. Is there any efficient way to get the process faster ?
Second way was to read audio file using 'native'. So sampled data type was up to bits per sample of an audio data. (I read integer data )
It was faster 5 times than first step but when I sounded it, it was not clean like first step output. But I reduced the steps using native. I did not need to convert data to 64 bit. So second step was faster.
If my question got you confused , could you read any audio file using first audioread() and then audioread('native') ? How do you get bit array (1,0,1,0,0,0...) from sampled data you get from audioread() or audioread('native')?
Thanks for your time.

Respuestas (1)

Jan
Jan el 3 de Dic. de 2021
Editada: Jan el 5 de Dic. de 2021
I do not really get, what you try to do. Which format does the audiofile have? What do you call "bit stream"?
Instead of explaining the code, it would be easier to understand, if you post the code.
dec2bin converts the decimal numbers to a char vector. What do you do with str2num afterwards? Do you know the faster and safer tools str2double and sscanf?
The conversion between different types can be avoided to save time:
bin = rem(floor(dec(:) .* pow2(1-nBit:0).'), 2);
This converts integer values to a vector of 0 and 1.
  7 comentarios
nur dsc
nur dsc el 6 de Dic. de 2021
Okay Jan.
Let me wait for others to share code and explain me the faster way to do it.
Thanks for help !
Jan
Jan el 6 de Dic. de 2021
You are welcome. I have still do not know, what you want to solve, so I cannot provide more suggestions.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by