Skip to content
example.py 2.2 KiB
Newer Older
# -*- coding: utf-8 -*-
"""

Copyright 2016 Julien Audiffren

This code is related to the paper :
[Preprocessing of the Nintendo Wii Board Signal to Derive More
Accurate Descriptors of Statokinesigrams, Audiffren and Contal] 

If you use this algorithm in your research work, please cite this paper.

Licence :
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or any later
 version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.


"""


from resampling import SWARII
import pylab as plb
import numpy as np


def parse_wbb_file(file_adress):
    time = []
    signal = []
    f = open(file_adress,'rt+')
    l = f.readline()
    l = f.readline()
    
    while len(l)>0:
        
        data = l.split(" ")
        t = 0.001*float(data[0])
        x = float(data[1])
        y = float(data[2])
        
        time.append(t)
        signal.append([x,y])
        l=f.readline()
    
    return np.array(time),np.array(signal)
        
    




if __name__=='__main__':

    resampling_method = SWARII(window_size=0.25,desired_frequency=25)
    time,signal = parse_wbb_file('example_wbb_statokinesigram.txt')
    resampled_time, resampled_signal = resampling_method.resample(time,signal)
    
    
    
    fig,ax = plb.subplots(2)
    ax[0].plot(time,signal[:,0],c='b',label='original signal')
    ax[0].plot(resampled_time,resampled_signal[:,0],c='r',label='resampled signal')
    ax[0].set_xlabel("time")
    ax[0].set_ylabel("X coordinate")
    ax[0].set_title("X")
    ax[0].legend()
    
    ax[1].plot(time,signal[:,1],c='b',label='original signal')
    ax[1].plot(resampled_time,resampled_signal[:,1],c='r',label='resampled signal')
    ax[1].set_xlabel("time")
    ax[1].set_ylabel("Y coordinate")
    ax[1].set_title("Y")
    ax[1].legend()
    
    plb.show()