performance - Python scipy butterworth runtime is drastically different on 2 arrays of similar size. Help me understand why? -


i analyzing neural signals (specifically local field potentials) recorded in brains of awake behaving rats. have 2 signals recorded on 2 different days same subject. 1 of them 1586996 samples long (12.7mb), while second 1465754 samples long (11.7mb).

i naively thought shorter data take less time filter scipy.signal.butter, totally wrong. astonished discover takes 45 s run on first one, takes whopping 8092.6 s (almost 2.5 hours) run on second one! second file takes on 180 x long filter though shorter! how can there such huge discrepancy? , can reduce run time?

here code:

import numpy np import time  # load data (you might have provide filepath) lfp1 = np.fromfile('rk97_2017-01-19_raw_30k_30pres_ger_lfp.dat', dtype='float') # longer data file lfp2 = np.fromfile('rk97_2017-02-12_raw_30k_30pres_pp_lfp.dat', dtype='float') # shorter data file  sf = 3000 # sampling freuqency (hz)  def butter_filt(order, low, high, signal):     # note: freuqencies must divided nyquist frequency!     scipy.signal import butter,filtfilt     b, = butter(order, [low, high], btype='bandpass')     filt_signal = filtfilt(b, a, signal)     return filt_signal   nyq = 0.5 * sf low = 10 / nyq high = 33 / nyq order = 4  # filter first signal start_time = time.time() lfp_filt1 = butter_filt(order, low, high, lfp1) print("--- %s seconds ---" % np.round(time.time() - start_time,decimals = 2))  # filter second signal start_time = time.time() lfp_filt2 = butter_filt(order, low, high, lfp2) print("--- %s seconds ---" % np.round(time.time() - start_time,decimals = 2)) 

i have uploaded two data files git hub can load data, run above code, , check data yourself.

some thoughts: second data file has more power in frequency band filtering (10 - 33 hz), since stimulus elicits short oscillatory bursts around 20hz in signal (visible eye if @ data). can cause filtering slow down much?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -