1
$\begingroup$

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.

$\endgroup$

1 Answer 1

2
$\begingroup$

I suppose, in human's voice and in violin's sound first harmonic's fft abs is greater than half the maximum

You are supposing wrong. The harmonic structure can be quite complicated and sometimes the fundamental is entirely missing or very weak.

(FFT's pitch)

The sound has a pitch, but the FFT doesn't have one. In fact FFT is not a great method for pitch detection because of limited frequency resolution and spectral leakage

What's the best snipet for catch first batch greater than half the "FFTabs"?

index = find(FFTabs > 0.5*max(FFTabs)); will give the indices of all values in the FFT that exceed half the max, but it's not going to help you much, I'm afraid.

$\endgroup$
3
  • $\begingroup$ Dear sir, please let me express you my sincere gratitude for you answered my question, and more for your helpful instructions. Then do you suggest me matlab's pitch function? Regards. $\endgroup$ Commented Oct 22, 2022 at 12:09
  • $\begingroup$ Assuming you want to do audio pitch detection: there is large body of research around this. A good starting point is this ccrma.stanford.edu/~pdelac/154/m154paper.htm. For high precision audio tuners, I prefer PLLs $\endgroup$
    – Hilmar
    Commented Oct 22, 2022 at 16:19
  • $\begingroup$ Dear sir, many thanks for your additional information. Regards. $\endgroup$ Commented Oct 24, 2022 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.