用numpy

时间:2019-04-04 17:50:33

标签: python numpy scipy scientific-computing

我在大学里进行了测量。信号有很多噪声,但是是周期性的。

My raw signal

我知道信号开始的点(x = 36400)以及频率(1Hz)和采样率(48000)。因此,我可以每48000点“削减”单个期间。我可以生成类似于[[period1],[period2],...,[period100]]的数组,其中每个周期都包含测量值。

我现在想在每个周期内求平均值,以得到较小的噪声信号。我知道如何使用for循环来执行此操作,但是有没有快速的方法来使用numpy?

1 个答案:

答案 0 :(得分:1)

首先,您需要对数组进行切片以获得有意义的部分

n_periods = 10  # or however man
beginning_idx = 1000  # or whever the good data begins

raw_signal = ...  # this is the data you read in
good_signal = raw_signal[beginning_idx:beginning_idx + n_periods * 48000]
periodic = good_signal.reshape(n_periods, 48000)
avg_signal = periodic.mean(axis=0)