<<<<<<< HEAD
# -*- coding: utf-8 -*-
"""
Created on Tue May  9 12:13:27 2017

@author: Hyun-seok
"""
import numpy as np
import math
import matplotlib.pyplot as plt

def mag(x):
    #Calculates Magnitude (sqrt(x^2+y^2+z^2))
    #Takes list of tuples (x, y, z)
    return math.sqrt(sum(float(i)**2 for i in x))

def linesplit(number):
    #Parses log data into values into a iterable list
    #Takes an integer between 0 and 3. 0 is time, 1 is x, 2 is y, 3 is z.
    #Be sure to sanitize the created list to make it readable for the program
    return [line.split(",")[number] for line in lines]

def sanitize(lst):
    #Gets rid of unnessesary spaces from the log file.
    #Use to after linesplit to make lists readable by python
    return [s.rstrip() for s in lst]


#Have log.txt in the same folder as this code.
#Name of log has to be same as name in the open function

with open('logvdd.txt') as log:
    raw_time = []
    raw_x = []
    raw_y = []
    raw_z = []
    for line in log:
        li = line.strip()
        if not line.strip().startswith("#"):
            raw_time.append(line.split(",")[0])
            raw_x.append(line.split(",")[1])
            raw_y.append(line.split(",")[2])
            raw_z.append(line.split(",")[3])

time = [values.rstrip() for values in raw_time]
x = [values.rstrip() for values in raw_x]
y = [values.rstrip() for values in raw_y]
z = [values.rstrip() for values in raw_z]

#consult matplotlib libraries, especially pyplot.
plt.figure()

#subplot 1. X axis read-outs on a regular graph. Green
plt.subplot(3, 1, 1)
plt.plot(time, x, 'g')
plt.axhline(y=0, color='b', linestyle='-') #just a line on y=0 for reference
plt.ylabel("Acceleration m/s**2")
plt.xlabel("Time (s)")

#subplot 2. Y axis read-outs on a regular graph. Red
plt.subplot(3, 1, 2)
plt.plot(time, y, 'r')
plt.axhline(y=0, color='b', linestyle='-') #just a line on y=0 for reference
plt.ylabel("Acceleration m/s**2")
plt.xlabel("Time (s)")

#subplot 3. Z axis read-outs on a regular graph. Blue
plt.subplot(3, 1, 3)
plt.plot(time, z)
plt.axhline(y=0, color='b', linestyle='-')
plt.ylabel("Acceleration m/s**2")
plt.xlabel("Time (s)")
plt.show()

=======
# -*- coding: utf-8 -*-
"""
Created on Tue May  9 12:13:27 2017

@author: Hyun-seok
"""
import numpy as np
import math
import matplotlib.pyplot as plt

def mag(x):
    #Calculates Magnitude (sqrt(x^2+y^2+z^2))
    #Takes list of tuples (x, y, z)
    return math.sqrt(sum(float(i)**2 for i in x))

def linesplit(number):
    #Parses log data into values into a iterable list
    #Takes an integer between 0 and 3. 0 is time, 1 is x, 2 is y, 3 is z.
    #Be sure to sanitize the created list to make it readable for the program
    return [line.split(",")[number] for line in lines]

def sanitize(lst):
    #Gets rid of unnessesary spaces from the log file.
    #Use to after linesplit to make lists readable by python
    return [s.rstrip() for s in lst]


#Have log.txt in the same folder as this code.
#Name of log has to be same as name in the open function

with open('log.txt') as log:
    lines = log.readlines()
    
    rawtime = linesplit(0)
    rawX = linesplit(1)
    rawY = linesplit(2)
    rawZ = linesplit(3)
    
    time = sanitize(rawtime)     
    x = sanitize(rawX)
    y = sanitize(rawY)
    z = sanitize(rawZ)

    #consult matplotlib libraries, especially pyplot.
    plt.figure()

    #subplot 1. X axis read-outs on a regular graph. Green
    plt.subplot(3, 1, 1)
    plt.plot(time, x, 'g')
    plt.axhline(y=0, color='b', linestyle='-') #just a line on y=0 for reference
    plt.ylabel("Amplitude (normalized log scale)")
    plt.xlabel("Frequency (in Hertz)")

    #subplot 2. Y axis read-outs on a regular graph. Red
    plt.subplot(3, 1, 2)
    plt.plot(time, y, 'r')
    plt.axhline(y=0, color='b', linestyle='-') #just a line on y=0 for reference
    plt.ylabel("acceleration m/s**2")
    plt.xlabel("time (s)")

    #subplot 3. Z axis read-outs on a regular graph. Blue
    plt.subplot(3, 1, 3)
    plt.plot(time, z)
    plt.axhline(y=0, color='b', linestyle='-')
    plt.ylabel("acceleration m/s**2")
    plt.xlabel("time (s)")
    plt.show()

>>>>>>> 30f08022b85e2a73a674a63069ca1383533668f0
