MATLAB Answers

warning Data clipped during write to file

134 views (last 30 days)
Judyta
Judyta on 4 Dec 2012
Commented: Walter Roberson on 8 Jun 2016
Im trying to create .wav file
s3 = (s2-min(s2))./(max(s2)-min(s2)).*2-1;
wavwrite(s3, 1250, 16, 'signal.wav');
and I got those warnings:
Warning: Data clipped during write to file:2012-11-23_13-08-18p.wav
> In wavwrite>PCM_Quantize at 285
In wavwrite>write_wavedat at 301
In wavwrite at 138
Does anybody knows how to solve it?
I fougth that clipped during write means that my data are not in the range of -1 and 1?

  0 Comments

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 4 Dec 2012
-1 exactly is allowed in the data, but +1 exactly is not allowed.

  0 Comments

Sign in to comment.


Jan
Jan on 5 Dec 2012
The documentation explains: For 16 bit precision, the values are limited to –1.0 <= y < +1.0, when the signal is provided as floating point format. A workaround is to convert the data manually before calling wavwrite():
yInt = y * 32768;
yInt(yInt == 32768) = 32767;

  3 Comments

Ingo Schalk-Schupp
Ingo Schalk-Schupp on 20 Oct 2015
However, this does not circumvent clipping but only suppresses the warning. I suggest multiplying by 32767 in the case of 16-bit integers.
Saurabh Kataria
Saurabh Kataria on 8 Jun 2016
I agree that it does not prevent clipping, maybe the answer is to normalize the data to fit in [-1,+1] range. Mathematically, I mean:
y = y./(max(abs(y));
Walter Roberson
Walter Roberson on 8 Jun 2016
+1 exactly is not permitted in wavwrite() . You need to normalize to [-1, 1) if you are going to normalize in floating point.

Sign in to comment.


Judyta
Judyta on 5 Dec 2012
Thank You for your answers, i wanted to ask one more thing, When this warning about clipping occurs, what really happends with those samples equal to 1? are reduced or avoided?
and Jan Simon, thank You for Your answer but i don't understand what this code does. May I please ask you to explain me?

  1 Comment

Daniel Shub
Daniel Shub on 5 Dec 2012
They are "reduced" by clipping them to the maximum/minimum allowed value. A difference between 1 and 1-2^15 is probably not anything to worry about.

Sign in to comment.

Sign in to answer this question.