Azzera filtri
Azzera filtri

Writing a wav file using Matlab

2 visualizzazioni (ultimi 30 giorni)
Micaela
Micaela il 11 Ott 2012
Commentato: Shlomit il 15 Dic 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.

Risposta accettata

Wayne King
Wayne King il 11 Ott 2012
Modificato: Wayne King il 11 Ott 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 Commenti
Micaela
Micaela il 12 Ott 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 il 15 Dic 2014
This helped a lot, Thank you Micaela!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by