Parseval's theorem in Python Parseval's theorem in Python numpy numpy

Parseval's theorem in Python


Your normalization factor is coming from trying to apply Parseval's theorem for the Fourier transform of a continuous signal to a discrete sequence. On the side panel of the wikipedia article on the Discrete Fourier transform there is some discussion on the relationship of the Fourier transform, the Fourier series, the Discrete Fourier Transform and sampling with Dirac combs.

To make a long story short, Parseval's theorem, when applied to DFTs, doesn't require integration, but summation: a 2*pi you are creating by multipliying by dt and df your summations.

Note also that, because you are using scipy.fftpack.rfft, what you are getting is not properly the DFT of your data, but only the positive half of it, since the negative would be symmetric to it. So since you are only adding half the data, plus the 0in the DC term, there's the missing 2 to get to the 4*pi that @unutbu found.

In any case, if datay holds your sequence, you can verify Parseval's theorem as follows:

fouriery = fftpack.rfft(datay)N = len(datay)parseval_1 = np.sum(datay**2)parseval_2 = (fouriery[0]**2 + 2 * np.sum(fouriery[1:]**2)) / Nprint parseval_1 - parseval_2

Using scipy.fftpack.fft or numpy.fft.fft the second summation does not need to take on such a weird form:

fouriery_1 = fftpack.fft(datay)fouriery_2 = np.fft.fft(datay)N = len(datay)parseval_1 = np.sum(datay**2)parseval_2_1 = np.sum(np.abs(fouriery_1)**2) / Nparseval_2_2 = np.sum(np.abs(fouriery_2)**2) / Nprint parseval_1 - parseval_2_1print parseval_1 - parseval_2_2