Skip to content
DeepForgeby svx
All problems
HardCalculusca-173

Parseval Energy Check

Problem

Parseval's theorem says the time-domain energy of a length-N sequence equals (1/N) times the frequency-domain energy, where X[k] = sum of x[n]*e^(-2*pi*i*k*n/N).

Compute the DFT with real arithmetic and return (1/N) * sum of |X[k]|^2, which equals the sum of x[n]^2.

Hint

Expand the squared magnitude of the DFT and use the orthogonality of complex exponentials.

Test cases

case 1
in: [[1,0,0,0]]
expected: 1
case 2
in: [[1,1,1,1]]
expected: 4
case 3
in: [[1,-1,1,-1]]
expected: 4
case 4
in: [[0.5,0.5]]
expected: 0.5
Starter codePython
def parseval_energy(x):
    # Your code here
    pass

4 test cases · run your code against them in the editor