2
$\begingroup$

I already have a low-pass filter and want to remove the DC offset of a signal with a high-pass one. I guess you can subtract a low-pass filtered signal from the original signal and the result is a high-pass filtered signal?

My low-pass filter:

x = input, raw signal
y = output, low-pass filtered signal
n = current sample
n - 1 = previous sample

y(n) = y(n - 1) + (x(n) - y(n - 1)) / alpha

High-pass filter:

x = input, raw signal
y = input, low-pass filtered signal
z = output, high-pass filtered signal
n = current sample

z(n) = x(n) - y(n)

Is this last equation correct?

$\endgroup$
8
$\begingroup$

The result will indeed be a high pass filter. From your difference equation, the transfer function of the low pass filter is

$$H_l(z)=\frac{\beta}{1-(1-\beta)z^{-1}}\tag{1}$$

with $\beta=1/\alpha$. Note that this is actually a leaky integrator, not a classic low pass filter, because its frequency response does not have a zero at Nyquist.

The high pass filter has the transfer function

$$H_h(z)=1-H_l(z)=(1-\beta)\frac{1-z^{-1}}{1-(1-\beta)z^{-1}}\tag{2}$$

which has a zero at DC (i.e. at $z=1$), as it should. However, it is scaled, i.e. its value at Nyquist ($z=-1$) is not $1$, but $2(1-\beta)/(2-\beta)$. So in order to have a 0 dB gain at Nyquist, you need to scale your high pass filter with the inverse of that factor:

$$H'_h(z)=\frac{2-\beta}{2(1-\beta)}H_h(z)=\left(1-\frac{\beta}{2}\right)\frac{1-z^{-1}}{1-(1-\beta)z^{-1}}\tag{3}$$

EDIT:

You can compute the 3dB cut-off frequencies of the low pass filter (1) and of the high pass filter (2) by solving

$$|H_l(e^{j\omega_c})|^2=\frac12\quad\text{and}\quad |H'_h(e^{j\omega_c})|^2=\frac12$$

After some algebra this gives for the low pass filter

$$\cos\omega_c=1-\frac{\beta^2}{2(1-\beta)}$$

and for the high pass filter

$$\cos\omega_c=\frac{1}{1+\frac{\beta^2}{2(1-\beta)}}$$

where $\omega$ is the normalized frequency in radians:

$$\omega=2\pi\frac{f}{f_s}$$

with the sampling frequency $f_s$.

$\endgroup$
  • $\begingroup$ Thank you @Matt L. Is there a way to quantify the cutoff frequencies of the low and high-pass filters as a function of alpha? I'm new to much of this, so please forgive me if it's not just the 1 - beta term. $\endgroup$ – tarabyte Jan 25 '15 at 5:23
  • 1
    $\begingroup$ @tarabyte: I've added the formulas for the cut-off frequencies to my answer. $\endgroup$ – Matt L. Jan 25 '15 at 9:39
4
$\begingroup$

For an LTI system another method to generate a highpass filter impulse response $h_{hp}[n]$, from an existing lowpass filter impulse reponse $h_{lp}[n]$ is the following: $$h_{high}[n]=(-1)^n h_{low}[n]$$

From the DTFT properties we can see that: $$h_{high}[n]=e^{j\pi n} h_{low}[n]$$ $$H_{high}(e^{j\omega})=H_{low}(e^{j(\omega - \pi)})$$

which would produce a highpass filter from a lowpass filter, as a result of the right shift by $\pi$ in its spectrum. Note that this highpass filter will have the exact spectral shape of the prototype lowpass filter, however it won't be a complementary highpass counterpart of the given lowpass filter. Which means their spectral sum $H_{lp}(e^{j\omega}) + H_{hp}(e^{j\omega})$ is not unity. In your example, you would get the complementary filter if you use the definition as: $H_{hp}(e^{j\omega})= 1 - H_{lp}(e^{j\omega})$ assuming both DTFTs to be real (zero phase), if they are not, you may define the highpass filter as $$H_{high}(e^{j\omega})= e^{j\omega d} - H_{low}(e^{j\omega})$$

$\endgroup$

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.