How do I prevent peak clipping when using audiowrite?

조회 수: 13 (최근 30일)
Ranya
Ranya 2014년 7월 28일
댓글: Walter Roberson 2018년 4월 6일
Hi,
I'm new to using Matlab. I have something like this:
%Takes wav file and reads it
[y,fs]=audioread('sampleaudio.wav')
%Runs it through hearing aid function (I have this already programmed)
y = WDRC(y, fs)
%creates new wav file
audiowrite('sampleaudioWDRC.wav',y,fs)
The problem is I keep getting this error
Warning: Data clipped when writing file.
> In audiowrite>clipInputData at 389
In audiowrite at 167
How do I fix this? Any help would be appreciated, thanks!

답변 (4개)

Joseph Cheng
Joseph Cheng 2014년 7월 28일
What is the max and min of your y after your hearing aid function and what was it before the hearing aid function? you may be writing values out of the -1 and 1 range for signed single class numbers. Perhapse normalizing it to the maximum range for the class that your y is in.

Star Strider
Star Strider 2014년 7월 28일
The audiowrite function may not be your only option. See the documentation for Export to Audio Files for more information.
  댓글 수: 1
Star Strider
Star Strider 2014년 7월 28일
편집: Star Strider 2014년 7월 28일
It suggests you use the save function instead of wavwrite to avoid the clipping problem. Use load (link at the end of the save page) to load them back into your workspace. If you specifically save your data as:
save('sampleaudio.mat', 'y', 'fs')
you can then load it as:
load('sampleaudio.mat')
in any MATLAB script or function, and y and fs will be in the workspace of that script or function.
There are variations of both the save and load functions you can experiment with if you want to.

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


Ranya
Ranya 2014년 7월 28일
Thanks for the response. I can't find much info in that link.

Andrea Genovese
Andrea Genovese 2018년 4월 6일
You have to normalize (limit the range between -1 to +1)
y = y/max(abs(y)) % for mono
y = y/max(abs(y(:))) % for stereo
You can also then decide to leave more headroom for the problem of true-peak in poor DAC system
y = y * 0.9 % Now it will peak at a value of 0.9
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 4월 6일
Note:
The older wavwrite() had slightly different rules:
-1 <= x < 1
whereas audiowrite has the rule
-1 <= x <= 1
With wavwrite(), using
y/max(abs(y))
could leave you with +1 exactly if the maximum happened to be positive, so for that older wavwrite, it would be preferred to use
y / max(abs(y)) * (1-eps)
This is equivalent to using a "headroom" of eps in what Andrea wrote.

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

카테고리

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