calculate energy of signal in matlab

To calculate the energy of a signal in MATLAB, you can follow these steps:

  1. Square each element of the signal
  2. Sum the squared values The resulting value is the energy of the signal.

Here's how you can do it in MATLAB:

main.m
% Generate a signal
t = 0:0.1:10; % time vector
f = 1; % frequency
x = sin(2*pi*f*t); % signal

% Calculate energy
E = sum(x.^2); % square each element and sum

disp(['The energy of the signal is: ', num2str(E)]);
214 chars
10 lines

In this example, we generate a sine wave signal and calculate its energy using the sum and .^ (element-wise power) operators. The resulting value is displayed using the disp function.

gistlibby LogSnag