Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

buttord

Butterworth filter order and cutoff


Description

Compute butterworth filter order and cutoff for the desired response characteristics.

Usage

buttord(Wp, Ws, Rp, Rs)

Arguments

Wp, Ws

pass-band and stop-band edges. For a low-pass or high-pass filter, Wp and Ws are scalars. For a band-pass or band-rejection filter, both are vectors of length 2. For a low-pass filter, Wp < Ws. For a high-pass filter, Ws > Wp. For a band-pass (Ws[1] < Wp[1] < Wp[2] < Ws[2]) or band-reject (Wp[1] < Ws[1] < Ws[2] < Wp[2]) filter design, Wp gives the edges of the pass band, and Ws gives the edges of the stop band. Frequencies are normalized to [0,1], corresponding to the range [0, Fs/2].

Rp

allowable decibels of ripple in the pass band.

Rs

minimum attenuation in the stop band in dB.

Details

Deriving the order and cutoff is based on:

|H(W)|^2 = 1 / [1+(W/Wc)^(2n)] = 10^(-R/10)

With some algebra, you can solve simultaneously for Wc and n given Ws, Rs and Wp, Rp. For high-pass filters, subtracting the band edges from Fs/2, performing the test, and swapping the resulting Wc back works beautifully. For bandpass- and bandstop-filters, this process significantly overdesigns. Artificially dividing n by 2 in this case helps a lot, but it still overdesigns.

Value

An object of class FilterOfOrder with the following list elements:

n

filter order

Wc

cutoff frequency

type

filter type, one of “low”, “high”, “stop”, or “pass”

This object can be passed directly to butter to compute filter coefficients.

Author(s)

Original Octave version by Paul Kienzle, pkienzle@user.sf.net. Conversion to R by Tom Short.

References

Octave Forge http://octave.sf.net

See Also

Examples

Fs <- 10000
btord <- buttord(1000/(Fs/2), 1200/(Fs/2), 0.5, 29)
plot(c(0, 1000, 1000, 0, 0), c(0, 0, -0.5, -0.5, 0),
     type = "l", xlab = "Frequency (Hz)", ylab = "Attenuation (dB)")
bt <- butter(btord)
plot(c(0, 1000, 1000, 0, 0), c(0, 0, -0.5, -0.5, 0),
     type = "l", xlab = "Frequency (Hz)", ylab = "Attenuation (dB)",
     col = "red", ylim = c(-10,0), xlim = c(0,2000))
hf <- freqz(bt, Fs = Fs)
lines(hf$f, 20*log10(abs(hf$h)))

signal

Signal Processing

v0.7-6
GPL-2
Authors
Uwe Ligges [aut, cre] (new maintainer), Tom Short [aut] (port to R), Paul Kienzle [aut] (majority of the original sources), Sarah Schnackenberg [ctb] (various test cases and bug fixes), David Billinghurst [ctb], Hans-Werner Borchers [ctb], Andre Carezia [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], E. Farhi [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Sebastian Krey [ctb], Bill Lash [ctb], Friedrich Leisch [ctb], Olaf Mersmann [ctb], Paulo Neis [ctb], Jaakko Ruohio [ctb], Julius O. Smith III [ctb], Doug Stewart [ctb], Andreas Weingessel [ctb]
Initial release
2015-07-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.