在振动信号中查找峰值

finding peaks in a vibration signal(在振动信号中查找峰值)

本文介绍了在振动信号中查找峰值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python的新手,我刚刚毕业,我的论文是关于振动分析的,所以当我开始学习Python的时候。我想做一个应用程序来读取信号,并提供关于图形的具体信息,如峰值,这是我目前拥有的

    import tkinter as tk
    from tkinter import ttk
    from tkinter import filedialog as fd
    import matplotlib.pyplot as plt
    from matplotlib.widgets import Cursor
    import numpy as np
    import os
    
    Raw_1 = []
    Raw_2 = []
    clean_1 = []
    clean_2 = []
    
    
    # create the root window
    root = tk.Tk()
    root.title("Yazid ")
    root.resizable(True, True)
    root.geometry("400x400")
    # full screen
    class FullScreenApp(object):
        def __init__(self, master, **kwargs):
            self.master = master
            pad = 3
            self._geom = "200x200+0+0"
            master.geometry(
                "{0}x{1}+0+0".format(
                    master.winfo_screenwidth() - pad, master.winfo_screenheight() - pad
                )
            )
            master.bind("<Escape>", self.toggle_geom)
    
        def toggle_geom(self, event):
            geom = self.master.winfo_geometry()
            print(geom, self._geom)
            self.master.geometry(self._geom)
            self._geom = geom
    
    
    def select_file():
        filetypes = (("text files", "*.txt"), ("All files", "*.*"))
        # get the txt file
        filename = fd.askopenfilename(
            title="select file", initialdir="/", filetypes=filetypes
        )
    
        # Get the raw list
        for line in open(filename, "r"):
            lines = [i for i in line.split("       ")]
            Raw_1.append(lines[0].replace(",", "."))
            Raw_2.append(lines[1].replace(",", "."))
        # clean means get rid of the first three lines
        for item in Raw_1[3:]:
            clean_1.append(item)
        for item in Raw_2[3:]:
            clean_2.append(item)
        # convert to float (geting the X and Y axes)
        x = [float(i) for i in clean_1]
        y = [float(i) for i in clean_2]
    
        # plotting the points
        fig = plt.figure()
        ax = fig.subplots()
        ax.plot(x, y, color="r")
        ax.grid()
    
        # naming the x axis
        plt.xlabel(Raw_2[0])
        # naming the y axis
        plt.ylabel(Raw_1[0])
    
        # title graph
        fname = os.path.splitext(filename)[0]
        name = os.path.basename(fname)
        plt.title(name)
    
        # Defining the cursor
        cursor = Cursor(ax, horizOn=True, vertOn=True, useblit=True, color="r", linewidth=1)
    
        # Creating an annotating box
        annot = ax.annotate(
            "",
            xy=(0, 0),
            xytext=(-40, 40),
            textcoords="offset points",
            bbox=dict(boxstyle="round4", fc="linen", ec="k", lw=1),
            arrowprops=dict(arrowstyle="-|>"),
        )
        annot.set_visible(False)
    
        # function to show the plot
        plt.show()
    
    # open button
    open_button = ttk.Button(root, text="Open a File", command=select_file)
    
    open_button.pack(expand=True)
    
    
    # run the application
    root.mainloop()

我要删除前三行,因为第一行包含每列的名称,后两行有一些暂态(我有1600多个值)

我的代码产生以下结果

我希望它标记这些峰值,并在y轴上给出它们的值

谢谢您

推荐答案

您可以从scipy.signal.find_peaks开始。在文档中,您将了解如何执行类似于此的示例。

橙色十字是用find_peaks选择的点,您有几个参数要调优,而且它可能比您尝试从头开始实现的效率更高。在此之后,如果您可以更好地完成该函数所做的工作,则可以使用您的实现为库做出贡献。

这篇关于在振动信号中查找峰值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在振动信号中查找峰值

基础教程推荐