17.01.2013 Views

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Another 4-pole lowpass... (click this to go back to the index)<br />

Type : 4-pole LP/HP<br />

References : Posted by fuzzpilz [AT] gmx [DOT] net<br />

Notes :<br />

Vaguely based on the Stilson/Smith Moog paper, but going in a rather different direction from others I've seen here.<br />

The parameters are peak frequency and peak magnitude (g below); both are reasonably accurate for magnitudes above 1. DC gain is 1.<br />

The filter has some undesirable properties - e.g. it's unstable for low peak freqs if implemented in single precision (haven't been able to cleanly<br />

separate it into biquads or onepoles to see if that helps), and it responds so strongly to parameter changes that it's not advisable to update the<br />

coefficients much more rarely than, say, every eight samples during sweeps, which makes it somewhat expensive.<br />

I like the sound, however, and the accuracy is nice to have, since many filters are not very strong in that respect.<br />

I haven't looked at the HP again for a while, but IIRC it had approximately the same good and bad sides.<br />

Code :<br />

double coef[9];<br />

double d[4];<br />

double omega; //peak freq<br />

double g; //peak mag<br />

// calculating coefficients:<br />

double k,p,q,a;<br />

double a0,a1,a2,a3,a4;<br />

k=(4.0*g-3.0)/(g+1.0);<br />

p=1.0-0.25*k;p*=p;<br />

// LP:<br />

a=1.0/(tan(0.5*omega)*(1.0+p));<br />

p=1.0+a;<br />

q=1.0-a;<br />

a0=1.0/(k+p*p*p*p);<br />

a1=4.0*(k+p*p*p*q);<br />

a2=6.0*(k+p*p*q*q);<br />

a3=4.0*(k+p*q*q*q);<br />

a4= (k+q*q*q*q);<br />

p=a0*(k+1.0);<br />

coef[0]=p;<br />

coef[1]=4.0*p;<br />

coef[2]=6.0*p;<br />

coef[3]=4.0*p;<br />

coef[4]=p;<br />

coef[5]=-a1*a0;<br />

coef[6]=-a2*a0;<br />

coef[7]=-a3*a0;<br />

coef[8]=-a4*a0;<br />

// or HP:<br />

a=tan(0.5*omega)/(1.0+p);<br />

p=a+1.0;<br />

q=a-1.0;<br />

a0=1.0/(p*p*p*p+k);<br />

a1=4.0*(p*p*p*q-k);<br />

a2=6.0*(p*p*q*q+k);<br />

a3=4.0*(p*q*q*q-k);<br />

a4= (q*q*q*q+k);<br />

p=a0*(k+1.0);<br />

coef[0]=p;<br />

coef[1]=-4.0*p;<br />

coef[2]=6.0*p;<br />

coef[3]=-4.0*p;<br />

coef[4]=p;<br />

coef[5]=-a1*a0;<br />

coef[6]=-a2*a0;<br />

coef[7]=-a3*a0;<br />

coef[8]=-a4*a0;<br />

// per sample:<br />

out=coef[0]*in+d[0];<br />

d[0]=coef[1]*in+coef[5]*out+d[1];<br />

d[1]=coef[2]*in+coef[6]*out+d[2];<br />

d[2]=coef[3]*in+coef[7]*out+d[3];<br />

d[3]=coef[4]*in+coef[8]*out;<br />

Comments<br />

from : Christian@savioursofsoul.de<br />

comment : Yet untested object pascal translation:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!