Cannot plot Fourier Transform

2 次查看(过去 30 天)
Reza Babadian
Reza Babadian 2019-6-12
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?

回答(1 个)

David Goodmanson
David Goodmanson 2019-6-12
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.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by