-
Notifications
You must be signed in to change notification settings - Fork 1
/
characterize-freq-content.py
57 lines (48 loc) · 1.38 KB
/
characterize-freq-content.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
===============================================================================
Script 'characterize-freq-content.py'
===============================================================================
This script plots pupil data and kernel and analyzes by FFT.
"""
# @author: Dan McCloy ([email protected])
# Created on Fri Sep 25 11:15:34 2015
# License: BSD (3-clause)
import os
import os.path as op
import numpy as np
from scipy.fftpack import fft, fftfreq
import matplotlib.pyplot as plt
plt.ioff()
# flags
savefig = False
# file I/O
work_dir = os.getcwd()
data_file = op.join(work_dir, 'rev_data.npz') # voc_data.npz
dd = np.load(data_file)
data_zscore, fs, kernel = dd['zscores'], dd['fs'], dd['kernel']
# data_deconv, t_fit, subjects = dd['fits'], dd['t_fit'], dd['subjects']
'''
data_zscore.shape
16, 40, 2, 2, 2, 6550
subj trials 200/600gap maint/switch 10/20chan samples
'''
data = data_zscore.mean(axis=(0, 1, 2, 4))
maint = data[0, :]
switch = data[1, :]
def do_fft(signal):
_fft = fft(signal, 8192)
ampl = np.abs(_fft)
power = ampl ** 2
norm = power / np.max(power)
freqs = fftfreq(8192, 1./fs)
plt.plot(freqs, norm)
return None
for sig in [kernel, maint, switch]:
do_fft(sig)
plt.xlim(0, 10)
if savefig:
plt.save(op.join('figures', 'freq-content.pdf'))
else:
plt.ion()
plt.show()