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

kaiserord

Kaiser filter order and cutoff frequency


Description

Return the parameters needed to produce a FIR filter of the desired specification from a Kaiser window.

Usage

kaiserord(f, m, dev, fs = 2)

Arguments

f

frequency bands, given as pairs, with the first half of the first pair assumed to start at 0 and the last half of the last pair assumed to end at 1. It is important to separate the band edges, since narrow transition regions require large order filters.

m

magnitude within each band. Should be non-zero for pass band and zero for stop band. All passbands must have the same magnitude, or you will get the error that pass and stop bands must be strictly alternating.

dev

deviation within each band. Since all bands in the resulting filter have the same deviation, only the minimum deviation is used. In this version, a single scalar will work just as well.

fs

sampling rate. Used to convert the frequency specification into the c(0, 1) range, where 1 corresponds to the Nyquist frequency, fs / 2.

Details

Given a set of specifications in the frequency domain, kaiserord estimates the minimum FIR filter order that will approximately meet the specifications. kaiserord converts the given filter specifications into passband and stopband ripples and converts cutoff frequencies into the form needed for windowed FIR filter design.

kaiserord uses empirically derived formulas for estimating the orders of lowpass filters, as well as differentiators and Hilbert transformers. Estimates for multiband filters (such as band-pass filters) are derived from the low-pass design formulas.

The design formulas that underlie the Kaiser window and its application to FIR filter design are

β =

0.1102(α - 8.7), α > 50

0.5842(α -21)^{0.4} + 0.07886(α - 21), 21 ≤ α ≤ 50

0, α < 21

where α = -20log_{10}(δ) is the stopband attenuation expressed in decibels, n=(α - 8) / 2.285(Δω), where n is the filter order and Δω is the width of the smallest transition region.

Value

A list of class FilterSpecs with the following list elements:

n

filter order

Wc

cutoff frequency

type

filter type, one of "low", "high", "stop", "pass", "DC-0", or "DC-1".

beta

shape parameter

Author(s)

Paul Kienzle.
Conversion to R by Tom Short,
adapted by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

See Also

Examples

fs <- 11025
op <- par(mfrow = c(2, 2), mar = c(3, 3, 1, 1))
for (i in 1:4) {
  if (i == 1) {
    bands <- c(1200, 1500)
    mag <- c(1, 0)
    dev <- c(0.1, 0.1)
  }
  if (i == 2) {
    bands <- c(1000, 1500)
    mag <- c(0, 1)
    dev <- c(0.1, 0.1)
  }
  if (i == 3) {
    bands <- c(1000, 1200, 3000, 3500)
    mag <- c(0, 1, 0)
    dev <- 0.1
  }
  if (i == 4) {
    bands <- 100 * c(10, 13, 15, 20, 30, 33, 35, 40)
    mag <- c(1, 0, 1, 0, 1)
    dev <- 0.05
  }
  kaisprm <- kaiserord(bands, mag, dev, fs)
  d <- max(1, trunc(kaisprm$n / 10))
  if (mag[length(mag)] == 1 && (d %% 2) == 1) {
     d <- d + 1
  }
  f1 <- freqz(fir1(kaisprm$n, kaisprm$Wc, kaisprm$type,
                   kaiser(kaisprm$n + 1, kaisprm$beta),
                   scale = FALSE),
              fs = fs)
  f2 <- freqz(fir1(kaisprm$n - d, kaisprm$Wc, kaisprm$type,
                   kaiser(kaisprm$n - d + 1, kaisprm$beta),
                   scale = FALSE),
              fs = fs)
  plot(f1$w, abs(f1$h), col = "blue", type = "l",  xlab = "", ylab = "")
  lines(f2$w, abs(f2$h), col = "red")
  legend("right", paste("order", c(kaisprm$n-d, kaisprm$n)),
         col = c("red", "blue"), lty = 1, bty = "n")
  b <- c(0, bands, fs/2)
  for (i in seq(2, length(b), by=2)) {
    hi <- mag[i/2] + dev[1]
    lo <- max(mag[i/2] - dev[1], 0)
    lines(c(b[i-1], b[i], b[i], b[i-1], b[i-1]), c(hi, hi, lo, lo, hi))
  }
}
par(op)

gsignal

Signal Processing

v0.3-1
GPL-3
Authors
Geert van Boxtel [aut, cre] (Maintainer), Tom Short [aut] (Author of 'signal' package), Paul Kienzle [aut] (Majority of the original sources), Ben Abbott [ctb], Juan Aguado [ctb], Muthiah Annamalai [ctb], Leonardo Araujo [ctb], William Asquith [ctb], David Bateman [ctb], David Billinghurst [ctb], Juan Pablo Carbajal [ctb], André Carezia [ctb], Vincent Cautaerts [ctb], Eric Chassande-Mottin [ctb], Luca Citi [ctb], Dave Cogdell [ctb], Carlo de Falco [ctb], Carne Draug [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], R.G.H Eschauzier [ctb], Andrew Fitting [ctb], Alan J. Greenberger [ctb], Mike Gross [ctb], Daniel Gunyan [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Jake Janovetz [ctb], Alexander Klein [ctb], Peter V. Lanspeary [ctb], Bill Lash [ctb], Friedrich Leissh [ctb], Laurent S. Mazet [ctb], Mike Miller [ctb], Petr Mikulik [ctb], Paolo Neis [ctb], Georgios Ouzounis [ctb], Sylvain Pelissier [ctb], Francesco Potortì [ctb], Charles Praplan [ctb], Lukas F. Reichlin [ctb], Tony Richardson [ctb], Asbjorn Sabo [ctb], Thomas Sailer [ctb], Rolf Schirmacher [ctb], Rolf Schirmacher [ctb], Ivan Selesnick [ctb], Julius O. Smith III [ctb], Peter L. Soendergaard [ctb], Quentin Spencer [ctb], Doug Stewart [ctb], P. Sudeepam [ctb], Stefan van der Walt [ctb], Andreas Weber [ctb], P. Sudeepam [ctb], Andreas Weingessel [ctb]
Initial release
2021-05-02

We don't support your browser anymore

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