# Calculating FT using matlab quad function

• MATLAB
• lefti2003
In summary, a user is seeking help with using the quad function and has provided a snippet of code that is causing errors. They are receiving an error message about undefined functions for input arguments of type sym and are unsure how to resolve it. Another user suggests using finite limits instead of infinity to solve the issue.
lefti2003
Hi All,
I am new to this forum and new to using the quad function. Some assistance would be most helpful. I appreciate all help in advance.

I have a .m file called OneExpDecay.m that has the following

syms t
x=exp(-2*t^2);
[RX,IX]=ft(x,-inf,inf);

then I have an ft.m that has the following

function [RX,IX]=ft(x,a,b)
syms t f
fr=@(t)x*cos(2*pi*f.*t);
fim=@(t)x*sin(2*pi*f.*t);

When I run OneExpDecay.m I get the following errors that I do not understand how to resolve

?? Undefined function or method 'isfinite' for input arguments of type 'sym'.

Error in ==> quad at 81
if ~isfinite(y(1))

Error in ==> ft at 4

Error in ==> OneExpDecay at 3
[RX,IX]=ft(x,-inf,inf);

Thanks
Lefti

The error that your receiving about functions being undefined for inputs of type sym means that you're trying to send a symbol into a function that is expecting a number (or numbers).

Here, my guess is that you need to use finite limits (inf and -inf won't cut it). Try replacing them with numbers.

Hope this helps.

-Kerry

Hello Lefti,

It seems like the error is occurring because the quad function in your ft.m file is only designed to work with numerical inputs, not symbolic inputs. The isfinite function is used to check if a value is a finite number, and since your input is a symbolic expression, it is not recognized.

To resolve this issue, you may need to use a different function or approach to calculate the Fourier transform of a symbolic expression. You can try looking into the symbolic toolbox in Matlab or using other functions such as symsum or int to perform the integration.

I hope this helps. Good luck with your calculations!

## 1. How do I use the quad function in Matlab to calculate the Fourier Transform (FT)?

The quad function in Matlab is used to perform numerical integration. To use it for calculating the Fourier Transform, you need to define the function you want to integrate as a function handle and specify the limits of integration. For example, if you want to calculate the FT of a function f(x), you would use the following syntax: quad(@f, a, b), where a and b are the lower and upper limits of integration, respectively. The output of the quad function will be the value of the integral, which is the FT of the function f(x).

## 2. Can the quad function in Matlab handle complex functions for calculating the FT?

Yes, the quad function in Matlab can handle complex functions for calculating the FT. You just need to define the function as a function handle and make sure that the limits of integration are appropriate for the function. For example, if you want to calculate the FT of a complex function g(x), you would use the syntax: quad(@g, c, d), where c and d are the lower and upper limits of integration, respectively.

## 3. What is the accuracy of the quad function when calculating the FT in Matlab?

The accuracy of the quad function in Matlab depends on the function being integrated and the limits of integration. It uses adaptive quadrature algorithms to estimate the value of the integral, so the accuracy can be affected by the function's behavior. In general, the quad function provides accurate results for most functions, but it is always a good idea to check the convergence of the integral by adjusting the tolerance level.

## 4. Can I use the quad function in Matlab to calculate the inverse Fourier Transform (IFT)?

Yes, you can use the quad function in Matlab to calculate the inverse Fourier Transform. The process is similar to calculating the FT, but you need to define the function you want to integrate as the inverse Fourier Transform of the desired function. For example, if you want to calculate the IFT of a function F(k), you would use the syntax: quad(@F, l, m), where l and m are the lower and upper limits of integration, respectively.

## 5. Are there any limitations to using the quad function for calculating the FT in Matlab?

The quad function in Matlab is a powerful tool for calculating the FT, but it does have some limitations. It may not be suitable for highly oscillatory functions or functions with singularities at the limits of integration. In such cases, it is recommended to use other numerical integration methods or to adjust the limits of integration to avoid the problematic regions.

Replies
1
Views
3K
Replies
8
Views
663
Replies
5
Views
2K
Replies
4
Views
1K
Replies
3
Views
3K
Replies
5
Views
2K
Replies
1
Views
1K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
3
Views
2K