Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

signal.resample

Resamples an array to a requested number of samples using Fourier-domain processing. It supports arbitrary integer upsampling or downsampling, optional spectral windowing, and optional output sample positions.

How it works

The function transforms the signal with an FFT, shortens or zero-pads its spectrum to the requested length, and transforms it back. It can also return sample positions when equally spaced input times are supplied; the Fourier approach treats the signal as periodic.

Syntax

scipy.signal.resample(x, num, t=None, axis=0, window=None, domain='time')

Parameters

NameTypeDescription
xarray_likeInput signal or array to resample.
numintNumber of samples in the output signal; it may be greater or less than the input length.
tarray_like, optionalOptional equally spaced sample positions associated with x.
axisint, optionalAxis of x that is resampled; default is 0.
windowarray_like, callable, string, float, or tuple, optionalOptional window applied in the Fourier domain.
domain{'time', 'freq'}, optionalInput domain, either time or frequency; default is 'time'.

Returns

resampled_x, or (resampled_x, resampled_t) when t is supplied.

Key points

  • Use resample when you need an arbitrary integer output length along one array dimension.
  • Downsampling removes spectral samples, while upsampling inserts zero-valued spectral samples before the inverse transform.
  • The Fourier approach combines ideal antialiasing with flexible integer length changes.
  • Pass t only when the input positions are equally spaced and correspond to the samples in x.
  • The output begins at the same signal value as the input, while its sample spacing changes according to the requested length.
  • Use window to shape the spectrum before changing its length, for example to reduce unwanted spectral effects.

Common mistakes

  • The Fourier method assumes periodic continuation, so discontinuities at the signal boundaries can create artifacts.
  • Choose num independently of the input length to upsample or downsample.

Example: Double a signal's sample count

import numpy as np
from scipy.signal import resample

x = np.sin(2 * np.pi * 5 * np.arange(100) / 100)
y = resample(x, 200)
print(y.shape)

This doubles a periodic signal's sample count using Fourier-domain resampling.

When to use it

Change sample density

Convert a periodic waveform to a different integer sample count for analysis or visualization.

Normalize sequence length

Create a uniformly sized signal representation from periodic sequences with differing lengths.

Shape spectral content

Apply a Fourier-domain window while changing the signal's sample count.

Interview questions

QHow does scipy.signal.resample change the sampling rate?

It uses Fourier-domain resampling: the FFT is shortened for downsampling or zero-padded for upsampling, then an inverse transform produces the output. This supports arbitrary integer output lengths and an ideal antialiasing filter.

Follow-up: What assumption can invalidate the result? The method assumes periodic data, so endpoint discontinuities may introduce ringing or other artifacts.

QWhat does the axis parameter control?

The axis parameter selects the dimension to resample and defaults to axis 0. The other dimensions retain their corresponding sizes and values are processed independently along the selected axis.

Follow-up: How would you resample each row of a 2-D array? Pass axis=1 so the columns, rather than rows, define the resampled dimension.

QWhat changes when t is provided?

With t supplied, t must represent equally spaced sample positions associated with x. The function returns both the resampled data and corresponding output positions; without t, it returns only the data array.

Follow-up: What determines the new position spacing? It is the original spacing multiplied by len(x) / num.

  • scipy.signal.resample_poly
  • scipy.signal.upfirdn
  • scipy.fft.fft
  • scipy.fft.ifft

Source: resample — SciPy v1.17.0 Manual. Checked 2026-10-15.