본문 바로가기
Programming/python

파이썬으로 signal processing (scipy.signal)

by 르미르미 2020. 4. 16.

python 으로 signal processing 하는 방법을 알아보다가 찾은 scipy.signal 

 

Signal processing (scipy.signal) — SciPy v1.4.1 Reference Guide

ellip(N, rp, rs, Wn[, btype, analog, output, fs]) Elliptic (Cauer) digital and analog filter design.

docs.scipy.org

convolution, filtering, peak finding, spectral analysis 등이 가능하다. 

from scipy.signal import #butter, freqz, filtfilt, find_peaks 

 

오늘은 내가 궁금한 거 3가지만 정리

 

Butter - low pass filter 같은 butterworth filter 처리 

 

Matlab-sytle IIR filter design 

butter(N, wn[, btype, analog, output='ba', fs]) : Butterworth digital and analog filter design 

N : the order of the filter (int)

Wn : the critical freqeuncy or frequencies

btype : filter type {'lowpass', 'highpass', 'bandpass', 'bandstop'}

fs : sample frequency 

return b, a : Numerator(b) and denominator(a) polynomials of the IIR filter.

 b, a = butter(order, normal_cutoff, btype='low', analog=False)

 

 

filtfilt - filter를 data와 맞춰줌 

 

filtering 

filtfilt(b, a, x[, axis, padtype, padlen, ...]) : Apply a digital filter forward and backward to a signal 

y=filtfilt(b, a, data)

 

def butter_lowpass_filter(data, cutoff, fs, order):
  normal_cutoff=cutoff/nyq
  b, a = butter(order, normal_cutoff, btype='low', analog=False)
  y=filtfilt(b, a, data)
  return y 

 

 

find_peaks - 근처 값과 비교하여 local maxima peak를 찾아줌

 

find_peaks(x, height=None, threshold=None, distance=None, prominence=None, width=None, wlen=None, rel_height=0.5, plateau_size=None)

 

find_peaks example (https://docs.scipy.org/)

 

signal preprocessing도 가능하고 signal에서 peak 찾는 것도 가능하다. 

뿐만 아니라 peak width, height도 구할 수 있으니 더 좋다. 

 

 

댓글