Error Plotting Magnitude Spectrum of Fourier Transform With fplot

2 次查看(过去 30 天)
hi I have the following code to calculate a fourier transform, which seems to be calculate the correct answer:
syms t;
x1 = exp(-t/2).*(sin(4*t)).*heaviside(t);
X1 = fourier(x1);
interval = abs(X1);
fplot(X1, [0 interval]);
However the fplot outputs a blank plot and returns a bunch of errors, the first of which is:
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions
to reduce operands to logical scalar values.
It's puzzling to me because there aren't any logical operators in the fplot command. Any help would be appreciated.

采纳的回答

Star Strider
Star Strider 2025-3-14
Your code just needed to be tweeaked a bit. I changed the plot lilmits to show more of the function.
Try this —
syms t w
x1 = exp(-t/2).*(sin(4*t)).*heaviside(t)
x1 = 
X1 = symfun(fourier(x1),w) % Create Function From Result
X1(w) = 
interval = vpa(abs(X1(pi)))
interval = 
0.56243798938644957323168410831368
figure
fplot(abs(X1), [0 2*pi], DisplayName='|X1(\omega)|')
hold on
fplot(real(X1), [0 2*pi], '--r', DisplayName='Re(X1(\omega))')
fplot(imag(X1), [0 2*pi], '--g', DisplayName='Im(X1(\omega))')
hold off
grid
xlabel('\omega')
ylabel('Magnitude')
legend(Location='best')
.

更多回答(0 个)

类别

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

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by