Calculating energy and power of a signal

조회 수: 401 (최근 30일)
geometry geometry
geometry geometry 2018년 3월 18일
댓글: Walter Roberson 2021년 10월 24일
I tried this code to calculate energy and power of the input function f(x). but I get error. how can I fix it?
syms x y z energy pow t;
f=input('enter function: ','s');
f = symfun(eval(f), x);
f=f*conj(f);
f = str2func(['@(x)' vectorize(f)]);
z(t)=integral(y,-t,t);
energy=limit(z(t),t=infinity);
pow=limit(z/t,t=infinity)

채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 18일
I suggest that instead of using
f = str2func(['@(x)' vectorize(f)]);
that you use
f = matlabFunction(f);
However, you could just comment out all of your handling of f, as you never use f after you make it into a function handle.
You have
z(t)=integral(y,-t,t);
At this point your y is a symbolic variable. integral() cannot be applied to symbolic variables: you would need to use int(y, -t, t) -- which is a value you can easily predict will be 0, since the integral of y with respect to y over y = a to y = b is 1/2 b^2 - 1/2 a^2 and with a = -t and b = -t that is going to be 1/2 t^2 - 1/2 (-t)^2 which is going to be 0.
  댓글 수: 2
geometry geometry
geometry geometry 2018년 3월 19일
Thanks helping me. I tried this code and it works well.
syms x y z energy pow;
f=input('enter function: ','s');
f = symfun(eval(f), x);
f=f*conj(f);
f = matlabFunction(f);
y(t)=int(f,-t,t);
energy=limit(y(t),t,inf);
z(t)=y(t)/(2*t);
pow=limit(z(t),t,inf);
geometry geometry
geometry geometry 2018년 3월 19일
Now I'm trying to the same works for discrete time signals and I have tried this code:
syms n f z N;
f=input('enter function: ','s');
f = symfun(eval(f), n);
f=f*conj(f);
f = matlabFunction(f);
y(N)=symsum(f, -N , N);
energy=limit(y(N),N,inf);
z(N)=y(N)/(2*N+1);
pow=limit(z(N),N,inf);
but I have several problems. first how can I write the symbols n and N are integers and the second is that symsum doesn't work well. Could you help me?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

SHREEVARSHINI R
SHREEVARSHINI R 2021년 10월 24일
write a matlab program to find the energy and power of the signal x(t) = 10sin(10*pi*t).

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by