Learn R Programming

seewave (version 1.4.3)

fir: Finite Impulse Response filter

Description

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

Usage

fir(wave, f, from = FALSE, to = FALSE, bandpass = TRUE, custom = NULL,
wl = 512)

Arguments

wave
data describing a time wave or a Sample object created generated a wav file with loadSample (package Sound).
f
sampling frequency of wave (in Hz). Does not need to be specified if wave is a Sample object.
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
wl
window length of the impulse filter (even number of points).

Value

  • fir returns a one-column matrix describing the new wave.

Details

This function is based on the reverse of the Fourier Transform (fft) and on a convolution (convolve) between the wave to be filtered and the impulse filter.

References

Stoddard, P. K. (1998). Application of Filters in Bioacoustics. In: Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds), Animal acoustic communication. Springer, Berlin, Heidelberg,pp. 105-127.

See Also

ffilter,lfs, afilter, fir1, fir2

Examples

Run this code
a<-noise(f=8000,d=1)
# low-pass
b<-fir(a,f=8000,to=1500)
spectro(b,f=8000)
# high-pass
c<-fir(a,f=8000,from=2500)
spectro(c,f=8000)
# band-pass
d<-fir(a,f=8000,from=1000,to=2000)
spectro(d,f=8000)
# band-stop
e<-fir(a,f=8000,from=1500,to=2500,bandpass=FALSE)
spectro(e,f=8000)
# custom filter manually generated
myfilter1<-rep(c(rep(0,64),rep(1,64)),4)
g<-fir(a,f=8000,custom=myfilter1)
spectro(g,f=8000)
# custom filter generated using spec()
data(orni)
myfilter2<-spec(orni,f=22050,at=0.21,wl=512,plot=FALSE)
b<-noise(d=1,f=22050)
h<-fir(b,f=8000,custom=myfilter2)
spectro(h,f=8000)

Run the code above in your browser using DataLab