How to see if a .WAV file is saturated?

8 次查看(过去 30 天)
Hello everyone,
I have a .wav file that I want to see if its signal is saturated or not.
In case it is saturated I would like to change the gain in order to prevent the saturation.
Do you have any idea about how to do this?
Thank you in advance.
  1 个评论
Mathieu NOE
Mathieu NOE 2023-5-22
hello
if you take the abs of the magnitude of your data and if this is very close to 1 for a good amount of samples (above 1% ?) , then you know it's clipped

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2023-5-22
移动:Walter Roberson 2023-5-22
You may have to choose your "very close to 1" to be fairly strict for "above 1%" to work out as a boundary
Nsamp = 30000;
Fs = 8000;
t = (0:Nsamp-1)./Fs;
F = 5;
sig1 = sin(F*2*pi*t);
plot(t, sig1); title('unsaturated 5Hz')
sig2 = max(min(sig1*1.5, 1), -1);
plot(t, sig2); title('saturated 5Hz')
mean(abs(sig1) > 0.99988) * 100
ans = 0.8733
mean(abs(sig2) > 0.99988) * 100
ans = 53.6233
If you use a boundary of 0.99987 then more than 1% of the original non-saturated sine is "close" to 1. But more than 50% of the 1.5 * saturated signal is.
load handel %y, Fs
hNsamp = length(y);
hFs = y;
ht = (0:hNsamp-1)./Fs;
hsig1 = y;
plot(ht, hsig1); title('unsaturated Handel')
hsig2 = max(min(hsig1*1.5, 1), -1);
plot(ht, hsig2); title('saturated Handel')
mean(abs(hsig1) > 0.99988) * 100
ans = 0
mean(abs(hsig2) > 0.99988) * 100
ans = 0.2694
max(abs(hsig1))
ans = 0.8000
The original handel signal is -0.8 to +0.8 so none of it is "close" to 1 in the unsaturated version.
With 50% over-saturation, the peak would be 1.2 -- but even though this was constructed to be saturated (clipped) only about 1/4 of 1% is above the boundary that was needed for the pure sine wave.
We conclude from this that the strategy proposed by @Mathieu NOE cannot reliably distinguish clipping -- at least not by itself.
  8 个评论
Mathieu NOE
Mathieu NOE 2023-5-25
Just one remark
a good audio engineer asks the musicians to play the loudest part of their music and then set the microphone sensivity and analog gains so that the levels recorded remains 10 to 12 dB below clip level (headroom)
that means , we usually don't use the full range of the wav file dynamics, max 25% in practice (most of the time). Naturally there is a micro loss of accuracy vs the case you would use 99% of the range, but at your ears it would probably remains unoticeable.
At the beginning of the CD era, the co-inventors had devised that even a resolution of 14 bits was enough.
So using wav format on 16 bits with only 25% dynamic usage is good enough for many cases. Only the purist would say (maybe) something against it.
Walter Roberson
Walter Roberson 2023-5-25
Some purists complain about their 24 bit per sample audio file not being good enough... (Sorry, Neil Young!)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Applications 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by