I tried to use bessel filter from here, but in the case of a large dataset, I have overshoot. Since I know a bessel filter shouldn't have overshoot, is this code wrong or am I doing something else wrong?

// Sample rate : 1e9
// Cut off Frequency : 50e6

int s=50000;
double[] sample = new double[s];

for(int i=s/2; i<s; i++) {
  sample[i] = 1.0;

for (int i = 0; i<sample.length; i++) {
    xv[0] = xv[1];
    xv[1] = xv[2];
    xv[2] = xv[3]; 
    xv[3] = sample[i] / GAIN;
    yv[0] = yv[1]; 
    yv[1] = yv[2]; 
    yv[2] = yv[3]; 
    yv[3] = (xv[0] + xv[3]) + 3 * (xv[1] + xv[2])
          + (  0.3402988787 * yv[0]) 
          + ( -1.4152725242 * yv[1])
          + (  2.0223552191 * yv[2]);
    filteredValue[i] = yv[3];

All coefficients have been calculated based on source on given website, it might been messy because its used for chebyshev and butterworth filters as well.


migrated from stackoverflow.com Aug 14 '12 at 12:59

This question came from our site for professional and enthusiast programmers.

  • $\begingroup$ More information would be helpful. Do you have example code or at least a plot that could show what you're asking about? $\endgroup$ – Jason R Aug 14 '12 at 15:21
  • $\begingroup$ example of code you have on website what i used, it automatically generated filter for given parameters. In my case parameters does not different, my graph has large overshoot if i use large dataset (100k elements, for smaller set (50 elements) overshoot is smaller, barely noticeable $\endgroup$ – user902383 Aug 15 '12 at 10:29
  • $\begingroup$ You need to provide much more information than you've given in order to get a good answer. We can't tell if you've done something wrong unless we see some indication of what you've actually done. While the linked page does generate C code that can implement a filter, it is not complete. A full example, or at the bare minimum, plots of what you're seeing would be needed. $\endgroup$ – Jason R Aug 15 '12 at 12:48
  • $\begingroup$ unfortunately i cant add plot because i dont have required reputation $\endgroup$ – user902383 Aug 15 '12 at 14:59

It's not exactly clear what you mean by overshoot. Let's define it as "when filtering a square wave, the max of of the the output should not exceed the steady state of max of the square wave".

In this case your statement "as i know bessel filter shouldnt have overshoot" is wrong. A bessel filter will indeed overshoot. A few first order filters will not overshoot (butterworth, chebychev, ...) but any filter of order > 1 will overshoot.

  • 1
    $\begingroup$ +1: A Bessel filter does overshoot. However, there are a few other filters of order >1 that don't overshoot. $\endgroup$ – David Cary Aug 20 '12 at 15:46
  • $\begingroup$ Gaussian filters don't overshoot (but also require predicting the future) $\endgroup$ – endolith Mar 29 '16 at 0:03
  • $\begingroup$ Bessel filters tend to have a very slight overshoot which is "felt" for the lower orders. As higher orders come into play, the overshoot converges towards zero, more precisely the filters converges towards an ideal delay, exp(-s). Here's a step response for a sweep from N=2..20: imgur.com/SVgSse0 . Gaussian filters do not overshoot, but precise matching is required for any of its approximations of any order (though matching is true for any filter). $\endgroup$ – a concerned citizen Sep 30 '16 at 13:53

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.