calculate energy and power of a discrete and continious signal in matlab in matlab

To calculate the energy and power of a discrete or continuous signal in MATLAB, you can follow these steps:

  1. For a discrete signal:

    • Define your signal as a vector in MATLAB.
    • Calculate the energy using the formula: energy = sum(abs(signal).^2).
    • Calculate the power using the formula: power = energy / length(signal).
  2. For a continuous signal:

    • Define your signal as a function in MATLAB.
    • Calculate the energy using the formula: energy = integral(@(t) abs(signal(t)).^2, tstart, tend), where tstart and tend are the start and end times of the signal.
    • Calculate the power using the formula: power = energy / (tend - tstart).

Here's an example for a discrete signal:

main.m
% Define the discrete signal
signal = [1, 2, -2, 1, 0];

% Calculate the energy
energy = sum(abs(signal).^2);

% Calculate the power
power = energy / length(signal);
166 chars
9 lines

And here's an example for a continuous signal:

main.m
% Define the continuous signal as a function
signal = @(t) exp(-t).*sin(2*pi*t);

% Define the start and end times of the signal
tstart = 0;
tend = 10;

% Calculate the energy
energy = integral(@(t) abs(signal(t)).^2, tstart, tend);

% Calculate the power
power = energy / (tend - tstart);
290 chars
13 lines

Make sure to replace signal with your actual signal, and adjust the integration limits (tstart, tend) for the continuous signal based on the signal's characteristics.

related categories

gistlibby LogSnag