Hello !

I test my project initially made for Matlab with Octave.
And I have a problem with the xcorr method.
the code :
a = [1 2  -1 -1]
b = [-1 1 2 -1 -1 1 2 -1]
round(xcorr(a,b))
return in matlab : -1     0     6     0    -6     0     7     0    -5
0     1     0     0     0     0
and in Octave :  0  -0  -0   0  -1   0   6  -0  -6   0   7  -0  -5  -0   1
than we see that there a shift problem, there is 4 0 after in matlab and
after in Octave.
In my project and in this example if I replace the xcorr with the method :
function [R, lags] = my_xcorr (X, Y)
    N = max(length(X),length(Y))
    maxlag=N-1
    M = 2^nextpow2(N + maxlag)

    %% compute cross-correlation of X and Y
    post = fft (postpad(Y,M));
    pre = fft (postpad(prepad(X,length(X)+maxlag),M));
    cor = conj (ifft (conj(post(:)) .* pre(:)));
    R = cor(1:2*maxlag+1);

    if isreal(X) && (isempty(Y) || isreal(Y))
        R=real(R);
    end
    if isvector(X)
        R = R';
    end

    lags = [-maxlag:maxlag];
end

it will work great.
this method is the same as xcorr implementation (
http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/signal/inst/xcorr.m?revision=HEAD&content-type=text/plain)
where I remove the code I don't need (but necessary ;-) ) an I replace the
line :

    pre = fft (postpad(prepad(X,N+maxlag),M));
by
    pre = fft (postpad(prepad(X,length(X)+maxlag),M));


Is it a good fix ? And can it be integrated in the next release of octave
forge ?


CU and thanks in advance.
Steph


-- 
Stéphane Brunner
mail : [EMAIL PROTECTED]
messageries instantanées : [EMAIL PROTECTED] (
http://talk.google.com)
--------------------------------------
http://www.ubuntu-fr.org - Distribution Linux
http://fr.wikipedia.org - Encyclopédie communautaire
http://mozilla-europe.org - Navigateur internet / Client de messagerie
http://framasoft.net - Annuaire de logiciel libre (gratuit)
http://jeuxlibres.net - Jeux Libres (gratuit)
http://openstreetmap.org - Cartographie libre (en développement)
--------------------------------------
Il existe 10 sortes de personnes : celles qui connaissent le binaire, et les
autres.
--------------------------------------
Si un jour on te reproche que ton travail n'est pas un travail de
professionnel, dis toi que :
Des amateurs ont construit l'arche de Noé, et des professionnels le Titanic.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to