graph TD
A[Need to change sample rate] --> B{Only downsampling?}
B -- Yes --> C{Integer factor and standard filtering is fine?}
C -- Yes --> D[Use DECIMATE]
C -- No --> E[Use RESAMPLE_POLY or UPFIRDN]
B -- No --> F{Need arbitrary output length via FFT and periodic assumption is acceptable?}
F -- Yes --> G[Use RESAMPLE]
F -- No --> H{Need explicit FIR or boundary mode control?}
H -- Yes --> I[Use RESAMPLE_POLY]
I --> J{Need custom FIR coefficients / low-level control?}
J -- Yes --> K[Use UPFIRDN]
J -- No --> L[Stay with RESAMPLE_POLY]
H -- No --> L
Resampling
Overview
Introduction Resampling in digital signal processing is the process of changing a signal’s sampling rate while preserving the information content needed for the task at hand. In practical terms, it converts data from one time grid to another: for example, from 48 kHz to 16 kHz for speech analytics, or from irregular internal simulation rates to fixed reporting rates for engineering dashboards. Mathematically, resampling combines interpolation (for rate increase), decimation (for rate decrease), and filtering (to prevent distortion). A concise background reference is Resampling (signal processing).
For business and technical users, resampling is often less about theory and more about interoperability and model quality. Data arrives from sensors, PLCs, test rigs, lab equipment, audio pipelines, and software logs at many different frequencies. Teams need a common rate to compare channels, run feature extraction, train machine-learning models, and produce consistent plots. Without careful resampling, analyses can be misleading: frequencies can fold into lower bands (aliasing), transients can be shifted in time, and boundary artifacts can appear as false anomalies.
Boardflare’s resampling category wraps core functionality from SciPy’s scipy.signal module, especially DECIMATE, RESAMPLE, RESAMPLE_POLY, and UPFIRDN. These are complementary rather than redundant:
- DECIMATE is specialized downsampling with anti-alias filtering.
- RESAMPLE uses an FFT/Fourier method for arbitrary output lengths.
- RESAMPLE_POLY performs rational-rate conversion with FIR polyphase filtering.
- UPFIRDN is the low-level multirate primitive: upsample, FIR filter, then downsample efficiently.
This split is important for practitioners because there is no single “best” resampler for every workload. Some pipelines prioritize strict periodic assumptions and spectral sharpness, some need stable edge behavior for non-periodic records, and some need raw throughput on long arrays. Choosing the right function materially affects compute cost, phase behavior, and downstream model reliability.
When to Use It Resampling is most useful when the job to be done is “make data comparable and usable across systems that do not share the same clock.” The following scenarios represent common production cases where these tools solve concrete problems.
Industrial condition monitoring across mixed sensor hardware
A manufacturing team may collect vibration at 25.6 kHz, temperature at 1 Hz, and motor current at 5 kHz. For fault classification, features must be aligned to shared windows. A practical approach is to downsample high-rate channels after low-pass filtering, often with DECIMATE for integer reduction or RESAMPLE_POLY for rational ratios. The result is synchronized channels that preserve fault-relevant frequency bands while reducing storage and training costs.Speech and audio analytics standardization
Contact center recordings may arrive at 8 kHz, 16 kHz, or 48 kHz depending on codec and source device. Most ASR and NLP front ends expect a fixed target rate (commonly 16 kHz). For arbitrary-length conversion with periodic assumptions acceptable over short frames, RESAMPLE can be effective. For robust handling of non-periodic clips and predictable FIR behavior, RESAMPLE_POLY is usually preferred. This step improves model compatibility and reduces false phoneme boundaries caused by naive interpolation.Telemetry aggregation for real-time dashboards
Engineering telemetry often has inconsistent update rates and occasional bursts. To compute fleet KPIs every second or every minute, raw feeds must be rate-converted before aggregation. UPFIRDN is useful in custom pipelines where teams design the FIR coefficients explicitly (e.g., application-specific passband ripple). If the requirement is only integer decimation with sensible defaults, DECIMATE is a faster path to stable metrics.Simulation-to-test correlation in R&D
Simulators may output signals on one grid while test benches sample on another. Analysts need comparable spectra and transients to validate models. RESAMPLE is convenient when target sample count is predetermined and periodic framing is reasonable. RESAMPLE_POLY is often the safer default for finite, non-periodic records where edge handling and controllable filter design matter.Data volume control without losing physics
Long-duration recordings can be expensive to store and query. Downsampling reduces volume, but direct point skipping destroys spectral integrity. DECIMATE and RESAMPLE_POLY preserve content in the retained band by applying anti-alias filtering first, enabling smaller datasets while keeping trends and harmonics that drive decisions.
In each case, the core value is the same: resampling converts “hard-to-use raw streams” into “analysis-ready signals” without introducing avoidable artifacts.
How It Works At a high level, sampling rate conversion from input rate f_s to output rate f_s' is controlled by a ratio:
r = \frac{f_s'}{f_s}.
When r < 1, the process is downsampling; when r > 1, it is upsampling. For rational ratios,
r = \frac{L}{M},
where L is an upsampling factor and M is a downsampling factor.
The central signal-processing constraint is aliasing. If a signal is downsampled by M, its new Nyquist frequency becomes \pi/M (normalized radian frequency), so energy above that threshold must be attenuated before decimation. A standard decimation pipeline is:
y[n] = (x[n] * h[n])\downarrow M,
where h[n] is an anti-alias low-pass filter and \downarrow M means keep every M-th sample.
For rational conversion:
y[n] = \left(\left(x[n] \uparrow L\right) * h[n]\right)\downarrow M,
with \uparrow L denoting zero insertion between samples.
Boardflare’s four functions map to this theory as follows.
DECIMATE
This function implements anti-aliased integer downsampling and exposes filter family choices (iir or fir). In SciPy, defaults are typically an order-8 Chebyshev Type I IIR or an FIR/Hamming design depending on mode. The zero_phase option is operationally important: it uses forward-backward filtering (filtfilt) for IIR or delay compensation for FIR to reduce phase distortion. This is usually desirable in feature pipelines where event timing matters.
RESAMPLE
This function performs FFT-domain resampling by truncating or zero-padding the Fourier representation and transforming back. Conceptually:
X[k] = \mathcal{F}\{x[n]\}, \qquad \tilde{X}[k] = \text{pad/truncate}(X[k]), \qquad y[n] = \mathcal{F}^{-1}\{\tilde{X}[k]\}.
Its strengths are arbitrary output lengths and an idealized anti-alias perspective in the Fourier domain. Its main assumption is periodic continuation of the input segment, which can produce edge ringing for non-periodic signals. This makes it attractive for periodic or frame-based contexts, but potentially less robust on finite one-off records with strong boundary discontinuities.
RESAMPLE_POLY
This function applies the rational-rate formula with polyphase FIR filtering. Polyphase decomposition reorganizes filtering work so unnecessary multiplications are skipped, substantially improving efficiency for many large or awkward lengths (especially with prime-size FFT-unfriendly arrays). SciPy documents that this is often faster than Fourier resampling in those cases. It also provides practical boundary control via padtype and optional cval, making behavior near record edges more explicit than pure FFT periodic extension.
UPFIRDN
This is the foundational primitive behind many multirate operations: upsample, FIR filter, downsample, executed with a polyphase algorithm. It is ideal when users need direct control of FIR coefficients h[n] and extension mode. In implementation terms, it offers efficient complexity compared with a naive cascade and enables custom interpolation/decimation kernels used in DSP-heavy systems.
From a modeling standpoint, three assumptions should always be checked before choosing a method:
- Sampling regularity: these tools assume uniformly spaced input samples; irregular timestamps require interpolation-oriented workflows.
- Bandwidth relative to target Nyquist: if high-frequency content exceeds the post-conversion Nyquist and is not filtered, aliasing is inevitable.
- Boundary behavior: finite windows have edges; periodic assumption (RESAMPLE) and padding assumptions (RESAMPLE_POLY, UPFIRDN) can affect transient interpretation.
In production settings, these assumptions matter as much as parameter values. Teams that encode them explicitly in their pipeline specs get much more stable outcomes than teams that treat resampling as a one-line format conversion.
Primary implementation references: SciPy signal processing documentation, including function docs for decimate, resample, resample_poly, and upfirdn.
Practical Example Consider a predictive-maintenance team monitoring a rotating machine. Vibration is sampled at 12,800 Hz, but the feature service and historical warehouse are standardized at 3,200 Hz for cost and compatibility. The team needs to preserve harmonics up to 1,200 Hz and maintain event timing for fault onset detection.
Step-by-step workflow:
Define technical requirements
Input f_s = 12{,}800 Hz, target f_s' = 3{,}200 Hz. This is a 4:1 downsample ratio. The target Nyquist is 1,600 Hz, so preserving content up to 1,200 Hz is feasible if anti-alias filtering attenuates frequencies above 1,600 Hz.Choose a baseline converter
Because the ratio is integer and the objective is straightforward downsampling, DECIMATE is an operationally simple first choice. Setq=4, keepzero_phase=trueto avoid phase shift in event timing features.Validate spectral integrity
Compare pre/post power spectra and confirm that high-frequency components above 1,600 Hz do not fold into the retained band. If leakage or undesired transition width appears, tune filter order or switch to an FIR-focused approach.Handle non-ideal boundaries
If records are short and non-periodic with strong edges (e.g., startup transients), evaluate RESAMPLE_POLY with explicitpoly_padtype(line,mean, orconstant) and compare edge behavior. In many industrial traces, this reduces boundary artifacts versus periodic FFT assumptions.Scale to heterogeneous feeds
Suppose another subsystem samples at 10,000 Hz and must also land at 3,200 Hz. The ratio is 3200/10000 = 8/25, so rational conversion is needed. RESAMPLE_POLY withup=8,down=25provides a direct path with FIR control.Advance to custom filter control when needed
If the analytics team requires a specific passband ripple and stopband attenuation profile tied to regulatory standards, design FIR coefficients externally and apply UPFIRDN. This gives direct governance over the filter kernel while preserving efficient multirate execution.Reserve Fourier resampling for specific use cases
For periodic laboratory sweeps where analysts need exact output length matching and often compare harmonically structured signals, RESAMPLE is convenient and mathematically elegant. For finite non-periodic telemetry, it should be validated carefully at boundaries before standardization.
Business outcome: the team reduces storage and model runtime while retaining the vibration signatures used for bearing-fault detection. More importantly, the resampling process is documented as a governed transformation rather than an opaque preprocessing step, improving auditability and reproducibility across engineering and data science teams.
How to Choose Use the decision logic below to select the right calculator quickly.
Comparison summary:
| Function | Best Fit | Strengths | Tradeoffs | Typical Trigger |
|---|---|---|---|---|
| DECIMATE | Integer downsampling | Built-in anti-alias filtering, simple API, zero_phase option |
Focused scope (downsampling only), less direct control than low-level FIR workflows | “I need clean downsampling by an integer factor now.” |
| RESAMPLE | Arbitrary output sample count, FFT-centric workflows | Flexible target length, strong spectral interpretation in Fourier domain | Assumes periodic signal; potential edge ringing on non-periodic records; FFT size can impact speed | “I need exactly N output samples and periodic framing is acceptable.” |
| RESAMPLE_POLY | Rational rate conversion for non-periodic finite signals | Polyphase efficiency, FIR-based behavior, explicit padtype handling |
Requires thinking in up/down ratios and FIR/window choices |
“I need robust, production-friendly rate conversion with boundary control.” |
| UPFIRDN | Custom multirate DSP pipelines | Maximum control over FIR coefficients and modes; efficient polyphase primitive | More design responsibility (you own filter design quality) | “I need low-level, governed filter behavior beyond canned defaults.” |
Practical chooser rules:
- Start with DECIMATE for straightforward integer downsampling.
- Use RESAMPLE_POLY as the general-purpose default for rational conversion and non-periodic data.
- Use RESAMPLE when exact output length and periodic FFT assumptions align with the use case.
- Use UPFIRDN when DSP engineers must enforce custom FIR designs or advanced extension modes.
If two options appear viable, evaluate them on four measurable criteria: spectral error in the retained band, phase/timing distortion, boundary artifact magnitude, and runtime at production batch sizes. The best choice is the one that meets signal-quality thresholds with the simplest maintainable configuration.
DECIMATE
Decimation reduces the sampling rate of a signal by an integer factor while suppressing frequency content that would otherwise alias into the lower-rate signal. The input is first passed through a low-pass filter and is then kept at every q-th sample.
If the original sampling rate is f_s and the decimation factor is q, the new sampling rate becomes:
f_{s,\text{new}} = \frac{f_s}{q}
This wrapper exposes SciPy’s IIR and FIR anti-alias filtering modes. The default IIR mode uses an order-8 Chebyshev Type I filter, while the FIR mode uses a Hamming-window FIR design whose default order scales with the decimation factor.
Excel Usage
=DECIMATE(x, q, n, decimate_ftype, zero_phase)
x(list[list], required): The data to be downsampled.q(int, required): The downsampling factor.n(int, optional, default: null): The order of the filter. Defaults to 8 for IIR and 20*q for FIR.decimate_ftype(str, optional, default: “iir”): The type of lowpass filter.zero_phase(bool, optional, default: true): Prevent phase shift by filtering with filtfilt (IIR) or shifting (FIR).
Returns (list[list]): A 2D array of the downsampled signal.
Example 1: Downsample by 4 (IIR)
Inputs:
| x | q | |||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 4 |
Excel formula:
=DECIMATE({1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}, 4)
Expected output:
| Result | |||||||
|---|---|---|---|---|---|---|---|
| 0.990849 | 4.93716 | 8.91137 | 12.8262 | 16.8428 | 20.7077 | 24.7702 | 28.6382 |
Example 2: Downsample by 2 (FIR)
Inputs:
| x | q | decimate_ftype | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2 | fir |
Excel formula:
=DECIMATE({1,2,3,4,5,6,7,8}, 2, "fir")
Expected output:
| Result | |||
|---|---|---|---|
| 0.788906 | 3.23884 | 4.66274 | 7.64716 |
Example 3: Downsample by 3 without zero-phase filtering
Inputs:
| x | q | zero_phase | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 3 | false |
Excel formula:
=DECIMATE({1,2,3,4,5,6,7,8,9,10,11,12}, 3, FALSE)
Expected output:
| Result | |||
|---|---|---|---|
| 0.0000347995 | 0.0192557 | 0.47327 | 2.68031 |
Example 4: Downsample by 2 with custom IIR filter order
Inputs:
| x | q | n | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1.5 | 2 | 2.5 | 3 | 3.5 | 4 | 4.5 | 5 | 5.5 | 6 | 6.5 | 7 | 7.5 | 8 | 8.5 | 2 | 4 |
Excel formula:
=DECIMATE({1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5}, 2, 4)
Expected output:
| Result | |||||||
|---|---|---|---|---|---|---|---|
| 0.988349 | 1.9774 | 2.96535 | 3.95458 | 4.94223 | 5.93224 | 6.91825 | 7.9112 |
Python Code
Show Code
import numpy as np
from scipy.signal import decimate as scipy_decimate
def decimate(x, q, n=None, decimate_ftype='iir', zero_phase=True):
"""
Downsample the signal after applying an anti-aliasing filter.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.decimate.html
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): The data to be downsampled.
q (int): The downsampling factor.
n (int, optional): The order of the filter. Defaults to 8 for IIR and 20*q for FIR. Default is None.
decimate_ftype (str, optional): The type of lowpass filter. Valid options: IIR, FIR. Default is 'iir'.
zero_phase (bool, optional): Prevent phase shift by filtering with filtfilt (IIR) or shifting (FIR). Default is True.
Returns:
list[list]: A 2D array of the downsampled signal.
"""
try:
def to_1d(v):
if isinstance(v, list):
return np.array([float(x) for row in v for x in row])
return np.array([float(v)])
x_arr = to_1d(x)
result = scipy_decimate(
x_arr,
int(q),
n=int(n) if n is not None else None,
ftype=decimate_ftype,
zero_phase=bool(zero_phase)
)
return [result.tolist()]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
RESAMPLE
This function changes the number of samples in a signal using an FFT-based resampling method. The method interprets the signal as periodic, modifies its spectrum, and then reconstructs a uniformly resampled sequence.
If a signal has N input samples and is converted to M output samples, the sample spacing changes in proportion to:
\Delta t_{\text{new}} = \Delta t_{\text{old}} \cdot \frac{N}{M}
The Fourier approach is especially useful for band-limited periodic signals. When sample positions t are supplied, SciPy also returns the resampled coordinate vector corresponding to the new spacing.
Excel Usage
=RESAMPLE(x, num, t, window, resample_domain)
x(list[list], required): The data to be resampled.num(int, required): The number of samples in the resampled signal.t(list[list], optional, default: null): Optional equally spaced sample positions (Excel range).window(str, optional, default: null): Specifies the window applied in the Fourier domain (defaults to None).resample_domain(str, optional, default: “time”): A string indicating the domain of the input x.
Returns (list[list]): A 2D array where the first row is resampled x, and the second row is resampled t (if t was provided).
Example 1: Basic Resample
Inputs:
| x | num | ||||
|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 10 |
Excel formula:
=RESAMPLE({1,2,3,4,5}, 10)
Expected output:
| Result | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0.763932 | 2 | 3 | 3 | 3 | 4 | 5.23607 | 5 | 3 |
Example 2: Resample with t
Inputs:
| x | num | t | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 10 | 0 | 1 | 2 | 3 | 4 |
Excel formula:
=RESAMPLE({1,2,3,4,5}, 10, {0,1,2,3,4})
Expected output:
| Result | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0.763932 | 2 | 3 | 3 | 3 | 4 | 5.23607 | 5 | 3 |
| 0 | 0.5 | 1 | 1.5 | 2 | 2.5 | 3 | 3.5 | 4 | 4.5 |
Example 3: Frequency-domain resample preserves sample count request
Inputs:
| x | num | resample_domain | |||||
|---|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 0 | 0 | 0 | 3 | freq |
Excel formula:
=RESAMPLE({1,0,0,0,0,0}, 3, "freq")
Expected output:
| Result | ||
|---|---|---|
| 0.166667 | 0.166667 | 0.166667 |
Example 4: Resample using a Hann Fourier window
Inputs:
| x | num | window | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | -1 | 0 | 1 | 0 | -1 | 12 | hann |
Excel formula:
=RESAMPLE({0,1,0,-1,0,1,0,-1}, 12, "hann")
Expected output:
| Result | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.433013 | 0.433013 | 0 | -0.433013 | -0.433013 | 0 | 0.433013 | 0.433013 | 0 | -0.433013 | -0.433013 |
Python Code
Show Code
import numpy as np
from scipy.signal import resample as scipy_resample
def resample(x, num, t=None, window=None, resample_domain='time'):
"""
Resample x to num samples using Fourier method.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.resample.html
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): The data to be resampled.
num (int): The number of samples in the resampled signal.
t (list[list], optional): Optional equally spaced sample positions (Excel range). Default is None.
window (str, optional): Specifies the window applied in the Fourier domain (defaults to None). Default is None.
resample_domain (str, optional): A string indicating the domain of the input x. Valid options: Time, Frequency. Default is 'time'.
Returns:
list[list]: A 2D array where the first row is resampled x, and the second row is resampled t (if t was provided).
"""
try:
def to_1d(v):
if v is None: return None
if isinstance(v, list):
return np.array([float(x) for row in v for x in row])
return np.array([float(v)])
x_arr = to_1d(x)
t_arr = to_1d(t)
# Handle result structure
result = scipy_resample(
x_arr,
int(num),
t=t_arr,
window=window,
domain=resample_domain
)
if t_arr is not None:
res_x, res_t = result
return [res_x.tolist(), res_t.tolist()]
else:
return [result.tolist()]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
RESAMPLE_POLY
Polyphase resampling changes a signal’s sampling rate by first inserting additional samples, then applying a low-pass FIR filter, and finally keeping every selected output sample. It is often preferred over FFT-based resampling for long signals or lengths with large prime factors.
For an upsampling factor u and downsampling factor d, the resulting sample-rate conversion ratio is:
\frac{f_{s,\text{out}}}{f_{s,\text{in}}} = \frac{u}{d}
The low-pass filter is designed so that spectral images created during upsampling are suppressed before downsampling. Boundary behavior is controlled with the selected padding mode.
Excel Usage
=RESAMPLE_POLY(x, up, down, window, poly_padtype, cval)
x(list[list], required): The data to be resampled.up(int, required): The upsampling factor.down(int, required): The downsampling factor.window(str, optional, default: “kaiser”): Desired window to use for the FIR filter (defaults to Kaiser window with beta=5).poly_padtype(str, optional, default: “constant”): The signal extension mode to use at boundaries.cval(float, optional, default: 0): Value to use if padtype is ‘constant’.
Returns (list[list]): A 2D array of the resampled data.
Example 1: Upsample by 2
Inputs:
| x | up | down | ||
|---|---|---|---|---|
| 1 | 2 | 3 | 2 | 1 |
Excel formula:
=RESAMPLE_POLY({1,2,3}, 2, 1)
Expected output:
| Result | |||||
|---|---|---|---|---|---|
| 1.00052 | 1.29462 | 2.00103 | 2.96514 | 3.00155 | 1.60706 |
Example 2: Downsample by 2
Inputs:
| x | up | down | |||||
|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 1 | 2 |
Excel formula:
=RESAMPLE_POLY({1,2,3,4,5,6}, 1, 2)
Expected output:
| Result | ||
|---|---|---|
| 1.06167 | 2.7954 | 5.46644 |
Example 3: Resample by a 3-to-2 polyphase ratio
Inputs:
| x | up | down | |||||
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | -1 | 0 | 1 | 3 | 2 |
Excel formula:
=RESAMPLE_POLY({0,1,0,-1,0,1}, 3, 2)
Expected output:
| Result | ||||||||
|---|---|---|---|---|---|---|---|---|
| 2.79341e-17 | 0.761991 | 0.925732 | 3.1772e-17 | -0.876403 | -0.876403 | 3.1772e-17 | 0.925732 | 0.761991 |
Example 4: Resample with line boundary extension
Inputs:
| x | up | down | poly_padtype | ||||
|---|---|---|---|---|---|---|---|
| 2 | 3 | 5 | 7 | 11 | 2 | 1 | line |
Excel formula:
=RESAMPLE_POLY({2,3,5,7,11}, 2, 1, "line")
Expected output:
| Result | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| 2.00103 | 2.44091 | 3.00155 | 3.98362 | 5.00259 | 5.81483 | 7.00362 | 8.92601 | 11.0057 | 12.392 |
Python Code
Show Code
import numpy as np
from scipy.signal import resample_poly as scipy_resample_poly
def resample_poly(x, up, down, window='kaiser', poly_padtype='constant', cval=0):
"""
Resample x along the matrix using polyphase filtering.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.resample_poly.html
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): The data to be resampled.
up (int): The upsampling factor.
down (int): The downsampling factor.
window (str, optional): Desired window to use for the FIR filter (defaults to Kaiser window with beta=5). Default is 'kaiser'.
poly_padtype (str, optional): The signal extension mode to use at boundaries. Valid options: Constant, Line, Mean, Median, Maximum, Minimum. Default is 'constant'.
cval (float, optional): Value to use if padtype is 'constant'. Default is 0.
Returns:
list[list]: A 2D array of the resampled data.
"""
try:
def to_1d(v):
if isinstance(v, list):
return np.array([float(x) for row in v for x in row])
return np.array([float(v)])
x_arr = to_1d(x)
# Preserve SciPy's default Kaiser tuple when users leave the window as the wrapper default.
win = window
if win == "kaiser":
win = ("kaiser", 5.0)
kwargs = {
"window": win,
"padtype": poly_padtype,
}
if poly_padtype == "constant":
kwargs["cval"] = float(cval)
result = scipy_resample_poly(x_arr, int(up), int(down), **kwargs)
return [result.tolist()]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
UPFIRDN
This function combines three multirate operations into one efficient polyphase routine: insert samples during upsampling, apply an FIR filter, and then retain samples according to the downsampling factor. It is a core building block for interpolation, decimation, and rational sample-rate conversion.
If the interpolation factor is u and the decimation factor is d, the output sampling rate satisfies:
f_{s,\text{out}} = f_{s,\text{in}} \cdot \frac{u}{d}
Compared with explicitly inserting zeros, filtering, and decimating in separate passes, the polyphase implementation reduces redundant work and is therefore more efficient for many signal-processing pipelines.
Excel Usage
=UPFIRDN(h, x, up, down, upfirdn_mode, cval)
h(list[list], required): 1-D FIR filter coefficients (Excel range).x(list[list], required): Input signal array.up(int, optional, default: 1): Upsampling rate.down(int, optional, default: 1): Downsampling rate.upfirdn_mode(str, optional, default: “constant”): The signal extension mode to use.cval(float, optional, default: 0): The constant value to use when mode is ‘constant’.
Returns (list[list]): A 2D array of the output signal.
Example 1: Simple FIR filter
Inputs:
| h | x | ||||
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 |
Excel formula:
=UPFIRDN({1,1,1}, {1,1,1})
Expected output:
| Result | ||||
|---|---|---|---|---|
| 1 | 2 | 3 | 2 | 1 |
Example 2: Upsample with zeros
Inputs:
| h | x | up | ||
|---|---|---|---|---|
| 1 | 1 | 2 | 3 | 3 |
Excel formula:
=UPFIRDN({1}, {1,2,3}, 3)
Expected output:
| Result | ||||||
|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 2 | 0 | 0 | 3 |
Example 3: FIR filter with decimation by 3
Inputs:
| h | x | down | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 3 |
Excel formula:
=UPFIRDN({1}, {0,1,2,3,4,5,6,7,8,9}, 3)
Expected output:
| Result | |||
|---|---|---|---|
| 0 | 3 | 6 | 9 |
Example 4: Linear boundary extension during interpolation
Inputs:
| h | x | up | upfirdn_mode | ||||
|---|---|---|---|---|---|---|---|
| 0.5 | 1 | 0.5 | 1 | 2 | 3 | 2 | line |
Excel formula:
=UPFIRDN({0.5,1,0.5}, {1,2,3}, 2, "line")
Expected output:
| Result | ||||||
|---|---|---|---|---|---|---|
| 0.5 | 1 | 1.5 | 2 | 2.5 | 3 | 3.5 |
Python Code
Show Code
import numpy as np
from scipy.signal import upfirdn as scipy_upfirdn
def upfirdn(h, x, up=1, down=1, upfirdn_mode='constant', cval=0):
"""
Upsample, FIR filter, and downsample.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.upfirdn.html
This example function is provided as-is without any representation of accuracy.
Args:
h (list[list]): 1-D FIR filter coefficients (Excel range).
x (list[list]): Input signal array.
up (int, optional): Upsampling rate. Default is 1.
down (int, optional): Downsampling rate. Default is 1.
upfirdn_mode (str, optional): The signal extension mode to use. Valid options: Constant, Symmetric, Reflect, Anti-Reflect, Anti-Symmetric, Edge, Wrap, Smooth, Line. Default is 'constant'.
cval (float, optional): The constant value to use when mode is 'constant'. Default is 0.
Returns:
list[list]: A 2D array of the output signal.
"""
try:
def to_1d(v):
if isinstance(v, list):
return np.array([float(x) for row in v for x in row])
return np.array([float(v)])
h_arr = to_1d(h)
x_arr = to_1d(x)
result = scipy_upfirdn(
h_arr,
x_arr,
up=int(up),
down=int(down),
mode=upfirdn_mode,
cval=float(cval)
)
return [result.tolist()]
except Exception as e:
return f"Error: {str(e)}"Online Calculator