What is the fastest way to get bit stream from 1D float data ?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Jan
2021-12-3
编辑:Jan
2021-12-5
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 个评论
Jan
2021-12-6
You are welcome. I have still do not know, what you want to solve, so I cannot provide more suggestions.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!