Writing a wav file using Matlab

2 次查看(过去 30 天)
I have a question: I have created some audio files using Matlab, with a sampling frequency of 10000 Hz, and when I try to use the function wavwrite in order to generate the corresponding wav files, I have this warning:
"Data clipped during write to file..."
I know that this problem is generated by the amplitude of the signals, because it must be normalized to 1, and I have tried to use this line of code:
signal = signal/max(abs(signal));
but the problem isn't solved. Can anyone tell me how can I solve this problem? Thanks a lot.

采纳的回答

Wayne King
Wayne King 2012-10-11
编辑:Wayne King 2012-10-11
If you are using
wavwrite(Y,FS,WAVEFILE)
then the acceptable range for the data, Y, is -1.0 <= Y < +1.0
so I'm assuming that you have values in your output equal to 1, which is resulting in the clipping. One thing you can do is to use 32 bits to write the file. That has output format implications -- see the help for wavwrite
wavwrite(Y,FS,32,WAVEFILE)
or you can add a small deltaA to your scaling factor that would avoid you getting a 1.
deltaA = 0.1;
signal = signal./(max(abs(signal))+deltaA);
  3 个评论
Micaela
Micaela 2012-10-12
Ok, I have solved the problem with this line of code (supposing that I write the file with 24 bits) :
signal = signal./max(abs(signal(:)))*(1-(2^-(24-1)));
Thank you of all:)
Shlomit
Shlomit 2014-12-15
This helped a lot, Thank you Micaela!

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by