Error in converting binary to audio after recording the audio and converting it into binary .......KINDLY HELP!!

조회 수: 2 (최근 30일)
i recorded an audio , converted it into binary and now i have to convert it back into the audio but there is noise in the audio signal which i got in the result , its not the same. what should i do to get the same audio as i recorded ...after converting it back from binary . i even normalised the values... i am new to matlab ... kindly help... i will be very grateful for this .

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 17일
format long g
myRecording = randn(5,1)
myRecording = 5×1
-0.742153922329459 1.51715451030976 -0.738441174539258 1.86274349485519 0.470504960861284
wavebinary = dec2bin( typecast( single(myRecording(:)), 'uint16'), 16 ) - '0';
size(wavebinary)
ans = 1×2
10 16
Notice that is N x 16 where N is number of samples times 2 (you are converting myRecording to single no matter whether it is integer or single or double, so the result of the single() will be 32 bits per sample no matter what the original bits per sample. Then you typecast() into two 16 bit halves, and you convert each 16 bit value to binary. Each converted value creates a 16 bit row.
Now look further and see that you construct
sounddata = double(bin2dec( char( reshape( wavebinary, 16, []).'+'0')));
So you would take that 10 x 16 data in which the rows represent the binary of half of one sample, and you would reshape it to be 16 rows... which in this case would give you 10 columns. But that is the wrong bit order. You are taking like
1 : 16
17 : 32
33 : 48
and rearranging it like
[1 17 33 ... 16 32 48 ...]
The flaw here is that when you create wavebinary you should be doing
wavebinary = reshape((dec2bin( typecast( single(myRecording(:)), 'uint16'), 16 ) - '0').', 1, []);
and now with the transpose the bit order would follow the way you are reconstructing.
  댓글 수: 7
Walter Roberson
Walter Roberson 2021년 6월 18일
Displaying variables in graphics format takes time and memory. In order to prevent opening a variable from potentially taking a long time and using too much memory, Mathworks made a decision to limit the display t o 524288 elements. I do not know how Mathworks choose that exact number; it is 2^19 entries
Why is the data more than 524288 elements? Well,
format long g
%you are converting elements to single() which is 32 bits each
load handel.mat
handel_samples = numel(y)
handel_samples =
73113
required_bits = handel_samples * 32
required_bits =
2339616
max_samples_supported = 524288 / 32
max_samples_supported =
16384
max_time_at_8192 = max_samples_supported / Fs
max_time_at_8192 =
2
actual_time = handel_samples / Fs
actual_time =
8.9249267578125
So the handel data is just under 9 seconds long, but at 8192 samples per second, anything over 2 seconds would exceed the Variable Browser limit of 524288 elements.
To observe the data that was encoded into bits, at the command window ask to disp() some subset of it, such as disp(wavbin(1:100)) . Realistically speaking, there is no way that you would truly want to look by hand through all of the 2339616 bits of the data... what would you even look for by eye?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by