Procesamiento Señales


In [1]:
# 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 [2]:
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 [3]:
for i in range(0,5):
    graficar('presentacion1.csv', i)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-7cf5be15799e> in <module>()
      1 for i in range(0,5):
----> 2     graficar('prueba.csv', i)

<ipython-input-2-b6bc6c993c05> in graficar(filename, imu)
     42     plt.ylabel("Aceleracion ($m/s^2$)")
     43     plt.figure()
---> 44     plt.plot(t, gx, t, gy, t, gz)
     45     plt.title("Giroscopio, IMU: " + str(imu))
     46     plt.legend(['X', 'Y', 'Z'])

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in plot(*args, **kwargs)
   2985         ax.hold(hold)
   2986     try:
-> 2987         ret = ax.plot(*args, **kwargs)
   2988         draw_if_interactive()
   2989     finally:

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in plot(self, *args, **kwargs)
   4135         lines = []
   4136 
-> 4137         for line in self._get_lines(*args, **kwargs):
   4138             self.add_line(line)
   4139             lines.append(line)

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in _grab_next_args(self, *args, **kwargs)
    315                 return
    316             if len(remaining) <= 3:
--> 317                 for seg in self._plot_args(remaining, kwargs):
    318                     yield seg
    319                 return

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in _plot_args(self, tup, kwargs)
    293             x = np.arange(y.shape[0], dtype=float)
    294 
--> 295         x, y = self._xy_from_xy(x, y)
    296 
    297         if self.command == 'plot':

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in _xy_from_xy(self, x, y)
    235         y = np.atleast_1d(y)
    236         if x.shape[0] != y.shape[0]:
--> 237             raise ValueError("x and y must have same first dimension")
    238         if x.ndim > 2 or y.ndim > 2:
    239             raise ValueError("x and y can be no greater than 2-D")

ValueError: x and y must have same first dimension