1
$\begingroup$

I'm very new to signal processing, but was asked to implement a filter function for Butterworth low pass filter for given order, cutoff frequency and sample rate.

After reading some articles I think i figured out what I have to do is:

  1. Calculate the poles of the digital transfer function H(s)
  2. Use bilinear transformation to get the poles of the analog transfer function H(z)
  3. Write difference equation with y(k) = ...

For now I implemented the calculation of the poles, which seems to work:

     public class ButterworthBase
  {
    private const double Gain = 1; // Gain for Butterworth 

    public ButterworthBase(int order, double cutoffFrequency, double sampleRate)
    {
      // calc digital cutoff frequency
      double wc = 2 * Math.PI * cutoffFrequency;

      var poles = new ImaginaryNumber[order];

      // calc poles TODO: calc only (order) n / 2 poles => mirror real axis to get the other n/2 poles
      for (int k = 1; k <= order; k++)
      {
        // poles[k] = wc * Math.Exp( i * exponent);

        double exponent = (Math.PI / (2.0 * (double)order)) * (2.0 * k + (double)order - 1.0);
        double real = Math.Cos(exponent);
        double imaginary = Math.Sin(exponent);
        poles[k - 1] = new ImaginaryNumber(wc * real, wc * imaginary);
      }

      // bilinear transformation of poles:
      var transformedPoles = new ImaginaryNumber[order];

      for (int k = 1; k <= order; k++)
      {
        var transformedPole = new ImaginaryNumber(0, 0);



        transformedPoles[k - 1] = transformedPole;
      }
    }
  }

  public class ImaginaryNumber
  {
    public double Real { get; }
    public double Imaginary { get; }

    public ImaginaryNumber(double real, double imaginary)
    {
      Real = real;
      Imaginary = imaginary;
    }
  }

I'm struggling at the transformation, I know the transfer function is s -> 2/T (1-z^-1)/(1+z^-1) where T = sampling period.

Can anyone help me please?

$\endgroup$
  • $\begingroup$ Welcome to DSP.SE! This is close to off-topic ("Writing code to a specification.") but I think it's close enough to not being that because you've explained what you don't understand, so I'll leave it open. An answer could involve no code, but still be acceptable. $\endgroup$ – Peter K. Mar 9 '18 at 14:37
  • 2
    $\begingroup$ Thanks Peter. You don't have to implement a solution for me. Implementing is a minor problem. I'm just a little bit confused what to do now. I let my code run for order = 4 and calculated 4 imaginary poles. But how do I transform them now? $\endgroup$ – user3292642 Mar 9 '18 at 14:50
  • $\begingroup$ Does this answer help? $\endgroup$ – Matt L. Mar 9 '18 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.