简体   繁体   English

过滤数据时出现MemoryError

[英]MemoryError while filtering data

I am implementing a filtfilt filter, but I am getting a MemoryError. 我正在实现filtfilt过滤器,但是却遇到了MemoryError。 I have tried with two different computers and the error remains. 我尝试使用两台不同的计算机,但错误仍然存​​在。

  File "C:\Users\UserName\lib\site-packages\scipy\signal\signaltools.py", line 3129, in filtfilt
    zi = lfilter_zi(b, a)
  File "C:\Users\UserName\lib\site-packages\scipy\signal\signaltools.py", line 2689, in lfilter_zi
    IminusA = np.eye(n - 1) - linalg.companion(a).T
  File "C:\Users\UserName\lib\site-packages\numpy\lib\twodim_base.py", line 201, in eye
    m = zeros((N, M), dtype=dtype, order=order)
MemoryError

Any clues how to solve this? 任何线索如何解决这个问题? My data isn't that huge (1D array with length 3011723). 我的数据不是很大(长度为3011723的一维数组)。 I'm using Pycharm at python win63. 我在python win63上使用Pycharm。 I'd be very grateful for help. 我将非常感谢您的帮助。

This is a sample code where the error occurs: 这是发生错误的示例代码:

from numpy import arange, random
from scipy.signal import kaiserord, firwin, filtfilt

fs = 1000
data = random.uniform(size=3011723)

nyq_rate = fs / 2.0

# The desired width of the transition from pass to stop, relative to the Nyquist rate
width = 0.1/nyq_rate

# The desired attenuation in the stop band, in dB.
ripple_db = 100.0

# Compute the order and Kaiser parameter for the FIR filter.
N, beta = kaiserord(ripple_db, width)

# Use firwin with a Kaiser window to create a lowpass FIR filter.
taps = firwin(N, 300/nyq_rate, window=('kaiser', beta), pass_zero=True)

# Use lfilter to filter x with the FIR filter.
filtered_data = filtfilt(taps, 1.0, data)

Best, DTake 最好,DTake

Your problem occurs when scipy.signal.filtfilt tries to compute the companion matrix. scipy.signal.filtfilt尝试计算伴随矩阵时,会发生您的问题。 For the intermediate calculation, it creates an array of size (3011723, 3011723) , which is roughly around 72563 GB . 对于中间计算,它将创建一个大小为(3011723, 3011723)的数组,大约为72563 GB It is clear that it can't fit into the memory. 显然,它无法放入内存中。

I don't see any other option but to reduce the sample size. 除了缩小样本量之外,我没有其他选择。

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

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