netpyne.support.filter

Module with support functions for filtering data

Signal filtering functions copied to NetPyNE from ObsPy by Sam Neymotin (NKI)

Originally:
Filename: filter.py
Purpose: Various Seismogram Filtering Functions
Author: Tobias Megies, Moritz Beyreuther, Yannik Behr

Email: tobias.megies@geophysik.uni-muenchen.de

Various Seismogram Filtering Functions

copyright: The ObsPy Development Team (devs@obspy.org) license: GNU Lesser General Public License, Version 3 (https://www.gnu.org/copyleft/lesser.html)

Functions:

bandpass(data, freqmin, freqmax, df[, ...])

Butterworth-Bandpass Filter.

bandstop(data, freqmin, freqmax, df[, ...])

Butterworth-Bandstop Filter.

lowpass(data, freq, df[, corners, zerophase])

Butterworth-Lowpass Filter.

highpass(data, freq, df[, corners, zerophase])

Butterworth-Highpass Filter.

envelope(data)

Envelope of a function.

remez_fir(data, freqmin, freqmax, df)

The minimax optimal bandpass using Remez algorithm.

lowpass_fir(data, freq, df[, winlen])

FIR-Lowpass Filter.

integer_decimation(data, decimation_factor)

Downsampling by applying a simple integer decimation.

lowpass_cheby_2(data, freq, df[, maxorder, ...])

Cheby2-Lowpass Filter

netpyne.support.filter.bandpass(data, freqmin, freqmax, df, corners=4, zerophase=True)[source]

Butterworth-Bandpass Filter.

Filter data from freqmin to freqmax using corners corners. The filter uses scipy.signal.iirfilter() (for design) and scipy.signal.sosfilt() (for applying the filter).

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • freqmin – Pass band low corner frequency.

  • freqmax – Pass band high corner frequency.

  • df – Sampling rate in Hz.

  • corners – Filter corners / order.

  • zerophase – If True, apply filter once forwards and once backwards. This results in twice the filter order but zero phase shift in the resulting filtered trace.

Returns:

Filtered data.

netpyne.support.filter.bandstop(data, freqmin, freqmax, df, corners=4, zerophase=False)[source]

Butterworth-Bandstop Filter.

Filter data removing data between frequencies freqmin and freqmax using corners corners. The filter uses scipy.signal.iirfilter() (for design) and scipy.signal.sosfilt() (for applying the filter).

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • freqmin – Stop band low corner frequency.

  • freqmax – Stop band high corner frequency.

  • df – Sampling rate in Hz.

  • corners – Filter corners / order.

  • zerophase – If True, apply filter once forwards and once backwards. This results in twice the number of corners but zero phase shift in the resulting filtered trace.

Returns:

Filtered data.

netpyne.support.filter.lowpass(data, freq, df, corners=4, zerophase=False)[source]

Butterworth-Lowpass Filter.

Filter data removing data over certain frequency freq using corners corners. The filter uses scipy.signal.iirfilter() (for design) and scipy.signal.sosfilt() (for applying the filter).

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • freq – Filter corner frequency.

  • df – Sampling rate in Hz.

  • corners – Filter corners / order.

  • zerophase – If True, apply filter once forwards and once backwards. This results in twice the number of corners but zero phase shift in the resulting filtered trace.

Returns:

Filtered data.

netpyne.support.filter.highpass(data, freq, df, corners=4, zerophase=False)[source]

Butterworth-Highpass Filter.

Filter data removing data below certain frequency freq using corners corners. The filter uses scipy.signal.iirfilter() (for design) and scipy.signal.sosfilt() (for applying the filter).

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • freq – Filter corner frequency.

  • df – Sampling rate in Hz.

  • corners – Filter corners / order.

  • zerophase – If True, apply filter once forwards and once backwards. This results in twice the number of corners but zero phase shift in the resulting filtered trace.

Returns:

Filtered data.

netpyne.support.filter.envelope(data)[source]

Envelope of a function.

Computes the envelope of the given function. The envelope is determined by adding the squared amplitudes of the function and it’s Hilbert-Transform and then taking the square-root. (See [Kanasewich1981]) The envelope at the start/end should not be taken too seriously.

Parameters:

data (numpy.ndarray) – Data to make envelope of.

Returns:

Envelope of input data.

netpyne.support.filter.remez_fir(data, freqmin, freqmax, df)[source]

The minimax optimal bandpass using Remez algorithm. (experimental)

Warning

This is experimental code. Use with caution!

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • freqmin – Low corner frequency.

  • freqmax – High corner frequency.

  • df – Sampling rate in Hz.

Returns:

Filtered data.

Finite impulse response (FIR) filter whose transfer function minimizes the maximum error between the desired gain and the realized gain in the specified bands using the Remez exchange algorithm.

Added in version 0.6.2.

netpyne.support.filter.lowpass_fir(data, freq, df, winlen=2048)[source]

FIR-Lowpass Filter. (experimental)

Warning

This is experimental code. Use with caution!

Filter data by passing data only below a certain frequency.

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • freq – Data below this frequency pass.

  • df – Sampling rate in Hz.

  • winlen – Window length for filter in samples, must be power of 2; Default 2048

Returns:

Filtered data.

Added in version 0.6.2.

netpyne.support.filter.integer_decimation(data, decimation_factor)[source]

Downsampling by applying a simple integer decimation.

Make sure that no signal is present in frequency bands above the new Nyquist frequency (samp_rate/2/decimation_factor), e.g. by applying a lowpass filter beforehand! New sampling rate is old sampling rate divided by decimation_factor.

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • decimation_factor – Integer decimation factor

Returns:

Downsampled data (array length: old length / decimation_factor)

netpyne.support.filter.lowpass_cheby_2(data, freq, df, maxorder=12, ba=False, freq_passband=False)[source]

Cheby2-Lowpass Filter

Filter data by passing data only below a certain frequency. The main purpose of this cheby2 filter is downsampling. #318 shows some plots of this filter design itself.

This method will iteratively design a filter, whose pass band frequency is determined dynamically, such that the values above the stop band frequency are lower than -96dB.

Parameters:
  • data (numpy.ndarray) – Data to filter.

  • freq – The frequency above which signals are attenuated with 95 dB

  • df – Sampling rate in Hz.

  • maxorder – Maximal order of the designed cheby2 filter

  • ba – If True return only the filter coefficients (b, a) instead of filtering

  • freq_passband – If True return additionally to the filtered data, the iteratively determined pass band frequency

Returns:

Filtered data.