why is wavwrite clipping my data

2 次查看(过去 30 天)
Hello all,
I have this sinwave and I want to save it as a wav file. I use the wavwrite function but when I run the script I get a warning saying that the data has been clipped during write to file.
Is there a way to scale everything like the function soundsc does?
Thanks a bunch...

采纳的回答

Jan
Jan 2013-3-28
Whenever you get a problem with a command in Matlab, it is recommended to read the intructions:
doc wavwrite
There you find, that the range is limited to –1.0 <= y < +1.0 for 8, 16 and 24 bits, while +1.0 is allowed for 32 bit only. Or if you have integer data (ayour see, it would be helpfujl if you explain this detail in your question), there are other ranges also.

更多回答(2 个)

Wayne King
Wayne King 2013-3-28
编辑:Wayne King 2013-3-28
the values in your sine wave likely exceed [-1, 1] or come so close to [-1, 1] that they are 1 for all intents and purposes. The are a number of ways to work around this.
%assuming the sine wave is zero mean
t = 0:0.001:1-0.001;
x = 2*cos(2*pi*100*t);
[val,idx] = max(abs(x));
x = x./(max(abs(x))+0.01);
wavwrite(x,1000,16,'test.wav');
If it's not zero mean then first subtract the mean
x = 2+cos(2*pi*100*t);
x = x-mean(x);
x = x./(max(abs(x))+0.01);

tony karamp
tony karamp 2013-4-1
Thank you all for your answers!!

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by