modified eemd.h to be compatible with c++
This commit is contained in:
parent
b09fd62041
commit
cf067ad2cd
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.15.2)
|
cmake_minimum_required(VERSION 3.15.2)
|
||||||
# 设置工程名称
|
# 设置工程名称
|
||||||
project(LibEEMD VERSION 1.4.1 LANGUAGES C)
|
project(LibEEMD VERSION 1.4.1)
|
||||||
# 添加配置配件编写的函数
|
# 添加配置配件编写的函数
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
@ -84,5 +84,15 @@ macro(add_sample name)
|
|||||||
target_link_libraries(${name} PUBLIC eemd)
|
target_link_libraries(${name} PUBLIC eemd)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
macro(add_sample_cxx name)
|
||||||
|
# 添加可执行文件 命令行
|
||||||
|
add_executable(${name} examples/${name}.cpp)
|
||||||
|
# 为安装文件添加动态库的搜索地址 在Windows下并没有什么用 直接忽略
|
||||||
|
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||||
|
# 链接动态库
|
||||||
|
target_link_libraries(${name} PUBLIC eemd)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
add_sample(eemd_example)
|
add_sample(eemd_example)
|
||||||
|
add_sample_cxx(eemd_example2)
|
||||||
add_sample(ceemdan_example)
|
add_sample(ceemdan_example)
|
||||||
|
73
src/examples/eemd_example2.cpp
Normal file
73
src/examples/eemd_example2.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* Copyright 2013 Perttu Luukko
|
||||||
|
|
||||||
|
* This file is part of libeemd.
|
||||||
|
|
||||||
|
* libeemd is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
|
||||||
|
* libeemd is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with libeemd. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <gsl/gsl_math.h>
|
||||||
|
const double pi = M_PI;
|
||||||
|
|
||||||
|
#include "../lib/eemd.h"
|
||||||
|
|
||||||
|
const size_t ensemble_size = 250;
|
||||||
|
const unsigned int S_number = 4;
|
||||||
|
const unsigned int num_siftings = 50;
|
||||||
|
const double noise_strength = 0.2;
|
||||||
|
const unsigned long int rng_seed = 0;
|
||||||
|
const char outfile[] = "eemd_example2.out";
|
||||||
|
|
||||||
|
// An example signal to decompose
|
||||||
|
const size_t N = 1024;
|
||||||
|
static inline double input_signal(double x) {
|
||||||
|
const double omega = x/(N-1);
|
||||||
|
return 2*sin(30*pi*omega) + 4.0*sin(20*pi*omega)*sin(0.2*pi*omega) + sin(10*pi*omega);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
// Define input data
|
||||||
|
double* inp = new double [N];
|
||||||
|
for (size_t i=0; i<N; i++) {
|
||||||
|
inp[i] = input_signal((double)i);
|
||||||
|
}
|
||||||
|
// Allocate memory for output data
|
||||||
|
size_t M = emd_num_imfs(N);
|
||||||
|
double* outp = new double [M*N];
|
||||||
|
// Run eemd
|
||||||
|
libeemd_error_code err = eemd(inp, N, outp, M, ensemble_size, noise_strength, S_number, num_siftings, rng_seed);
|
||||||
|
if (err != EMD_SUCCESS) {
|
||||||
|
emd_report_if_error(err);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
// Write output to file
|
||||||
|
std::ofstream fp;
|
||||||
|
fp.open(outfile);
|
||||||
|
// Output in columns
|
||||||
|
for (size_t j=0; j<N; j++) {
|
||||||
|
fp << inp[j] << " ";
|
||||||
|
for (size_t i=0; i<M; i++) {
|
||||||
|
fp << outp[i*N+j] << " ";
|
||||||
|
}
|
||||||
|
fp << "\n";
|
||||||
|
}
|
||||||
|
std::clog << "Done!\n";
|
||||||
|
// Cleanup
|
||||||
|
fp.close();
|
||||||
|
delete[] inp;
|
||||||
|
delete[] outp;
|
||||||
|
}
|
@ -45,6 +45,10 @@
|
|||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// Possible error codes returned by functions eemd, ceemdan and
|
// Possible error codes returned by functions eemd, ceemdan and
|
||||||
// emd_evaluate_spline
|
// emd_evaluate_spline
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -85,8 +89,8 @@ void emd_report_to_file_if_error(FILE* file, libeemd_error_code err);
|
|||||||
// the sifting ends when either criterion is fulfilled. The final parameter is
|
// the sifting ends when either criterion is fulfilled. The final parameter is
|
||||||
// the seed given to the random number generator. A value of zero denotes a
|
// the seed given to the random number generator. A value of zero denotes a
|
||||||
// RNG-specific default value.
|
// RNG-specific default value.
|
||||||
libeemd_error_code eemd(double const* restrict input, size_t N,
|
libeemd_error_code eemd(double const* input, size_t N,
|
||||||
double* restrict output, size_t M,
|
double* output, size_t M,
|
||||||
unsigned int ensemble_size, double noise_strength, unsigned int
|
unsigned int ensemble_size, double noise_strength, unsigned int
|
||||||
S_number, unsigned int num_siftings, unsigned long int rng_seed);
|
S_number, unsigned int num_siftings, unsigned long int rng_seed);
|
||||||
|
|
||||||
@ -97,8 +101,8 @@ libeemd_error_code eemd(double const* restrict input, size_t N,
|
|||||||
// (2011) 4144-4147
|
// (2011) 4144-4147
|
||||||
//
|
//
|
||||||
// Parameters are identical to routine eemd
|
// Parameters are identical to routine eemd
|
||||||
libeemd_error_code ceemdan(double const* restrict input, size_t N,
|
libeemd_error_code ceemdan(double const* input, size_t N,
|
||||||
double* restrict output, size_t M,
|
double* output, size_t M,
|
||||||
unsigned int ensemble_size, double noise_strength, unsigned int
|
unsigned int ensemble_size, double noise_strength, unsigned int
|
||||||
S_number, unsigned int num_siftings, unsigned long int rng_seed);
|
S_number, unsigned int num_siftings, unsigned long int rng_seed);
|
||||||
|
|
||||||
@ -108,9 +112,9 @@ libeemd_error_code ceemdan(double const* restrict input, size_t N,
|
|||||||
// arrays for the coordinates must be at least size N. The method also counts
|
// arrays for the coordinates must be at least size N. The method also counts
|
||||||
// the number of zero crossings in the data, and saves the results into the
|
// the number of zero crossings in the data, and saves the results into the
|
||||||
// pointer given as num_zero_crossings_ptr.
|
// pointer given as num_zero_crossings_ptr.
|
||||||
void emd_find_extrema(double const* restrict x, size_t N,
|
void emd_find_extrema(double const* x, size_t N,
|
||||||
double* restrict maxx, double* restrict maxy, size_t* num_max_ptr,
|
double* maxx, double* maxy, size_t* num_max_ptr,
|
||||||
double* restrict minx, double* restrict miny, size_t* num_min_ptr,
|
double* minx, double* miny, size_t* num_min_ptr,
|
||||||
size_t* num_zero_crossings_ptr);
|
size_t* num_zero_crossings_ptr);
|
||||||
|
|
||||||
// Return the number of IMFs that can be extracted from input data of length N,
|
// Return the number of IMFs that can be extracted from input data of length N,
|
||||||
@ -129,7 +133,11 @@ size_t emd_num_imfs(size_t N);
|
|||||||
//
|
//
|
||||||
// This routine is mainly exported so that it can be tested separately to
|
// This routine is mainly exported so that it can be tested separately to
|
||||||
// produce identical results to the Matlab routine 'spline'.
|
// produce identical results to the Matlab routine 'spline'.
|
||||||
libeemd_error_code emd_evaluate_spline(double const* restrict x, double const* restrict y,
|
libeemd_error_code emd_evaluate_spline(double const* x, double const* y,
|
||||||
size_t N, double* restrict spline_y, double* spline_workspace);
|
size_t N, double* spline_y, double* spline_workspace);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _EEMD_H_
|
#endif // _EEMD_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user