__init__.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. """
  2. =======================================
  3. Signal processing (:mod:`scipy.signal`)
  4. =======================================
  5. Convolution
  6. ===========
  7. .. autosummary::
  8. :toctree: generated/
  9. convolve -- N-D convolution.
  10. correlate -- N-D correlation.
  11. fftconvolve -- N-D convolution using the FFT.
  12. oaconvolve -- N-D convolution using the overlap-add method.
  13. convolve2d -- 2-D convolution (more options).
  14. correlate2d -- 2-D correlation (more options).
  15. sepfir2d -- Convolve with a 2-D separable FIR filter.
  16. choose_conv_method -- Chooses faster of FFT and direct convolution methods.
  17. correlation_lags -- Determines lag indices for 1D cross-correlation.
  18. B-splines
  19. =========
  20. .. autosummary::
  21. :toctree: generated/
  22. bspline -- B-spline basis function of order n.
  23. cubic -- B-spline basis function of order 3.
  24. quadratic -- B-spline basis function of order 2.
  25. gauss_spline -- Gaussian approximation to the B-spline basis function.
  26. cspline1d -- Coefficients for 1-D cubic (3rd order) B-spline.
  27. qspline1d -- Coefficients for 1-D quadratic (2nd order) B-spline.
  28. cspline2d -- Coefficients for 2-D cubic (3rd order) B-spline.
  29. qspline2d -- Coefficients for 2-D quadratic (2nd order) B-spline.
  30. cspline1d_eval -- Evaluate a cubic spline at the given points.
  31. qspline1d_eval -- Evaluate a quadratic spline at the given points.
  32. spline_filter -- Smoothing spline (cubic) filtering of a rank-2 array.
  33. Filtering
  34. =========
  35. .. autosummary::
  36. :toctree: generated/
  37. order_filter -- N-D order filter.
  38. medfilt -- N-D median filter.
  39. medfilt2d -- 2-D median filter (faster).
  40. wiener -- N-D Wiener filter.
  41. symiirorder1 -- 2nd-order IIR filter (cascade of first-order systems).
  42. symiirorder2 -- 4th-order IIR filter (cascade of second-order systems).
  43. lfilter -- 1-D FIR and IIR digital linear filtering.
  44. lfiltic -- Construct initial conditions for `lfilter`.
  45. lfilter_zi -- Compute an initial state zi for the lfilter function that
  46. -- corresponds to the steady state of the step response.
  47. filtfilt -- A forward-backward filter.
  48. savgol_filter -- Filter a signal using the Savitzky-Golay filter.
  49. deconvolve -- 1-D deconvolution using lfilter.
  50. sosfilt -- 1-D IIR digital linear filtering using
  51. -- a second-order sections filter representation.
  52. sosfilt_zi -- Compute an initial state zi for the sosfilt function that
  53. -- corresponds to the steady state of the step response.
  54. sosfiltfilt -- A forward-backward filter for second-order sections.
  55. hilbert -- Compute 1-D analytic signal, using the Hilbert transform.
  56. hilbert2 -- Compute 2-D analytic signal, using the Hilbert transform.
  57. decimate -- Downsample a signal.
  58. detrend -- Remove linear and/or constant trends from data.
  59. resample -- Resample using Fourier method.
  60. resample_poly -- Resample using polyphase filtering method.
  61. upfirdn -- Upsample, apply FIR filter, downsample.
  62. Filter design
  63. =============
  64. .. autosummary::
  65. :toctree: generated/
  66. bilinear -- Digital filter from an analog filter using
  67. -- the bilinear transform.
  68. bilinear_zpk -- Digital filter from an analog filter using
  69. -- the bilinear transform.
  70. findfreqs -- Find array of frequencies for computing filter response.
  71. firls -- FIR filter design using least-squares error minimization.
  72. firwin -- Windowed FIR filter design, with frequency response
  73. -- defined as pass and stop bands.
  74. firwin2 -- Windowed FIR filter design, with arbitrary frequency
  75. -- response.
  76. freqs -- Analog filter frequency response from TF coefficients.
  77. freqs_zpk -- Analog filter frequency response from ZPK coefficients.
  78. freqz -- Digital filter frequency response from TF coefficients.
  79. freqz_zpk -- Digital filter frequency response from ZPK coefficients.
  80. sosfreqz -- Digital filter frequency response for SOS format filter.
  81. gammatone -- FIR and IIR gammatone filter design.
  82. group_delay -- Digital filter group delay.
  83. iirdesign -- IIR filter design given bands and gains.
  84. iirfilter -- IIR filter design given order and critical frequencies.
  85. kaiser_atten -- Compute the attenuation of a Kaiser FIR filter, given
  86. -- the number of taps and the transition width at
  87. -- discontinuities in the frequency response.
  88. kaiser_beta -- Compute the Kaiser parameter beta, given the desired
  89. -- FIR filter attenuation.
  90. kaiserord -- Design a Kaiser window to limit ripple and width of
  91. -- transition region.
  92. minimum_phase -- Convert a linear phase FIR filter to minimum phase.
  93. savgol_coeffs -- Compute the FIR filter coefficients for a Savitzky-Golay
  94. -- filter.
  95. remez -- Optimal FIR filter design.
  96. unique_roots -- Unique roots and their multiplicities.
  97. residue -- Partial fraction expansion of b(s) / a(s).
  98. residuez -- Partial fraction expansion of b(z) / a(z).
  99. invres -- Inverse partial fraction expansion for analog filter.
  100. invresz -- Inverse partial fraction expansion for digital filter.
  101. BadCoefficients -- Warning on badly conditioned filter coefficients.
  102. Lower-level filter design functions:
  103. .. autosummary::
  104. :toctree: generated/
  105. abcd_normalize -- Check state-space matrices and ensure they are rank-2.
  106. band_stop_obj -- Band Stop Objective Function for order minimization.
  107. besselap -- Return (z,p,k) for analog prototype of Bessel filter.
  108. buttap -- Return (z,p,k) for analog prototype of Butterworth filter.
  109. cheb1ap -- Return (z,p,k) for type I Chebyshev filter.
  110. cheb2ap -- Return (z,p,k) for type II Chebyshev filter.
  111. cmplx_sort -- Sort roots based on magnitude.
  112. ellipap -- Return (z,p,k) for analog prototype of elliptic filter.
  113. lp2bp -- Transform a lowpass filter prototype to a bandpass filter.
  114. lp2bp_zpk -- Transform a lowpass filter prototype to a bandpass filter.
  115. lp2bs -- Transform a lowpass filter prototype to a bandstop filter.
  116. lp2bs_zpk -- Transform a lowpass filter prototype to a bandstop filter.
  117. lp2hp -- Transform a lowpass filter prototype to a highpass filter.
  118. lp2hp_zpk -- Transform a lowpass filter prototype to a highpass filter.
  119. lp2lp -- Transform a lowpass filter prototype to a lowpass filter.
  120. lp2lp_zpk -- Transform a lowpass filter prototype to a lowpass filter.
  121. normalize -- Normalize polynomial representation of a transfer function.
  122. Matlab-style IIR filter design
  123. ==============================
  124. .. autosummary::
  125. :toctree: generated/
  126. butter -- Butterworth
  127. buttord
  128. cheby1 -- Chebyshev Type I
  129. cheb1ord
  130. cheby2 -- Chebyshev Type II
  131. cheb2ord
  132. ellip -- Elliptic (Cauer)
  133. ellipord
  134. bessel -- Bessel (no order selection available -- try butterod)
  135. iirnotch -- Design second-order IIR notch digital filter.
  136. iirpeak -- Design second-order IIR peak (resonant) digital filter.
  137. iircomb -- Design IIR comb filter.
  138. Continuous-time linear systems
  139. ==============================
  140. .. autosummary::
  141. :toctree: generated/
  142. lti -- Continuous-time linear time invariant system base class.
  143. StateSpace -- Linear time invariant system in state space form.
  144. TransferFunction -- Linear time invariant system in transfer function form.
  145. ZerosPolesGain -- Linear time invariant system in zeros, poles, gain form.
  146. lsim -- Continuous-time simulation of output to linear system.
  147. lsim2 -- Like lsim, but `scipy.integrate.odeint` is used.
  148. impulse -- Impulse response of linear, time-invariant (LTI) system.
  149. impulse2 -- Like impulse, but `scipy.integrate.odeint` is used.
  150. step -- Step response of continuous-time LTI system.
  151. step2 -- Like step, but `scipy.integrate.odeint` is used.
  152. freqresp -- Frequency response of a continuous-time LTI system.
  153. bode -- Bode magnitude and phase data (continuous-time LTI).
  154. Discrete-time linear systems
  155. ============================
  156. .. autosummary::
  157. :toctree: generated/
  158. dlti -- Discrete-time linear time invariant system base class.
  159. StateSpace -- Linear time invariant system in state space form.
  160. TransferFunction -- Linear time invariant system in transfer function form.
  161. ZerosPolesGain -- Linear time invariant system in zeros, poles, gain form.
  162. dlsim -- Simulation of output to a discrete-time linear system.
  163. dimpulse -- Impulse response of a discrete-time LTI system.
  164. dstep -- Step response of a discrete-time LTI system.
  165. dfreqresp -- Frequency response of a discrete-time LTI system.
  166. dbode -- Bode magnitude and phase data (discrete-time LTI).
  167. LTI representations
  168. ===================
  169. .. autosummary::
  170. :toctree: generated/
  171. tf2zpk -- Transfer function to zero-pole-gain.
  172. tf2sos -- Transfer function to second-order sections.
  173. tf2ss -- Transfer function to state-space.
  174. zpk2tf -- Zero-pole-gain to transfer function.
  175. zpk2sos -- Zero-pole-gain to second-order sections.
  176. zpk2ss -- Zero-pole-gain to state-space.
  177. ss2tf -- State-pace to transfer function.
  178. ss2zpk -- State-space to pole-zero-gain.
  179. sos2zpk -- Second-order sections to zero-pole-gain.
  180. sos2tf -- Second-order sections to transfer function.
  181. cont2discrete -- Continuous-time to discrete-time LTI conversion.
  182. place_poles -- Pole placement.
  183. Waveforms
  184. =========
  185. .. autosummary::
  186. :toctree: generated/
  187. chirp -- Frequency swept cosine signal, with several freq functions.
  188. gausspulse -- Gaussian modulated sinusoid.
  189. max_len_seq -- Maximum length sequence.
  190. sawtooth -- Periodic sawtooth.
  191. square -- Square wave.
  192. sweep_poly -- Frequency swept cosine signal; freq is arbitrary polynomial.
  193. unit_impulse -- Discrete unit impulse.
  194. Window functions
  195. ================
  196. For window functions, see the `scipy.signal.windows` namespace.
  197. In the `scipy.signal` namespace, there is a convenience function to
  198. obtain these windows by name:
  199. .. autosummary::
  200. :toctree: generated/
  201. get_window -- Return a window of a given length and type.
  202. Wavelets
  203. ========
  204. .. autosummary::
  205. :toctree: generated/
  206. cascade -- Compute scaling function and wavelet from coefficients.
  207. daub -- Return low-pass.
  208. morlet -- Complex Morlet wavelet.
  209. qmf -- Return quadrature mirror filter from low-pass.
  210. ricker -- Return ricker wavelet.
  211. morlet2 -- Return Morlet wavelet, compatible with cwt.
  212. cwt -- Perform continuous wavelet transform.
  213. Peak finding
  214. ============
  215. .. autosummary::
  216. :toctree: generated/
  217. argrelmin -- Calculate the relative minima of data.
  218. argrelmax -- Calculate the relative maxima of data.
  219. argrelextrema -- Calculate the relative extrema of data.
  220. find_peaks -- Find a subset of peaks inside a signal.
  221. find_peaks_cwt -- Find peaks in a 1-D array with wavelet transformation.
  222. peak_prominences -- Calculate the prominence of each peak in a signal.
  223. peak_widths -- Calculate the width of each peak in a signal.
  224. Spectral analysis
  225. =================
  226. .. autosummary::
  227. :toctree: generated/
  228. periodogram -- Compute a (modified) periodogram.
  229. welch -- Compute a periodogram using Welch's method.
  230. csd -- Compute the cross spectral density, using Welch's method.
  231. coherence -- Compute the magnitude squared coherence, using Welch's method.
  232. spectrogram -- Compute the spectrogram.
  233. lombscargle -- Computes the Lomb-Scargle periodogram.
  234. vectorstrength -- Computes the vector strength.
  235. stft -- Compute the Short Time Fourier Transform.
  236. istft -- Compute the Inverse Short Time Fourier Transform.
  237. check_COLA -- Check the COLA constraint for iSTFT reconstruction.
  238. check_NOLA -- Check the NOLA constraint for iSTFT reconstruction.
  239. Chirp Z-transform and Zoom FFT
  240. ============================================
  241. .. autosummary::
  242. :toctree: generated/
  243. czt - Chirp z-transform convenience function
  244. zoom_fft - Zoom FFT convenience function
  245. CZT - Chirp z-transform function generator
  246. ZoomFFT - Zoom FFT function generator
  247. czt_points - Output the z-plane points sampled by a chirp z-transform
  248. The functions are simpler to use than the classes, but are less efficient when
  249. using the same transform on many arrays of the same length, since they
  250. repeatedly generate the same chirp signal with every call. In these cases,
  251. use the classes to create a reusable function instead.
  252. """
  253. from . import _sigtools, windows
  254. from ._waveforms import *
  255. from ._max_len_seq import max_len_seq
  256. from ._upfirdn import upfirdn
  257. from ._spline import ( # noqa: F401
  258. cspline2d,
  259. qspline2d,
  260. sepfir2d,
  261. symiirorder1,
  262. symiirorder2,
  263. )
  264. from ._bsplines import *
  265. from ._filter_design import *
  266. from ._fir_filter_design import *
  267. from ._ltisys import *
  268. from ._lti_conversion import *
  269. from ._signaltools import *
  270. from ._savitzky_golay import savgol_coeffs, savgol_filter
  271. from ._spectral_py import *
  272. from ._wavelets import *
  273. from ._peak_finding import *
  274. from ._czt import *
  275. from .windows import get_window # keep this one in signal namespace
  276. # Deprecated namespaces, to be removed in v2.0.0
  277. from . import (
  278. bsplines, filter_design, fir_filter_design, lti_conversion, ltisys,
  279. spectral, signaltools, waveforms, wavelets, spline
  280. )
  281. # deal with * -> windows.* doc-only soft-deprecation
  282. deprecated_windows = ('boxcar', 'triang', 'parzen', 'bohman', 'blackman',
  283. 'nuttall', 'blackmanharris', 'flattop', 'bartlett',
  284. 'barthann', 'hamming', 'kaiser', 'gaussian',
  285. 'general_gaussian', 'chebwin', 'cosine',
  286. 'hann', 'exponential', 'tukey')
  287. def deco(name):
  288. f = getattr(windows, name)
  289. # Add deprecation to docstring
  290. def wrapped(*args, **kwargs):
  291. return f(*args, **kwargs)
  292. wrapped.__name__ = name
  293. wrapped.__module__ = 'scipy.signal'
  294. if hasattr(f, '__qualname__'):
  295. wrapped.__qualname__ = f.__qualname__
  296. if f.__doc__:
  297. lines = f.__doc__.splitlines()
  298. for li, line in enumerate(lines):
  299. if line.strip() == 'Parameters':
  300. break
  301. else:
  302. raise RuntimeError('dev error: badly formatted doc')
  303. spacing = ' ' * line.find('P')
  304. lines.insert(li, ('{0}.. warning:: scipy.signal.{1} is deprecated,\n'
  305. '{0} use scipy.signal.windows.{1} '
  306. 'instead.\n'.format(spacing, name)))
  307. wrapped.__doc__ = '\n'.join(lines)
  308. return wrapped
  309. for name in deprecated_windows:
  310. locals()[name] = deco(name)
  311. del deprecated_windows, name, deco
  312. __all__ = [s for s in dir() if not s.startswith('_')]
  313. from scipy._lib._testutils import PytestTester
  314. test = PytestTester(__name__)
  315. del PytestTester