resample

resample(arr: ndarray, sfreq: int | float, new_sfreq: int | float, axis: int = -1) ndarray[source][source]

Resample an array through linear interpolation.

Parameters:
  • arr (array) – The array to resample.

  • sfreq (int) – The original sampling frequency.

  • new_sfreq (int) – The new sampling frequency.

  • axis (int)

Returns:

resampled – The resampled array.

Return type:

array

Examples

>>> import numpy as np
>>> arr = np.arange(10)
>>> resample(arr, 10, 5)
array([0.  , 2.25, 4.5 , 6.75, 9.  ])
>>> resample(arr, 10.2, 5.1)
array([0.  , 2.25, 4.5 , 6.75, 9.  ])
>>> resample(arr, 10, 20)
array([0.        , 0.47368421, 0.94736842, 1.42105263, 1.89473684,
       2.36842105, 2.84210526, 3.31578947, 3.78947368, 4.26315789,
       4.73684211, 5.21052632, 5.68421053, 6.15789474, 6.63157895,
       7.10526316, 7.57894737, 8.05263158, 8.52631579, 9.        ])
>>> resample(arr, 10, 7)
array([0. , 1.5, 3. , 4.5, 6. , 7.5, 9. ])
>>> arr = np.arange(30).reshape(5, 6)
>>> resample(arr, 6, 10)
array([[ 0.        ,  0.55555556,  1.11111111,  1.66666667,  2.22222222,
         2.77777778,  3.33333333,  3.88888889,  4.44444444,  5.        ],
       [ 6.        ,  6.55555556,  7.11111111,  7.66666667,  8.22222222,
         8.77777778,  9.33333333,  9.88888889, 10.44444444, 11.        ],
       [12.        , 12.55555556, 13.11111111, 13.66666667, 14.22222222,
        14.77777778, 15.33333333, 15.88888889, 16.44444444, 17.        ],
       [18.        , 18.55555556, 19.11111111, 19.66666667, 20.22222222,
        20.77777778, 21.33333333, 21.88888889, 22.44444444, 23.        ],
       [24.        , 24.55555556, 25.11111111, 25.66666667, 26.22222222,
        26.77777778, 27.33333333, 27.88888889, 28.44444444, 29.        ]])