Cannot plot Fourier Transform

12 visualizzazioni (ultimi 30 giorni)
Reza Babadian
Reza Babadian il 12 Giu 2019
Modificato: Paul il 22 Apr 2025
Hello. I want to compute and plot the fourier transform of a function with fourier(x) function in matlab. The function I am trouble with is (sin(2*t)/(pi*t))^2. It seems that it's fourier transform cannot be computed. This is the code that I have written:
clear;
clc;
syms t w
h = sin(4*(t-1))./(pi*(t-1));
figure
fplot(t, h)
H = fourier(h, t, w);
magnitude_H = abs(H);
phase_H = angle(H);
figure
fplot(magnitude_H)
figure
fplot(phase_H)
% Define Input and calculate it's fourier transform
x = (sin(2*t)./(pi*t)).^2;
figure
fplot(t, x)
X = fourier(x, t, w);
figure
fplot(X)
% Calculate output in freq domain
Y = X*H;
figure
fplot(abs(Y));
y(t) = ifourier(Y, w, t)
figure
fplot(y)
this is the error:
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your
function to return an output with the same size and shape as the input arguments.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function.FunctionLine/updateFunction
In matlab.graphics.function.FunctionLine/set.Function_I
In matlab.graphics.function.FunctionLine/set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 237)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 192)
In fplot>vectorizeFplot (line 192)
In fplot (line 162)
In Untitled3 (line 23)
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in FunctionLine update: Unable to convert
expression into double array.
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in FunctionLine update: Unable to convert
expression into double array.
Is there a fix for my code?

Risposte (2)

David Goodmanson
David Goodmanson il 12 Giu 2019
Hi Reza,
If you take a look at X, the result is
X = -((pi*w*sign(w))/2 + fourier(cos(4*t)/t^2, t, w)/2)/pi^2
which shows that Matlab symbolic is not able to handle this integral. The result is in fact a triangle pulse whose base extends from w = -4 to w = 4 and whose height at w=0 is 2/pi.

Paul
Paul il 22 Apr 2025
Modificato: Paul il 22 Apr 2025
Hi David,
I just came across this old post.
syms t w
h = sin(4*(t-1))./(pi*(t-1));
H = fourier(h, t, w);
% Define Input and calculate its fourier transform
x = (sin(2*t)./(pi*t)).^2;
X = fourier(x, t, w)
X = 
My experience is that fourier works better when operating on exponentials rather than sin and/or cos.
X = fourier(rewrite(x,'exp'),t,w)
X = 
Which is the triangular pulse that you described.
figure
fplot(X)
Continuing
Y = X*H;
y = simplify(ifourier(Y,w,t))
y = 

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by