cross correlation to calculate delay

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

cross correlation to calculate delay

DDGG
dear all,

How would it be possible to calculate the delay between to correlated
signals in SC?
Is there any Server Side solution?

thank you

ddgg




--
Sent from: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SuperCollider-Users-New-Use-this-f2676391.html

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: cross correlation to calculate delay

DDGG
I read in this article (https://de.mathworks.com/help/signal/ref/xcorr.html)
that the delay is the result of the cross correlation between 2 signals so I
tried:

(
fork ({
        var corr, buf;
       
        Buffer.freeAll;
        s.sync;
        buf = Buffer.alloc(s, 0.5*s.sampleRate, 2);

        SynthDef(\corr, {
                arg
                delTime;
                var
                in1 = SinOsc.ar(300, 0, 0.1),
                in2 = DelayL.ar(in1, 0.5, 0.3),
                rec1 = RecordBuf.ar([in1, in2], buf.bufnum, loop:0, doneAction: 2);
                0;
        }).add;
       
        s.sync;
       
        a = Synth(\corr).onFree{corr.value};
       
        corr = {
                buf.loadToFloatArray(action: { arg a;
                        var
                        ch1 = a.unlace(2)[0],
                        ch2 = a.unlace(2)[1];
                       
                        ch1.corr(ch2).postln; // returns 0.63245553162585 instead of 0.3
                });
        }
})
)

which probably mad me think that the method corr does not calculate the
crossCorrelation

so I was trying to implement it on a synthdef:

(
var fftSize = 2048;

~corr = Buffer.alloc(s, 2048);

SynthDef(\corr, {
        arg
        delTime = 0.1;
        var
        sin = SinOsc.ar(400, 0 , 0.1),
        del = DelayL.ar(sin, 0.2, delTime),
       
        buf1 = LocalBuf(fftSize, 1),
        buf2 = LocalBuf(fftSize, 1),
       
        fft1 = FFT(buf1, sin),
        fft2 = FFT(buf2, del),
        fft2conj = PV_Conj(fft2),
       
        corr = PV_Mul(fft1, fft2conj);
       
        /* what's next?*/
       
        0;
}).play;
)

but I don't know how to proceed from here...any suggestion?
thanks again
ddgg



--
Sent from: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SuperCollider-Users-New-Use-this-f2676391.html

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/