0

I'm trying to implement the Butterworth filter as a high pass filter inside a function, where every time stip a measurement will be passed (inside this function I do have buffers for storing the data).

However, I'm using the Matlab built-in function butter to calculate the coefficient. The problem is the filtered signal starts to diverge.

I can tell that this diverge comes because of the discretization but is there any way to solve this issue without high complexity?

Marcus Müller
  • 30,525
  • 4
  • 34
  • 58
jon
  • 9
  • 2
  • 1
    We can't really tell what's happening without looking at your code and a lot more details – Hilmar Aug 09 '22 at 14:09
  • Please edit your question to tell us: are you calculating the coefficients in the Laplace domain then translating them to the z domain, or are you generating the coefficients directly in the z domain? If you're translating, what transform? What is your filter order? Are you realizing the filter as a cascade of 2nd-order sections, or as one giant high-order filter? What algorithm are you using to realize your filter? Personally, I don't look at code unless I can help it, so if, in addition to posting your code, you also post your filter coefficients in the z domain, that will help. – TimWescott Aug 09 '22 at 19:19
  • Sorry for the late answer, but I found out that my implementation is true and the problem is caused when I have a really small cut-off frequency (10^-4) – jon Aug 10 '22 at 11:44
  • 1
    @jon You're running into numerical problems, see this answer for some workarounds. But if your poles are reeealy close to the origin, you're asking for trouble, unless you have GMP or similar. – a concerned citizen Aug 10 '22 at 14:03
  • Yes it is a numerical problem :( – jon Aug 10 '22 at 16:22
  • jon, you're having a numerical problem computing coefficients for a high-pass filter (HPF) with a very low cut-off frequency (relative to Nyquist). Have you tried using the formulae at the Audio EQ Cookbook? Use that and then use this trig identity: $$ 1 - \cos(\omega) \ = \ 2 \sin^2 \left( \frac{\omega}{2} \right) $$ and re-jigger your coefficient formulae. I think you'll have less trouble with numerical probs. – robert bristow-johnson Aug 10 '22 at 19:42
  • Thanks a lot, it sounds really helpful – jon Aug 11 '22 at 08:13

0 Answers0