I expect to identify the first harmonic (FFT's pitch) by looking for the first batch of Matlab's fft
magnitude greater than half the maximum.
I suppose that in human's voice and in violin's sound the first harmonic's FFT magnitude is greater than half the maximum ( $2.3610
\cdot 10^8$ in code).
Then with the max
function I identify the first harmonic. What's the best snipet to catch the first batch greater than half the FFT magnitude?
I have posted this question at matlab yesterday but no answer yet. Regards.
SampFreq = 16000;
Segm = 1:2048;
Pitch = 45;
FirstHarmAngles = Pitch*2*pi/SampFreq*Segm+1.9*pi;
SinFirstHarmAngles = sin(FirstHarmAngles);
SecondHarmAngles = Pitch*2*2*pi/SampFreq*Segm+2.9*pi;
SinSecondHarmAngles = sin(SecondHarmAngles);
ThirdHarmAngles = Pitch*3*2*pi/SampFreq*Segm+0.3*pi;
SinThirdHarmAngles = sin(ThirdHarmAngles);
Xn=170000*SinFirstHarmAngles+220000*...
SinSecondHarmAngles+150000*...
SinThirdHarmAngles;
FFTXn = fft(Xn,16384);
FFTabs = abs(FFTXn);
plot(FFTabs(1:200));
maxabs = max(FFTabs);
for a = 1:8000
if FFTabs(a) > maxabs/2 && FFTabs(a+1) < maxabs/2
break
end
end
[maxInFirstBatch, FFTpitch] = max(FFTabs)
To address the issue, I have attached it below line plot(FFTabs(1:200));
in code.