I'm trying to cross correlate a temperature signal with a strain signal. I want to get the time delay between the two signals then I want to shift the temperature signal in time so that I can use it further for PCA.
The problem is I did the cross correlation and everything but the shifted temperature signal has no effect at all, it's the same as the correrlated signal.
You can download a data set here : http://www.mediafire.com/file/r7dg7i9dacvpl2j/curve_fitting_ahmed.xlsx/file You can look at the figures
The first signal is the shifted signal I suppose
The last ACF is the cross correlated signal
df = pd.read_excel(file_path, skip_blank_lines=False, skiprows=1)
def process_data_time_delay(temperature, strain, df):
from scipy import signal
# normalization before ACF
def normalize(data):
return (data - np.mean(data, axis=0).reshape((1, -11))) / (np.std(data, axis=0).reshape((1, -1)))
# select subset of columns, seems relevant as a group
SCOLS = ['T1', 'W_A1']
# just to see the data
f = plt.figure()
ax = f.add_subplot(111)
df[SCOLS[:2]].iloc[::10].plot(ax=ax)
ax.set_title('Raw data')
# normalization
normalized = normalize(df[SCOLS].values)
f = plt.figure()
ax = f.add_subplot(111)
ax.plot(np.arange(normalized.shape[0]), normalized[:, 0], label='TW_A1')
ax.plot(np.arange(normalized.shape[0]), normalized[:, 1], label='W_A1')
ax.set_title('Normalized')
# ACF between two components
x1x2 = np.correlate(normalized[:, 0], normalized[:, 1], 'full')
# see the results
f = plt.figure()
ax = f.add_subplot(111)
ax.plot(x1x2)
ax.set_title('ACF')
df['TIMESTAMP'] = pd.to_datetime(df['TIMESTAMP'])
peaks_indices = signal.find_peaks_cwt(array(x1x2).flatten(), np.arange(1,10))
print(peaks_indices)
delta_index = np.argmax(peaks_indices);
print(delta_index)
delta_time = df['TIMESTAMP'][delta_index] - df['TIMESTAMP'][0]
# assuming timestamps is a datetime64 numpy array that can be easily obtained from pandas;
shifted_signal = x1x2[delta_index:]
f = plt.figure()
ax = f.add_subplot(111)
ax.plot(shifted_signal)
# mainloop
plt.show()
return x1x2
答案 0 :(得分:0)
信号的形状应相似,但时标有所变化。