3

I'm trying to do a noise removal by FFT in R. The trouble I'm having is that I get a y-axis shift during the process and I'm not sure what the cause is. I have read up on FFT and used this resource as a guide. See below for the code I have been executing as well as sample graphics of the result. Here is a dropbox link to the csv file. data.csv

data=read.csv('data.csv')
plot(data,type='l')

#FFT filtration function
fft.filter=function(data,threshold){
  temp=fft(data)
  temp[threshold:length(data)-threshold]=0+0i
  temp=Re(fft(temp,inverse=TRUE)/length(temp))
  return(temp)
}

data2=data
data2$Signal=fft.filter(data2$Signal,100)

Unfiltered Plot: enter image description here

Filtered Plot: enter image description here

As the images show, the data scaling looks fine, I'm just getting a shift that I don't think I should be. The FFT function is working to remove noise from the series.

scs217
  • 2,218
  • 2
  • 17
  • 18

1 Answers1

2

There is a problem with the indexing. It is indexing from 0 to length(data)-threshold, whereas you want threshold:(length(data)-threshold) I believe. Change the indexing line to

temp[threshold:(length(data)-threshold)]=0+0i
Rorschach
  • 31,301
  • 5
  • 78
  • 129