This is a biquad implementation I use:
float my_biquad(float in, float *coeffs, int scalefactor, float *delay)
{
float out = coeffs[2] * in + delay[0];
out = out * (float)pow( 2, scalefactor );
delay[0] = delay[1] + coeffs[1]*in - coeffs[4]*out;
delay[1] = coeffs[0]*in - coeffs[3]*out;
// etc...
return out;
}
It cascades several biquads:
for(int j=0;j<num_biquads;j++)
{
tmp = biquad(...);
}
Each biquad has its coefficients and a scalefactor. Scalefactor is integer.
On the other hand, I have a Matlab filter:
[B_coeffs, A_coeffs ] = butter(4, 100/(16000/2), 'high');
I need to implement the Matlab filter using the above biquad.
I tried using tf2sos
which gave me two biquad sections:
[ss, gn] = tf2sos(B_coeffs, A_coeffs);
but feeding ss
coefficients to biquad
in C gave different results than Matlab version. Gain gn
is left unused, and I don't even have scalefactors
.
How do I go from Matlab to this particular version of biquad in C? How to create proper coeffs
and scalefactors
?
out = out * (float)pow( 2, scalefactor );
. This produces the same result as Matlab version. $\endgroup$