필터 지우기
필터 지우기

Why does audiowrite modify my data frames slightly?

조회 수: 2 (최근 30일)
Hafsa Asad
Hafsa Asad 2018년 7월 31일
댓글: Hafsa Asad 2018년 8월 11일
I have a vector that I want to write to an audio file (any format, .wav or .mp4 or any other audio format). Afterwards, I want the exact decimal floating point values back when I read that audio file later. It is a project about audio stenography. Problem is that reading that audio file gives values that are slightly different. I want exact. I cannot even truncate them to any fixed length because different elements of my vector have different number of digits in floating point. Here is a brief version of the code I am having trouble with:
>> Fs= 8000
>> my_vector= [-0.74446 , 0.009]
>> audiowrite('newfile.wav', my_vector, Fs)
>> recovered_vector= audioread('newfile.wav')
recovered_vector =
-0.744476318359375
0.008972167968750
I wanted the same values back, -0.74446 and 0.009. I tried with different audio formats (.og, .ogg, .mp4, .wav). wav was giving closest results but they are still not exact. I also tried with changing the image quality parameter with .ogg (it does not work with .wav) but it did not help.
I think its a really basic thing that I am missing here....Any help would be much appreciated.
Thanks.

채택된 답변

Dinesh Iyer
Dinesh Iyer 2018년 8월 3일
편집: Dinesh Iyer 2018년 8월 3일
For MP4 and OGG, you cannot expect sample accuracy because they are lossy compression formats.
For WAV, the difference is because the audiowrite call writes the data to the WAV file as 16-bit integers and not double precision. So, there is a loss of precision going from double -> int16 -> double.
Try
audiowrite('myfile.wav', my_vector, 44100, 'BitsPerSample', 64)
For FLAC, the maximum supported bits per sample is 24 which will again result in a loss of precision because of double -> 24-bit -> double conversion.
  댓글 수: 1
Hafsa Asad
Hafsa Asad 2018년 8월 11일
thank you. your answer explains why i am getting those values but your code gives same results as mine.... values are not same. i guess its not possible

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

추가 답변 (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