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.

Formant filter (click this to go back to the index)<br />

References : Posted by Alex<br />

Code :<br />

/*<br />

Public <strong>source</strong> <strong>code</strong> by alex@smartelectronix.com<br />

Simple example of implementation of formant filter<br />

Vowelnum can be 0,1,2,3,4 A,E,I,O,U<br />

Good for spectral rich input like saw or square<br />

*/<br />

//-------------------------------------------------------------VOWEL COEFFICIENTS<br />

const double coeff[5][11]= {<br />

{ 8.11044e-06,<br />

8.943665402,-36.83889529,92.01697887,-154.337906,181.6233289,<br />

-151.8651235, 89.09614114,-35.10298511,8.388101016,-0.923313471 ///A<br />

},<br />

{4.36215e-06,<br />

8.90438318,-36.55179099,91.05750846,-152.422234,179.1170248, ///E<br />

-149.6496211,87.78352223,-34.60687431,8.282228154,-0.914150747<br />

},<br />

{ 3.33819e-06,<br />

8.893102966,-36.49532826,90.96543286,-152.4545478,179.4835618,<br />

-150.315433,88.43409371,-34.98612086,8.407803364,-0.932568035 ///I<br />

},<br />

{1.13572e-06,<br />

8.994734087,-37.2084849,93.22900521,-156.6929844,184.596544, ///O<br />

-154.3755513,90.49663749,-35.58964535,8.478996281,-0.929252233<br />

},<br />

{4.09431e-07,<br />

8.997322763,-37.20218544,93.11385476,-156.2530937,183.7080141, ///U<br />

-153.2631681,89.59539726,-35.12454591,8.338655623,-0.910251753<br />

}<br />

};<br />

//--------------------------------------------------------------------------------static<br />

double memory[10]={0,0,0,0,0,0,0,0,0,0};<br />

//--------------------------------------------------------------------------------float<br />

formant_filter(float *in, int vowelnum)<br />

{<br />

res= (float) ( coeff[vowelnum][0] *in +<br />

coeff[vowelnum][1] *memory[0] +<br />

coeff[vowelnum][2] *memory[1] +<br />

coeff[vowelnum][3] *memory[2] +<br />

coeff[vowelnum][4] *memory[3] +<br />

coeff[vowelnum][5] *memory[4] +<br />

coeff[vowelnum][6] *memory[5] +<br />

coeff[vowelnum][7] *memory[6] +<br />

coeff[vowelnum][8] *memory[7] +<br />

coeff[vowelnum][9] *memory[8] +<br />

coeff[vowelnum][10] *memory[9] );<br />

memory[9]= memory[8];<br />

memory[8]= memory[7];<br />

memory[7]= memory[6];<br />

memory[6]= memory[5];<br />

memory[5]= memory[4];<br />

memory[4]= memory[3];<br />

memory[3]= memory[2];<br />

memory[2]= memory[1];<br />

memory[1]= memory[0];<br />

memory[0]=(double) res;<br />

return res;<br />

}<br />

Comments<br />

from : rhettanderson@yahoo.com<br />

comment : Where did the coefficients come from? Do they relate to frequencies somehow? Are they male or female? Etc.<br />

from : el98shn@ing.umu.se<br />

comment : And are the coeffiecients for 44k1hz?<br />

/stefancrs<br />

from : meeloo@meeloo.net<br />

comment : It seem to be ok at 44KHz although I get quite lot of distortion with this filter.<br />

There are typos in the given <strong>code</strong> too, the correct version looks like this i think:<br />

float formant_filter(float *in, int vowelnum)<br />

{<br />

float res= (float) ( coeff[vowelnum][0]* (*in) +<br />

coeff[vowelnum][1] *memory[0] +<br />

coeff[vowelnum][2] *memory[1] +<br />

coeff[vowelnum][3] *memory[2] +<br />

coeff[vowelnum][4] *memory[3] +<br />

coeff[vowelnum][5] *memory[4] +<br />

coeff[vowelnum][6] *memory[5] +<br />

coeff[vowelnum][7] *memory[6] +<br />

coeff[vowelnum][8] *memory[7] +<br />

coeff[vowelnum][9] *memory[8] +<br />

coeff[vowelnum][10] *memory[9] );

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

Saved successfully!

Ooh no, something went wrong!