1

Suppose I have a length 100 vector x, in Matlab, I can run fft(x,32) to get a length 32 complex vector.

But how to do it in R?

fft(x,32) will not work and will still return a length 100 complex vector.

hxd1011
  • 885
  • 2
  • 11
  • 23

1 Answers1

4

From MatLab documentation:

Y = fft(X,n) returns the n-point DFT. If no value is specified, Y is the same size as X.

If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n.

If X is a vector and the length of X is greater than n, then X is truncated to length n. ...

To achieve same result in R:

fft(x[1:32])
HubertL
  • 19,246
  • 3
  • 32
  • 51
  • But @HubertL, what happens if `lenght(x)=1000` and `n=1024`, as in the matlab [doc](https://nl.mathworks.com/help/matlab/ref/fft.html#buuutyt-10) ? – fina Aug 25 '19 at 09:56
  • 2
    Hi @fina, you can pad X wilth zeros using `c(X, rep(0,n-length(X)))` – HubertL Aug 26 '19 at 19:23