简体   繁体   English

下采样(时间、幅度)波形

[英]Downsample (time, amplitude) waveform

I'm trying to downsample millions of waveforms described as time, amplitude in.csv files:我正在尝试对 .csv 文件中描述为时间、幅度的数百万个波形进行下采样:

.csv file example .csv 文件示例

0.000e+00 0.000e+00
1.000e-12 7.052e-09
2.000e-12 2.253e-05
3.000e-12 5.915e-04
4.000e-12 2.229e-03
5.000e-12 3.059e-03
6.000e-12 3.467e-03
8.000e-12 4.035e-03
1.100e-11 4.172e-03
1.500e-11 5.274e-03
1.700e-11 9.348e-03
1.800e-11 1.464e-02
1.900e-11 2.236e-02
2.200e-11 4.992e-02
3.100e-11 1.337e-01
4.000e-11 1.997e-01
4.400e-11 2.133e-01
4.700e-11 2.163e-01
5.100e-11 2.190e-01
5.400e-11 2.202e-01
6.000e-11 2.288e-01
6.700e-11 2.703e-01
7.100e-11 3.152e-01
7.400e-11 3.514e-01
8.200e-11 4.578e-01
8.900e-11 5.702e-01
9.500e-11 6.724e-01
1.000e-10 7.499e-01
1.060e-10 8.225e-01
1.140e-10 8.912e-01
1.250e-10 9.414e-01
1.460e-10 9.801e-01
2.000e-10 9.972e-01
4.710e-10 9.997e-01
1.401e-09 1.000e+00
2.175e-09 1.000e+00
2.180e-09 9.999e-01
2.189e-09 9.999e-01
2.199e-09 9.999e-01
2.208e-09 9.999e-01
2.214e-09 9.999e-01
2.228e-09 9.999e-01
2.247e-09 9.999e-01
4.169e-09 1.000e+00
8.058e-09 1.000e+00
8.062e-09 1.000e+00
8.063e-09 9.923e-01
8.064e-09 9.573e-01
8.066e-09 8.743e-01
8.068e-09 7.772e-01
8.070e-09 6.769e-01
8.071e-09 6.253e-01
8.072e-09 5.734e-01
8.073e-09 5.210e-01
8.074e-09 4.695e-01
8.075e-09 4.198e-01
8.077e-09 3.328e-01
8.079e-09 2.571e-01
8.081e-09 1.982e-01
8.084e-09 1.341e-01
8.088e-09 8.178e-02
8.095e-09 3.922e-02
8.111e-09 1.167e-02
8.165e-09 1.574e-03
8.375e-09 2.750e-04
8.792e-09 4.565e-05
1.115e-08 1.574e-05
2.753e-08 1.574e-05
3.000e-08 1.123e-05

Python code Python 代码

If I plot the.csv file it gives:如果我 plot .csv 文件它给出:

import csv
import matplotlib.pyplot as plt
from scipy import signal

with open(csv_file, 'r') as f_read:
    csv_reader = csv.reader(f_read, delimiter = _delimiter)
    time_ori, amplitude_ori = [[float(i) for i in x] for x in zip(*csv_reader)]

plt.plot(time_ori, amplitude_ori, '-o')
plt.show()

在此处输入图像描述

Question

My goal here is to decrease the number of points in the waveform.我的目标是减少波形中的点数。 Unfortunately the time step isn't constant, so I tried to use reduced = signal.decimate(amplitude_ori, 2) which does reduce the number of points.不幸的是时间步长不是恒定的,所以我尝试使用reduced = signal.decimate(amplitude_ori, 2)这确实减少了点数。 However, I don't know how to remove the associated time values with regard to the amplitude values that were removed.但是,我不知道如何删除与已删除的振幅值相关的time值。 Can decimate() return the index of the removed elements? decimate()可以返回被移除元素的索引吗? I can't compare because sometimes the amplitude can be the same.我无法比较,因为有时振幅可能相同。

I'm open to other suggestions.我愿意接受其他建议。 I used decimate() since it seemed appropriate in my case.我使用decimate()因为它对我来说似乎合适。

EDIT:编辑:

The time precision can vary from waveform to waveform, so I can't define a threshold for the minimum time step.时间精度因波形而异,因此我无法为最小时间步长定义阈值。

import numpy as np

x = np.loadtxt('read.csv')
x = np.sort(x)
threshold = 1e-5
keep = abs(np.diff(x[:,1])) > threshold
keep = np.hstack(([True],keep))
out = [x[i] for i in range(len(x)) if keep[i]]
out = np.array(out)

set "threshold" as the minimum time difference you need between two points将“阈值”设置为两点之间所需的最小时间差

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM