Effacer les filtres
Effacer les filtres

fouriertransform with piecewise function

26 vues (au cours des 30 derniers jours)
Elisa
Elisa le 11 Déc 2022
Modifié(e) : Paul le 13 Déc 2022
I am trying to apply a fft (fourier transform) into a piecewise function, but i receive the following message: "Error using fft
Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or logical."
Code:
figure(1);
syms t
x = piecewise(-1/2<=t<=1/2, 1-abs(t), t<-1/2, 0 , t>1/2, 0);
fplot(x,[-2,2])
grid
xlabel("Time")
ylabel("Amplitude")
fa = 15000;
t = 0:1/fa:2;
y=fft(x);
f = -fa:1:fa;
figure(2);
subplot(2,1,1);
plot(f,abs(y_ajustado)/fa);
xlabel("Frequency (Hz)")
ylabel("Amplitude")
xlim([0 400])
subplot(2,1,2)
plot(f,angle(y_ajustado));
xlabel("Frequency (Hz)")
ylabel("Fase (Graus)")
xlim([0 400])

Réponse acceptée

VBBV
VBBV le 11 Déc 2022
use double and subs() the result of x
figure(1);
syms t
x = piecewise(-1/2<=t<=1/2, 1-abs(t), t<-1/2, 0 , t>1/2, 0)
x = 
fplot(x,[-2,2])
grid
xlabel("Time")
ylabel("Amplitude")
fa = 15000;
t = 0:1/fa:2;
y=fft(double(subs(x,t)));
plot(t,real(y),t,imag(y))
  2 commentaires
Elisa
Elisa le 12 Déc 2022
thank you!!!!
Paul
Paul le 12 Déc 2022
Modifié(e) : Paul le 13 Déc 2022
Why is y plotted agains t? Shouldn't y be plotted against frequency? And the fft is only taken for the portion of the signal for t>=0, but it's non-zero for t < 0.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by