Clear Filters
Clear Filters

How to see if a .WAV file is saturated?

4 views (last 30 days)
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 Comment
Mathieu NOE
Mathieu NOE on 22 May 2023
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

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 22 May 2023
Moved: Walter Roberson on 22 May 2023
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 Comments
Mathieu NOE
Mathieu NOE on 25 May 2023
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 on 25 May 2023
Some purists complain about their 24 bit per sample audio file not being good enough... (Sorry, Neil Young!)

Sign in to comment.

More Answers (0)

Categories

Find more on Applications in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!