EMD工具箱,在MATLAB中實(shí)現(xiàn)EMD的各種功能所必須的工具箱。
工具箱的安裝
運(yùn)行install_emd.m文件可以實(shí)現(xiàn)此工具箱的安裝,uninstall_emd.m實(shí)現(xiàn)卸載。
1、首先下載emd工具箱,50樓網(wǎng)址里面可以下。下載后解壓放在matlab的work工作路徑下package_emd文件夾。
2、打開matlab,選擇File- Set Path- Add with Subfolders-你剛才下載的工具箱(package_emd)點(diǎn)進(jìn)去- Save- Close。
3、此時(shí)選擇work下package_emd文件夾作為工作路徑,即是C:\Program Files\MATLAB\R2010a\toolbox\package_emd。
4、在Command Window里面輸入mex -setup回車,問是否選擇已有的編譯器你選y回車,再問選擇哪個(gè)編譯器,你可以選擇C++的那個(gè)選擇相應(yīng)的編號(hào)(如 2)回車,然后讓你核對(duì)是否選擇對(duì)了編譯器等等,你輸入y回車。就安裝成功了
>> mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
[1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2010a\sys\lcc
[2] Microsoft Visual C++ 6.0 in C:\Program Files\Microsoft Visual Studio
[0] None
Compiler: 2
Please verify your choices:
Compiler: Microsoft Visual C++ 6.0
Location: C:\Program Files\Microsoft Visual Studio
Are these correct [y]/n? y
Trying to update options file: C:\Users\Administrator\AppData\Roaming\MathWorks\MATLAB\R2010a\mexopts.bat
From template: C:\PROGRA~1\MATLAB\R2010a\bin\win32\mexopts\msvc60opts.bat
Done . . .
**************************************************************************
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:
http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9
Building with the -largeArrayDims option enables the new API.
**************************************************************************
MATLAB的emd的工具箱 可是不知道怎么用 也不知道怎么用它來處理txt中的數(shù)據(jù)
安裝中的問題
但是安裝的時(shí)候,如果使用的是VS的編譯器(mbuild –setup、mex –setup設(shè)置),會(huì)報(bào)找不到complex.h的問題(用Linux下的Matlab不會(huì)出錯(cuò)),從而使cemdc2_fix.c等文件編譯失敗,這幾個(gè)文件是為了快速實(shí)現(xiàn)計(jì)算EMD而用c編寫的,所以即使編譯失敗,也不影響直接使用emd.m實(shí)現(xiàn)EMD功能。如果想編譯成功,可如下修改:(摘自http://www.chinavib.com/thread-79866-1-1.html)
G. Rilling 07年3月份的程序,運(yùn)行作者的install_emd.m,出現(xiàn)找不到complex.h的問題,以下是個(gè)人的理解和解決過程:(個(gè)人的運(yùn)行環(huán)境為matlab6.5)
complex.h的問題
產(chǎn)生原因:采用matlab的C編譯函數(shù)mex時(shí),定義了C99_OK的宏(EMDS/make_emdc.m (28行)),利用的是ANSI C99標(biāo)準(zhǔn)如果個(gè)人的電腦中沒有相關(guān)的支持,就會(huì)出現(xiàn)這個(gè)問題。
解決方法:EMDS/make_emdc.m中第28行中mex(’-DC99_OK‘,args(:))語句中的 '-DC99_OK' 即可。
注意:
改完之后,運(yùn)行install_emd,會(huì)出現(xiàn)M_PI沒有定義的問題,缺少了常數(shù)PI的宏定義,導(dǎo)致一些.c文件編譯失敗。
產(chǎn)生原因:去掉C99_OK之后,程序中使用的是作者提供的 emd_complex.h和emd_complex.c兩個(gè)文件來支持復(fù)數(shù)運(yùn)算,這兩個(gè)文件中,并沒有定義M_PI這個(gè)宏。
解決方法:M_PI這個(gè)宏,只在兩個(gè)文件中(clocal_mean.c和clocal_mean2.c)使用,個(gè)人的解決方法是,在相應(yīng)的頭文件(clocal_mean.h和clocal_mean2.h)中加入M_PI的宏定義即可。
在兩個(gè).h文件中分別加入一下語句:
#define CLOCAL_MEAN_H
#ifndef M_PI
#define M_PI 3.1415926
#endif
安裝完成后,編譯輸出的.dll文件會(huì)出現(xiàn),重復(fù)后綴名的問題,及 xxx.dll 變成了 xxx.dll.dll自己去掉多余的.dll即可
最后,關(guān)于版本問題:作者推薦使用7.1+版本,但只是針對(duì)個(gè)別的函數(shù)有影響,主要是作者提供的例子程序,無法在matlab6.5環(huán)境中運(yùn)行,算法的主要功能函數(shù)并不受影響。
工具箱的使用
工具箱函數(shù)
運(yùn)行help index_emd可以查看工具箱提供的函數(shù),如下
index_emd.M list of functions in the EMD package
type help function_name for more information on
a specific function
Empirical Mode Decomposition
emd - computes EMD and bivariate/complex EMD with various options
emd_local -
computes local EMD variation
emd_online - computes on-line
EMD variation. Note that it does not truly
apply on-line: the function is only a demonstration.
emdc - fast implementation for EMD with Cauchy-like stopping
criterion
(requires compilation, see make_emdc function)
emdc_fix - fast implementation for EMD with predefined number of
iterations
(requires compilation, see make_emdc function)
cemdc - fast implementation for bivariate/complex EMD (first
algorithm)
with Cauchy-like stopping criterion (requires compilation,
see make_emdc function)
cemdc_fix -
fast implementation for bivariate/complex EMD (first
algorithm)
with predefined number of iterations (requires compilation,
see make_emdc function)
cemdc2 - fast implementation for bivariate/complex EMD (second
algorithm)
with Cauchy-like stopping criterion (requires compilation,
see make_emdc function)
cemdc2_fix - fast
implementation for bivariate/complex EMD (second algorithm)
with predefined number of iterations (requires compilation,
see make_emdc function)
Utilities
install_emd - setup Matlab's
path and compile the C codes.
uninstall_emd - revert the modifications made by install_emd and
remove the
files (optional).
make_emdc - compile all C codes
emd_visu - visualization of EMD
cemd_visu - visualization of bivariate/complex EMD (automatically
called
by emd_visu when the input is complex)
cenvelope - compute envelope curves for bivariate/complex EMD
cemd_disp - visualization of envelope curves and tube envelope
plot3c - plot a complex vector in 3 dimensions
plotc - plot the projection of a complex vector on a variable
direction
dirstretch -
directional stretching of a complex vector
hhspectrum -
compute Hilbert-Huang spectrum (need the Time-Frequency
Toolbox
http://tftb.nongnu.org)
toimage - transform a spectrum made of 1D functions (e.g., output of
"hhspectrum") in an 2D image
disp_hhs - display the image output of "toimage" as a Hilbert-Huang
spectrum
addtag - add a tag to a graphic object (uses the Tag property as a
list
of keywords or "tags")
rmtag - remove a tag from a graphic object (uses the Tag property
as
a list of keywords or "tags")
hastag - test whether a graphic object has a specific tag (uses the
Tag
property as a list of keywords or "tags")
findtag - find objects having a specific tag (uses the Tag property
as
a list of keywords or "tags")
Examples from G. Rilling, P. Flandrin and P.
Gon鏰lves,
"On
Empirical Mode Decomposition and its algorithms"
IEEE-EURASIP
Workshop on Nonlinear Signal and Image Processing
NSIP-03,
Grado (I), June 2003
emd_fmsin - Fig. 1: a 3-component example (need the Time-Frequency
Toolbox http://tftb.nongnu.org)
emd_triang - Fig. 2: another 3-component example
emd_sampling - Fig. 3: effect of sampling on 1 tone
emd_separation - Fig. 4: separation of 2 tones
ex_online - Sect 3.4: the way emd_online.m works
triangular_signal - subroutine called by emd_triang (formerly
triang.m)
Examples from G. Rilling, P. Flandrin, P.
Gon鏰lves and J. M. Lilly,
"Bivariate
Empirical Mode Decomposition",
Signal
Processing Letters (submitted)
bivariate_EMD_principle - Fig. 1: principle of the bivariate/complex EMD
bivariate_EMD_mean_definitions - Fig. 2: definition of the mean for
each algorithm.
Also allows to test other signals and parameter sets.
bivariate_EMD_illustration - Fig. 3: illustration of the bivariate EMD
on an oceanographic float position record
稍做整理如下:
EMD分解函數(shù)
函數(shù) | 功能 |
emd | 計(jì)算EMD、雙變量/復(fù)數(shù)EMD |
emd_local | 計(jì)算local EMD |
emd_online | 計(jì)算在線EMD(不是真正在線應(yīng)用,此函數(shù)只是一個(gè)示范) |
emdc | 使用Cauchy-like停止準(zhǔn)則的快速EMD實(shí)現(xiàn),需編譯 |
emdc_fix | 使用預(yù)定義迭代次數(shù)的快速EMD實(shí)現(xiàn),需編譯 |
cemdc | 使用Cauchy-like停止準(zhǔn)則的快速雙變量/復(fù)數(shù)EMD實(shí)現(xiàn)(方法1),需編譯 |
cemdc_fix | 使用預(yù)定義迭代次數(shù)的快速雙變量/復(fù)數(shù)EMD實(shí)現(xiàn)(方法1),需編譯 |
cemdc2 | 使用Cauchy-like停止準(zhǔn)則的快速雙變量/復(fù)數(shù)EMD實(shí)現(xiàn)(方法2),需編譯 |
cemdc2_fix | 使用預(yù)定義迭代次數(shù)的快速雙變量/復(fù)數(shù)EMD實(shí)現(xiàn)(方法2),需編譯 |
工具函數(shù)
函數(shù) | 功能 |
install_emd | 設(shè)置Matlab路徑,編譯c代碼 |
uninstall_emd | 回復(fù)install_emd做的修改,移除文件 |
make_emdc | 編譯c代碼 |
emd_visu | EMD可視化 |
cemd_visu | 雙變量/復(fù)數(shù)EMD可視化(emd_visu的輸入是雙變量或復(fù)數(shù)時(shí)自動(dòng)改為調(diào)用cemd_visu) |
cenvelope | 計(jì)算雙變量EMD的包絡(luò)曲線 |
cemd_disp | 顯示復(fù)數(shù)包絡(luò)曲線 |
plot3c | 三維中繪制復(fù)數(shù)向量 |
plotc | 繪制復(fù)數(shù)向量在一個(gè)可變方向上的投影 |
dirstretch | 復(fù)數(shù)向量的方向拉伸 |
hhspectrum | 計(jì)算Hilbert-Huang譜(需要時(shí)頻工具箱http://tftb.nongnu.org) |
toimage | 將一個(gè)一維函數(shù)譜轉(zhuǎn)化為圖像 |
disp_hhs | 以Hilbert-Huang譜的形式顯示toimage函數(shù)的輸出 |
addtag | 添加標(biāo)簽到一個(gè)圖形對(duì)象 |
rmtag | 移除標(biāo)簽從一個(gè)圖形對(duì)象 |
hastag | 測試一個(gè)圖形對(duì)象是否有指定的標(biāo)簽 |
findtag | 找有指定標(biāo)簽的圖形對(duì)象 |
來自《On Empirical Mode Decomposition and its algorithms》的Examples
函數(shù) | 功能 |
emd_fmsin | 一個(gè)包含3組分的例子(需要時(shí)頻工具箱) |
emd_triang | 另一個(gè)包含3組分的例子 |
emd_sampling | effect of sampling on 1 tone |
emd_separation | separation of 2 tones |
ex_online | the way emd_online.m works |
triangular_signal | emd_triang文件調(diào)用的子程序 |
來自《Bivariate Empirical Mode Decomposition》的Examples
函數(shù) | 功能 |
bivariate_EMD_principle | 雙變量/復(fù)數(shù)EMD原則 |
bivariate_EMD_mean_definitions | 各種方法的平均值的定義 |
bivariate_EMD_illustration | 雙變量EMD在海洋漂流位置的應(yīng)用圖解 |
工具箱使用示例
EMD
clc
clear all
close all
% 原始數(shù)據(jù)
fs = 1000;
ts = 1/fs;
t=0:ts:0.3;
z=2*sin(2*pi*10*t) + 5.*sin(2*pi*100*t);
figure
plot(t, z)
title('原始信號(hào)')
% EMD
imf=emd(z);
emd_visu(z,t,imf)
[A,f,tt]=hhspectrum(imf);
[im,tt]=toimage(A,f);
disp_hhs(im);
邊際譜
clc
clear all
close all
% 原始數(shù)據(jù)
fs = 1000;
ts = 1/fs;
t=0:ts:0.3;
y=2*sin(2*pi*10*t);% + 5.*sin(2*pi*100*t);
figure
plot(t, y)
title('原始信號(hào)')
% 求Hilbert-Huang譜
[A,fh,th] = hhspectrum(y);
figure
subplot(211)
plot(th*ts, A)
title('瞬時(shí)幅值') % 就是包絡(luò)
subplot(212)
plot(th*ts, fh*fs)
title('瞬時(shí)頻率')
% 顯示結(jié)果
[im,tt,ff] = toimage(A,fh,th);
disp_hhs(im,tt)
colormap(flipud(gray))
% 編程實(shí)現(xiàn)顯示
figure
imagesc(tt*ts,[0,0.5*fs],im);
ylabel('frequency/Hz')
set(gca,'YDir','normal')
xlabel('time/s')
title('Hilbert-Huang spectrum')
例子程序
更詳細(xì)的使用說明可以參見例子程序,如emd_fmsin.m程序,運(yùn)行結(jié)果如下
EMD分解如下
可以看到,EMD實(shí)現(xiàn)的3個(gè)組分的分離(即分別分解到了IMF1~3中),可見EMD的強(qiáng)大功能。