Writing a wav file using Matlab

4 views (last 30 days)
Micaela
Micaela on 11 Oct 2012
Commented: Shlomit on 15 Dec 2014
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.

Accepted Answer

Wayne King
Wayne King on 11 Oct 2012
Edited: Wayne King on 11 Oct 2012
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 Comments
Micaela
Micaela on 12 Oct 2012
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 on 15 Dec 2014
This helped a lot, Thank you Micaela!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!