Last active
April 4, 2016 15:36
-
-
Save mbillingr/1c03de8ed0bb5e47e39eade935a2c587 to your computer and use it in GitHub Desktop.
Toy example that shows what happens to the DTF when a sinusoid is added to white noise signals
This file contains 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
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn | |
from scot.var import VAR | |
from scot.connectivity import connectivity | |
fs = 100 | |
n = 10001 | |
disturbance = np.sin(np.arange(n) * 2 * np.pi * 20 / fs) | |
for i in range(3): | |
np.random.seed(42) | |
if i == 0: | |
# three white noise signals | |
x = np.random.randn(3, n) | |
elif i == 1: | |
# a sinusoid added to the three signals | |
x = np.random.randn(3, n) | |
x += disturbance | |
elif i == 2: | |
# in addition to adding the sinusoid, now we also include a fourth | |
# signal that contains only the sinousoid (and a little noise) | |
x = np.random.randn(4, n) | |
x[3, :] *= 0.03 | |
x += disturbance | |
plt.figure() | |
var = VAR(15).fit(x) | |
S = connectivity('S', var.coef, var.rescov) | |
C = connectivity('DTF', var.coef, var.rescov) | |
f = np.abs(np.linspace(0, fs / 2, S.shape[-1])) | |
for i in range(x.shape[0]): | |
for j in range(x.shape[0]): | |
plt.subplot(x.shape[0], x.shape[0], i * x.shape[0] + j + 1) | |
if i == j: | |
plt.fill_between(f, 0, S[i, j, :], color=seaborn.color_palette()[1]) | |
else: | |
plt.fill_between(f, 0, C[i, j, :], color = seaborn.color_palette()[0]) | |
plt.ylim(0, 1) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results:
![image](https://cloud.githubusercontent.com/assets/2392396/14251666/584479ba-fa84-11e5-84d9-c095eff89007.png)
![image](https://cloud.githubusercontent.com/assets/2392396/14251672/5e298ece-fa84-11e5-8cf9-c932140fac33.png)
![image](https://cloud.githubusercontent.com/assets/2392396/14251674/60d1e82e-fa84-11e5-93d7-2d1b7f952417.png)