Skip to content

Instantly share code, notes, and snippets.

@s-yoshiki
Created November 25, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-yoshiki/cf7b5fe56533e7a0d6db to your computer and use it in GitHub Desktop.
Save s-yoshiki/cf7b5fe56533e7a0d6db to your computer and use it in GitHub Desktop.
#ローパス関数
def low_path(xx):
sample_rate = 100.0
nsamples = 400
t = arange(nsamples) / sample_rate
#t = framerate
x = xx
nyq_rate = sample_rate / 2.0 #ナイキスト周波数
width = 5.0/nyq_rate #正規化
ripple_db = 60.0
numtaps = 255#フィルタ係数(タップ)の数(要奇数)
cutoff_hz = 10.0
b = scipy.signal.firwin(numtaps, cutoff_hz/nyq_rate)
filtered_x = scipy.signal.lfilter(b, 1.0, x)
return filtered_x
def band_path(xx):
sample_rate = 100.0
nsamples = 400
t = arange(nsamples) / sample_rate
#t = framerate
x = xx
nyq_rate = sample_rate / 2.0 #ナイキスト周波数
width = 5.0/nyq_rate #正規化
ripple_db = 60.0
numtaps = 255#フィルタ係数(タップ)の数(要奇数)
cutoff_hz = 10.0
fe1 = 10.0/nyq_rate
fe2 = 30.0/nyq_rate
b = scipy.signal.firwin(numtaps, [fe1,fe2],pass_zero=False)
filtered_x = scipy.signal.lfilter(b, 1.0, x)
return filtered_x
def high_path(xx):
sample_rate = 100.0
nsamples = 400
t = arange(nsamples) / sample_rate
#t = framerate
x = xx
nyq_rate = sample_rate / 2.0 #ナイキスト周波数
width = 5.0/nyq_rate #正規化
ripple_db = 60.0
numtaps = 255#フィルタ係数(タップ)の数(要奇数)
#cutoff_hz = 300.0
#30*10^2[Hz]
fe = 30.0/nyq_rate
b = scipy.signal.firwin(numtaps, fe ,pass_zero=False)
filtered_x = scipy.signal.lfilter(b, 1.0, x)
return filtered_x
def fft_proc(data,framerate,start,sample_num):
#X= scipy.fftpack.fft(data[start:start+sample_num]) # fft
X= np.fft.fft(data[start:start+sample_num]) # fft
freqList = np.fft.fftfreq(sample_num, d=1.0/framerate) # 周波数軸の値を計算
amplitudeSpectrum = [np.sqrt(c.real ** 2 + c.imag ** 2) for c in X] # 振幅スペクトル
return freqList, amplitudeSpectrum
def read_wave(filename):
wf=wave.open(filename,"r")
framerate=wf.getframerate()# サンプリング周波数
data=wf.readframes(wf.getnframes())
data=frombuffer(data,dtype="int16")/32768.0 #正規化
wf.close()
return data, framerate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment