Clear Filters
Clear Filters

fouriertransform with piecewise function

11 views (last 30 days)
Elisa
Elisa on 11 Dec 2022
Edited: Paul on 13 Dec 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])

Accepted Answer

VBBV
VBBV on 11 Dec 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 Comments
Paul
Paul on 12 Dec 2022
Edited: Paul on 13 Dec 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!