__init__.py 15 KB

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