SciPy

Signal processing (scipy.signal)

Convolution

convolve(in1, in2[, mode, method])

Convolve two N-dimensional arrays.

correlate(in1, in2[, mode, method])

Cross-correlate two N-dimensional arrays.

fftconvolve(in1, in2[, mode, axes])

Convolve two N-dimensional arrays using FFT.

convolve2d(in1, in2[, mode, boundary, fillvalue])

Convolve two 2-dimensional arrays.

correlate2d(in1, in2[, mode, boundary, …])

Cross-correlate two 2-dimensional arrays.

sepfir2d()

Description:

choose_conv_method(in1, in2[, mode, measure])

Find the fastest convolution/correlation method.

B-splines

bspline(x, n)

B-spline basis function of order n.

cubic(x)

A cubic B-spline.

quadratic(x)

A quadratic B-spline.

gauss_spline(x, n)

Gaussian approximation to B-spline basis function of order n.

cspline1d(signal[, lamb])

Compute cubic spline coefficients for rank-1 array.

qspline1d(signal[, lamb])

Compute quadratic spline coefficients for rank-1 array.

cspline2d()

Description:

qspline2d()

Description:

cspline1d_eval(cj, newx[, dx, x0])

Evaluate a spline at the new set of points.

qspline1d_eval(cj, newx[, dx, x0])

Evaluate a quadratic spline at the new set of points.

spline_filter(Iin[, lmbda])

Smoothing spline (cubic) filtering of a rank-2 array.

Filtering

order_filter(a, domain, rank)

Perform an order filter on an N-dimensional array.

medfilt(volume[, kernel_size])

Perform a median filter on an N-dimensional array.

medfilt2d(input[, kernel_size])

Median filter a 2-dimensional array.

wiener(im[, mysize, noise])

Perform a Wiener filter on an N-dimensional array.

symiirorder1()

Implement a smoothing IIR filter with mirror-symmetric boundary conditions using a cascade of first-order sections.

symiirorder2()

Implement a smoothing IIR filter with mirror-symmetric boundary conditions using a cascade of second-order sections.

lfilter(b, a, x[, axis, zi])

Filter data along one-dimension with an IIR or FIR filter.

lfiltic(b, a, y[, x])

Construct initial conditions for lfilter given input and output vectors.

lfilter_zi(b, a)

Construct initial conditions for lfilter for step response steady-state.

filtfilt(b, a, x[, axis, padtype, padlen, …])

Apply a digital filter forward and backward to a signal.

savgol_filter(x, window_length, polyorder[, …])

Apply a Savitzky-Golay filter to an array.

deconvolve(signal, divisor)

Deconvolves divisor out of signal using inverse filtering.

sosfilt(sos, x[, axis, zi])

Filter data along one dimension using cascaded second-order sections.

sosfilt_zi(sos)

Construct initial conditions for sosfilt for step response steady-state.

sosfiltfilt(sos, x[, axis, padtype, padlen])

A forward-backward digital filter using cascaded second-order sections.

hilbert(x[, N, axis])

Compute the analytic signal, using the Hilbert transform.

hilbert2(x[, N])

Compute the ‘2-D’ analytic signal of x

decimate(x, q[, n, ftype, axis, zero_phase])

Downsample the signal after applying an anti-aliasing filter.

detrend(data[, axis, type, bp])

Remove linear trend along axis from data.

resample(x, num[, t, axis, window])

Resample x to num samples using Fourier method along the given axis.

resample_poly(x, up, down[, axis, window])

Resample x along the given axis using polyphase filtering.

upfirdn(h, x[, up, down, axis])

Upsample, FIR filter, and downsample

Filter design

bilinear(b, a[, fs])

Return a digital filter from an analog one using a bilinear transform.

bilinear_zpk(z, p, k, fs)

Return a digital IIR filter from an analog one using a bilinear transform.

findfreqs(num, den, N[, kind])

Find array of frequencies for computing the response of an analog filter.

firls(numtaps, bands, desired[, weight, nyq, fs])

FIR filter design using least-squares error minimization.

firwin(numtaps, cutoff[, width, window, …])

FIR filter design using the window method.

firwin2(numtaps, freq, gain[, nfreqs, …])

FIR filter design using the window method.

freqs(b, a[, worN, plot])

Compute frequency response of analog filter.

freqs_zpk(z, p, k[, worN])

Compute frequency response of analog filter.

freqz(b[, a, worN, whole, plot, fs])

Compute the frequency response of a digital filter.

freqz_zpk(z, p, k[, worN, whole, fs])

Compute the frequency response of a digital filter in ZPK form.

sosfreqz(sos[, worN, whole, fs])

Compute the frequency response of a digital filter in SOS format.

group_delay(system[, w, whole, fs])

Compute the group delay of a digital filter.

iirdesign(wp, ws, gpass, gstop[, analog, …])

Complete IIR digital and analog filter design.

iirfilter(N, Wn[, rp, rs, btype, analog, …])

IIR digital and analog filter design given order and critical points.

kaiser_atten(numtaps, width)

Compute the attenuation of a Kaiser FIR filter.

kaiser_beta(a)

Compute the Kaiser parameter beta, given the attenuation a.

kaiserord(ripple, width)

Determine the filter window parameters for the Kaiser window method.

minimum_phase(h[, method, n_fft])

Convert a linear-phase FIR filter to minimum phase

savgol_coeffs(window_length, polyorder[, …])

Compute the coefficients for a 1-d Savitzky-Golay FIR filter.

remez(numtaps, bands, desired[, weight, Hz, …])

Calculate the minimax optimal filter using the Remez exchange algorithm.

unique_roots(p[, tol, rtype])

Determine unique roots and their multiplicities from a list of roots.

residue(b, a[, tol, rtype])

Compute partial-fraction expansion of b(s) / a(s).

residuez(b, a[, tol, rtype])

Compute partial-fraction expansion of b(z) / a(z).

invres(r, p, k[, tol, rtype])

Compute b(s) and a(s) from partial fraction expansion.

invresz(r, p, k[, tol, rtype])

Compute b(z) and a(z) from partial fraction expansion.

BadCoefficients

Warning about badly conditioned filter coefficients

Lower-level filter design functions:

abcd_normalize([A, B, C, D])

Check state-space matrices and ensure they are two-dimensional.

band_stop_obj(wp, ind, passb, stopb, gpass, …)

Band Stop Objective Function for order minimization.

besselap(N[, norm])

Return (z,p,k) for analog prototype of an Nth-order Bessel filter.

buttap(N)

Return (z,p,k) for analog prototype of Nth-order Butterworth filter.

cheb1ap(N, rp)

Return (z,p,k) for Nth-order Chebyshev type I analog lowpass filter.

cheb2ap(N, rs)

Return (z,p,k) for Nth-order Chebyshev type I analog lowpass filter.

cmplx_sort(p)

Sort roots based on magnitude.

ellipap(N, rp, rs)

Return (z,p,k) of Nth-order elliptic analog lowpass filter.

lp2bp(b, a[, wo, bw])

Transform a lowpass filter prototype to a bandpass filter.

lp2bp_zpk(z, p, k[, wo, bw])

Transform a lowpass filter prototype to a bandpass filter.

lp2bs(b, a[, wo, bw])

Transform a lowpass filter prototype to a bandstop filter.

lp2bs_zpk(z, p, k[, wo, bw])

Transform a lowpass filter prototype to a bandstop filter.

lp2hp(b, a[, wo])

Transform a lowpass filter prototype to a highpass filter.

lp2hp_zpk(z, p, k[, wo])

Transform a lowpass filter prototype to a highpass filter.

lp2lp(b, a[, wo])

Transform a lowpass filter prototype to a different frequency.

lp2lp_zpk(z, p, k[, wo])

Transform a lowpass filter prototype to a different frequency.

normalize(b, a)

Normalize numerator/denominator of a continuous-time transfer function.

Matlab-style IIR filter design

butter(N, Wn[, btype, analog, output, fs])

Butterworth digital and analog filter design.

buttord(wp, ws, gpass, gstop[, analog, fs])

Butterworth filter order selection.

cheby1(N, rp, Wn[, btype, analog, output, fs])

Chebyshev type I digital and analog filter design.

cheb1ord(wp, ws, gpass, gstop[, analog, fs])

Chebyshev type I filter order selection.

cheby2(N, rs, Wn[, btype, analog, output, fs])

Chebyshev type II digital and analog filter design.

cheb2ord(wp, ws, gpass, gstop[, analog, fs])

Chebyshev type II filter order selection.

ellip(N, rp, rs, Wn[, btype, analog, output, fs])

Elliptic (Cauer) digital and analog filter design.

ellipord(wp, ws, gpass, gstop[, analog, fs])

Elliptic (Cauer) filter order selection.

bessel(N, Wn[, btype, analog, output, norm, fs])

Bessel/Thomson digital and analog filter design.

iirnotch(w0, Q[, fs])

Design second-order IIR notch digital filter.

iirpeak(w0, Q[, fs])

Design second-order IIR peak (resonant) digital filter.

Continuous-Time Linear Systems

lti(*system)

Continuous-time linear time invariant system base class.

StateSpace(*system, **kwargs)

Linear Time Invariant system in state-space form.

TransferFunction(*system, **kwargs)

Linear Time Invariant system class in transfer function form.

ZerosPolesGain(*system, **kwargs)

Linear Time Invariant system class in zeros, poles, gain form.

lsim(system, U, T[, X0, interp])

Simulate output of a continuous-time linear system.

lsim2(system[, U, T, X0])

Simulate output of a continuous-time linear system, by using the ODE solver scipy.integrate.odeint.

impulse(system[, X0, T, N])

Impulse response of continuous-time system.

impulse2(system[, X0, T, N])

Impulse response of a single-input, continuous-time linear system.

step(system[, X0, T, N])

Step response of continuous-time system.

step2(system[, X0, T, N])

Step response of continuous-time system.

freqresp(system[, w, n])

Calculate the frequency response of a continuous-time system.

bode(system[, w, n])

Calculate Bode magnitude and phase data of a continuous-time system.

Discrete-Time Linear Systems

dlti(*system, **kwargs)

Discrete-time linear time invariant system base class.

StateSpace(*system, **kwargs)

Linear Time Invariant system in state-space form.

TransferFunction(*system, **kwargs)

Linear Time Invariant system class in transfer function form.

ZerosPolesGain(*system, **kwargs)

Linear Time Invariant system class in zeros, poles, gain form.

dlsim(system, u[, t, x0])

Simulate output of a discrete-time linear system.

dimpulse(system[, x0, t, n])

Impulse response of discrete-time system.

dstep(system[, x0, t, n])

Step response of discrete-time system.

dfreqresp(system[, w, n, whole])

Calculate the frequency response of a discrete-time system.

dbode(system[, w, n])

Calculate Bode magnitude and phase data of a discrete-time system.

LTI Representations

tf2zpk(b, a)

Return zero, pole, gain (z, p, k) representation from a numerator, denominator representation of a linear filter.

tf2sos(b, a[, pairing])

Return second-order sections from transfer function representation

tf2ss(num, den)

Transfer function to state-space representation.

zpk2tf(z, p, k)

Return polynomial transfer function representation from zeros and poles

zpk2sos(z, p, k[, pairing])

Return second-order sections from zeros, poles, and gain of a system

zpk2ss(z, p, k)

Zero-pole-gain representation to state-space representation

ss2tf(A, B, C, D[, input])

State-space to transfer function.

ss2zpk(A, B, C, D[, input])

State-space representation to zero-pole-gain representation.

sos2zpk(sos)

Return zeros, poles, and gain of a series of second-order sections

sos2tf(sos)

Return a single transfer function from a series of second-order sections

cont2discrete(system, dt[, method, alpha])

Transform a continuous to a discrete state-space system.

place_poles(A, B, poles[, method, rtol, maxiter])

Compute K such that eigenvalues (A - dot(B, K))=poles.

Waveforms

chirp(t, f0, t1, f1[, method, phi, vertex_zero])

Frequency-swept cosine generator.

gausspulse(t[, fc, bw, bwr, tpr, retquad, …])

Return a Gaussian modulated sinusoid:

max_len_seq(nbits[, state, length, taps])

Maximum length sequence (MLS) generator.

sawtooth(t[, width])

Return a periodic sawtooth or triangle waveform.

square(t[, duty])

Return a periodic square-wave waveform.

sweep_poly(t, poly[, phi])

Frequency-swept cosine generator, with a time-dependent frequency.

unit_impulse(shape[, idx, dtype])

Unit impulse signal (discrete delta function) or unit basis vector.

Window functions

Most window functions are available in the scipy.signal.windows namespace, but we list them here for convenience:

get_window(window, Nx[, fftbins])

Return a window.

windows.barthann(M[, sym])

Return a modified Bartlett-Hann window.

windows.bartlett(M[, sym])

Return a Bartlett window.

windows.blackman(M[, sym])

Return a Blackman window.

windows.blackmanharris(M[, sym])

Return a minimum 4-term Blackman-Harris window.

windows.bohman(M[, sym])

Return a Bohman window.

windows.boxcar(M[, sym])

Return a boxcar or rectangular window.

windows.chebwin(M, at[, sym])

Return a Dolph-Chebyshev window.

windows.cosine(M[, sym])

Return a window with a simple cosine shape.

windows.dpss(M, NW[, Kmax, sym, norm, …])

Compute the Discrete Prolate Spheroidal Sequences (DPSS).

windows.exponential(M[, center, tau, sym])

Return an exponential (or Poisson) window.

windows.flattop(M[, sym])

Return a flat top window.

windows.gaussian(M, std[, sym])

Return a Gaussian window.

windows.general_cosine(M, a[, sym])

Generic weighted sum of cosine terms window

windows.general_gaussian(M, p, sig[, sym])

Return a window with a generalized Gaussian shape.

windows.general_hamming(M, alpha[, sym])

Return a generalized Hamming window.

windows.hamming(M[, sym])

Return a Hamming window.

windows.hann(M[, sym])

Return a Hann window.

windows.hanning(\*args, \*\*kwds)

hanning is deprecated, use scipy.signal.windows.hann instead!

windows.kaiser(M, beta[, sym])

Return a Kaiser window.

windows.nuttall(M[, sym])

Return a minimum 4-term Blackman-Harris window according to Nuttall.

windows.parzen(M[, sym])

Return a Parzen window.

windows.slepian(M, width[, sym])

Return a digital Slepian (DPSS) window.

windows.triang(M[, sym])

Return a triangular window.

windows.tukey(M[, alpha, sym])

Return a Tukey window, also known as a tapered cosine window.

Wavelets

cascade(hk[, J])

Return (x, phi, psi) at dyadic points K/2**J from filter coefficients.

daub(p)

The coefficients for the FIR low-pass filter producing Daubechies wavelets.

morlet(M[, w, s, complete])

Complex Morlet wavelet.

qmf(hk)

Return high-pass qmf filter from low-pass

ricker(points, a)

Return a Ricker wavelet, also known as the “Mexican hat wavelet”.

cwt(data, wavelet, widths)

Continuous wavelet transform.

Peak finding

argrelmin(data[, axis, order, mode])

Calculate the relative minima of data.

argrelmax(data[, axis, order, mode])

Calculate the relative maxima of data.

argrelextrema(data, comparator[, axis, …])

Calculate the relative extrema of data.

find_peaks(x[, height, threshold, distance, …])

Find peaks inside a signal based on peak properties.

find_peaks_cwt(vector, widths[, wavelet, …])

Find peaks in a 1-D array with wavelet transformation.

peak_prominences(x, peaks[, wlen])

Calculate the prominence of each peak in a signal.

peak_widths(x, peaks[, rel_height, …])

Calculate the width of each peak in a signal.

Spectral Analysis

periodogram(x[, fs, window, nfft, detrend, …])

Estimate power spectral density using a periodogram.

welch(x[, fs, window, nperseg, noverlap, …])

Estimate power spectral density using Welch’s method.

csd(x, y[, fs, window, nperseg, noverlap, …])

Estimate the cross power spectral density, Pxy, using Welch’s method.

coherence(x, y[, fs, window, nperseg, …])

Estimate the magnitude squared coherence estimate, Cxy, of discrete-time signals X and Y using Welch’s method.

spectrogram(x[, fs, window, nperseg, …])

Compute a spectrogram with consecutive Fourier transforms.

lombscargle(x, y, freqs)

Computes the Lomb-Scargle periodogram.

vectorstrength(events, period)

Determine the vector strength of the events corresponding to the given period.

stft(x[, fs, window, nperseg, noverlap, …])

Compute the Short Time Fourier Transform (STFT).

istft(Zxx[, fs, window, nperseg, noverlap, …])

Perform the inverse Short Time Fourier transform (iSTFT).

check_COLA(window, nperseg, noverlap[, tol])

Check whether the Constant OverLap Add (COLA) constraint is met

check_NOLA(window, nperseg, noverlap[, tol])

Check whether the Nonzero Overlap Add (NOLA) constraint is met