我如何在没有信号跳变的情况下检测数据

时间:2018-09-20 07:46:38

标签: python signal-processing

我有以下包含跳跃的数据,我想知道如何检测这些跳跃,然后使用插值法将彼此之间的非跳跃点连接起来? enter image description here Here是一个数据集,其中的应变为W_A1

可能由mikuszefski尝试删除跳线...

import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import leastsq

def strain( t, a, b, c, d ):
    return a * t**3 + b * t**2 + c * t + d

def residuals( params, x1Data, x2Data, yData ):
    s1, s2, a, b, c, d = params
    cxData = [ (s1**2 * x1 + s2**2 * x2) /( s1**2 + s2**2 ) for x1, x2 in zip( x1Data, x2Data) ]
    diff = [ strain( x, a, b, c, d ) -y for x, y in zip( cxData, yData ) ]
    return diff


def simple_remove_jumps( inData, minHeight, order=2 ):
    out = np.array(inData).copy()
    nn = len( out )
    jumpList = np.fromiter( ( y - x for x, y in zip( out[ :-1 ], out[ 1: ] ) ), np.float)
    for pos, j in enumerate( jumpList ):
        if abs( j) > minHeight and pos < nn - 1:
            left = out[ :pos + 1 ]
            right = out[ pos + 1: ]
            if order == 0:
                right += (out[ pos ] - out[ pos + 1 ] ) ## zero order
            elif order == 1 and pos:
                right += ( 2 * out[ pos ] - out[ pos - 1 ] ) - out[ pos + 1 ] ## first order assuming constant dx
            elif order == 2 and pos > 1:
                right += ( 3 * out[ pos ] - 3 * out[ pos - 1 ] + out[ pos - 2 ] ) - out[ pos + 1 ] ## first order assuming constant dx
            else:
                assert 0
    return out

data = list()
with open('data.csv', 'r') as fpntr:
    for i in range(260):
        inline = fpntr.readline().strip()
        if i > 1:
            locData = inline.replace(',,', ',0,')
            locData =  locData.split(',')[ 2: ]
            locData = [ float( x ) for x in locData ]
            data += [ np.array( locData ) ]  

data = np.array( data )

newt1 = simple_remove_jumps( data[:,0], .0004, order=2 )

fig = plt.figure()
ax = fig.add_subplot( 3, 1, 1 )
bx = fig.add_subplot( 3, 1, 2 )
cx = fig.add_subplot( 3, 1, 3 )
ax.plot( data[:,0 ] )
ax.plot( newt1 )
bx.plot( data[:,1 ] )
bx.plot( data[:, -5 ] )
cx.plot( data[:,1 ] , data[:,0 ], linestyle='', marker='o' )
cx.plot( data[:, -5 ] , data[:,0 ], linestyle='', marker='o' )
cx.plot( data[:, 1 ] , newt1, linestyle='', marker='o' )
plt.show()

0 个答案:

没有答案