Multiple errors with an integral
12 views (last 30 days)
Show older comments
Reymi Chacon
on 24 Feb 2018
Commented: Walter Roberson
on 6 Jan 2022
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.
0 Comments
Accepted Answer
Steven Lord
on 24 Feb 2018
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 Comments
Walter Roberson
on 24 Feb 2018
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()
More Answers (1)
nassima el ouarie
on 6 Jan 2022
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 Comment
Walter Roberson
on 6 Jan 2022
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!