I have text files from sensor data such as accelerometers and gyroscopes such as:
% Accelerometer data recorded with 'snsrlog'
%
% Sampling frequency: 100 Hz
%
% Label description:
% 0: Default Label
% 1: pick up phone
%
% Column description:
% 1: Seconds.milliseconds since 1970
% 2: Number of skipped measurements
% 3: Acceleration value in x-direction
% 4: Acceleration value in y-direction
% 5: Acceleration value in z-direction
% 6: Label used for the current sample
%
%
1495573445.162 0 0.021973 0.012283 -0.995468 1
1495573445.172 0 0.021072 0.013779 -0.994308 1
1495573445.182 0 0.020157 0.015717 -0.995575 1
1495573445.192 0 0.017883 0.012756 -0.993927 1
1495573445.202 0 0.021194 0.012161 -0.994705 1
1495573445.212 0 0.019638 0.013718 -0.994019 1
1495573445.222 0 0.019440 0.010803 -0.994476 1
with much more in the files.
I want to create a sliding window of size 50 for each column of accelerometer axes because the sampling frequency is 100Hz. I can print out each line of the first column like this:
def sliding_window(filename, stepSize, windowSize):
with open(filename) as infile:
for line in infile:
print(line.split()[0])
However, I shouldn't be printing out the first 17 lines as they are just comments in the text file. How would I go about making this sliding window?
Add a startswith
condition:
if not line.startswith('%'):
print(line.split()[0])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.