Using xcorr in pitch detections
7 views (last 30 days)
Show older comments
I'm currently switching from fft to this function and I found some questions. What I have known is that we should calculate the frequency through comparing the positons of adjacent local maxima, but I don't know how I should use my maxima. I'm testing things with a 120Hz sine wave:
t=(0:999)*(1/1000); x = sin(2*pi*120*t); R = xcorr(x); [pks,locs]=findpeaks( R );
the locs have differences of 8 or 9, which is still correct ( 1/(9/1000) < 120 < 1/(8/1000) )
But I don't know how to get 120 as my answer using effective codes.
How much maxima should I count into the average value, etc?
And I don't think my code works with mixed frequencies... Can someone give me a direction?
0 Comments
Accepted Answer
Daniel Shub
on 22 Aug 2011
Pitch detection is a huge field with many different algorithms each with advantages and disadvantages. How close to 120 do you need to get. What i your answer is 121, 120.1, 120.01, ...
One easy way to get around the problem is to increase your sampling rate.
Fs = 1e6;
t=(0:(Fs-1))*(1/Fs);
x = sin(2*pi*120*t);
R = xcorr(x);
[pks,locs]=findpeaks(R);
[min(Fs./diff(locs)), mean(Fs./diff(locs)), max(Fs./diff(locs))]
ans =
119.9904 120.0000 120.0048
6 Comments
Daniel Shub
on 24 May 2012
That is a lot of questions. Why don't you try and implement something with this code and see where you get stuck. Also if the answer is helpful, consider voting for it.
More Answers (0)
See Also
Categories
Find more on Measurements and Spatial Audio in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!