# Problems designing high pass FIR filter with $f_\textrm{cutoff} \ll f_\textrm{s}$

Is there any inherant problems with high-passing a signal with a very low cutoff frequency compared to the sampling rate?

I'm not sure what I am missing as I cant find any info on it.

sample_rate = 250
nyq_rate = sample_rate / 2.0
f_hp_freq = 0.1
f_hp_transition = f_hp_freq + 0.1
numtaps = 125
b = signal.remez(numtaps, [0, f_hp_freq, f_hp_transition, nyq_rate], [0, 1], Hz=sample_rate, type='bandpass')


or

b = signal.firwin2(125, [0, f_hp_freq, f_hp_transition, nyq_rate], [0, 0, 1, 1], nyq=nyq_rate)


by reducing the sampling rate to less than $10\textrm{ Hz}$ or by significantly increasing the filter order < 1000 I can get acceptable results, but no other way. What am I overlooking?

@poipoikuroi: I don't think you are "overlooking" anything. If IIR filters are allowed you can build a simple "DC Blocking" filter with a narrow stopband (using floating-point arithmetic) centered at zero Hz. (Search the web for DC Blocker.) However, those filters have wildly nonlinear phase near zero Hz.

If linear phase is mandatory then your super-narrow stopband width requirement makes your FIR filter impractical due to needing thousands of taps. So as you've noticed, you'll have to either widen your stopband width or lower your data sample rate. I developed a computationally-efficient linear-phase DC blocking filter that uses cascaded moving average filters. Perhaps it might be of interest to you. See: https://www.dsprelated.com/showarticle/58.php

Does your eeg software package use one or two FIR filters to remove both DC and line noise? If your eeg software uses a single high-pass FIR to remove both DC and line noise, then I'll bet that filter's stopband width is, say, 90 or 100 Hz. (Which is much more "practical" than the FIR filter you're trying to design.)

You can understand the problem as follows:

The highpass should essentially filter out only the DC part (or almost only). Hence, its frequency domain response becomes roughly $H(f) = 1-\delta(f)$. Accordingly, its impulse response is rougly $h(t)=\delta(f)-1$ and is hence very very long. So, your FIR filter would need to have a very high order to achieve this low cutoff frequency.

• So what you are saying, my scenario is "impossible"/impractical? The mne eeg analyzation package says that it uses FIR filtering for removing line noise and dc offset I read somewhere in their docs. Not sure how they make that possible. – trondhe Dec 12 '16 at 18:27
• I just said you need a very high FIR filter order. Maybe, you can find a smaller order, when allowing IIR filters (but then having linear phase might not be possible). E.g. see embedded.com/design/configurable-systems/4007653/… and dsp.stackexchange.com/questions/17453/… – Maximilian Matthé Dec 12 '16 at 18:38

This is a well know problem with the Remez type algorithms. The first problem is that the usual formulas to predict the order of the filter needed to meet the spec do not perform well when the critical frequencies are near 0 or fs/2. So getting a reasonable estimate of the length of filter needed is difficult.

The second problem relates to the Remez type approach - it samples the frequency grid and then looks for the extreme points in the frequency domain and then adjusts the grid so that the deviation at these points is reduced. Then algorithm then repeats this procedure until it converges.

The problem is that the algorithm needs enough sample points in both the defined stopband and passband regions - if you don't have enough points then the algorithm can fail to converge. Many of the filter design algorithms (I believe Matlab, for example ) use the filter length as an estimate of the sampling grid density e.g. they may use 10 x as many points as the length of filter. This leads back to the first problem noted above, and the resulting grid may not be dense enough.

Even with a dense enough grid you can run into numerical issues. This typically shows up when your filter lengths get longer than 1000. Note - not every filter > 1000 points has problems.