How do I prevent peak clipping when using audiowrite?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponses (4)
Joseph Cheng
le 28 Juil 2014
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.
0 commentaires
Star Strider
le 28 Juil 2014
The audiowrite function may not be your only option. See the documentation for Export to Audio Files for more information.
1 commentaire
Star Strider
le 28 Juil 2014
Modifié(e) : Star Strider
le 28 Juil 2014
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.
Andrea Genovese
le 6 Avr 2018
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 commentaire
Walter Roberson
le 6 Avr 2018
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.
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!