10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

scipyでフィルタ作成

Last updated at Posted at 2013-12-08

引き続きscipyネタ.
公式のリファレンスを眺めていたところ,フィルタ作成用の関数を発見したので早速実験.
今回はremez法と窓関数法でローパスフィルタを作ってみた.

filter.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import scipy as sp
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

if __name__ == '__main__':
    #64タップで通過域が0〜0.25, 阻止域が0.3〜0.5なフィルタ
    taps = 64;
    edge = [ 0,  0.25 , 0.3, 0.5 ]
    gain = [ 1.0,  0.000 ]
    weight = [ 0.2, 1.0 ]

    remez_impres = sp.signal.remez( taps,  edge, gain )
    remez_freq, remez_fresponse = sp.signal.freqz( remez_impres )
    remez_amp = np.abs( remez_fresponse )

    wf_impres = sp.signal.firwin( taps, 2.0 * edge[1] );
    wf_freq, wf_fresponse = sp.signal.freqz( wf_impres )
    wf_amp = np.abs( wf_fresponse )

    plt.subplot(221)
    plt.semilogy( remez_freq / ( 2 * np.pi ),  remez_amp, 'b-' )
    plt.title( 'Frequency Response( Remez )' )

    plt.subplot(222)
    plt.plot( remez_impres, 'b-' )
    plt.title( 'Impres Response( Remez )' )

    plt.subplot(223)
    plt.semilogy( wf_freq / ( 2 * np.pi ),  wf_amp, 'b-' )
    plt.title( 'Frequency Response( Window )' )

    plt.subplot(224)
    plt.plot( wf_impres, 'b-' )
    plt.title( 'Impres Response( Window )' )
    plt.show()

窓関数法が思いのほか良かった.
パラメータの設定も楽だし,気軽に使いたいときはこっちの方が良いと思う.

filter_design.png

10
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?