3

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))
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
Miau25
  • 31
  • 2
  • 3
    `fft` is a discrete operation. Your `h` is a symbolic function. Try this one instead: https://www.mathworks.com/help/symbolic/sym.fourier.html – Cris Luengo May 31 '22 at 22:42

1 Answers1

0

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
LNiederha
  • 911
  • 4
  • 18