-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a new algorithm #23
a new algorithm #23
Conversation
I do not think that @cwilso is actively accepting pull requests at this time, seeing that this previous pull request has not yet been accepted. Might I suggest you apply your pull requests here? That is, if your work is applicable, as I know that @markmarijnissen has made quite a few changes himself. |
Also, can you make it more descriptive? |
Also, I am - I've just been very busy. Will take a look over break.
…On Sun, Dec 4, 2016 at 3:30 PM, Dawid Pregel ***@***.***> wrote:
Also, can you make it more descriptive?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAe8eVcAxWRKVM_uHSj5HU0j739mMY8Kks5rE0z9gaJpZM4Ks9Em>
.
|
Hello again! I've been really afk. this is how I would tag the 4 steps // trim
var r1=0, r2=SIZE-1, thres=0.2;
for (var i=0; i<SIZE/2; i++)
if (Math.abs(buf[i])<thres) { r1=i; break; }
for (var i=1; i<SIZE/2; i++)
if (Math.abs(buf[SIZE-i])<thres) { r2=SIZE-i; break; }
buf = buf.slice(r1,r2);
SIZE = buf.length;
// autocorrelation
var c = new Array(SIZE).fill(0);
for (var i=0; i<SIZE; i++)
for (var j=0; j<SIZE-i; j++)
c[i] = c[i] + buf[j]*buf[j+i];
// find first dip
var d=0; while (c[d]>c[d+1]) d++;
// find max
var maxval=-1, maxpos=-1;
for (var i=d; i<SIZE; i++) {
if (c[i] > maxval) {
maxval = c[i];
maxpos = i;
}
}
var T0 = maxpos;
// interpolation
var x1=c[T0-1], x2=c[T0], x3=c[T0+1];
a = (x1 + x3 - 2*x2)/2;
b = (x3 - x1)/2;
if (a) T0 = T0 - b/(2*a); trimming cuts the edges of the signal so that it starts and ends near zero. This is used to neutralize an inherent instability of the autocorrelation version I use. autocorrelation is just autocorrelation. The original version. find first dip / find max are self descriptive. interpolation is parabolic interpolation. It helps with precision. We suppose that a parabola pass through the three points that comprise the peak. 'a' and 'b' are the unknowns from the linear equation system and b/(2a) is the "error" in the abscissa. Well x1,x2,x3 should be y1,y2,y3 because they are the ordinates. I hope that helps. |
I tried your version dalatant, but I had errors in two spots:
and
The errors were both "undefined is not a function" on my emulator, but when I ran it on chrome it worked perfectly fine. Why is it coming up with these errors? Thanks for reading! |
@dalatant The new algorithm is also very cluttered with for loops. It is impossible to run something in the background as six for loops are repeated over and over. Is there a way to condense the code, so everything runs faster and smoother, without interrupting the accuracy of the algorithm? I would greatly appreciate it! |
Haven't looked at the code, but perhaps webworker is an option?
Op vr 6 jan. 2017 06:42 schreef aworld1 <[email protected]>:
… @dalatant <https://github.com/dalatant> The new algorithm is also very
cluttered with for loops. It is impossible to run something in the
background as six for loops are repeated over and over. Is there a way to
condense the code, so everything runs faster and smoother, without
interrupting the accuracy of the algorithm? I would greatly appreciate it!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABOmDfA2fh9yntMZDztRLibAXREz1NIIks5rPdRYgaJpZM4Ks9Em>
.
|
Really where did you run it aworld1? I doubled the buffer because it was so fast in my pc that I couldn't read the indications, and I use an intel p4 that I bought in 2003. Condensing the code doesn't mean optimizing. |
Also keep in mind that it could work even with the big buffer. A big candidate for the lag is the way the algorithm is recurring inside the app. |
I was so thrilled about this app but time passed. And I'm still thrilled! :p Check out my implementation |
@dalatant, thesis for? Just curious, my BSC's dissertation was in Greece and relevant to digital sound processing. Math or CS background? |
@fllprbt I studied information and communication systems engineering in Samos, a 5yr school. Ye we had dsp and signal processing and all that painful stuff :). |
This algorithm has given me far better results in all of my tests, especially for low notes. Thanks for this! I hope it gets committed at some point, because this is excellent! |
Just a naïve question: |
@qnp the only difference between correlation and convolution is that in convolution the 2nd signal is time-reversed. So if you convolve a signal with its reversed copy (as impulse response) that will be an autocorrelation. I've never used ConvolverNode before, but if it can convolve two given signals then yes you can do it that way. |
@dalatant thanks to this PR I am experiencing an improved detection on a side project of mine. Thanks x 💯** 💯! |
Any chance this PR gets merges, @cwilso? :) I have a web audio app and was looking into options to add Karaoke mode in it, googling pitch detection got me here. |
question, what sort of instruments did you use to test this? |
I use it with an harmonica |
@Meleeman01 Hmm nice question. Οnly an acoustic and an electric guitar. And also my voice. I actually don't have any other (musical) organ. Also good to know that it works on harmonica hehe. |
Well I mean... when live testing the application... |
While doing my thesis on pitch detection, I came up with this utterly simple technique that boosts up autocorrelation performance. The algorithm you use right now has a 30% error rate while this one gives 3.7% tested over a 1500-sample database of 4 instruments that I collected from web.
It works quite well. It may seem unstable but it is only due to high resolution in cents. The low strings of an electric guitar have a natural ±0.3hz ≈ 5cents average fluctuation in their fundamental frequency during a pluck, according to spectrogram. So this is rather normal.
Thesis is in Greek but I am preparing a website with details in English. Thanks to the Web Audio API and this demo I also managed to translate this into a web app. Thanks for sharing.