传感数据分析——高通滤波与低通滤波

传感数据分析------高通滤波与低通滤波

文章目录


前言

对于传感信号而言,我们可以提取其中的高频信息和低频信息,低频信息往往是信号的趋势,高频信息往往是一些突变或异常的信号,根据实际需求分离信号中的高低频特征具有实际意义。本文将使用scipy库中的signal模块实现高低通滤波器的设计,并采用计算周期特征,以下直接上代码。


本文正文内容

一、运行环境

系统: Windows 10 / Ubuntu 20.04

编程语言: Python 3.8

文本编译器: Vscode

所需库:matplotlib >= 2.2.2 , numpy >= 1.19.5, scipy >= 1.1.0

二、Python实现

代码如下(示例):

python 复制代码
# @copyright all reseved
# @author: Persist_Zhang
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt

# 生成一个模拟信号
fs = 1000  # 采样频率
t = np.arange(0, 1, 1/fs)  # 时间向量
f1 = 50  # 低频信号频率
f2 = 120  # 高频信号频率
x = np.sin(2 * np.pi * f1 * t) + np.sin(2 * np.pi * f2 * t)  # 模拟信号

# 设计低通滤波器
nyquist = 0.5 * fs
low = 40 / nyquist
b, a = signal.butter(4, low, btype='low')

# 应用低通滤波器
y_low = signal.filtfilt(b, a, x)

# 设计高通滤波器
high = 60 / nyquist
b, a = signal.butter(4, high, btype='high')

# 应用高通滤波器
y_high = signal.filtfilt(b, a, x)

# 计算周期特征
fft_x = np.fft.fft(x)
fft_y_low = np.fft.fft(y_low)
fft_y_high = np.fft.fft(y_high)

# 绘制结果
plt.figure()
plt.subplot(3, 1, 1)
plt.plot(t, x)
plt.title('Original Signal')
plt.subplot(3, 1, 2)
plt.plot(t, y_low)
plt.title('Low-Frequency Signal')
plt.subplot(3, 1, 3)
plt.plot(t, y_high)
plt.title('High-Frequency Signal')
plt.savefig('./figure/filtered_signals.png')
plt.show()
# 绘制频谱
plt.figure()
plt.subplot(3, 1, 1)
plt.plot(np.abs(fft_x))
plt.title('The spectrum of the original signal')
plt.subplot(3, 1, 2)
plt.plot(np.abs(fft_y_low))
plt.title('The spectrum of the signal after low-pass filtering')
plt.subplot(3, 1, 3)
plt.plot(np.abs(fft_y_high))
plt.title('The spectrum of the signal after high-pass filtering')
plt.savefig('./figure/filtered_signals_spectrum.png')
plt.show()

结果图

上图为信号的高低频频谱,下图为原始信号与高频信号(设定大于120Hz)和低频信号(设定为小于50Hz)图。


总结

以上就是本文关于传感信号分析中高低频滤波器设计的内容,全部代码见上,还望多多收藏点赞,后续将会更新与分享更多传感数据处理的代码。

相关推荐
安替-AnTi6 小时前
基于 React 和 TypeScript 搭建的机器学米其林餐厅数据分析项目
react.js·typescript·数据分析·毕设·米其林
拓端研究室15 小时前
视频讲解|核密度估计朴素贝叶斯:业务数据分类—从理论到实践
人工智能·分类·数据挖掘
秀儿还能再秀19 小时前
基于Excel的数据分析思维与分析方法
数据分析·excel
大千AI助手1 天前
DTW模版匹配:弹性对齐的时间序列相似度度量算法
人工智能·算法·机器学习·数据挖掘·模版匹配·dtw模版匹配
要努力啊啊啊1 天前
YOLOv3-SPP Auto-Anchor 聚类调试指南!
人工智能·深度学习·yolo·目标检测·目标跟踪·数据挖掘
好开心啊没烦恼1 天前
Python 数据分析:numpy,说人话,说说数组维度。听故事学知识点怎么这么容易?
开发语言·人工智能·python·数据挖掘·数据分析·numpy
生态遥感监测笔记1 天前
GEE利用已有土地利用数据选取样本点并进行分类
人工智能·算法·机器学习·分类·数据挖掘
涤生大数据1 天前
Apache Spark 4.0:将大数据分析提升到新的水平
数据分析·spark·apache·数据开发
遇雪长安1 天前
差分定位技术:原理、分类与应用场景
算法·分类·数据挖掘·rtk·差分定位
可观测性用观测云1 天前
Pipeline 引用外部数据源最佳实践
数据分析