I have a question regarding the following piece of code that I found to measure how much noise is included in a piece of audio:
Sx = fft(x .* hann(length(x), 'periodic'))
pk2rms = max(abs(Sx))/sqrt(sum(abs(Sx).^2)/length(Sx))
This code shall calculate the peak-to-rms ratio of a signal and shall be used to measure the noise that is included in an audio signal.
As far as I understand, the max(abs(Sx))
calculates the Peak, and the sqrt(sum(abs(Sx).^2)
calculates the RMS. But I don't get why this is the case. Why do I first have to apply FFT to calculate the Peak? Isn't the peak just the highest amplitude that is included in a signal? If that was true, I should take do max(abs(x))
without converting the signal into frequency-domain?
And why do I have to divide the whole thing by the length of the signal?
I can imagine that the answers to my questions could be obvious to some of you experts, but I couldn't find proper answers until now.
Thank you very much in advantage!