find energy of signal in frequency domain in matlab

To find the energy of a signal in frequency domain using Matlab, we first need to take the Fourier transform of the signal. After that, we calculate the absolute square of the Fourier transform to obtain the energy spectrum. Finally, we integrate the energy spectrum over the frequency range to obtain the total energy of the signal.

Here's the Matlab code to find the energy of a signal x:

main.m
% length of the signal
N = length(x);

% Fourier transform of the signal
X = fft(x);

% energy spectrum
P = abs(X).^2/N;

% frequency vector
f = (0:N-1)*(fs/N);

% total energy of the signal
E = sum(P)*(f(2)-f(1));
215 chars
15 lines
  • N is the length of the signal x.
  • fs is the sampling frequency.
  • X is the Fourier transform of the signal x.
  • P is the energy spectrum of the signal x.
  • f is the frequency vector.
  • E is the total energy of the signal x.

gistlibby LogSnag