Last active
November 9, 2023 14:56
-
-
Save jcheong0428/f6e4e4d7e846ee17f585caf34cd57498 to your computer and use it in GitHub Desktop.
Windowed time lagged cross correlations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Windowed time lagged cross correlation | |
| seconds = 5 | |
| fps = 30 | |
| no_splits = 20 | |
| samples_per_split = df.shape[0]/no_splits | |
| rss=[] | |
| for t in range(0, no_splits): | |
| d1 = df['S1_Joy'].loc[(t)*samples_per_split:(t+1)*samples_per_split] | |
| d2 = df['S2_Joy'].loc[(t)*samples_per_split:(t+1)*samples_per_split] | |
| rs = [crosscorr(d1,d2, lag) for lag in range(-int(seconds*fps),int(seconds*fps+1))] | |
| rss.append(rs) | |
| rss = pd.DataFrame(rss) | |
| f,ax = plt.subplots(figsize=(10,5)) | |
| sns.heatmap(rss,cmap='RdBu_r',ax=ax) | |
| ax.set(title=f'Windowed Time Lagged Cross Correlation',xlim=[0,301], xlabel='Offset',ylabel='Window epochs') | |
| ax.set_xticks([0, 50, 100, 151, 201, 251, 301]) | |
| ax.set_xticklabels([-150, -100, -50, 0, 50, 100, 150]); | |
| # Rolling window time lagged cross correlation | |
| seconds = 5 | |
| fps = 30 | |
| window_size = 300 #samples | |
| t_start = 0 | |
| t_end = t_start + window_size | |
| step_size = 30 | |
| rss=[] | |
| while t_end < 5400: | |
| d1 = df['S1_Joy'].iloc[t_start:t_end] | |
| d2 = df['S2_Joy'].iloc[t_start:t_end] | |
| rs = [crosscorr(d1,d2, lag, wrap=False) for lag in range(-int(seconds*fps),int(seconds*fps+1))] | |
| rss.append(rs) | |
| t_start = t_start + step_size | |
| t_end = t_end + step_size | |
| rss = pd.DataFrame(rss) | |
| f,ax = plt.subplots(figsize=(10,10)) | |
| sns.heatmap(rss,cmap='RdBu_r',ax=ax) | |
| ax.set(title=f'Rolling Windowed Time Lagged Cross Correlation',xlim=[0,301], xlabel='Offset',ylabel='Epochs') | |
| ax.set_xticks([0, 50, 100, 151, 201, 251, 301]) | |
| ax.set_xticklabels([-150, -100, -50, 0, 50, 100, 150]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment