In [1]:
from scipy import signal, stats
import numpy as np
import pandas as pd
from matplotlib.pyplot import *
%matplotlib inline
In [2]:
# the sampling frequency of ganglion is 200 Hz
fs = 200
In [3]:
d = pd.read_csv('data/smell_1491953550.csv')
d.head()
Out[3]:
In [4]:
## check the sampling rate (should be ~200Hz)
diffs = np.diff(d.timestamps)
diffs = diffs[diffs < 0.1]
1/np.mean(diffs)
Out[4]:
In [5]:
X = np.array(d.ix[:, 1:5])
tag = np.array(d.tag)
In [6]:
freq, y_baseline = signal.welch(X[tag == 'baseline'].T, fs=fs)
freq, y_smell = signal.welch(X[tag == 'smell'].T, fs=fs)
y_baseline = y_baseline.T
y_smell = y_smell.T
In [13]:
figure(figsize=(14,4))
for i in range(y_baseline.shape[1]):
_ = plot(freq, np.log(y_baseline[:, i]), label='Channel {}'.format(i+1))
legend()
title('Baseline')
xlim(0,50)
_ = xlabel('Frequency (Hz)')
In [14]:
figure(figsize=(14,4))
for i in range(y_smell.shape[1]):
_ = plot(freq, np.log(y_smell[:, i]), label='Channel {}'.format(i+1))
legend()
title('During smell')
xlim(0,50)
_ = xlabel('Frequency (Hz)')
In [15]:
def moving_average(sig, n=5):
filt = np.ones(n) / n
return np.convolve(sig, filt, 'same')
In [17]:
figure(figsize=(14,4))
diffs = np.log(y_smell) - np.log(y_baseline)
for i in range(diffs.shape[1]):
avg = moving_average(diffs[:, i], n=3)
_ = plot(freq, avg, label='Channel {}'.format(i+1))
title('Difference of\nDuring smell vs Baseline')
xlim(0,50)
legend()
_ = xlabel('Frequency (Hz)')
In [ ]:
In [ ]:
In [ ]: