Multiple errors with an integral

12 次查看(过去 30 天)
I am trying to find the energy of a signal in the frequency domain, but I am having trouble with the integral. I have had multiple errors which is why I did not choose one for the title. Some are: "Undefined function 'abs' for input arguments of type 'function_handle'", Error using integralCalc (...)set the 'ArrayValued' option to true..",etc.
This is the code:
clc
Fs=33280;
t = 0:1/Fs:(N/Fs)-(1/Fs);
N = 256;
x = 4*sin(1040*pi*t) + cos(3120*pi*t);
w = (-2*pi*Fs)/2:(2*pi*Fs)/N:(2*pi*Fs)/2-(2*pi*Fs)/N;
X =@(w) 1/N*fftshift(fft(x));
Px = integral((abs(X)).^2,-inf,inf);
disp(Px)
The error says: Undefined function 'abs' for input arguments of type 'function_handle'.
x is the signal in time, and X is the signal in the domain of frequency after Fourier.

采纳的回答

Steven Lord
Steven Lord 2018-2-24
The abs function is not defined for function handles. You will need to create a new function handle that evaluates your original function handle and takes the abs of the values it returns:
absX = @(w) abs(X(w));
Now take the integral of absX instead of X.
  3 个评论
Walter Roberson
Walter Roberson 2018-2-24
You removed the @(w) from your definition of X. You still need a @()
X =@(x) 1/N*fftshift(fft(x));
It is not clear how your vector, w, of 256 (N) points, fits into all of this.
It looks to me as if w is intended to be your signal and that you are asked to calculate its energy. integral() is for calculating integrals of functions (or formulae) and you do not appear to have a function here. It appears to me that you should be doing a numeric integration such as by using trapz()
Reymi Chacon
Reymi Chacon 2018-2-24
Ah thank you. It seems trapz works without problems.

请先登录,再进行评论。

更多回答(1 个)

nassima el ouarie
please help me why the integration function is not working i don't know why ??
i want to compute this integral but this is what ti gives me matlab :
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in JENERALANDA (line 12)
JG1=integral(f,L1,L2);
this is the function i wrote to compute the integral :
function [JGL] = JENERALANDA()
syms L;
q=1.602176620*10^(-19);
Lw=(90*10^(-9));
w=(900*10^(-9));
N=50;
B=changalphaB();
Z=changalphaW();
L1=(0.24*10^(-6));
L2=(1.08*10^(-6));
f=@(L) ((2.3*10^(18)).*(1-exp(-B.*w-Z.*N.*Lw)));
JG1=integral(f,L1,L2);
JGL=-(q.*(JG1));
end
  1 个评论
Walter Roberson
Walter Roberson 2022-1-6
f=@(L) ((2.3*10^(18)).*(1-exp(-B.*w-Z.*N.*Lw)));
That does not use L, so no matter what the input it always returns the same output.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by