Skip to main content

Resample

Namespace: RTPROCESSINGLIB  ·  Library: DSP Library

Python equivalent

mne.filter.resample in MNE-Python.

#include <dsp/resample.h>

class UTILSLIB::Resample

Polyphase anti-aliased rational resampling for MEG/EEG data.

// Resample from 1000 Hz to 250 Hz (4:1 decimation)
Eigen::RowVectorXd downsampled = Resample::resample(vecData, 250.0, 1000.0);

// Resample all channels of a raw data matrix
Eigen::MatrixXd ds = Resample::resampleMatrix(matData, 250.0, 1000.0);

Static Methods

resample(vecData, dNewSFreq, dOldSFreq, iNZeros)

Resample a single-channel row vector from dOldSFreq to dNewSFreq.

The ratio is reduced to its lowest terms p/q via GCD, then a polyphase Hamming-windowed sinc filter is applied. The output length is ceil(nSamples · p / q).

Parameters:

  • vecData : const Eigen::RowVectorXd & Input row vector (calibrated, SI units).

  • dNewSFreq : double Target sampling frequency in Hz.

  • dOldSFreq : double Original sampling frequency in Hz.

  • iNZeros : int Number of sinc zero-crossings on each side of the kernel (default 10). Higher values give better stopband attenuation at the cost of speed.

Returns:

  • Eigen::RowVectorXd — Resampled row vector.

resampleMatrix(matData, dNewSFreq, dOldSFreq, vecPicks, iNZeros)

Resample every row of a data matrix.

Parameters:

  • matData : const Eigen::MatrixXd & Input matrix (n_channels × n_samples).

  • dNewSFreq : double Target sampling frequency in Hz.

  • dOldSFreq : double Original sampling frequency in Hz.

  • vecPicks : const Eigen::RowVectorXi & Optional channel indices to resample; if empty all rows are processed. Non-selected rows are returned at their original length — in practice always pass picks or leave empty for a uniform matrix result.

  • iNZeros : int Sinc zero-crossings per side (default 10).

Returns:

  • Eigen::MatrixXd — Resampled matrix (n_channels × n_new_samples).

Authors of this file