Declaration of Resample — polyphase anti-aliased rational resampling for MEG/EEG data. More...


Go to the source code of this file.
Classes | |
| class | UTILSLIB::Resample |
| Polyphase anti-aliased rational resampling for MEG/EEG data. More... | |
Namespaces | |
| namespace | UTILSLIB |
| Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms). | |
Declaration of Resample — polyphase anti-aliased rational resampling for MEG/EEG data.
Copyright (C) 2026, Christoph Dinh. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Algorithm: Given input rate oldSFreq and target rate newSFreq, the rational ratio p/q is computed after GCD reduction. An anti-aliasing low-pass FIR is built using a Hamming-windowed sinc with cutoff = min(p,q) / (2·max(p,q)) (as a fraction of the upsampled Nyquist). The filter is evaluated lazily via the polyphase identity:
y[m] = p · Σ_j h[m·q − j·p] · x[j]
where the summation is restricted to j values for which the tap index m·q − j·p lies in [0, L−1]. No explicit upsampling (inserting p−1 zeros) is performed.
The filter delay (halfLen = nZeros · max(p,q) samples at the upsampled rate) is absorbed into the output indexing so that the first output sample corresponds to the first input sample.
Reference: similar approach to scipy.signal.resample_poly.
Definition in file resample.h.