Paul check with the code which WMAX posted how to obtain coefficients.
ns=4; % number of stages
f1=350;
f2=2000;
fsh=44100/2;
[z3,p3,k3]=butter(ns,[f1,f2]/fsh,'bandpass');
[s3,g3]=zp2sos(z3,p3,k3);
s3x=s3,[1,1,2,3,5,6]); s3x,2)=0;
bp=round((s3x*((2^15)-1)/2))
If this code is correct simply what we have to do is
ex:-
Stage 0 = 16384 0 32767 16384 -27508 11754
Stage 0, B0=16384*(1073741824.0),
B1 = 32767*(1073741824.0),
B2 = 16384 *(1073741824.0),
A1 = -27508* (1073741824.0),
A2 = 11754 * (1073741824.0)
Am i right ?
No it not correct:
Paul uses as coefficients (int) 2^31 and not short (2^15)
1073741824.0 = 2^30 = (2^31) /2
OK we can argue if we should subtract 1 to limit positive numbers or not.
it would be bp = s3x *2^30;
but better send to biquad.coefficients 's3x' as this function also allows float to be passed, as indicated by the documentation and the code you looked up.
the full code would be
Code:
[z3,p3,k3]=butter(ns,[f1,f2]/fsh,'bandpass');
[s3,g3]=zp2sos(z3,p3,k3);
s3x=s3(:,[1,2,3,5,6]); % NOTE: this is what audio biquad expects (it does ot want a0 only: b0,b1,b2,a1,a2)
bp=floor((s3x*2^30)) % make sure no overflow by using floor
Note: that this code is not consistent with coefficient generation code used by Paul.
have not figured out why