I have an easy script, taken from an example of Matlab help page of fft:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear; close all; clc; beep off
Fs = 100; % Sampling frequency
t = -0.5:1/Fs:0.5; % Time vector
L = length(t); % Signal length
x = 1/(4*sqrt(2*pi*0.01))*(exp(-t.^2/(2*0.01))); % signal
nfft1 = 2^nextpow2(L); % first nfft
nfft2=nfft1/2; % new nfft (lower than first one)
dt=1/Fs; % time resolution
Y1 = fft(x,nfft1)*dt; Y2 = fft(x,nfft2)*dt; % Fourier transforms
f1 = Fs*(0:(nfft1/2))/nfft1; f2 = Fs*(0:(nfft2/2))/nfft2; % frequency arrays
P1 = Y1.*conj(Y1); P2 = Y2.*conj(Y2); % power spectra
df1=f1(2)-f1(1); df2=f2(2)-f2(1); % frequency resolutions
e=sum(abs(x).^2)/Fs % Energy from temporal domain
E1=sum(P1)*df1 % Energy from frequency domain with nfft1
E2=sum(P2)*df2 % Energy from frequency domain with nfft2
basically, I do the fft firstly with a nfft higher than the signal length (nfft1) and then with a lower nfft (nfft2); I get than the energy obtained with nfft1 is equal to the energy obtained from temporal domain, while energy obtained with a lower nfft is different. Could anyone explain why?
Best Answer