What is the fastest way to get bit stream from 1D float data ?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Jan
le 3 Déc 2021
Modifié(e) : Jan
le 5 Déc 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 commentaires
Jan
le 6 Déc 2021
You are welcome. I have still do not know, what you want to solve, so I cannot provide more suggestions.
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!