在振动信号中找到峰值

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 选择的点,您有几个参数需要调整,这可能比您尝试从头开始实施更有成效。在那之后,如果您可以更好地完成该功能所做的工作,您可以通过您的实现为库做出贡献。