Cross Correlation with Discrete signals
By : CZ云遥
Date : March 29 2020, 07:55 AM
Hope that helps Just do the regular cross correlation. Afterwards set the lags vector accordingly.

CrossCorrelation of two signals
By : SkyWaiting
Date : March 29 2020, 07:55 AM
To fix the issue you can do You seem to have a slight misunderstanding of how crosscorrelation works. Crosscorrelation takes one signal, and compares it with shifted versions of another signal. If you recall, the (unnormalized) crosscorrelation of two signals is defined as: code :
s = [0 0 0 0 1 1 1 1 1 0 0 0 0]
h = [1 1 1 1 1 0 0 0 0 0 0 0 0]
s ** h = (0)(1) + (0)(1) + (0)(1) + (0)(1) + (1)(1) + (0)(1) + (0)(1) + (0)(1) + (0)(1)
= 1
s = [0 0 0 0 1 1 1 1 1 0 0 0 0]
h = [0 1 1 1 1 1 0 0 0 0 0 0 0]
s ** h = (0)(1) + (0)(1) + (0)(1) + (0)(1) + (1)(1) + (1)(1) + (0)(1) + (0)(1) + (0)(1)
= 2
s = [0 0 0 0 1 1 1 1 1 0 0 0 0]
h = [0 0 0 0 1 1 1 1 1 0 0 0 0]
s = [0 0 0 0 1 1 1 1 1 0 0 0 0]
h = [0 0 0 0 0 1 1 1 1 1 0 0 0]
s = [0 0 0 0 1 1 1 1 1 0 0 0 0]
h = [0 0 0 0 0 0 0 0 1 1 1 1 1]

Cross Correlation with signals of different length in MATLAB
By : plrnvld
Date : March 29 2020, 07:55 AM
this will help I have 2 signals of different lengths where the shorter signal is the same as the longer n samples shifted. I want to find the maximum normalized crosscorrelation between these two signals. Since it is normalized should give 1. The xcorr function lags vary from 441 to 441 samples. , Suppose x and y are the shorter and longer signals you have. code :
nx = length(x);
ny = length(y);
cc = nan(1,nynx+1);
for ii = 0 : nynx
id = (1:nx) + ii;
cc(ii+1) = sum(x.*y(id))/(sqrt(sum(x.^2)*sum(y(id).^2)));
end
[ccmx,idmx] = max(cc);

Normalizing crosscorrelation to [1,1] for different length signals
By : Megha Jain
Date : March 29 2020, 07:55 AM

Cross correlation / similarity of signals  calculate time lag
By : Nickolass
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , One possible solution to your problem is Mean Squared Error (MSE). Given two signals a and b of same dimensions, MSE is the average value of the elementwise squares of the difference between a and b. The code would look like follows (based on this): code :
import numpy as np
import matplotlib.pyplot as plt
a = np.array([10, 20, 10, 30, 20, 10, 28, 22, 10])
b = np.array([28, 22])
mse = np.ndarray((len(a)  len(b) + 1))
for i in range(c.size):
mse[i] = np.square(np.subtract(a[i:i+len(b)],b)).mean()
print(mse.argmin())
plt.plot(mse)

