1
$\begingroup$

I'm trying to calculate the Butterworth filter gain. If I use the formula mentioned on Wikipedia: $$ G^2(\omega) = \frac{G_0^2} {1+\left(\frac{j\omega}{j\omega_c}\right)^{2n}} $$

I don't get a matching result from calculating the gain directly from the filter's magnitude using R's signal package.

library(signal)

# Butterworth filter


# Gain formula from wikipedia
Butterworth_gain <- function(freq, cutoff_frequency, n = 1) {
        1/(1+(freq/cutoff_frequency)^(2*n))
    
}

bf <- butter(n = 2, W = .6, type = "low")
bfr <- freqz(bf)

plot(bfr$f, abs(bfr$h)^2, ty ='l')
lines(bfr$f, Butterworth_gain(bfr$f,  pi*.6, n = 2), col = 'red')

enter image description here

$\endgroup$
1
$\begingroup$

The function butter() computes the coefficients of a discrete-time ("digital") Butterworth filter, whereas the gain formula you used is valid for a continuous-time ("analog") Butterworth filter. According to the R documentation you can use butter() to compute an analog filter using the plane argument.

The gain of a discrete-time Butterworth filter is obtained by the bilinear transform, which substitutes the "analog" frequency variable by $\tan(\omega/2)$, where $\omega$ is the frequency in radians, normalized by the sampling frequency. For a discrete-time unit gain lowpass filter of order $n$, the squared gain is given by

$$G^2(\omega)=\frac{1}{1+\left(\frac{\tan(\omega/2)}{\tan(\omega_c/2)}\right)^{2n}},\qquad |\omega|\le\pi\tag{1}$$

$\endgroup$
6
  • $\begingroup$ I see, thank you! I actually need an expression for the filter's gain in order to be able to estimate the filter's cutoff frequency and order from a filtered signal where I know the true spectrum. Any advice on what to look for? $\endgroup$ – Crataegus Feb 23 at 12:30
  • 1
    $\begingroup$ @Crataegus: You mean the gain of a digital Butterworth filter? $\endgroup$ – Matt L. Feb 23 at 12:51
  • $\begingroup$ yes exactly, ideally I want to have an expression similar to the one mentioned in Wikipedia but for a digital filter. $\endgroup$ – Crataegus Feb 23 at 13:00
  • 1
    $\begingroup$ @Crataegus: I've added the formula for the discrete-time case. $\endgroup$ – Matt L. Feb 23 at 14:06
  • $\begingroup$ It looks like OP is using the squared formula, but is the built-in one also squared? $\endgroup$ – a concerned citizen Feb 23 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.