2013-04-03 29 views
2

我必須測量下圖中信號的擺率。我需要用灰色箭頭標記的部分的轉換速率。 signal to process擺率測量

此刻,我用漢恩窗口平滑信號,以擺脫最終的噪音,並使峯值變平。然後我搜索(從右邊開始)30%和70%的點並計算這兩點之間的轉換率。 但我的問題是,平滑後信號變平坦。因此計算的擺率不像應該那樣高。如果我減少平滑,那麼峯值(可以在圖像中看到右側)變得更高,並且最終在錯誤的位置找到30%的點。

是否有更好/更安全的方法來查找所需的擺率?

回答

3

如果你知道什麼之間看重你的信號正在轉變,你的噪音不太大,你可以簡單地計算出的30%的所有口岸和70%所有交叉點之間的時間差,並保持最小的一個:

import numpy as np 
import matplotlib.pyplot as plt 

s100, s0 = 5, 0 

signal = np.concatenate((np.ones((25,)) * s100, 
         s100 + (np.random.rand(25) - 0.5) * (s100-s0), 
         np.linspace(s100, s0, 25), 
         s0 + (np.random.rand(25) - 0.5) * (s100-s0), 
         np.ones((25,)) * s0)) 


# Interpolate to find crossings with 30% and 70% of signal 
# The general linear interpolation formula between (x0, y0) and (x1, y1) is: 
# y = y0 + (x-x0) * (y1-y0)/(x1-x0) 
# to find the x at which the crossing with y happens: 
# x = x0 + (y-y0) * (x1-x0)/(y1-y0) 
# Because we are using indices as time, x1-x0 == 1, and if the crossing 
# happens within the interval, then 0 <= x <= 1. 
# The following code is just a vectorized version of the above 
delta_s = np.diff(signal) 
t30 = (s0 + (s100-s0)*.3 - signal[:-1])/delta_s 
idx30 = np.where((t30 > 0) & (t30 < 1))[0] 
t30 = idx30 + t30[idx30] 
t70 = (s0 + (s100-s0)*.7 - signal[:-1])/delta_s 
idx70 = np.where((t70 > 0) & (t70 < 1))[0] 
t70 = idx70 + t70[idx70] 

# compute all possible transition times, keep the smallest 
idx = np.unravel_index(np.argmin(t30[:, None] - t70), 
         (len(t30), len(t70),)) 

print t30[idx[0]] - t70[idx[1]] 
# 9.6 

plt. plot(signal) 
plt.plot(t30, [s0 + (s100-s0)*.3]*len(t30), 'go') 
plt.plot(t30[idx[0]], [s0 + (s100-s0)*.3], 'o', mec='g', mfc='None', ms=10) 
plt.plot(t70, [s0 + (s100-s0)*.7]*len(t70), 'ro') 
plt.plot(t70[idx[1]], [s0 + (s100-s0)*.7], 'o', mec='r', mfc='None', ms=10) 
plt.show() 

enter image description here

+0

非常有趣的方法。但目前我無法理解你的實現。你如何獲得時間信息?您的信號不包含任何時間值。 – wewa

+0

@wewa我正在使用陣列中的位置作爲時間的代理。如果你的信號是以一個恆定的時間步長'dt'採樣的,那麼你所需要做的就是把所有的東西都乘以實際時間。 – Jaime

+0

謝謝你,那就是我的想法。但對我而言,如何計算't30','t70','idx30','idx70'和'idx'並不是很清楚。你能否在你的代碼中評論這個? – wewa