EmptyMan - 1 year ago 145

Python Question

How to change the sampling rate of the data in the list

`result`

The current sampling rate is 256, but the desired sampling rate is 250.

Given:

- - a list of data with a sampling frequency of 256.
`result`

- - the amount of signal in the channel
`buf.size`

I tried to use

`scipy.signal.resample`

`from scipy import signal`

result250 = signal.resample(result, buf.size, t=None, axis=0, window=None)

Traceback (most recent call last):

File "****.py", line 82, in <module>

result250 = signal.resample(result, buf.size, t=None, axis=0, window=None)

File "****\scipy\signal\signaltools.py", line 1651, in resample

X = fft(x, axis=axis)

File "****\scipy\fftpack\basic.py", line 249, in fft

tmp = _asfarray(x)

File "****\scipy\fftpack\basic.py", line 134, in _asfarray

return numpy.asfarray(x)

File "****\numpy\lib\type_check.py", line 105, in asfarray

return asarray(a, dtype=dtype)

File "****\numpy\core\numeric.py", line 482, in asarray

return array(a, dtype, copy=False, order=order)

ValueError: invalid literal for float(): 3.3126, 6.6876, 9.3126, 10.0627, ****

There is another option of linear interpolation (preferable), but I also can not figure out how to use.

`scipy.interpolate.interp1d`

Answer Source

You must record the time (in seconds - `f.file_duration`

).
My answer:

```
x250 = np.arange(0, f.file_duration, 0.004) #frequency 250
x256 = np.arange(0, f.file_duration, 0.00390625) #frequency 256
result256 = np.interp(x256, x250, result)
```