Skip to content

Instantly share code, notes, and snippets.

@Piyush3dB
Created March 10, 2015 12:13
Show Gist options
  • Save Piyush3dB/0e377979a4e941021922 to your computer and use it in GitHub Desktop.
Save Piyush3dB/0e377979a4e941021922 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import numpy as np
# Specify length of signal
N = 512;
# Generate time domain signal
x = np.random.rand(N).astype('complex')
# Evaluate signal power in the time domain
pTD = np.inner(np.conj(x),x)
# Transform signal to frequency domain
X = np.fft.fft(x)
# Calculate signal power in the frequency domain
pFD = np.inner(np.conj(X),X)/N
# pTD must = pFD
print "Time Domain Power = " + str(pTD)
print "Freq Domain Power = " + str(pFD)
@Piyush3dB
Copy link
Author

Python snippet to show power equivalence between the time domain and frequency domain representation of a discrete signal. An implementation Parseval's Theorem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment