# X sampling
x = seq(0,1, 0.001) * 2 * pi
# Generate a peak with noise at its basis
f = function(x, a = 0.2, b = 2) {
(cos((x+pi)) + 1)^b + rnorm(length(x)) * a
}
curve(f(x*2*pi))
# Various color scale
my.col = colorRampPalette(c("blue2", "red2", "green3"), space = "Lab")(length(x))
my.col = colorRampPalette(c("blue2", "orange2", "green3"), space = "Lab")(length(x))
my.col = colorRampPalette(c("blue2", "magenta2", "red3"), space = "Lab")(length(x))
# X sampling post inverse FFT
xt = (x + pi) %% (2*pi) - pi
plot(x, xt)
We mix a negative shift. Because enlargment rises before and fails before the peak, the rising trajectory and the failing trajectory do not overlap. The cross-correlation shows shift of 1/20.
y1 = f(x, 0.2, 4) * 4
y2 = f(x + (2*pi/20), 0.2, 4)
plot(y1, col = my.col)
points(y2, col = my.col)
plot(y1, y2, col = my.col)
y1.fft = fft(y1)
y2.fft = fft(y2)
plot(xt, Re(fft(y1.fft*Conj(y2.fft), inverse = TRUE))/1e6, col = my.col)
abline(v = 2 * pi / 20)
We mix a negative shift and a positive shift. Because enlargment rises before and fails after the peak, the rising trajectory and the failing trajectory overlap. The cross-correlation shows shift of zero.
y3 = f(x+(2*pi/10), 0.2, 4) + f(x-(2*pi/10), 0.2, 4)
plot(y1, col = my.col)
points(y3, col = my.col)
plot(y1, y3, col = my.col)
y3.fft = fft(y3)
plot(xt, Re(fft(y1.fft*Conj(y3.fft), inverse = TRUE))/1e6, col = my.col)
abline(v = 0) # No shift