Learn R Programming

seewave (version 1.5.5)

ffilter: Frequency filter

Description

This function filters out a selected frequency section of a time wave (low-pass, high-pass, low-stop, high-stop, bandpass or bandstop frequency filter).

Usage

ffilter(wave, f, from = FALSE, to = FALSE, bandpass = TRUE,
custom = NULL, wl = 512, wn = "hanning", Sample = FALSE)

Arguments

wave
a vector, a matrix (first column), an object of class ts, Sample (left channel), or Wave (left channel).
f
sampling frequency of wave (in Hz). Does not need to be specified if wave is an object of class ts, Sample, or Wave<
from
start frequency (in Hz) where to apply the filter.
to
end frequency (in Hz) where to apply the filter.
bandpass
if TRUE a band-pass filter is applied between from and to, if FALSE a band-stop filter is applied between from and to (by default TRUE).
custom
a vector describing the frequency response of a custom filter. This can be manually generated or obtained with spec and meanspec. wl is no
wl
window length for the analysis (even number of points).
wn
window name, see ftwindow (by default "hanning").
Sample
if TRUE and plot is FALSE returns an object of class Sample.

Value

  • A new wave is returned as a one-column matrix or as a Sample object if Sample is TRUE.

Details

A short-term Fourier transform is first applied to the signal (see spectro), then the frequency filter is applied and the new signal is eventually generated using the reverse of the Fourier Transform (fft). There is therefore neither temporal modifications nor amplitude modifications.

See Also

afilter,lfs,fir

Examples

Run this code
a<-noise(f=8000,d=1)
# low-pass
b<-ffilter(a,f=8000,to=1500)
spectro(b,f=8000,wl=512)
# high-pass
c<-ffilter(a,f=8000,from=2500)
spectro(c,f=8000,wl=512)
# band-pass
d<-ffilter(a,f=8000,from=1000,to=2000)
spectro(d,f=8000,wl=512)
# band-stop
e<-ffilter(a,f=8000,from=1500,to=2500,bandpass=FALSE)
spectro(e,f=8000,wl=512)
# custom
myfilter1<-rep(c(rep(0,32),rep(1,32)),4)
g<-fir(a,f=8000,custom=myfilter1)
spectro(g,f=8000)

Run the code above in your browser using DataLab