def Signal(): global E_imfNo E_imfNo = np.zeros(50, dtype=np.int) # EEMD options max_imf = 7 """ 信号参数: N:采样频率500Hz tMin:采样开始时间 tMax:采样结束时间 2*np.pi """ N = 500 tMin, tMax = 0, 2 * np.pi T = np.linspace(tMin, tMax, N) # 信号S:是多个信号叠加信号 S = 3 * np.sin(4 * T) + 4 * np.cos(9 * T) + np.sin(8.11 * T + 1.2) # EEMD计算 eemd = EEMD() eemd.trials = 50 eemd.noise_seed(12345) E_IMFs = eemd.eemd(S) imfNo = E_IMFs.shape[0] # Plot results in a grid c = np.floor(np.sqrt(imfNo + 1)) r = np.ceil((imfNo + 1) / c) plt.ioff() plt.subplot(r, c, 1) plt.plot(T, S, 'r') plt.xlim((tMin, tMax)) plt.title("Original signal") i = 1 for imf in E_IMFs: plt.subplot(len(E_IMFs), 1, i) plt.plot(imf) i += 1 # for num in range(imfNo): # plt.subplot(r, c, num + 2) # plt.plot(T, E_IMFs[num], 'g') # plt.xlim((tMin, tMax)) # plt.title("Imf " + str(num + 1)) plt.text(0, 0, str(format(i, '.4f')), style='italic', ha='center', wrap=True) plt.save("haha.jpg")
from PyEMD import EEMD, CEEMDAN import numpy as np import pandas as pd from bokeh.plotting import figure, output_file, show df = pd.read_csv(f'training_datas/ETH-USD.csv', names=['time', 'low', 'high', 'open', 'close', 'volume']) # output to static HTML file output_file("viz/lines.html") eemd = EEMD() trials = 100 eemd.trials = trials eemd.noise_width = 0.08 #np.std(df['close'].values[300:300+(60*5)]) print(eemd.noise_width) # create a new plot with a title and axis labels p = figure(title="simple line example", x_axis_label=f"{trials}", y_axis_label='price', plot_width=1000, plot_height=1000) ''' for a in df.columns.values[1:-1]: eemd_arrays = eemd(df[a].values[300:300+(60*5)]) p.line(range(len(eemd_arrays[-1])), df[a].values[300:300+(60*5)], legend=f"{a}", line_width=2, line_color=colors[count % len(colors)]) p.line(range(len(eemd_arrays[-1])), eemd_arrays[-1] + df[a].iloc[300] - eemd_arrays[-1][0], legend=f"EEMD-{a}", line_width=2, line_color=colors[count % len(colors)]) count += 1 ''' #series = eemd(df['close'].values[300:300+(60*5)])
def eemd2d(img, goal, nos_wn): # 2-D EEMD, an implenmation of HHT # written by Neil Po-Nan Li @ Inst. of Physics, Academia Sinica, Taiwan # v1. 2012/10/6 # v2. 2014/3/10 bug fixes # v2.1 2014/3/17 stablity issue fixed import numpy as np from PyEMD import EEMD sz = np.shape(img) n1 = sz[0] n2 = sz[1] nimf = goal eemd = EEMD() eemd.trials = goal eemd.noise_width = nos_wn emd = eemd.EMD emd.extrema_detection = "parabol" std_img = np.std(img) img = img / std_img #% 2-D EEMD dim#1 G = np.zeros([n1, n2, nimf + 1]) for u in range(0, n1 - 1): row_modes = eemd(img[u, :], max_imf=goal) if not row_modes.all: print("error in dim 1") row_modes[np.isnan(row_modes)] = 0 tz = np.shape(row_modes) nf = tz[0] G[u, :, 0:nf] = np.transpose(row_modes) # G = Gtmp[:,:,0:nimf] #% 2-D EEMD dim#2 D = np.zeros([n1, n2, nimf + 1, nimf + 1]) for m in range(0, nimf): print('Solving mode ', m + 1, '/', nimf) # solve and store for v in range(0, n2 - 1): col_modes = eemd(G[:, v, m], max_imf=goal) if not col_modes.all: print("error in dim 2") col_modes[np.isnan(col_modes)] = 0 tz = np.shape(col_modes) nf = tz[0] D[:, v, m, 0:nf] = np.transpose(col_modes) # D = Dtmp[:,:,0:nimf,0:nimf] #% Combine modes H = np.zeros([n1, n2, nimf]) for m in range(0, nimf): for k in range(m, nimf): H[:, :, m] = H[:, :, m] + D[:, :, m, k] H[:, :, m] = H[:, :, m] + D[:, :, k, m] H[:, :, m] = H[:, :, m] - D[:, :, m, m] # for m = (goal+1):-1:1 # H(:,:,m) = sum( sum( D(:,:,m:end,m:end), 4), 3); # if m < (goal+1) # H(:,:,m) = H(:,:,m) - sum( H(:,:, (m+1):end ), 3); # end # end modes = H * std_img # return modes return G, D, H
def test_general_eemd(self): S = np.random.random(100) eemd = EEMD() eemd.trials = 10 eemd.eemd(S)
# S_infrared = S_infrared.astype(DTYPE) # S_red = S_red.astype(DTYPE) # print("Input S_infrared.dtype: " + str(S_infrared.dtype)) # print("Input S_red.dtype: " + str(S_red.dtype)) # emd.FIXE_H = 5 # emd.nbsym = 2 # emd.spline_kind = 'cubic' # emd.DTYPE = DTYPE # --------------------------------------------------------------------------------------- # 进行EMD,并且画出结果 # -------------------------------------------------------------------------------------- # emd = EMD() eemd = EEMD() eemd.trials = 50 eemd.noise_seed(12345) eemd.noise_width = 0.01 imfs1 = eemd.eemd(S=S_infrared, T=None, max_imf=-1) imfNo1 = imfs1.shape[0] imfs2 = eemd.eemd(S=S_red, T=None, max_imf=-1) imfNo2 = imfs2.shape[0] c = np.floor(np.sqrt(imfNo1 + 1)) r = np.ceil((imfNo1 + 1) / c) plt.ioff() plt.subplot(r, c, 1) plt.plot(T, S_infrared, 'r')