【问题标题】:Pandas: Find end frequency spectrum above a defined thresholdPandas:查找高于定义阈值的结束频谱
【发布时间】:2020-06-23 17:18:58
【问题描述】:

长期阅读,第一次发帖。

我正在处理 Pandas DataFrames 中频率响应图的 x,y 数据。这是数据和图表的示例(请参阅帖子末尾的完整 .csv 文件):

fbc['x'],fbc['y']

(0    [89.25, 89.543, 89.719, 90.217, 90.422, 90.686...
 1    [89.25, 89.602, 90.422, 90.568, 90.744, 91.242...
 2    [89.25, 89.689, 89.895, 90.305, 91.008, 91.74,...
 3    [89.25, 89.514, 90.041, 90.275, 90.422, 90.832...
 Name: x, dtype: object,
 0    [-77.775, -77.869, -77.766, -76.572, -76.327, ...
 1    [-70.036, -70.223, -71.19, -71.229, -70.918, -...
 2    [-73.079, -73.354, -73.317, -72.753, -72.061, ...
 3    [-70.854, -71.377, -74.069, -74.712, -74.647, ...
 Name: y, dtype: object)

其中 x = 频率和 y = 幅度数据。每一个的结果图如下所示:

See x,y Plot of image in this link - not enough points to embed yet

我可以为 Dataframe 中 x,y 数据的每一行创建一个图。

我需要在 Pandas (Python) 中做的是在频率响应下降到本底噪声之前识别数据中的最高频率(永久)。如您所见,在某些地方 y 数据可能会达到非常低的值(例如 - 40。

如何在 Pandas / python 中检测(由于数据量非常大,理想情况下无需迭代)以找到最高频率(> -40),这样我就知道频率不会再次返回 基本上,我正在尝试找到频带的末端。我尝试过使用 Pandas 的一些统计数据(如果有这些数据也不错),但未能获得有用的数据。

提前感谢您提供的任何指示和方向。

这是一个.csv文件,可以用csv.reader导入:https://www.dropbox.com/s/ia7icov5fwh3h6j/sample_data.csv?dl=0

【问题讨论】:

  • 如您所见,样本数据中没有。您应该添加一个小样本数据和预期输出,而不是那些不完整的数据。
  • 从最后一次观察中迭代返回并返回 > -40 幅度的第一次观察的频率的方法怎么样?这符合你的目标吗?
  • 嗨@QuangHoang 感谢您的建议,我添加了一个包含我正在使用的数据集的 sample.csv 文件。
  • 嗨@katardin 向后工作是消除误报的好主意。是的,这总是可以满足我的要求。但是,我仍然需要在不遍历每一行的情况下执行此操作。我附加的数据集只有几行,但最终的数据集将有数十万行。

标签: python pandas dataframe frequency-analysis time-frequency


【解决方案1】:

我相信我已经想出了一个解决方案:

根据@katardin 的建议,我提出了以下建议,但我认为可以对其进行优化。同样,我将处理大量数据,因此如果有人能找到更优雅的解决方案,将不胜感激。

for row in fbc['y']:
    list_reverse = row

    # Reverse y data so we read from end (right to left)
    test_list = list_reverse[::-1]

    # Find value of y data above noise floor (>-50)
    res = next(x for x, val in enumerate(test_list) if val > -50) 

    # Since we reversed the y data we must take the opposite of the returned res to 
    # get the correct index
    index = len(test_list) - res

    # Print results
    print ("The index of element is : " + str(index))

其中输出为索引号如下:

The index of element is : 2460
The index of element is : 2400
The index of element is : 2398
The index of element is : 2382

我检查过的每一个都对应于我一直在寻找的确切的高频滚降点。好建议!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 2017-07-19
    • 1970-01-01
    • 2018-03-14
    • 2021-04-11
    • 1970-01-01
    相关资源
    最近更新 更多