FIRフィルタの設計by python
FIRフィルタの設計by python
○firwinの使い方
例)
scipy.signal.firwin(numtaps, cutoff, width=None, window='hamming', pass_zero=True, scale=True, nyq=1.0)
numtaps:タップ数
cutoff:カットオフ周波数
window:窓関数
pass_zero:
nyq:ナイキスト周波数
参考:https://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.signal.firwin.html
○scipy.absoluteの使い方
NumPy で絶対値 (負の数は正の数として出力、正の数は正の数として出力) を求めるには、np.absolute()があります。
参考https://docs.scipy.org/doc/numpy-1.9.1/reference/generated/numpy.absolute.html
○scipy.fft使い方
https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.fftpack.fft.html
○unwrapとは
連続だったデータもラップ(wrap)されて位相のジャンプが現れる。 これをUnwrapするたのもの
参考retrofocus28.blogspot.jp
#coding:utf8 import scipy import scipy.signal as ss from matplotlib import pyplot as pp import numpy as np import scipy.signal from pylab import * N = 221 fc = 1000. fc2 = 3000. Fs = 44100. #%% LPF h = ss.firwin(numtaps=N, cutoff=fc/(Fs/2.), window='blackman', pass_zero=True) #%% HPF f = ss.firwin(numtaps=N, cutoff=fc/(Fs/2.), window='blackman', pass_zero=False) #%% BPF e = ss.firwin(numtaps=N, cutoff=scipy.array([fc/(Fs/2.), fc2/(Fs/2.)]), window='blackman', pass_zero=False) #%% BEF h = ss.firwin(numtaps=N, cutoff=scipy.array([fc/(Fs/2.), fc2/(Fs/2.)]), window='blackman', pass_zero=True) #%% 表示 f = scipy.array(range(0, N)) * Fs / scipy.double(N) tf = scipy.fft(h) mag = scipy.absolute(tf) phase = scipy.unwrap(scipy.angle(tf)) * 180. / scipy.pi figure(1) subplot(3,1,1) pp.plot(h) grid('on', 'both') subplot(3,1,2) pp.semilogx(f, mag) xlim([20, 20000]) ylim([0, 1.2]) grid('on', 'both') subplot(3,1,3) pp.plot(f, phase) xlim([0, 20000]) grid('on', 'both') figure(2) subplot(3,1,1) pp.plot(f) grid('on', 'both') subplot(3,1,2) pp.semilogx(f, mag) xlim([20, 20000]) ylim([0, 1.2]) grid('on', 'both') subplot(3,1,3) pp.plot(f, phase) xlim([0, 20000]) grid('on', 'both') figure(3) subplot(3,1,1) pp.plot(e) grid('on', 'both') subplot(3,1,2) pp.semilogx(f, mag) xlim([20, 20000]) ylim([0, 1.2]) grid('on', 'both') subplot(3,1,3) pp.plot(f, phase) xlim([0, 20000]) grid('on', 'both') plt.show() || 参考