# FFT one-sided and Parseval theorem

I'm trying to get Parseval theorem working on a one-sided FFT. So far I have this code (matlab):

%% ODD
a = [1 2 3 4 5];
A = fft(a);
A1 = abs(A);
A2 = abs([A(1) 2*A(2:3)]);

Ea=sum(a.^2)
EA1=sum(A1.^2)/5
EA2=sum(A2.^2)/5

%% EVEN
b  = [1 2 3 4 5 6];
B  = fft(b);
B1 = abs(B);
B2 = abs([B(1) 2*B(2:3) B(4)]);

Eb =sum(b.^2)
EB1=sum(B1.^2)/6
EB2=sum(B2.^2)/6


And the output is:

Ea =  55
EA1 =  55
EA2 =  65
Eb =  91
EB1 =  91
EB2 =  107


The scaling for the one-sided is to preserve amplitude information and not for calculating Parseval theorem?

Parseval's theorem says that the the following relationship holds $$\sum_{n=1}^{N} a[n]\,a^*[n] = \frac{1}{N}\sum_{k=1}^{N} A[k]\,A^*[k]$$ where $$A[k]$$ is the discrete Fourier transform of $$a[n]$$, both assumed to be of length $$N$$ (no padding). This arises from the fact that the signal energy calculated from the time domain and frequency domain must be equal. See this answer for a little more detail about how this formula comes about.

If you want to calculate a one-sided spectrum, you need to throw away the negative frequencies (which are redundant when the signal is real). However, because half of the energy was contained in these entries, you need to multiply the energy in the remaining bins by 2 - except for the DC and Nyquist. I see that you have recognised correctly that the Nyquist is only present when $$N$$ is even, and that the first entry is the DC component regardless of $$N$$ - good. However, you have multipied the amplitudes by 2 (straight after the FFT), not the energy - the negative frequency bins contain half of the energy.

Instead, once you have calculated the discrete Fourier transform using the FFT algorithm (your variables $$A$$ and $$B$$), I would first then obtain the energy spectral density of the signal $$a[n]$$ using $$\textrm{ESD}_a[k] = |A[k]|^2 = A[k]\,A^*[k]$$ and then throw away the negative frequencies from this vector instead. This way you throw away half of the energy correctly, and you can confidently multiply the energy in the remaining bins by $$2$$.

The following code illustrates this:

%% ODD
a = [1 2 3 4 5];
A = fft(a);
ESD_a = A.*conj(A);
ESD_a_onesided = [ESD_a(1) 2*ESD_a(2:3)];

E_a_timedomain = sum(a.^2)
E_a_twosided = sum(ESD_a)/5
E_a_onesided = sum(ESD_a_onesided)/5

%% EVEN
b = [1 2 3 4 5 6];
B = fft(b);
ESD_b = B.*conj(B);
ESD_b_onesided = [ESD_b(1) 2*ESD_b(2:3) ESD_b(4)];

E_b_timedomain = sum(b.^2)
E_b_twosided = sum(ESD_b)/6
E_b_onesided = sum(ESD_b_onesided)/6


The result is then correctly

E_a_timedomain = 55
E_a_twosided = 55
E_a_onesided = 55

E_b_timedomain = 91
E_b_twosided = 91
E_b_onesided = 91


EDIT----------------------------

Actually, the energy values of $$55$$ and $$91$$ obtained are only correct if we are assuming the sampling period of the signal acquisition was $$T_s=1$$.

The signal energy of a continuous signal $$a(t)$$ is defined as $$E_s = \int_{-\infty}^{+\infty}|a(t)|^2\;dt$$ and the energy of a sampled version of it is then $$E_s = \sum_{n=1}^{N}|a[n]|^2\cdot T_s$$ and you can see that we need to account for the signal sampling period to get the right energy.

The following verifies Parseval's theorem if we for example had collected the signal at some other sampling period $$T_s\neq 1$$

Ts = 0.05; % the sampling period of acquisition
Fs = 1/Ts; % the sampling frequency of the acquisition

%% ODD
a = [1 2 3 4 5];
N = 5

A = fft(a)*Ts;
ESD_a = A.*conj(A);
ESD_a_onesided = [ESD_a(1) 2*ESD_a(2:3)];

E_a_timedomain = sum(a.*conj(a))*Ts
E_a_twosided = sum(ESD_a)*Fs/N
E_a_onesided = sum(ESD_a_onesided)*Fs/N

%% EVEN
b = [1 2 3 4 5 6];
N = 6

B = fft(b)*Ts;
ESD_b = B.*conj(B);
ESD_b_onesided = [ESD_b(1) 2*ESD_b(2:3) ESD_b(4)];

E_b_timedomain = sum(b.^2)*Ts
E_b_twosided = sum(ESD_b)*Fs/N
E_b_onesided = sum(ESD_b_onesided)*Fs/N


with the output

E_a_timedomain = 2.75 [signal^2 sec]
E_a_twosided   = 2.75 [signal^2 sec]
E_a_onesided   = 2.75 [signal^2 sec]

E_b_timedomain = 4.55 [signal^2 sec]
E_b_twosided   = 4.55 [signal^2 sec]
E_b_onesided   = 4.55 [signal^2 sec]

• Thank you for the long and detailed answer. So, the one-sided fft coefficients that are computed for properly representing the amplitudes cannot be directly used for calculating the energy? May 2 '20 at 16:00
• It doesn't really matter at what point you do your scaling. As long as you are clear what each quantity represents at each step. It depends what you want to show. In your example, if you increase you number of points then the values of the A1 vector will increase. You could apply scaling directly to the output of the FFT if you like. It is fine to multiply the amplitudes by 2, but you then need to make sure that when you calculate energy (which is proportional to amplitude squared, and gets bigger with more points) that you account for it (with another factor of sqrt(2) in that case). May 2 '20 at 16:44
• Yes thank you!! May 7 '20 at 10:14