EMD经验模态分解

9,679次阅读
5 条评论

共计 14971 个字符,预计需要花费 38 分钟才能阅读完成。

项目上的理论研究看到一种方法EMD+SVD方法识别,看了下EMD算法意义跟傅立叶变换差不多,也是将信号分解为不同的频率,但是区别与傅立叶无线长时间与小波变换选定小波基的问题,EMD给出了自适应分解方法。

关于时间序列平稳性的一般理解
所谓时间序列的平稳性,一般指宽平稳,即时间序列的均值和方差为与时间无关的常数,其协方差与时间间隔有关而也与时间无关。简单地说,就是一个平稳的时间序列指的是:遥想未来所能获得的样本时间序列,我们能断定其均值、方差、协方差必定与眼下已获得的样本时间序列等同。

反之,如果样本时间序列的本质特征只存在于所发生的当期,并不会延续到未来,亦即样本时间序列的均值、方差、协方差非常数,则这样一个时间序列不足以昭示未来,我们便称这样的样本时间序列是非平稳的。

形象地理解,平稳性就是要求经由样本时间序列所得到的拟合曲线在未来的一段期间内仍能顺着现有的形态“惯性”地延续下去;如果数据非平稳,则说明样本拟合曲线的形态不具有“惯性”延续的特点,也就是基于未来将要获得的样本时间序列所拟合出来的曲线将迥异于当前的样本拟合曲线。

事实上,世界上几乎不存在理想的“平稳”时间序列。欧阳首承教授曾指出:“平稳序列性消除了小概率事件”。即在欧阳教授的溃变论看来,EMD这一方法也是有问题的。但是,该方法确实扩展了平稳化这一传统思想的应用范围,即扩展到了对任何类型的时间序列的处理,也是了不起的新进展。

2:EMD方法:

EMD 方法在理论上可以应用于任何类型的时间序列(信号)的分解,因而在处理非平稳及非线性数据上,比之前的平稳化方法更具有明显的优势。所以,EMD方法一经提出就在不同的工程领域得到了迅速有效的应用,例如用在海洋、大气、天体观测资料与地球物理记录分析等方面。
该方法的关键是它能使复杂信号分解为有限个本征模函数(Intrinsic Mode Function,简称IMF),所分解出来的各IMF分量包含了原信号的不同时间尺度的局部特征信号。EMD分解方法是基于以下假设条件:
⑴数据至少有两个极值,一个最大值和一个最小值;
⑵数据的局部时域特性是由极值点间的时间尺度唯一确定;
⑶如果数据没有极值点但有拐点,则可以通过对数据微分一次或多次求得极值,然后再通过积分来获得分解结果。
经验模态分解的基本思想:将一个频率不规则的波化为多个单一频率的波+残波的形式。原波形 = ∑ IMFs + 余波。
    这种方法的本质是通过数据的特征时间尺度来获得本征波动模式,然后分解数据。这种分解过程可以形象地称之为“筛选(sifting)”过程。
分解过程是:找出原数据序列X(t)所有的极大值点并用三次样条插值函数拟合形成原数据的上包络线;同样,找出所有的极小值点,并将所有的极小值点通过三次样条插值函数拟合形成数据的下包络线,上包络线和下包络线的均值记作ml(其实,有学者将平均值改用中位值,可能更合理,因为是非平稳时间序列),将原数据序列X(t)减去该平均包络ml,得到一个新的数据序列hl,:
X(t)-ml=hl
由原数据减去包络平均后的新数据,若还存在负的局部极大值和正的局部极小值,说明这还不是一个本征模函数,需要继续进行“筛选”。如下图示意:EMD经验模态分解
EMD的Python代码实现如下:
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 10 15:28:19 2017

@author: admin

EMD算法,经验模态分解方法
ismonotonic 判定当前的时间序列是否是单调序列
findpeaks 寻找当前时间序列的极值点
isImf 判断当前的序列是否为IMF序列
getspline 获取当前样条曲线
emd 经验模态分解方法
"""
import numpy as np 

from scipy.interpolate import interp1d



#判定当前的时间序列是否是单调序列
def ismonotonic(x):
    max_peaks=findpeaks(x)
    min_peaks=findpeaks(-1*x)
    all_num=len(max_peaks)*len(min_peaks)
    if all_num>0:
        return False
    else:
        return True
        
#寻找当前时间序列的极值点
def findpeaks(x):
    
    df_index=np.nonzero(np.diff((np.diff(x)>0)+0)<0)
    
    u_data=np.nonzero((x[df_index[0]+1]>x[df_index[0]]))
    df_index[0][u_data[0]]+=1
    
    return df_index[0]
#判断当前的序列是否为IMF序列
def isImf(x):
    N=np.size(x)
    pass_zero=np.sum(x[0:N-2]*x[1:N-1]<0)
    peaks_num=np.size(findpeaks(x))+np.size(findpeaks(-x))
    if abs(pass_zero-peaks_num)>1:
        return False
    else:
        return True
#获取当前样条曲线
def getspline(x):
    N=np.size(x)
    peaks=findpeaks(x)
    print '当前极值点个数:',len(peaks)
    f=interp1d(np.concatenate(([0,1],peaks,[N+1])),np.concatenate(([0,1],x[peaks],[0])),kind='cubic')
    return f(np.linspace(1,N,N))
    
    
#经验模态分解方法
def emd(x):
    imf=[]
    while not ismonotonic(x):
        x1=x
        sd=np.inf
        while sd>0.1 or  (not isImf(x1)):
            print isImf(x1)
            s1=getspline(x1)
            s2=-getspline(-1*x1)
            x2=x1-(s1+s2)/2
            sd=np.sum((x1-x2)**2)/np.sum(x1**2)
            x1=x2
        
        imf.append(x1)
        x=x-x1
    imf.append(x)
    return imf

if __name__ == '__main__':
    test=np.array([0.109017283,0.923722444,1.651182239,2.020828578,1.799564813,1.422650123,0.662718505,0.330908056,0.147316657,0.396244021,0.453235051,0.916266988,1.053167851,0.63681763,0.532051493,0.08994018,-0.717732329,-0.855063616,-0.680475165,0.071406017,0.913073764,1.855207585,2.682944133,2.667465224,2.479280179,1.992408687,1.348050833,0.994006146,0.822142278,0.591994742,0.886954149,1.260592311,1.230028317,1.217631396,0.644643686,-0.135081116,-0.711964767,-1.064944545,-0.777929926,-0.146634022,0.601942369,1.625442452,2.087659234,2.174841679,1.944062547,1.418676464,0.57214484,0.036795538,-0.000609289,-0.26336984,0.094634086,0.297793896,0.396835119,0.007259407,-0.858480906,-1.394269789,-1.85579278,-2.160075311,-1.824350703,-1.291997551,-0.538101879,0.267661313,0.699446876,1.217420847,0.781731188,0.036382748,-0.437728422,-1.00805078,-1.325132926,-1.159238528,-1.021807838,-0.824617407,-0.79444614,-0.886456075,-1.424007393,-1.955984975,-2.68713261,-2.773011756,-2.671641565,-1.684411326,-0.962753773,0.089646659,0.683509031,0.974626316,0.57909196,0.316738557,-0.261988737,-1.078689298,-1.06546717,-0.981400467,-0.572131872,-0.342081116,-0.090577818,-0.224030397,-0.706924146,-1.320851645,-1.916472444,-1.941698461,-1.716268291,-1.087495455,-0.005622723,0.938624738,1.683385158,2.046688054,1.845156075,1.439595372,0.658465234,0.197282301,0.108990311,0.395379929,0.71815339,0.90361103,0.988130991,0.718943517,0.474426139,-0.188698577,-0.812292702,-0.917224647,-0.816960237,0.075973199,0.93365717,2.02850965,2.385186217,2.84923888,2.551232478,2.008260359,1.432964394,0.969423566,0.511909795,0.821705124,0.830056202,1.101133254,1.200842308,1.09199242,0.374060592,-0.157511494,-0.727140266,-1.015692864,-0.798837593,-0.376662826,0.688543921,1.44398107,2.093600529,2.087501624,1.912169477,1.396776932,0.713375255,0.036906952,-0.423291188,-0.325659809,0.021862763,0.295402323,0.28425045,-0.106604795,-0.38752117,-1.301782234,-1.820414882,-2.227422449,-2.132089253,-1.364103799,-0.484017931,0.44159941,0.801395813,0.86830821,0.930058769,0.21739668,-0.59377128,-1.074263788,-1.348982832,-1.092444315,-0.891845989,-0.665540137,-0.594968238,-0.932225219,-1.26198678,-1.965360528,-2.56298185,-2.770659502,-2.531302519,-1.954089722,-0.876918807,0.106246548,0.881404745,0.934158755,0.612265788,0.211081193,-0.507947232,-0.932325305,-1.113714709,-0.99951518,-0.549967323,-0.368592797,-0.051758275,-0.204206489,-0.627646631,-1.311060114,-1.725636347,-1.767148474,-1.658875671,-0.977381775,0.177248256,0.708712405,1.618516084,2.190492579,1.740386247,1.252984145,0.608749079,0.363034806,-0.092511633,0.177119024,0.644482762,0.916047958,1.110210837,0.883652232,0.475328758,-0.319724597,-0.672705358,-1.040423538,-0.555686523,0.001917248,1.016588957,1.811638672,2.55399336,2.857595409,2.338898565,1.813261182,1.178062425,0.934934391,0.659534713,0.6195693,1.100961118,1.22232423,1.109416176,0.91643165,0.342533287,-0.095494363,-0.828440558,-1.148293964,-0.912005693,-0.343021309,0.673082205,1.48036216,2.05082745,2.227430421,1.911263804,1.214131671,0.666121988,-0.036771033,-0.345128535,-0.323386902,0.086955281,0.31408288,0.062055494,-0.060151388,-0.586766977,-1.370055457,-1.83086834,-2.160409852,-2.03587881,-1.488370129,-0.520083487,0.344308001,0.901225381,1.007126713,0.860427071,0.100294868,-0.466612601,-0.878705299,-1.287068192,-1.292928333,-0.756712711,-0.714507057,-0.574854071,-0.930436328,-1.332537049,-1.953298191,-2.536412336,-2.719579176,-2.400670348,-2.005796991,-0.930500161,-0.232093818,0.63685561,1.076818372,0.788627522,0.19029056,-0.441066144,-0.818181571,-0.94212841,-0.914718186,-0.426309126,-0.338644033,-0.318258323,-0.35855891,-0.751326219,-1.346293002,-1.872268772,-1.813731021,-1.825806728,-1.008774526,-0.096930157,0.912181974,1.59755862,1.995292294,1.683425842,1.226951085,0.741508777,0.392138023,-0.066970314,0.437033816,0.499947822,0.98096552,1.152774873,1.003317487,0.355506082,-0.188551511,-0.71075053,-0.944332939,-0.60684374,0.06883858,0.915825004,1.878621401,2.788487197,2.751431604,2.607898791,1.953746064,1.308510202,0.815496473,0.675471764,0.609660989,0.765761838,1.213866346,1.224456795,1.046346949,0.48951725,-0.1180711,-0.678253216,-1.163668713,-1.006752546,-0.209134924,0.618424395,1.338712995,2.144335655,2.189153994,1.919323153,1.336410932,0.687377732,0.197791543,-0.264135607,-0.389046089,0.10134643,0.123204129,0.362306059,-0.104290662,-0.462812978,-1.389614804,-2.018226227,-2.090158845,-2.156900602,-1.364570545,-0.54400289,0.245051502,0.820141412,1.236885947,0.730875022,0.171962686,-0.574929903,-1.099692438,-1.326460192,-1.037592207,-0.990098498,-0.75882144,-0.663838057,-0.778637544,-1.492871117,-1.93728779,-2.669997981,-2.765273027,-2.703818636,-1.811793161,-0.881770045,-0.101729215,0.665772292,0.900051065,0.810425434,0.203821811,-0.303296165,-0.882685263,-1.112648061,-0.919990368,-0.607717734,-0.16889155,-0.124096817,-0.367863657,-0.7468802,-1.190157527,-1.829022384,-2.013316502,-1.565775935,-0.949470017,-0.036270582,0.885709983,1.516190761,1.962792,1.755829909,1.34090882,0.585741158,0.41592322,0.167202804,0.100395912,0.693491215,0.857434468,1.078040532,0.892954388,0.319421869,-0.477122982,-0.640958313,-0.917970562,-0.693800602,0.07486551,0.882088444,1.932504512,2.536218765,2.653056324,2.620551492,2.047450897,1.486514578,0.760812914,0.529488564,0.721147496,1.017759832,1.291356399,1.268749244,0.994756982,0.546338771,0.005470246,-0.679870108,-1.022651188,-0.911746069,-0.209403194,0.539374804,1.456473605,2.098420262,2.278280095,1.965780113,1.446810422,0.797081644,-0.144424684,-0.415806448,-0.308241862,-0.199792708,0.180267733,0.204297954,-0.020299192,-0.583344961,-1.377633851,-1.98829777,-2.106512546,-2.058789968,-1.569749459,-0.586754507,0.279791461,0.813192112,1.097461001,0.79090674,0.169698694,-0.485460119,-0.97252802,-1.312240054,-1.314039416,-0.966614942,-0.676900117,-0.568073154,-0.853087532,-1.407034487,-1.940366437,-2.548221342,-2.67148577,-2.530109293,-1.86601462,-0.960242583,-0.125098067,0.541319563,0.787644763,0.872996827,0.170964107,-0.313200813,-0.836092516,-0.86189034,-0.82348505,-0.710481637,-0.289782451,-0.02931777,-0.254921212,-0.504876273,-1.313806027,-1.942718063,-1.903046494,-1.75535689,-0.954649301,0.107804587,0.990410642,1.694138856,1.92773298,1.772889412,1.298709907,0.451497622,0.323067287,0.217507125,0.127295246,0.435588416,0.978293378,0.897066111,0.703067936,0.486139599,-0.256411242,-0.570023542,-1.012993272,-0.695449963,0.05714376,1.005991431,1.91214884,2.54027472,2.729207716,2.478946813,2.048048118,1.322614728,0.892236734,0.727786572,0.464881713,1.13150453,1.145338706,1.399744137,1.173505408,0.334165851,-0.17328917,-0.421702534,-1.052567556,-0.805666406,-0.226289745,0.71457546,1.541680462,1.925950382,2.142002888,1.941288388,1.303176656,0.86545862,0.089206336,-0.194186259,-0.299745338,-0.130750262,0.29539201,0.218211651,0.019573489,-0.695108578,-1.219421588,-2.088314963,-2.029184457,-1.935945376,-1.421613558,-0.703895405,0.219624687,0.879724094,1.151883827,0.664974365,0.320497681,-0.204244358,-1.067880917,-1.221221764,-1.274274433,-1.122752241,-0.542762993,-0.54960226,-0.901144878,-1.349959254,-2.022980715,-2.683041781,-3.040421826,-2.52587578,-1.911632003,-1.008721106,-0.117571075,0.452291165,0.831593769,0.710657431,0.084801918,-0.362192605,-0.898287957,-1.057963805,-1.059102842,-0.664226196,-0.216044783,-0.197475685,-0.267576057,-0.533605417,-1.229490352,-1.683794982,-1.711421829,-1.546635492,-0.919818724,0.195124872,0.86912713,1.595959783,2.149283983,1.832965974,1.304806576,0.777212547,0.257325356,0.089283895,0.218378723,0.532385959,0.821819455,1.041833552,0.813539672,0.551427509,-0.167430333,-0.592376188,-0.897749884,-0.642169826,0.158798914,1.097909916,1.868679493,2.690376834,2.799761068,2.573721519,2.219200072,1.514866503,0.940801201,0.659241945,0.635976703,0.939534967,1.390744749,1.065947651,0.954648456,0.462176339,-0.176155501,-0.94671653,-0.978198128,-0.781321477,-0.353391749,0.561856557,1.311274558,2.183050409,2.223204043,1.881877142,1.216471404,0.621827184,0.213769777,-0.21041209,-0.1806488,-0.120037556,0.232590606,0.315554207,-0.183485333,-0.499133249,-1.062473036,-2.062758043,-2.392517584,-2.027855309,-1.356717898,-0.595951667,0.243530928,0.854944466,0.924644103,0.603937018,0.349137988,-0.451795247,-1.13710706,-1.160504643,-1.338281904,-0.963233539,-0.615737749,-0.703087749,-0.88502226,-1.358334797,-1.804762654,-2.490966144,-2.792119405,-2.543667484,-1.893413702,-0.82038406,-0.061411753,0.554843667,0.907828719,0.685049245,0.270306473,-0.311298026,-0.762297867,-0.983101498,-0.852937231,-0.39745762,-0.373061091,-0.153213336,-0.453246235,-0.639457211,-1.306863873,-1.817465689,-2.11955641,-1.645831815,-0.985565996,-0.135478895,0.843848566,1.587976366,1.922424867,1.622655347,1.290817933,0.79296454,0.246072343,0.048678883,0.28747078,0.697893244,0.871531451,1.001147145,0.727426085,0.309470368,-0.130393546,-0.705879296,-0.807310676,-0.567024971,0.070552608,1.027721798,2.017732592,2.578811439,2.794785514,2.5325754,1.875773699,1.310802825,0.88266031,0.507873649,0.736633336,0.983317804,1.218546888,1.298241775,1.020728566,0.478851188,-0.191858799,-0.675383013,-1.040148114,-1.118409241,-0.307993256,0.607382214,1.528601262,2.158627881,2.091706438,1.983053132,1.332809039,0.591123805,0.047815713,-0.240747141,-0.201941826,0.023758618,0.148822866,0.133438029,0.051234872,-0.633936803,-1.167563409,-1.999384987,-2.245266884,-1.878467898,-1.291868277,-0.690685328,0.28002948,0.988405793,1.164376541,0.639839055,0.352820595,-0.414892285,-0.995611558,-1.29065593,-1.305144088,-0.94155473,-0.715488153,-0.388002846,-0.831069207,-1.378638392,-2.001402882,-2.598142328,-2.545008218,-2.457426611,-1.857896015,-0.838729797,-0.036287033,0.624239946,0.828104841,0.632963942,0.351438327,-0.330392435,-0.862314802,-0.877382456,-0.913828862,-0.55878097,-0.399048458,-0.070955054,-0.428471673,-0.830223816,-1.214079042,-1.752409258,-2.034682983,-1.703987719,-0.933949178,0.022002545,0.788448708,1.543599478,1.77016346,1.780282492,1.13690551,0.80158394,0.18319297,0.007839728,0.436114527,0.804023668,0.834264496,1.044113411,1.067308549,0.353215342,-0.019232626,-0.612533015,-0.878214747,-0.66932725,0.202289168,1.022161557,1.802109014,2.560401658,2.664392055,2.55176304,2.15318781,1.414482769,0.774108468,0.653814401,0.620034633,1.152987994,1.02917479,1.202147561,1.095491536,0.399022552,-0.189194187,-0.702875003,-0.905335007,-0.947002662,-0.276366024,0.540618004,1.421205693,2.057544132,2.123991274,1.986977834,1.3516866,0.564728076,0.072936971,-0.139515321,-0.116666995,0.066820912,0.209477896,0.175928167,-0.022931366,-0.658574771,-1.342225682,-1.814484841,-2.04115025,-1.961012232,-1.227301986,-0.740710286,0.261647014,0.863823144,1.192557517,0.818455843,0.158598985,-0.425635,-0.954101856,-1.249835805,-1.411292381,-0.848748422,-1.038969085,-0.608067023,-1.005208327,-1.396809084,-1.860144252,-2.588215993,-2.560470248,-2.443287963,-1.890030919,-1.041409682,-0.082564465,0.671464195,0.646713621,0.756020044,0.218929504,-0.32535547,-0.666257495,-1.080192805,-1.014246477,-0.469821835,-0.167600262,-0.132775472,-0.343086823,-0.706504097,-1.421995229,-1.780922194,-2.011247285,-1.746105767,-0.862797414,0.003034901,1.094702419,1.555537576,1.971481329,1.682913528,1.370888759,0.861899237,0.386088878,-0.093055835,0.325231424,0.58865618,0.94961958,0.993077094,0.705909715,0.496521307,-0.241688561,-0.727492958,-0.866931451,-0.380340713,0.262336905,0.819190425,1.817971934,2.619867219,2.544885569,2.661271109,1.968476042,1.501227392,0.76208704,0.526768741,0.921255193,1.009857837,1.17756798,1.164801902,1.128681275,0.515267555,-0.417382328,-0.858657107,-0.734101988,-0.855471292,-0.459332164,0.498983721,1.390638802,2.090053278,2.169577533,1.917123985,1.307231148,0.515928442,0.162622357,-0.274465299,-0.262318803,0.019498957,0.209283088,0.185785017,-0.032631817,-0.400659304,-1.254888885,-1.972474849,-2.272805675,-2.044485232,-1.590227774,-0.405210129,0.279805005,0.737955083,1.043165865,0.623976688,0.24921761,-0.499203208,-1.014145224,-1.231914122,-1.123173282,-1.032033718,-0.83651997,-0.62940561,-0.932366519,-1.318799851,-2.185468437,-2.451010988,-2.721548847,-2.632285195,-1.89710948,-0.867270251,0.209672292,0.598905772,1.021963015,0.608448297,0.211672053,-0.427991703,-0.836982446,-1.097629584,-1.058331714,-0.614862668,-0.213092226,-0.169096787,-0.302174593,-0.691195916,-1.25509417,-1.860890978,-1.974292024,-1.577115159,-0.926516714,-0.134789668])
    Ts = 0.001;
    #t=np.linspace(0,1,1000)
    #test =np.sin(2*np.pi*10*t) + np.sin(2*np.pi*50*t) + np.sin(2*np.pi*100*t) + 0.1*np.random.random(len(t))
    test_imf=emd(test)
    print test_imf
正文完
请博主喝杯咖啡吧!
post-qrcode
 
admin
版权声明:本站原创文章,由 admin 2017-01-17发表,共计14971字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(5 条评论)
验证码
donaldtone 评论达人 LV.1
2017-05-10 23:36:33 回复

请教一下,这个语句的意思:
Ts = 0.001;

另外,整个程序运行出错,python 3.5.2, windows 10

Traceback (most recent call last):
File “D:/AI/workspace/ML study/1-Basic/emd/emd-python.py”, line 211, in
test_imf = emd(test)
File “D:/AI/workspace/ML study/1-Basic/emd/emd-python.py”, line 68, in emd
s1 = getspline(x1)
File “D:/AI/workspace/ML study/1-Basic/emd/emd-python.py”, line 56, in getspline
f = interp1d(np.concatenate(([0, 1], peaks, [N + 1])), np.concatenate(([0, 1], x[peaks], [0])), kind=’cubic’)
File “C:\ProgramData\Anaconda3\lib\site-packages\scipy\interpolate\interpolate.py”, line 496, in __init__
check_finite=False)
File “C:\ProgramData\Anaconda3\lib\site-packages\scipy\interpolate\_bsplines.py”, line 697, in make_interp_spline
raise ValueError(“number of derivatives at boundaries.”)
ValueError: number of derivatives at boundaries.

 Windows  Firefox  加拿大魁北克魁北克
    admin 博主
    2017-05-11 07:32:52 回复

    @donaldtone 博客中给的代码是python2.7代码,从问题来看是getspline函数有问题,你可以单步调试一下

     iPhone  AppleWebKit  中国广东省深圳市联通
lcyuanjiang 评论达人 LV.1
2018-05-29 22:00:21 回复

挑不出while循环啊

 Macintosh  Chrome  中国广东省佛山市电信
lcyuanjiang 评论达人 LV.1
2018-05-29 22:00:47 回复

求博主帮忙

 Macintosh  Chrome  中国广东省佛山市电信
    admin 博主
    2018-06-01 07:45:47 回复

    @lcyuanjiang While循环条件可以适当修改,再试试

     iPhone  Chrome  中国广东省广州市联通