11.07.2014 Views

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

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.

APPENDIX B. PROGRAM LISTINGS 263<br />

window, <strong>and</strong> choose the Minimum closest to the integer<br />

mark as the harmonic. */<br />

while(i < arraysize) {<br />

if(ha[i] >= right_bound) {<br />

i++;<br />

break;<br />

} else {<br />

if((ha[i] > left_bound) && (ha[i] < right_bound)) {<br />

if(found) {<br />

if(fabs(harmonic - ha[i]) < df) {<br />

df = fabs(harmonic - ha[i]);<br />

curharmonic = i;<br />

}<br />

} else {<br />

df = fabs(harmonic - ha[i]);<br />

curharmonic = i;<br />

found = 1;<br />

}<br />

}<br />

i++;<br />

}<br />

}<br />

/* if a minimum is found in this window, enter the rounded <strong>of</strong>f<br />

integer ratio <strong>and</strong> the impedance level <strong>of</strong> the harmonic into<br />

a Harmonic structure <strong>and</strong> insert this into a vector. */<br />

if(found && (ha[i - 1] >= harmonic)) {<br />

h = (Harmonic)malloc(size<strong>of</strong>(*h));<br />

h->n = round(ha[curharmonic]);<br />

h->Z = ((Minimum)elementAt(minv, pos + curharmonic + 1))->Z;<br />

addElement(harmv, h);<br />

}<br />

/* if last Minimum reached, break */<br />

if(i == arraysize)<br />

break;<br />

}<br />

/* return all found harmonics */<br />

return harmv;<br />

}<br />

double harmAvgZ(Vector harmv) {<br />

int i;<br />

int numharm;<br />

double totalZ = 0.0;<br />

double totalfraction = 0.0;<br />

Harmonic h;<br />

/* maximum number <strong>of</strong> harmonics averaged<br />

is either HARMONICS_AVERAGED or the number<br />

<strong>of</strong> harmonics present */<br />

if(sizeVector(harmv) < HARMONICS_AVERAGED)<br />

numharm = sizeVector(harmv);<br />

else<br />

numharm = HARMONICS_AVERAGED;<br />

/* if no harmonics present, return NaN */

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

Saved successfully!

Ooh no, something went wrong!