[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Fwd: Potential serious problem with xcorr

**From**: |
JuanPi |

**Subject**: |
Fwd: Potential serious problem with xcorr |

**Date**: |
Tue, 2 Apr 2019 00:42:56 +0200 |

Hi Mike,
Just wanted to ask you something regarding xcorr in signal.
First of all, I get the same apparent mistake with matlab online, so
nothing to worry on that level.
However, have a look at the output of this code:
N = 256;
t = linspace (0, 1, N).' * 2 * pi;
dt = t(2) - t(1);
freq = 3;
x = sin (freq * t);
y = x.^2;
[C lag] = xcorr (x, y);
Cw = arrayfun (@(i)sum (x .* circshift (y, i)), lag.');
plot(lag, C, lag, Cw)
indeed the equivalence is obtained with
plot(lag, C, lag, cumtrapz(lag, Cw.*sign(lag.')))
So the C obtained with xcorr is sort of the integral of the actual
result for periodic signals.
I find this gross difference whenever I use periodic signals (both x and y).
I think the issue comes from the fact that xcorr is padding with
zeros, but here the signals are actually periodic.
Don't you think it would be nice to offer a warning about this in the
doc (which needs some fixing, will send patch), and maybe offer
xcorr_periodic or something like that for the case in which the
signals are periodic?
Regards,
--
JuanPi Carbajal
https://goo.gl/ayiJzi
-----
“An article about computational result is advertising, not
scholarship. The actual scholarship is the full software environment,
code and data, that produced the result.”
- Buckheit and Donoho
--
JuanPi Carbajal
https://goo.gl/ayiJzi
-----
“An article about computational result is advertising, not
scholarship. The actual scholarship is the full software environment,
code and data, that produced the result.”
- Buckheit and Donoho

**Fwd: Potential serious problem with xcorr**,
*JuanPi* **<=**