I'm looking to implement the designing of a Butterworth filter based on the implementation in MATLAB/Scipy into C# but I've ran out of knowledge and can't quite seem how to compute the coefficients b
and a
based on the order and the normalised cutoff frequency.
I think that I am calculating z, p and k
correctly using:
var z = new double[0];
var m = new List<double>();
var start = -order + 1;
var step = 2;
while (start <= order)
{
m.Add(start);
start += step;
}
var complexP = new List<Complex>();
for (var i = 0; i < m.Count; i++)
{
complexP.Add(-Complex.Exp(Math.PI*m[i]/(2*order)));
}
var k = 1;
I believe that to calculate b and a
using z, p and k
I have to find the coefficients of a polynomial based on the root provided by p
. But I'm struggling to understand how you calculate a coefficient of a polynomial based on a root value.
I understand the result of this should always return 1 as the first value of the a
vector but I can't find anything that describes how to calculate the coefficient, perhaps I've found the answer but I've brushed past it.
For the b
value I believe that this is k * polynomialCoefficients(z)
.
Also to note is that I haven't taken into consideration the cutoff values in to how they relate to z, p and k
but this doesn't look too difficult and I don't think it will affect the question.
I'm not looking for this is how you do it in C#, but a general run down of how to calculate the coefficient would help.