[Scipy-svn] r5554 - in trunk: . scipy/signal

scipy-svn@scip... scipy-svn@scip...
Sat Feb 14 16:07:55 CST 2009


Author: oliphant
Date: 2009-02-14 16:07:48 -0600 (Sat, 14 Feb 2009)
New Revision: 5554

Modified:
   trunk/THANKS.txt
   trunk/scipy/signal/signaltools.py
Log:
Add decimate function and add more THANKS for Josef P.

Modified: trunk/THANKS.txt
===================================================================
--- trunk/THANKS.txt	2009-02-14 22:02:56 UTC (rev 5553)
+++ trunk/THANKS.txt	2009-02-14 22:07:48 UTC (rev 5554)
@@ -34,7 +34,8 @@
 Anne Archibald for kd-trees and nearest neighbor in scipy.spatial.
 Pauli Virtanen for Sphinx documentation generation, online documentation
     framework and interpolation bugfixes.
-Josef Perktold for major improvements to scipy.stats and its test suite.
+Josef Perktold for major improvements to scipy.stats and its test suite and 
+              fixes and tests to optimize.curve_fit and leastsq.
 David Morrill for getting the scoreboard test system up and running.
 Louis Luangkesorn for providing multiple tests for the stats module.
 Jochen Kupper for the zoom feature in the now-deprecated plt plotting module.

Modified: trunk/scipy/signal/signaltools.py
===================================================================
--- trunk/scipy/signal/signaltools.py	2009-02-14 22:02:56 UTC (rev 5553)
+++ trunk/scipy/signal/signaltools.py	2009-02-14 22:07:48 UTC (rev 5554)
@@ -1534,15 +1534,13 @@
 
     return array(zi_return)
 
-
-
 def filtfilt(b,a,x):
     # FIXME:  For now only accepting 1d arrays
     ntaps=max(len(a),len(b))
     edge=ntaps*3
 
     if x.ndim != 1:
-        raise ValueError, "Filiflit is only accepting 1 dimension arrays."
+        raise ValueError, "filtflit only accepts 1-d arrays."
 
     #x must be bigger than edge
     if x.size < edge:
@@ -1555,7 +1553,7 @@
     if len(b) < ntaps:
         b=r_[b,zeros(len(a)-len(b))]
 
-    zi=lfilter_zi(b,a)
+    zi=lfiltir_zi(b,a)
 
     #Grow the signal to have edges for stabilizing
     #the filter with inverted replicas of the signal
@@ -1568,3 +1566,54 @@
     (y,zf)=lfilter(b,a,flipud(y),-1,zi*y[-1])
 
     return flipud(y[edge-1:-edge+1])
+
+
+from scipy.signal.filter_design import cheby1, 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
+
+    By default an order 8 Chebyshev type I filter is used or a 30 point FIR
+    filter with hamming window if ftype is 'fir'.
+
+    Parameters
+    ----------
+    x : N-d array
+      the signal to be downsampled
+    q : int
+      the downsampling factor
+    n : int or None
+      the order of the filter (1 less than the length for 'fir')
+    ftype : {'iir' or 'fir'}
+      the type of the lowpass filter
+    axis : int
+      the axis along which to decimate
+
+    Returns
+    -------
+    y : N-d array
+      the down-sampled signal
+
+    See also:  resample
+    """
+    
+    if not isinstance(q, int):
+        raise TypeError, "q must be an integer"
+
+    if n is None:
+        if ftype == 'fir':
+            n = 30
+        else:
+            n = 8
+    
+    if ftype == 'fir':
+        b = firwin(n+1, 1./q, window='hamming')
+        a = 1.
+    else:
+        b, a = cheby1(n, 0.05, 0.8/q)
+        
+    y = lfilter(b, a, x, axis=axis)
+
+    sl = [None]*y.ndim
+    sl[axis] = slice(None, None, q)    
+    return y[sl]



More information about the Scipy-svn mailing list