Skip to content

Commit

Permalink
Speed up hilbert transform by zero padding the fft/ifft
Browse files Browse the repository at this point in the history
  • Loading branch information
edeno committed Jun 5, 2018
1 parent ee76735 commit 1dc49e5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ripple_detection/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import pandas as pd
from scipy.fftpack import next_fast_len
from scipy.io import loadmat
from scipy.ndimage.filters import gaussian_filter1d
from scipy.signal import filtfilt, hilbert, remez
Expand Down Expand Up @@ -207,7 +208,10 @@ def _extend_segment(segments_to_extend, containing_segments):
def get_envelope(data, axis=0):
'''Extracts the instantaneous amplitude (envelope) of an analytic
signal using the Hilbert transform'''
return np.abs(hilbert(data, axis=axis))
n_samples = data.shape[axis]
instantaneous_amplitude = np.abs(
hilbert(data, N=next_fast_len(n_samples), axis=axis))
return np.take(instantaneous_amplitude, np.arange(n_samples), axis=axis)


def gaussian_smooth(data, sigma, sampling_frequency, axis=0, truncate=8):
Expand Down

0 comments on commit 1dc49e5

Please sign in to comment.