Multiple errors with an integral

12 visualizaciones (últimos 30 días)
Reymi Chacon
Reymi Chacon el 24 de Feb. de 2018
Comentada: Walter Roberson el 6 de En. de 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.

Respuesta aceptada

Steven Lord
Steven Lord el 24 de Feb. de 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 comentarios
Walter Roberson
Walter Roberson el 24 de Feb. de 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()
Reymi Chacon
Reymi Chacon el 24 de Feb. de 2018
Ah thank you. It seems trapz works without problems.

Iniciar sesión para comentar.

Más respuestas (1)

nassima el ouarie
nassima el ouarie el 6 de En. de 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 comentario
Walter Roberson
Walter Roberson el 6 de En. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by