Error Plotting Magnitude Spectrum of Fourier Transform With fplot

3 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Star Strider
Star Strider el 14 de Mzo. de 2025
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')
.
  2 comentarios
Star Strider
Star Strider el 14 de Mzo. de 2025
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by