Created
January 16, 2013 11:27
-
-
Save breuderink/4546493 to your computer and use it in GitHub Desktop.
Show EDF problem with Emotiv data.
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 logging, argparse, itertools | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy import signal | |
import eegtools | |
log = logging.getLogger(__name__) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Assess signal quality') | |
parser.add_argument('--subject', help='The subject ID.', default='1a-01') | |
args = parser.parse_args() | |
logging.basicConfig(level=logging.INFO) | |
log.setLevel(logging.INFO) | |
plt.ion() | |
d = eegtools.data.hmi_wow.load(args.subject) | |
# Perform filtering | |
(b, a) = signal.butter(2, np.array([.5, 40]) / (d.sample_rate / 2), 'band') | |
X = signal.lfilter(b, a, d.X, axis=1) | |
# Plot raw EEG | |
plt.figure(); plt.title('Filtered EEG') | |
win = slice(100 * d.sample_rate, 105 * d.sample_rate) | |
plt.plot(X[:,win].T + np.arange(X.shape[0]) * 60, c='k') | |
plt.ylabel('amplitude (mV)') | |
plt.xlabel('time (samples @ %dHz) ' % d.sample_rate) | |
# Analyze frequency spectrum. | |
plt.figure() | |
plt.psd(X[0], Fs=d.sample_rate) | |
plt.title('Power spectrum') | |
# Analyze covariance. | |
C = np.cov(X) | |
plt.matshow(C); plt.colorbar(); plt.title('Channel covariance') | |
plt.figure(); plt.title('Spectrum of channel covariance.') | |
plt.semilogy(np.sort(np.linalg.eigvalsh(C))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment