# fft function in R vs spec function from 'seewave' package? They don't give a similar frequency spectra

I understand that spec will give me the frequency and the corresponding amplitude of that component, whereas fft will compute the DFT of the signal and throw the complex numbers for each component which I have to plot as per the physical frequencies.

y is the time-series signal Fs is the sampling freq.

N = length(y);
f1=fft(y)
fa = seq(0,N-1,by=1)*(Fs/N)
plot(fa,abs(f1),type='l',xlim = c(0,3),ylim = c(0,50))
s1=spec(y,f=1000,plot = FALSE)
s1$$x<-s1$$x*1000   (KHz to Hz)
plot(s1$$x,s1$$y,type='l',xlim = c(0,3))


Red one is from spec function and blue is from fft function.

• FFT is a low level function to compute the raw complex valued DFT of the given data untouched. SPEC function seems to pre and post-process the FFT results (as @Florian indicated). Hence they would produce different (but nevertheless related) outputs. – Fat32 Jul 26 '19 at 12:12

Disclaimer: I don't know even a bit of R. But I checked the documentation of the spec function: A Hanning function is applied to the analysis window.

This may very well be the source of the difference in the two plots. The fft function does not apply any window (i.e., it's only the natural rectangular window we are seeing).

• Thanks! It makes sense. I am now trying to figure out what could be the best windowing function to apply. Trying to extract respiratory waveform from an accelerometer attached to the chest. I have noise around 0.1 Hz and some high-frequency noises. Freq of interest is around 0.1 to 2 Hz. – Rutuja Chhajed Jul 30 '19 at 6:45
• Apart from the strong DC component, I don't understand this peak at around 0.1 Hz. – Rutuja Chhajed Jul 30 '19 at 6:46