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]') plt.grid() plt.show() #FFT plt.figure() y = y T = t-t 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.grid() plt.xlabel('Frequency [Hz]') plt.ylabel('Power [W]')
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?