Multiple errors with an integral

조회 수: 9 (최근 30일)
Reymi Chacon
Reymi Chacon 2018년 2월 24일
댓글: Walter Roberson 2022년 1월 6일
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
nassima el ouarie 2022년 1월 6일
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