9
$\begingroup$

I'm trying to HP-filter a signal by LP-filtering it and subtracting the output from the original filter. To obtain the LP-filtered signal, I backward-forward filtered using a third-order Butterworth filter for a 16,000-sample signal. The cutoff frequency was 0.5 Hz @ 250 Hz. No window was used.

In the first 85% or so of samples, the output of this method seems to overlap completely with the actually HP-filtered signal. However, at the end of the output, there is a supsiciously sinc-like phenomenon.

  • What causes it?
  • What could I change to make this method feasible?

Here are the two signals overlaid. The blue one is HP-filtered, and the red one obtained by subtraction.

HP and orig-LP signals

Here is the absolute difference per sample. They are never exactly equal; the minimum difference is 8e-12. 87% of the values are below 0.01.

difference between the two methods

(If there's a better way to obtain an HP filter from an LP filter's $H(z)$, I'd be happy to learn it.)

$\endgroup$
  • $\begingroup$ Can you include the MATLAB code that you're using to generate the plots? The data isn't important; you could just simulate it with random samples instead if needed. $\endgroup$ – Jason R Nov 11 '11 at 22:21
0
$\begingroup$

Methinks @hotpaw2 is on the right track. My guess is that filtfilt is not handling the initial conditions for the reverse filter quite right. It sounds like a really hard problem -- I don't think I can fault Mathworks for getting it wrong...

The fix seems easy enough to me: zero-pad the end of your signal until the sinc goes away, and delete the (now nonzero!) padding after the filter.

$\endgroup$
0
$\begingroup$

You are doing a backwards-forwards filter for one, and a forwards-only filter for the other. Thus the two filters will behave differently at one or both edges.

If your signal is strongly stationary and exactly periodic in the data window length, you could try wrapping the data around circularly and start your filters outset by their impulse response lengths.

$\endgroup$
  • $\begingroup$ Sorry if I wasn't clear enough. The signal that I'm comparing to (blue) is also forward-backward filtered (filtfilt and butter(3,0.5/250,high)). The signal is from an ECG that I can't expect to be exactly periodic. $\endgroup$ – Andreas Nov 8 '11 at 17:25
  • $\begingroup$ Am I misunderstanding something? I can't understand the upvote as the first paragraph is clearly wrong. $\endgroup$ – Andreas Nov 10 '11 at 8:42

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.