I have been working on a Harmonic Product Spectrum Algorithm. Now, all the literature I've read about the subject tells me to downsample an N amount of times. How does one determine what this N value should be? Here is my implementation of Harmonic Product Spectrum so far. Feel free to tell me if I have gone wrong somewhere.
private int HarmonicProductSpectrum(Complex[] fftData, int n){
Complex[][] data = new Complex[n][fftData.length/n];
for(int i = 0; i<n; i++){
for(int j = 0; j<data[0].length; j++){
data[i][j] = fftData[j*(i+1)];
}
}
Complex[] result = new Complex[fftData.length/n];//Combines the arrays
for(int i = 0; i<result.length; i++){
Complex tmp = new Complex(1,0);
for(int j = 0; j<n; j++){//multiplies arrays together
tmp = tmp.times(data[j][i]);
}
result[i] = tmp;
}
//Calculates Maximum Magnitude of the array
double max = Double.MIN_VALUE;
int index = -1;
for(int i = 0; i<result.length; i++){
Complex c = result[i];
double tmp = c.getMagnitude();
if(tmp>max){
max = tmp;;
index = i;
}
}
return index*getFFTBinSize(fftData.length);
}