# Designing High Pass Filter to Remove DC Offset from a Signal

I want to design a high pass filter (f0*S/1+f0*S) in order to remove the dc offset from a signal ? (i.e. how to choose the frequency f0).

Thanks, Hacene

Ps : the filter is for MATLAB implementation, this is why i would like to have it in continuous time.

• look at this article: digitalsignallabs.com/dcblock.pdf, if you're interesting in digital implementation – Serj Jul 24 '14 at 9:35
• You don't really take a typical highpass filter for DC removal. The more precise approach is more of a notch filter at $\omega=0$. You can achieve this by placing zeros at $s=0$ and the same number of poles at positions slightly shifted into the causal real half plane and imaginary part vanishing. The poles and zeros will cancel everywhere but close to DC, where you get a response of 0. – Jazzmaniac Jul 24 '14 at 13:41
• uhm, @Jazzmaniac, a notch filter with the notch at $\omega=0$ is a highpass filter. and a quite typical one at that. – robert bristow-johnson Dec 6 '14 at 20:10
• @robertbristow-johnson, read again what I wrote. I said "typical highpass", which in no way implies that the notch is not a highpass. But you're probably just disagreeing because it's me. – Jazzmaniac Dec 7 '14 at 12:52
• listen, Jazz, i am not trying to pick a fight. originally, all's i was saying was that, given a notch filter design that puts the notch at angular frequency $\omega_0$, if you use that design and set $\omega_0=0$, you will get a high-pass filter. that said, this transformation works in both directions. just as $$H_\text{BPF}(s)=H_\text{LPF}(s)\Bigg|_{s\leftarrow Q \left(\frac{s}{\omega_0}+\frac{\omega_0}{s} \right)}$$ the same filter transformation will turn a HPF into a BRF (a.k.a. "notch filter"). i can't remember how it's done for $z$, but with bilinear transformation, there is a way. – robert bristow-johnson Dec 8 '14 at 21:23

If the DFT is the Uniform sampling from $0$ to $2 \pi$ then the first bin is given by:

$$x[k] = \sum_{n = 0}^{N - 1} x[n]$$

Namely it is the sum of all the samples.
Hence in order to remove the DC (Mean) all you need is a filter which has zero in its DC bin. Since, the filtered signal, which is a convolution (Circular) of the DFT of the input signal and the filter will have zero at the first bin which means the sum of the output is zero which means its mean is also zero, as wanted.

Simple and intuitive FIT would be an FIR with the length of signal which removes from the current sample the mean of all samples:

$$y[m] = x[m] - \frac{1}{N} \sum_{n = 0}^{N - 1} x[n]$$

This is a simple FIR.

Pay attention I assumed you have all the samples. If you don't, you need to make this FIR casual by only "Calculating" the sum of given samples.

This should be a comment, but my reputation is too low to leave one.

Anyway, if you need to remove only the DC component you can just remove the mean value from your signal in this way:

y = x-mean(x);


Here you might find useful infos https://stackoverflow.com/questions/5591278/high-pass-filtering-in-matlab

• That works for many signals, but not all. One example is a signal with a very large but short positive transient, after which the signal has no DC. – MBaz Dec 9 '14 at 1:33

The way you wrote it, 1/f0 defines the -3dB cutoff frequency. This is easy to see if you let s = 1/f0. The numerator becomes 1 and the denominator becomes 2. A gain of 1/2 is -3dB.

Since it's high-pass, frequencies > 1/f0 will be passed through the filter while frequencies < 1/f0 will be attenuated (the lower the frequency, the greater the attenuation).

Use the MATLAB detrend() function to remove the mean or DC offset from the frequency domain point of view. If your signal is X, then try executing the following in the MATLAB command window,

Y = detrend(X,'constant');