python实现重采样

  • 官网文档
  • 文档理解
  • 代码实现

官网文档

网址:https://github.com/scipy/scipy/blob/v1.4.1/scipy/signal/signaltools.py

def resample(x, num, t=None, axis=0, window=None):"""Resample `x` to `num` samples using Fourier method along the given axis.The resampled signal starts at the same value as `x` but is sampledwith a spacing of ``len(x) / num * (spacing of x)``.  Because aFourier method is used, the signal is assumed to be periodic.Parameters----------x : array_likeThe data to be resampled.num : intThe number of samples in the resampled signal.t : array_like, optionalIf `t` is given, it is assumed to be the equally spaced samplepositions associated with the signal data in `x`.axis : int, optionalThe axis of `x` that is resampled.  Default is 0.window : array_like, callable, string, float, or tuple, optionalSpecifies the window applied to the signal in the Fourierdomain.  See below for details.Returns-------resampled_x or (resampled_x, resampled_t)Either the resampled array, or, if `t` was given, a tuplecontaining the resampled array and the corresponding resampledpositions.
See Also--------decimate : Downsample the signal after applying an FIR or IIR filter.resample_poly : Resample using polyphase filtering and an FIR filter.Notes-----The argument `window` controls a Fourier-domain window that tapersthe Fourier spectrum before zero-padding to alleviate ringing inthe resampled values for sampled signals you didn't intend to beinterpreted as band-limited.If `window` is a function, then it is called with a vector of inputsindicating the frequency bins (i.e. fftfreq(x.shape[axis]) ).If `window` is an array of the same length as `x.shape[axis]` it isassumed to be the window to be applied directly in the Fourierdomain (with dc and low-frequency first).For any other type of `window`, the function `scipy.signal.get_window`is called to generate the window.The first sample of the returned vector is the same as the firstsample of the input vector.  The spacing between samples is changedfrom ``dx`` to ``dx * len(x) / num``.If `t` is not None, then it is used solely to calculate the resampledpositions `resampled_t`As noted, `resample` uses FFT transformations, which can be veryslow if the number of input or output samples is large and prime;see `scipy.fft.fft`.
 Examples--------Note that the end of the resampled data rises to meet the firstsample of the next cycle:>>> from scipy import signal>>> x = np.linspace(0, 10, 20, endpoint=False)>>> y = np.cos(-x**2/6.0)>>> f = signal.resample(y, 100)>>> xnew = np.linspace(0, 10, 100, endpoint=False)>>> import matplotlib.pyplot as plt>>> plt.plot(x, y, 'go-', xnew, f, '.-', 10, y[0], 'ro')>>> plt.legend(['data', 'resampled'], loc='best')>>> plt.show()"""x = np.asarray(x)Nx = x.shape[axis]

文档理解

len(x) / num * (spacing of x) = 新的采样间隔y
主要是这个公式,了解一个这段话就能理解,这代表的是新的采样间隔,
num代表的是重采样之后的采样个数。将代数整理一下。
len(x) / (spacing of x) =num / (spacing of y)
既然要重采样到统一的频率,那么两者的间隔是一样的。
len(x) / spacing of x = num / spacing of y = N,比例一致

举个例子,如果一开始长度是1250,250hz的一段数据,重采样到200hz,那么新的数据长度就是1000

列算式如下:
1250 / 250 = 1000 / 200 ( = 5 都等于5)

(原理是使用多相滤波和FIR滤波器重新采样。)

代码实现

#注意数据类型的要求,num是int类型
EcgData = wfdb.rdsamp(path, sampfrom=1250 * k, sampto = 1250 + 1250 * k)[0]
signal_resample = signal.resample(EcgData,int((len(EcgData))*(200/250)),axis = 0)
signal_resample = np.array(signal_resample)
#这里读取的长度是1250个数据,原数据采样率是250hz,需要重采样到200hz

重采样 resample相关推荐

  1. 集成学习模型(xgboost、lightgbm、catboost)进行回归预测构建实战:异常数据处理、缺失值处理、数据重采样resample、独热编码、预测特征检查、特征可视化、预测结构可视化、模型

    集成学习模型(xgboost.lightgbm.catboost)进行回归预测构建实战:异常数据处理.缺失值处理.数据重采样resample.独热编码.预测特征检查.特征可视化.预测结构可视化.模型保 ...

  2. Google Earth Engine(GEE)——Landsat卫星影像重采样提高分辨率

    如投影文档中所述,地球引擎在重新投影期间默认执行最近邻重采样.您可以使用resample()或reduceResolution()方法更改此行为.具体而言,当这些方法之一应用于输入图像时,将使用指定的 ...

  3. python与excel结合能做什么-Python网络爬虫与文本数据分析

    原标题:Python网络爬虫与文本数据分析 课程介绍 在过去的两年间,Python一路高歌猛进,成功窜上"最火编程语言"的宝座.惊奇的是使用Python最多的人群其实不是程序员,而 ...

  4. ML之Validation:机器学习中模型验证方法的简介、代码实现、案例应用之详细攻略

    ML之Validation:机器学习中模型验证方法的简介.代码实现.案例应用之详细攻略 目录 模型验证方法的简介 1.Hold-out验证 2.K-折交叉验证 3.自助重采样 模型验证方法的代码实现 ...

  5. 机器学习处理信号分离_[学习笔记]使用机器学习和深度学习处理信号基础知识...

    参考学习:Signal Generation and Preprocessing 本人只是为了了解信号处理的基础知识而做的学习笔记,涉及深度可能不够,有理解错误的地方请大胆指出,感激不尽 一.信号生成 ...

  6. python爬虫与数据分析实战27_Python网络爬虫与文本数据分析

    原标题:Python网络爬虫与文本数据分析 课程介绍 在过去的两年间,Python一路高歌猛进,成功窜上"最火编程语言"的宝座.惊奇的是使用Python最多的人群其实不是程序员,而 ...

  7. 【Python】干货分享 | Pandas处理时间序列的数据

    在进行金融数据的分析以及量化研究时,总是避免不了和时间序列的数据打交道,常见的时间序列的数据有比方说一天内随着时间变化的温度序列,又或者是交易时间内不断波动的股票价格序列,今天小编就为大家来介绍一下如 ...

  8. pandas之时间数据

    1.时间戳Timestamp() 参数可以为各种形式的时间,Timestamp()会将其转换为时间. time1 = pd.Timestamp('2019/7/13') time2 = pd.Time ...

  9. pandas时间序列与自回归ARIMA模型

    文章目录 知识点梳理 1 时间预处理 1.1 创造时间序列 1.2 选择时间序列 1.3 重采样 1.4 滑动窗口 1.5 差分 2.自回归ARIMA模型 1.平稳性(差分) 2. ACF与PACF ...

最新文章

  1. mysql 存储过程怎么多行注释_数据库通过存储过程批量添加注释(模板为oracle)...
  2. Referenced file contains errors (http://www.springframework.org/schema...错误--转载
  3. 交互式计算机图形学总结:第五章 光照和明暗绘制
  4. Java 泛型 泛型的约束与局限性
  5. dexpress 流程图_DevExpress控件使用经验总结
  6. vue+Java后端进行调试时如何解决跨域问题
  7. C++教程:C++工程构建常用工具有哪些?
  8. 新入职朋友说话时,一定不要用“你们”,用“咱们”
  9. 牛腩新闻发布系统—发布错误总结
  10. 2022年华为杯中国研究生数学建模竞赛A题思路
  11. 如何在Proteus中模拟Arduino
  12. Windows10系统旧电脑打包迁移新电脑
  13. 什么是DTC?为什么国内外如此火爆
  14. 在docker中出现的僵尸进程怎么处理
  15. 腾讯资深产品经理谈敏捷开发于游戏
  16. ha456.jar打开dump文件报Unsupported major.minor version 51.0异常
  17. BDD - SpecFlow Web UI 测试实践
  18. 最常见的编程风格【清风不惊云】
  19. WeakMap 与 WeakSet
  20. bootstrap动态调用select下拉框

热门文章

  1. ESP8266-Arduino编程实例-MPU6500加速计陀螺仪驱动
  2. 测量系统分析(MSA)在企业质量管理中的应用(转载)
  3. Linux LCD屏幕驱动调参实操
  4. 自动化软件测试 - 利用短信转发器结合Selenium读取短信验证码
  5. python 两种提取pdf中图片的包
  6. MySQL索引背后的数据结构及算法原理
  7. 优先级结合时间片轮转算法c语言,先来先服务/段作业优先/时间片轮转/优先级调度算法详解...
  8. Flutter初体验
  9. 精选提高开发效率的15个idea插件
  10. 关于u8 u16 u32的含义