Using xcorr in pitch detections
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Daniel Shub
2011-8-22
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 个评论
Daniel Shub
2012-5-24
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Spatial Audio 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!