Procesamiento Señales


In [4]:
# Pylab normal
import numpy as np
import matplotlib
from matplotlib import pylab, mlab, pyplot as plt
from __future__ import division

# Signal processing
import scipy.signal as signal
import scipy.stats as stats
# csv reader
import csv

# General plot configurations
%matplotlib inline
plt.rcParams['figure.figsize'] = 18, 8

In [5]:
freq = 100

def loadImu(fileName, imu_number):
    time = []
    acc_x = []
    acc_y = []
    acc_z = []
    gyro_x = []
    gyro_y = []
    gyro_z = []
    compass_x = []
    compass_y = []
    compass_z = []
    
    # opens a lab test file and loads data as vector
    with open(fileName, 'rb') as f:
        reader = csv.reader(f)
        for row in reader:
            try:
                if float(row[0]) == imu_number:
                    time.append(float(row[1]))
                    acc_x.append(float(row[2]))
                    acc_y.append(float(row[3]))
                    acc_z.append(float(row[4]))
                    gyro_x.append(float(row[5]))
                    gyro_y.append(float(row[6]))
                    gyro_z.append(float(row[7]))
                    compass_x.append(float(row[8]))
                    compass_y.append(float(row[9]))
                    compass_z.append(float(row[10]))
            except:
                pass
    return [time, acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z, compass_x, compass_y, compass_z]

def graficar(filename, imu):
    [t, ax, ay, az, gx, gy, gz, mx, my, mz] = loadImu(filename, imu)
    plt.figure()
    plt.plot(t, ax, t, ay, t, az)
    plt.title("Aceleracion, IMU: " + str(imu))
    plt.legend(['X', 'Y', 'Z'])
    plt.xlabel("Tiempo ($s$)")
    plt.ylabel("Aceleracion ($m/s^2$)")
    plt.figure()
    plt.plot(t, gx, t, gy, t, gz)
    plt.title("Giroscopio, IMU: " + str(imu))
    plt.legend(['X', 'Y', 'Z'])
    plt.xlabel("Tiempo ($s$)")
    plt.ylabel("Velocidad Angular ($º/s$)")
    plt.figure()
    plt.plot(t, mx, t, my, t, mz)
    plt.title("Magnetometro, IMU: " + str(imu))
    plt.legend(['X', 'Y', 'Z'])
    plt.xlabel("Tiempo ($s$)")
    plt.ylabel("Flujo Magnético ($Gs$)")

In [6]:
for i in range(0,5):
    graficar('presentacion1.csv', i)