[Scipy-svn] r6544 - trunk/scipy/signal

scipy-svn@scip... scipy-svn@scip...
Sat Jun 19 15:03:22 CDT 2010


Author: warren.weckesser
Date: 2010-06-19 15:03:22 -0500 (Sat, 19 Jun 2010)
New Revision: 6544

Added:
   trunk/scipy/signal/fir_filter_design.py
Modified:
   trunk/scipy/signal/__init__.py
   trunk/scipy/signal/filter_design.py
   trunk/scipy/signal/signaltools.py
Log:
REF: Start a separate module for functions related to FIR filter design by moving a couple functions from filter_design.py to fir_filter_design.py

Modified: trunk/scipy/signal/__init__.py
===================================================================
--- trunk/scipy/signal/__init__.py	2010-06-19 04:18:20 UTC (rev 6543)
+++ trunk/scipy/signal/__init__.py	2010-06-19 20:03:22 UTC (rev 6544)
@@ -8,6 +8,7 @@
 from waveforms import *
 from bsplines import *
 from filter_design import *
+from fir_filter_design import *
 from ltisys import *
 from windows import *
 from signaltools import *

Modified: trunk/scipy/signal/filter_design.py
===================================================================
--- trunk/scipy/signal/filter_design.py	2010-06-19 04:18:20 UTC (rev 6543)
+++ trunk/scipy/signal/filter_design.py	2010-06-19 20:03:22 UTC (rev 6544)
@@ -1542,72 +1542,4 @@
              'h' : 'highpass'
              }
 
-def kaiserord(ripple, width):
-    """Design a Kaiser window to limit ripple and width of transition region.
-
-    Parameters
-    ----------
-    ripple -- positive number specifying maximum ripple in passband (dB)
-                and minimum ripple in stopband
-    width  -- width of transition region (normalized so that 1 corresponds
-                to pi radians / sample)
-
-    Returns
-    -------
-    N, beta -- the order and beta parameter for the kaiser window.
-
-               signal.kaiser(N,beta,sym=0) returns the window as does
-               signal.get_window(beta,N)
-               signal.get_window(('kaiser',beta),N)
-
-    Uses the empirical equations discovered by Kaiser.
-
-    Oppenheim, Schafer, "Discrete-Time Signal Processing,", p.475-476.
-    """
-    A = abs(ripple)  # in case somebody is confused as to what's meant
-    if (A>50):
-        beta = 0.1102*(A-8.7)
-    elif (A>21):
-        beta = 0.5842*(A-21)**0.4 + 0.07886*(A-21)
-    else:
-        beta = 0.0
-    N = (A-8)/2.285/(pi*width)
-    return ceil(N), beta
-
-def firwin(N, cutoff, width=None, window='hamming'):
-    """
-    FIR Filter Design using windowed ideal filter method.
-
-    Parameters
-    ----------
-    N      -- order of filter (number of taps)
-    cutoff -- cutoff frequency of filter (normalized so that 1 corresponds to
-              Nyquist or pi radians / sample)
-
-    width  -- if width is not None, then assume it is the approximate width of
-              the transition region (normalized so that 1 corresonds to pi)
-              for use in kaiser FIR filter design.
-    window -- desired window to use. See get_window for a list
-              of windows and required parameters.
-
-    Returns
-    -------
-    h      -- coefficients of length N fir filter.
-
-    """
-
-    from signaltools import get_window
-    if isinstance(width,float):
-        A = 2.285*N*width + 8
-        if (A < 21): beta = 0.0
-        elif (A <= 50): beta = 0.5842*(A-21)**0.4 + 0.07886*(A-21)
-        else: beta = 0.1102*(A-8.7)
-        window=('kaiser',beta)
-
-    win = get_window(window,N,fftbins=1)
-    alpha = N//2
-    m = numpy.arange(0,N)
-    h = win*special.sinc(cutoff*(m-alpha))
-    return h / numpy.sum(h,axis=0)
-
 warnings.simplefilter("always", BadCoefficients)

Copied: trunk/scipy/signal/fir_filter_design.py (from rev 6543, trunk/scipy/signal/filter_design.py)
===================================================================
--- trunk/scipy/signal/fir_filter_design.py	                        (rev 0)
+++ trunk/scipy/signal/fir_filter_design.py	2010-06-19 20:03:22 UTC (rev 6544)
@@ -0,0 +1,74 @@
+"""Functions for FIR filter design."""
+
+import numpy
+from numpy import pi, ceil
+from scipy import special
+
+
+def kaiserord(ripple, width):
+    """Design a Kaiser window to limit ripple and width of transition region.
+
+    Parameters
+    ----------
+    ripple -- positive number specifying maximum ripple in passband (dB)
+                and minimum ripple in stopband
+    width  -- width of transition region (normalized so that 1 corresponds
+                to pi radians / sample)
+
+    Returns
+    -------
+    N, beta -- the order and beta parameter for the kaiser window.
+
+               signal.kaiser(N,beta,sym=0) returns the window as does
+               signal.get_window(beta,N)
+               signal.get_window(('kaiser',beta),N)
+
+    Uses the empirical equations discovered by Kaiser.
+
+    Oppenheim, Schafer, "Discrete-Time Signal Processing,", p.475-476.
+    """
+    A = abs(ripple)  # in case somebody is confused as to what's meant
+    if (A>50):
+        beta = 0.1102*(A-8.7)
+    elif (A>21):
+        beta = 0.5842*(A-21)**0.4 + 0.07886*(A-21)
+    else:
+        beta = 0.0
+    N = (A-8)/2.285/(pi*width)
+    return ceil(N), beta
+
+def firwin(N, cutoff, width=None, window='hamming'):
+    """
+    FIR Filter Design using windowed ideal filter method.
+
+    Parameters
+    ----------
+    N      -- order of filter (number of taps)
+    cutoff -- cutoff frequency of filter (normalized so that 1 corresponds to
+              Nyquist or pi radians / sample)
+
+    width  -- if width is not None, then assume it is the approximate width of
+              the transition region (normalized so that 1 corresonds to pi)
+              for use in kaiser FIR filter design.
+    window -- desired window to use. See get_window for a list
+              of windows and required parameters.
+
+    Returns
+    -------
+    h      -- coefficients of length N fir filter.
+
+    """
+
+    from signaltools import get_window
+    if isinstance(width,float):
+        A = 2.285*N*width + 8
+        if (A < 21): beta = 0.0
+        elif (A <= 50): beta = 0.5842*(A-21)**0.4 + 0.07886*(A-21)
+        else: beta = 0.1102*(A-8.7)
+        window=('kaiser',beta)
+
+    win = get_window(window,N,fftbins=1)
+    alpha = N//2
+    m = numpy.arange(0,N)
+    h = win*special.sinc(cutoff*(m-alpha))
+    return h / numpy.sum(h,axis=0)

Modified: trunk/scipy/signal/signaltools.py
===================================================================
--- trunk/scipy/signal/signaltools.py	2010-06-19 04:18:20 UTC (rev 6543)
+++ trunk/scipy/signal/signaltools.py	2010-06-19 20:03:22 UTC (rev 6544)
@@ -1284,7 +1284,8 @@
     return flipud(y[edge-1:-edge+1])
 
 
-from scipy.signal.filter_design import cheby1, firwin
+from scipy.signal.filter_design import cheby1
+from scipy.signal.fir_filter_design import firwin
 
 def decimate(x, q, n=None, ftype='iir', axis=-1):
     """downsample the signal x by an integer factor q, using an order n filter



More information about the Scipy-svn mailing list