filter.fft {spectral} | R Documentation |
Filter in the frequency domain
Description
This function provides a method to band pass filter in the frequency domain.
Usage
filter.fft(
y = stop("y-value is missing"),
x = NULL,
fc = 0,
BW = 0,
n = 3,
type = "poly"
)
Arguments
y |
numeric data vector |
x |
optional x-coordinate |
fc |
center frequency of the bandpass |
BW |
bandwith of the bandpass |
n |
parameter to control the stiffness of the bandpass |
type |
type of weightening function: "poly", "sinc", "bi-cubic","gauss", can be abbreviated |
Details
A signal is meant to be equaly spaced and causal, which means it starts
at
. For times
the signal is not defined. The filtering
itself takes place with the analytic function of
which provides an one sided
spectrum. Applying the Fourier transform, all properties of
will be
preserved.
The band pass is represented throughout a function in the form of four different types, i.e.
"polynom", "sin(x)/x", "bi-cubic", "gauss". A detailed
description about these types can be found in BP
.
Setting fc = 0
one can achieve a low pass filter.
Examples
## noisy signal with amplitude modulation
x <- seq(0,1, length.out=500)
# original data
y_org <- (1+sin(2*2*pi*x))*sin(20*2*pi*x)
# overlay some noise
y_noise <- y_org+rnorm(length(x),sd=0.2)
# filter the noisy data
y_filt <- filter.fft(y_noise,x,fc=20,BW=4,n=50)
# plot results
plot(x,y_noise,type="l",lwd=1,col="darkgrey",lty=2,ylab="y",main="Spectral filtering")
lines(x,y_org,lwd=5,col="grey")
lines(x,y_filt)
legend("topright",c("org","noisy","filtered"),col=c("grey","darkgrey","black")
,lty=c(1,2,1),lwd=c(5,1,1))