Error Plotting Magnitude Spectrum of Fourier Transform With fplot

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Star Strider
Star Strider il 14 Mar 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')
.

Più risposte (0)

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by