I've got this code, but it keeps returning random frequencies from 0 to about 1050. Please can you help me understand why this is happening.
My data length is 1024, sample rate is 8192, and data is a short array filled with input data from the mic.
float *iSignal = new float[2048];
float *oSignal = new float[2048];
int pitch = 0;
for(x=0;x<=1024;x++) {
iSignal[x] = data[x];
}
fft(iSignal,oSignal,1024); //Input data, output data, length of input and output data
for(int y=0;y< 2048;y+=2) {
if((pow(oSignal[y],2)+pow(oSignal[y+1],2))>(pow(oSignal[pitch],2)+pow(oSignal[(pitch)+1],2))) {
pitch = y;
}
}
double pitchF = pitch / (8192.0/1024);
printf("Pitch: %f\n",pitchF);
Thanks,
Niall.
Edit: Changed the code, but it's still returning random frequencies.