How to see if a .WAV file is saturated?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ricardo Duarte
le 19 Mai 2023
Commenté : Walter Roberson
le 25 Mai 2023
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 commentaire
Mathieu NOE
le 22 Mai 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
Réponse acceptée
Walter Roberson
le 22 Mai 2023
Déplacé(e) : Walter Roberson
le 22 Mai 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
mean(abs(sig2) > 0.99988) * 100
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
mean(abs(hsig2) > 0.99988) * 100
max(abs(hsig1))
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 commentaires
Mathieu NOE
le 25 Mai 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
le 25 Mai 2023
Some purists complain about their 24 bit per sample audio file not being good enough... (Sorry, Neil Young!)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Applications dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!