Week 25 Summary

This week I finally finished the coding for the program that could help me count the brain waves frequency. The only thing different from the original code was that I used a "for" loop to iterate the list and set conditions "if" to point out the maxima. When I counted it raw by hands, I got 23Hz; when I ran this program, I got 28Hz, which was not very off. For now, I decide to go with this program because this is so far the best way I could find to minimize the errors. Here is a complete look of the code:

import csv
import numpy as np
from scipy.signal import argrelextrema
import matplotlib.pyplot as plt

twoDimArray = []

def getColumn(x):
column = []
for row in twoDimArray[1:]:
column.append(float(row[x]))
return column

with open('target.csv') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
twoDimArray.append(row)

columns = {}
n = 0
for cell in twoDimArray[0]:
columns.update({cell:n})
n = n + 1

rows = {}
n = 0
for row in twoDimArray:
rows.update({row[0]:n})
n = n + 1
column0 = getColumn(0)
column1 = getColumn(1)

x = np.array(column0)
y = np.array(column1)

sortId = np.argsort(x)
x = x[sortId]
y = y[sortId]

for i in range(1, len(y)-1):
if (y[i]-y[i-1] >= 10) or (y[i]-y[i+1] >= 10):
print x[i]
print y[i]

And here is what the console looks like:

Comments