Wednesday, December 22, 2010

[DP] Window functions trial

I am studying the windowed-sinc filters and found SciPy has had a set of window functions to play around.

Below is my code to generate the plot of several window functions. Note that only 12 of them have been shown. There are four of them need more than one argument and I don't have time to figure out their parameters to get corresponding results.
from scipy import signal
from pylab import *

data_point = 500

windows =\
, 'triang'
, 'parzen'
, 'bohman'
, 'blackman'
, 'blackmanharris'
, 'nuttall'
, 'flattop'
, 'bartlett'
, 'hann'
, 'barthann'
, 'hamming'
#, 'kaiser'
#, 'gaussian'
#, 'general_gaussian'
#, 'slepian'

t = [i for i in range(data_point)]
steps = 3

for i in range(0,len(windows),steps):
        for j in range(i,i+steps):
                w = eval('signal.'+windows[j])(data_point)
                plot(t, w)
        legend((windows[i:i+steps]),loc='upper left')


The result:

Basically, the window functions return an array which has the size as you assigned. An easy example is as the following:

>>> from scipy import signal
>>> signal.blackman(50)
array([ -1.38777878e-17,   1.48858213e-03,   6.05806481e-03,
         1.40095693e-02,   2.58120534e-02,   4.20553960e-02,
         6.33894512e-02,   9.04534244e-02,   1.23800653e-01,
         1.63824257e-01,   2.10689158e-01,   2.64275593e-01,
         3.24138580e-01,   3.89486780e-01,   4.59182958e-01,
         5.31766851e-01,   6.05499812e-01,   6.78429126e-01,
         7.48468603e-01,   8.13490971e-01,   8.71426720e-01,
         9.20363618e-01,   9.58640963e-01,   9.84932919e-01,
         9.98315897e-01,   9.98315897e-01,   9.84932919e-01,
         9.58640963e-01,   9.20363618e-01,   8.71426720e-01,
         8.13490971e-01,   7.48468603e-01,   6.78429126e-01,
         6.05499812e-01,   5.31766851e-01,   4.59182958e-01,
         3.89486780e-01,   3.24138580e-01,   2.64275593e-01,
         2.10689158e-01,   1.63824257e-01,   1.23800653e-01,
         9.04534244e-02,   6.33894512e-02,   4.20553960e-02,
         2.58120534e-02,   1.40095693e-02,   6.05806481e-03,
         1.48858213e-03,  -1.38777878e-17])

  1. You can find the source code containing these window functions in the SciPy folder. Mine is located in /usr/lib/python2.6/dist-packages/scipy/signal/
  2. Documents can be found at
  3. There is a good book about the signal processing for engineers by Steven W. Smith: The Scientist and Engineer's Guide to Digital Signal Processing. The windowed-sinc filters are introduced in Chapter 16.

No comments:

Post a Comment