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!