簡體   English   中英

通過查找峰坐標確定 plot 的頻率

[英]Determining frequency of a plot by finding the coordinates of the peaks

我目前正在嘗試確定 position 的 plot 與時間的頻率:

1

其中時間和 position 數據集是浮點數列表。 我嘗試使用導入為fpscipy.signal.find_peaks但是當我運行此代碼時:

    peaks,_ = fp(pos)
    peak_times = []
    
    for i in range(len(peaks)):
        peak_times.append(t[i])
    
    peak_dists = [current-next for (current,next) in zip(peak_times,peak_times[1:])]
    approx_freq = sum(peak_dists)/len(peak_dists)
    
    return approx_freq

我收到一個類型錯誤: typeError: only integer scalar arrays can be converted to a scalar index

出了什么問題? 我該如何解決?

我在您的代碼中發現了一些錯誤。 以下是建議的更正:

peaks,_ = fp(pos)
peak_times = []

for i in peaks: # notice correction here! No range or len needed.
    peak_times.append(t[i])

peak_dists = [next-current for (current,next) in zip(peak_times,peak_times[1:])] # swapped next with current for positive result
approx_freq = 1/(sum(peak_dists)/len(peak_dists)) # take the inverse of what you did before

祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM