# Introduction

I was doing some thinking about how best to work with rotating spectra in R, and wanted to drop all the way down to using fft() instead of spectrum(). For a while, I was confused about some of the results, because the lengths of spectra created with fft were not what I expected. Then I saw that the problem was that I was using the default value of fast in the spectrum() function. The content of this post illustrates this.

# Results and discussion

By default, the R spectrum() function sets the argument fast=TRUE. This causes R to increase the speed of processing, but it also leads to spectrum lengths that can be surprising.

The following illustrates how the length of spectra computed with spectrum vary from the expected value of floor(length(data)/2).

# Conclusion

If the results of spectrum and fft are to be put on an equal footing, e.g. for numerical comparisons, then it makes sense to call the former as e.g. spectrum(..., fast=FALSE).

# Reference and resources

1. Jekyll source code for this blog entry: 2017-12-21-spectrum-length.Rmd

This website is written in Jekyll, and the source is available on GitHub.