Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- 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()