3
$\begingroup$

As descipbed in this great answer (thank you Matt L.), the suggested exact formula was very precise. I need a first order high-pass with similar precision.

EDIT: (clarification) The low-pass filter discussed in the link above was this one, derived from the simple RC filter. What I'm looking for is the discrete version of the simple high-pass RC filter with a formula for getting the exact alpha term (that's what Matt L. did) for an amplitude response of -3dB at a given cutoff frequency.

I've tried and measured the low pass version and it worked as expected.

$\endgroup$
2
  • $\begingroup$ could you put numbers to what you mean with "similar precision"? What kind of high-pass filter, i.e. cutting of where exactly? You don't really have a lot of degrees of freedom in a first-order system. To be exact, you have exactly two parameters you can adjust, at all. Now, I trust you have looked up the formulas describing the frequency response resulting from the choice of these two numbers, so could you try to specify what the question is? $\endgroup$ Jun 28, 2020 at 0:21
  • $\begingroup$ Thank you Mr Müller, I've edited my question. $\endgroup$ Jun 28, 2020 at 5:02

2 Answers 2

8
$\begingroup$

A discrete-time first-order high pass filter with unity gain at Nyquist and a zero at DC is described by the following difference equation:

$$y[n]=\frac{1+\alpha}{2}\big(x[n]-x[n-1]\big)+\alpha y[n-1],\qquad -1<\alpha<1\tag{1}$$

Its transfer function is given by

$$H(z)=\frac{1+\alpha}{2}\frac{1-z^{-1}}{1-\alpha z^{-1}}\tag{2}$$

Evaluating the squared magnitude of $(2)$ on the unit circle $z=e^{j\omega}$ and equating it to $\frac12$ ($-3$ dB) results in the following relation between $\alpha$ and the $3$ dB cut-off frequency $\omega_c$:

$$\begin{align}\big|H(e^{j\omega_c})\big|^2&=\frac{(1+\alpha)^2}{4}\frac{\left|1-e^{-j\omega_c}\right|^2}{\left|1-\alpha e^{-j\omega_c}\right|^2}\\&=\frac{(1+\alpha)^2}{4}\frac{2\big(1-\cos(\omega_c)\big)}{1-2\alpha\cos(\omega_c)+\alpha^2}\stackrel{!}{=}\frac12\tag{3}\end{align}$$

Eq. $(3)$ results in a quadratic equation for $\alpha$ with the solution

$$\alpha=\begin{cases}\displaystyle\frac{1-\sin(\omega_c)}{\cos(\omega_c)},&\omega_c\in(0,\pi)\setminus \frac{\pi}{2}\\0,&\omega_c=\frac{\pi}{2}\end{cases}\tag{4}$$

(where the requirement $|\alpha|<1$) has been taken into account).

For $\omega_c=\pi/2$ we obtain $\alpha=0$ and the corresponding filter is a simple $2$-tap FIR filter. All other cut-off frequencies $\omega_c\in(0,\pi)$ result in IIR filters.

The figure below shows the magnitude responses of $9$ high-pass filters with specified cut-off frequencies $0.1\pi,0.2\pi, \ldots,0.9\pi$. The corresponding values for $\alpha$ were computed according to Eq. $(4)$.

enter image description here

$\endgroup$
3
  • $\begingroup$ When taking the quadratic, both roots give identical magnitude, but inverted phase response. Aside from an awareness of the filter type (ie. LP, HP), is there a guide on which root to pick? $\endgroup$
    – bazz
    Mar 17 at 19:48
  • $\begingroup$ @bazz: The correct root is determined by the stability condition $|\alpha|<1$. The other root always results in an unstable solution. $\endgroup$
    – Matt L.
    Mar 18 at 7:47
  • $\begingroup$ Thank you. By putting eq. 2 into factored form we can observe how $\alpha$ plays a role on the poles and zeros. For this equation we have a pole directly at $\alpha$ which is why alpha must be in [-1, 1], right? It's to be kept within the unit circle. $\endgroup$
    – bazz
    Mar 18 at 19:00
2
$\begingroup$

Here are couple examples:

% R is the resistance value (in ohms)
% C is the capacitance value (in farrads)
% fs is the digital sample rate (in Hz)

% Constants
RC = R * C;
T  = 1 / fs;

% Analog Cutoff Fc
w = 1 / (RC);

% Prewarped coefficient for Bilinear transform
A = 1 / (tan((w*T) / 2));

% using Bilinear transform of
%
%             1          ( 1 - z^-1 )
% s -->  -----------  *  ------------
%         tan(w*T/2)     ( 1 + z^-1 )
%

b(1) = (A)/(1+A);
b(2) = -b(1);
a(2) = (1-A)/(1+A);

and an alternative implementation could be:

w = 2.0 * pi * fc/fs;
cx = cos(w);
sx = sin(w);
b0 =   cx + 1;
b1 = -(cx + 1);
a0 =   cx + sx + 1;
a1 =   sx - cx - 1;
$\endgroup$
1
  • $\begingroup$ Great answer! It was really hard to decide the accepted one between yours and Matt's but I had to choose one. Matt's answer was complemented with clear explanations and well presented. BTW I evaluated and plotted all three propositions and they were correct and identical. $\endgroup$ Jun 28, 2020 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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