signal processing
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all, I am still struggling with this and I don't know why its producing wrong answer. I have my two signals and I want to produce the delay time between the two signals and see if they both originate from the same source or not so delay time is not known and the two signals might not be from the same source..I have many source data and I need to do it for any two then calculate the delay time.the problem is that I only get large positive numbers for the delay and if I swap x,y in the xcorr argument I get totally different answer and I believe I should get the same answer as the x,y but opposite sign (minus/positive)...
Thank you all in advance,
x = sample1(:,1);
X = (x).';
y = sample2(:,1);
Y = (y).';
figure;
clf
subplot(3,1,1);
[xi,f]=ksdensity(X);
plot(f,xi);
line(repmat(X,2,1),repmat([0;0.1*max(xi)],1,length(X)),'color','r' );
subplot(3,1,2);
[xi,f]=ksdensity(Y);
plot(f,xi);
line(repmat(Y,2,1),repmat([0;0.1*max(xi)],1,length(Y)),'color','r' );
[Rxx,lags] = xcorr(X,Y);
[Z,delay] = max(Rxx);
lags(delay);
3 commentaires
Réponse acceptée
Daniel Shub
le 24 Août 2011
I do not quite see what you are finding in that delay is the same in both cases (0):
sample1 = [6.526760455502977E7
6.526803236688536E7
6.5268252754813336E7
6.526834674377677E7
6.526860278268609E7
6.526885882158541E7
6.526893660555825E7
6.526923801844921E7
6.526936765841391E7
6.526948757538823E7
6.527011957014128E7
6.527021680012478E7
6.527026541509657E7
6.527042422403239E7
6.5271075664836034E7
6.527129929376417E7];
sample2 = [6.52689008725069E7
6.526904023546197E7
6.526926062337003E7
6.526948425228816E7
6.526999633010681E7
6.527001901709762E7
6.527068342188179E7
6.527216131739556E7
6.527217752238616E7
6.527234605434227E7
6.527377857593433E7
6.527422907480074E7
6.527427768977253E7
6.527455641569267E7
6.5274640681675725E7
6.527486431061386E7];
x = sample1(:,1);
X = (x).';
y = sample2(:,1);
Y = (y).';
[Rxy,lags] = xcorr(X,Y);
[Zxy,delay] = max(Rxy);
lags(delay)
[Ryx,lags] = xcorr(Y,X);
[Zyx,delay] = max(Ryx);
lags(delay)
figure
plot(1:31, Rxy, 'b', 1:31, fliplr(Ryx), 'r')
figure
plot(Rxy-fliplr(Ryx))
There are some noticeable differences between Rxy and fliplr(Ryx), but they are are approaching double precision.
eps(sum(sample1.^2))
What happens if you scale your vectors?
0 commentaires
Plus de réponses (2)
Susan
le 24 Août 2011
2 commentaires
Jan
le 24 Août 2011
Daniel's code compare the results of XCORR if the inputs are swapped. He shows, that except for the reverted order and some rounding errors, the inputs are equal.
You can be sure that MATLAB is not confused by your source files. It does exactly what you told it to do. It MATLAB does "something else", it recieved different input data. Therefore its answer is not wrong, but your expectations. A general suggestion for such situations is a coffee break.
Jan
le 24 Août 2011
Did you get the point about FLIPLR?
"I believe I should get the same answer as the x,y but opposite
sign (minus/positive)"
But in addition the replies of xcorr(X,Y) and xcorr(Y,X) are reverted.
4 commentaires
Jan
le 24 Août 2011
See: "help hold".
If you have a question concerning plotting, it is always a good idea to type "help plot" and look in the "See also:" list at the bottom. This list is created very carefully to assist beginners and advanced MATLAB users.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!