# how to compute energy and power of discrete-time signal using symbolic calculations

95 views (last 30 days)
BLP on 10 Oct 2020
Commented: BLP on 15 Oct 2020
I would like to get some parameters of continous and discrete-time signals i.a. the total energy and the mean power using symbolic calculations. I do not have problem to do this for a continous signal:
syms t
A = 10; %[1]
B = 5;
f = 10; %[Hz]
s = A*sin(2*pi*f*t) + B;
Et = int(s.^2,t,-inf,inf)
Pt = limit((int(s.^2,t,-t,t))/(2*t),t,inf)
but I do not have any idea how to do this for the signal which is discrete in time. I have tried, unsaccessfully, the symsym function
En = symsum(s.^2,t,-inf,inf)
Pn = limit((symsum(s.^2,t,-t,t))/(2*t),t,inf)
I expect the energy to be infinite and this my cause some problems, but the power should be a finite number.
Does anybody have an idea how to solve this problem?

Swetha Polemoni on 15 Oct 2020
Hi,
I have tried your code and power is finite for discrete signal also. Use "simplify" to get limit value instead of limit expression. Following code is for better understanding.
syms t
A = 10; %[1]
B = 5;
f = 1; %[Hz]
s = A*sin(2*pi*f*t) + B;
En = simplify(symsum(s.^2,t,-inf,inf))
Pn =simplify( limit((symsum(s.^2,t,-t,t))/(2*t),t,inf))
Here Pn = 25. Analyzing it step by step
-> Consider the summation.
->Here Sin(200*pi*t) is always zero since it is being calculated at integer multiplies of 2*pi. So the summation results in 25*2t
->Now dividing the summation with 2t and applying limit t->infinite results in 25*2*t/2*t => Pn =25
Though Pn is not equal to Pt here, Pn=25 is correct. Pn and Pt are different, may be, because not every time discrete signal has same power/energy as continuos signal.
BLP on 15 Oct 2020
I am prety sure that the sumation of a sinus function of the lengthth qual to k*T, where T is the period of the sinus, will give zero - this may represent an area under the function, but in this case the sinus have both positive and negative valuesvalues which cancel each other totally. On the other hand, analogues sumation of suare of the sinus function cannot by equal to zero - because of the the square operation all values of the signal are positive.
sumS1sqr + sum10S1 + sumS5sqr
ans =
Of course using the limit for t->inf may give the final output equal to 25, but I do not understand why.
I expected some differences in the value pf the signal power for the continuous and discrete siganlas which will be due to the sampling, but when the power I get for the continuous signal is 75 and for the discrete ist 25 I expect an error in the code.
I thougt, that using the equations with t for the summation is wrong - I do not have any influence on the sampling interval. Therefore I have changed this and calculated new discrete signal and than I tried to calculate the energy and power but this did not help. Why - I do not know. Usnig fp and n instead of t I would like to check how the fp influence the power of the signal.
I have tried another way. I have defined a symbolic discrete signal and a vecotr o samples of discrete signal
syms n
A1 = 10; % [1]
B1 = 5;
f1 = 10; % [Hz] sinus frequency
fp2d = 100; % [Hz] sampling frequency
Tprob1d = 0.95; % [s] sampling time
ss2d = A1*sin(2*pi*f1*n/fp2d) + B1; % symbolic discrete signal
L = length(0:1/fp2d:Tprob1d);
s2d = subs(ss2d,1:L); % discrete signa as a vector
Than, I calculated power for both for a finite length equal one period
No2 = floor(fp2d/f1);
n1 = 1;
n2 = No2;
Pnss2dNo2 = double(limit((symsum(ss2d.^2,n,n1,n2))/(n2 - n1 + 1),n,inf))
Pns2dNo2 = double(1/(n2-n1+1)*sum(s2d(n1:n2).^2))
and the results are correct
Pnss2dNo2 = 75
Pns2dNo2 = 75
In this case, error caused by sampling equals zero.
Than I have changed the sampling frequency and repeted the calculations
syms n
A1 = 10; % [1]
B1 = 5;
f1 = 10; % [Hz] sinus frequency
fp2d = 20; % [Hz] sampling frequency
Tprob1d = 0.95; % [s] sampling time
ss2d = A1*sin(2*pi*f1*n/fp2d) + B1; % symbolic discrete signal
L = length(0:1/fp2d:Tprob1d);
s2d = subs(ss2d,1:L); % discrete signa as a vector
No2 = floor(fp2d/f1);
n1 = 1;
n2 = No2;
Pnss2dNo2 = double(limit((symsum(ss2d.^2,n,n1,n2))/(n2 - n1 + 1),n,inf))
Pns2dNo2 = double(1/(n2-n1+1)*sum(s2d(n1:n2).^2))
This time I got quite different results
Pnss2dNo2 = 25
Pns2dNo2 = 25
This in my opinion proves, that the problem is in the definition of the independetn variable (as t) which ends up in an erroneous sampling of the sinus function.
It does not chage the situation. Still, I do not have any idea why I canot get the proper value in a general case for infinite length of the signal ssd2 (se code and outputs below)?
Pnss2d = simplify(limit((symsum(ss2d.^2,n,-n,n))/(2*n + 1),n,inf))
Pnss2d =