To make my question as clear as possible I will go through an example. I want to plot one sided power spectrum of a signal. As an example my signal is sum of "50Hz sine with and amplitude of 1V" and "DC offset voltage of 1V". I create this signal and plot FFT of it where I define the power as amplitude square divided by two.

Here is my code:

import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import scipy.fftpack

f = 50 #signal freq
D = 1 #duration
fs = 800 #sampling freq
T = 1/f #signal period
N = int((D/(1/fs))+1) #number of smaples
t = np.linspace(0, D, num=N, endpoint=True) #time vector
dc = 1
y = np.sin(2*np.pi*f*t) + dc 

plt.plot(t, y,'-b')
plt.plot(t, y,'.r')
plt.title('~ Sinusoid ~')
plt.xlabel('time [s]')
plt.ylabel('Voltage [V]')

y = y
T = t[2]-t[1]
sampling_rate = 1/T
N = len(y)
yf = scipy.fftpack.fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N//2)
amplitude = 2.0/N * np.abs(yf[:N//2])
pow = amplitude*amplitude/2

plt.plot(xf, pow,'b')
plt.xlabel('Frequency [Hz]')
plt.ylabel('Power [W]')

enter image description here enter image description here

Now the rms power for the sine component can be calculated as (amplitude square)/2 which is 0.5W and this is what we see at the plot above.

And for the 1V DC component, I would say the rms power is (amplitude square) which is 1W. But the plot shows twice of it namely 2W.

My question is: Should I divide the power by two at 0Hz at FFT plot in my code or am I interpreting something wrong?


The factor of "2" comes from the contribution of the negative frequencies, which doesn't apply to DC.

A better way to plot this is to NOT multiply with 2 but plot the entire FFT range from -400Hz to +400Hz. There you will see three components: 1 W at DC and 0.25W each at -50Hz and +50Hz which is exactly what's happening here.

If you want to plot power spectrum one sided, you need to multiply by two EXCEPT for DC and Nyquist, which have no negative frequency equivalent.

  • $\begingroup$ But in that case one sided spectrum at 0Hz would be correct and for 50Hz it would be 1W. But 1V sine is 0.5W. Shouldn't I divide the DC component by two instead? Or let me ask you for this i.stack.imgur.com/5W67V.png signal what do you say for one sided spectrum's power values? 2 and 0.5? 1 and 00.5? or 1 and 1? $\endgroup$ – user16307 Jan 14 at 16:57
  • 2
    $\begingroup$ Your DC component produces 1 W. Your sine wave is 0.5 W, since the RMS of a sine wave with amplitude 1 is $\sqrt 2$ and the square of this is 0.5. Total power is 1.5W. If you look at it two-sided you should see 1 W at 0Hz and 0.25 W at 50Hz and -50Hz each. If you look at it one-sided you should 1 W at 0Hz and 0.5W at 50 Hz. However the total power sum must match the power in the time domain, i.e. 1.5W total power $\endgroup$ – Hilmar Jan 14 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.