xdas.signal.resample_poly#

xdas.signal.resample_poly(da, up, down, dim='last', window=('kaiser', 5.0), padtype='constant', cval=None, parallel=None)[source]#

Resample da along the given dimension using polyphase filtering.

The signal in da is upsampled by the factor up, a zero-phase low-pass FIR filter is applied, and then it is downsampled by the factor down. The resulting sample rate is up / down times the original sample rate. By default, values beyond the boundary of the signal are assumed to be zero during the filtering step.

Parameters:
  • da (DataArray) – The data to be resampled.

  • up (int) – The upsampling factor.

  • down (int) – The downsampling factor.

  • dim (str, optional) – The dimension of da that is resampled. Default is last.

  • window (string, tuple, or array_like, optional) – Desired window to use to design the low-pass filter, or the FIR filter coefficients to employ. See below for details.

  • padtype (string, optional) – constant, line, mean, median, maximum, minimum or any of the other signal extension modes supported by scipy.signal.upfirdn. Changes assumptions on values beyond the boundary. If constant, assumed to be cval (default zero). If line assumed to continue a linear trend defined by the first and last points. mean, median, maximum and minimum work as in np.pad and assume that the values beyond the boundary are the mean, median, maximum or minimum respectively of the array along the dimension.

  • cval (float, optional) – Value to use if padtype=’constant’. Default is zero.

  • parallel (bool or int, optional) – Number of threads to use. True uses all cores, False uses one, an int uses that many, None defers to the global xdas configuration. Default is None.

Notes

Splits on data discontinuities along dim.

Returns:

The resampled data.

Return type:

DataArray

Examples

This example is made to resample the input dataarray in the time domain at 100 samples with an original shape of 300 in time. The choosed window is a ‘hamming’ window. The dataarray is synthetic data.

>>> import xdas.signal as xs
>>> from xdas.synthetics import wavelet_wavefronts
>>> da = wavelet_wavefronts()
>>> xs.resample_poly(da, 2, 5, dim='time')
<xdas.DataArray (time: 120, distance: 401)>
[[-0.006378  0.012767 -0.002068 ... -0.033461  0.002603 -0.027478]
 [ 0.008851 -0.037799  0.009595 ...  0.053291 -0.0396    0.026909]
 [-0.034468  0.085153 -0.038036 ... -0.015803  0.030245  0.047028]
 ...
 [ 0.02834   0.053455 -0.155873 ...  0.033726 -0.036478 -0.016146]
 [ 0.015454 -0.062852  0.049064 ... -0.018409  0.113782 -0.072631]
 [-0.026921 -0.01264   0.087272 ...  0.001695 -0.147191  0.177587]]
Coordinates:
  * time (time): 2023-01-01T00:00:00.000 to 2023-01-01T00:00:05.950
  * distance (distance): 0.000 to 10000.000