1
$\begingroup$

I am a little new to matlab and would like to get some help on how to write a program or a function that can calculate the energy/power of a signal depending on whether the signal is an energy or a power signal. Here is the program the I tried:

function [ ] = power_or_energy( s,t)
%UNTITLED Summary of this function goes here
%   s is the input signal
%   t is the independent variable

s2=s.^2;
energy=int(s2,t,-inf,inf);

if energy~=inf && energy~=-inf
    disp ('the signal is an energy signal with energy equal to ' );
    disp(energy);
end

power=limit((int(s2,t,-t/2,t/2))/t,t,inf);

if power~=inf && power~=-inf
    disp('the signal is a power signal with power equal to ');
    disp(power);
end

But the problem here is that when i want to check it for a function like

t=0:0.01:10;
s=sin(t);
power_or_energy(s,t);

then i get the following error: "Undefined function 'int' for input arguments of type 'double'."

So how to i actually calculate the energy for such signals?

Also the above function works fine with the below input:

syms t;
s=sin(t);
power_or_energy(s,t);

Please help me in writing a function that can be used to find the energy of any input signal.

$\endgroup$
1
$\begingroup$

The Matlab function int needs a symbolic expression as an integrand, and a symbolic variable as an integration variable. In your example s and t are both vectors, and you can't use int in this case. If you want to compute the power or energy of discrete time signals, then you need to use the corresponding definitions:

$$E_x=\sum_{n=-\infty}^{\infty}|x_n|^2\\ P_x=\lim_{N\rightarrow\infty}\frac{1}{2N+1}\sum_{n=-N}^N|x_n|^2$$

In practice you will need to consider finite length signals unless you have an analytic formula for $x_n$ and some software package that can deal with the analytic evaluation of infinite sums. Obviously, finite length signals always have finite energy and $P_x=0$ according to above definition.

$\endgroup$
  • $\begingroup$ could u help me in implementing the power equation in matlab.I can do the energy part but could not make out how to calculate the power $\endgroup$ – suhail Sep 8 '14 at 12:20
  • $\begingroup$ @user94533: As I said in my answer, for finite length signals, the power is zero. $\endgroup$ – Matt L. Sep 8 '14 at 12:21
  • $\begingroup$ i meant for a signal like sin(t) which runs from -inf to inf .how do i calculate the power.also in case of a ramp function how do i do it using matlab.those are not finite length cases $\endgroup$ – suhail Sep 8 '14 at 12:25
  • $\begingroup$ @user94533: You mean a periodic ramp (sawtooth)? For periodic signals the power is $P_x=\frac{1}{N}\sum_{n=0}^{N-1}|x_n|^2$, where $N$ is the period. $\endgroup$ – Matt L. Sep 8 '14 at 12:28
-3
$\begingroup$

Refer this link for calculation of Energy and Power of signal: http://www.mathworks.com/matlabcentral/fileexchange/11202-automatic-gain-control

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.