Skip to main content
edited tags
Link
Matt L.
  • 92.5k
  • 10
  • 81
  • 184
some code formatting
Source Link
Matt L.
  • 92.5k
  • 10
  • 81
  • 184

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 weatherwhether the signal is an energy or a power signal. Here is the program the iI tried:

function [ ] = power_or_energy( s,t)

%UNTITLED Summary of this function goes here

% s is the input signal

% t is the independant variable

s2=s.^2;

energy=int(s2,t,-inf,inf);

if energy~=inf && energy~=-inf

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

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

end

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);

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:L

syms t;

s=sin(t);

power_or_energy(s,t);

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.

I am a little new to matlab and would like to get some help on how write a program or a function that can calculate the energy/power of a signal depending on weather 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 independant 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

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:L

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.

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.

Source Link
suhail
  • 25
  • 1
  • 2
  • 5

Calculating power and energy of a signal in matlab

I am a little new to matlab and would like to get some help on how write a program or a function that can calculate the energy/power of a signal depending on weather 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 independant 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

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:L

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.