Computing the Fourier transform of a symbolic function

Viewed 65

I am trying to graph the Fourier transform of this signal, but it keeps giving me this error:

Error using fft Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or logical

What can I do?

This is my code:

syms x
h=(2*heaviside(x-1))-2*heaviside(x-2)
fplot(h, [-4, 4])
xlabel('t');title('x(t)') 
F=fft(h);
fplot((F))
1 Answers

This question has already been asked on the matlab forum here.

All you have to do is call fourier instead of fft.

Your code should look something like this:

syms x;
h=(2*heaviside(x-1))-2*heaviside(x-2);
fplot(h, [-4, 4]);
xlabel('t');
title('x(t)');
F=fourier(h);
fplot(real(F), [-10, 10]);  % Plotting real part of the transform
Related