DSP.jl power spectra normalization

Can anyone explain the rationale behind the FFT normalization done in DSP.jl, for instance in the periodogram function ?

Here below is the concerned code of the fft2pow! function, which computes the power spectra.
I am concerned on the one-sided spectrum. In the code, the power spectrum is normalized by m1 for the first frequency bin, by m2 for bins 2:n-1 and by m1 or m2 for the last bin depending on whether the size of the window is even or odd:

function fft2pow!(out::Array{T}, s_fft::Vector{Complex{T}}, nfft::Int, r::Real, onesided::Bool, offset::Int=0) where T
m1 = convert(T, 1/r)
n = length(s_fft)
if onesided
m2 = convert(T, 2/r)
out[offset+1] += abs2(s_fft[1])*m1
for i = 2:n-1
@inbounds out[offset+i] += abs2(s_fft[i])*m2
end
out[offset+n] += abs2(s_fft[end])*ifelse(iseven(nfft), m1, m2)
else

Looking at the call of fft2pow! in the periodogram function at line 275 of unit periodograms.jl it seems to me that r here above is passed as fs*norm2, where fs is the sampling rate and norm2 is sum(abs2, window), where window is the taper.

I don’t see the interest in taking into account the sampling rate in the normalization of the power spectra. This leads to undesirable behavior. For example, I computed the power spectra for a pure sine wave at an exact discrete Fourier frequency (using a rectangular window) two times, changing only the sampling rate and i obtained different powers at the only non-zero frequency bin.

1 Like