Filter löschen
Filter löschen

fouriertransform with piecewise function

11 Ansichten (letzte 30 Tage)
Elisa
Elisa am 11 Dez. 2022
Bearbeitet: Paul am 13 Dez. 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])

Akzeptierte Antwort

VBBV
VBBV am 11 Dez. 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 Kommentare
Elisa
Elisa am 12 Dez. 2022
thank you!!!!
Paul
Paul am 12 Dez. 2022
Bearbeitet: Paul am 13 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by