diff --git a/CMakeLists.txt b/CMakeLists.txt index cc2a889..b456eaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.15.2) # 设置工程名称 -project(LibEEMD VERSION 1.4.1 LANGUAGES C) +project(LibEEMD VERSION 1.4.1) # 添加配置配件编写的函数 include(CMakePackageConfigHelpers) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c6580b..c345530 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,5 +84,15 @@ macro(add_sample name) target_link_libraries(${name} PUBLIC eemd) 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_cxx(eemd_example2) add_sample(ceemdan_example) diff --git a/src/examples/eemd_example2.cpp b/src/examples/eemd_example2.cpp new file mode 100644 index 0000000..ada1482 --- /dev/null +++ b/src/examples/eemd_example2.cpp @@ -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 . + */ + + +#include +#include +#include +#include +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 #endif +#ifdef __cplusplus +extern "C" { +#endif + // Possible error codes returned by functions eemd, ceemdan and // emd_evaluate_spline 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 seed given to the random number generator. A value of zero denotes a // RNG-specific default value. -libeemd_error_code eemd(double const* restrict input, size_t N, - double* restrict output, size_t M, +libeemd_error_code eemd(double const* input, size_t N, + double* output, size_t M, unsigned int ensemble_size, double noise_strength, unsigned int 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 // // Parameters are identical to routine eemd -libeemd_error_code ceemdan(double const* restrict input, size_t N, - double* restrict output, size_t M, +libeemd_error_code ceemdan(double const* input, size_t N, + double* output, size_t M, unsigned int ensemble_size, double noise_strength, unsigned int 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 // the number of zero crossings in the data, and saves the results into the // pointer given as num_zero_crossings_ptr. -void emd_find_extrema(double const* restrict x, size_t N, - double* restrict maxx, double* restrict maxy, size_t* num_max_ptr, - double* restrict minx, double* restrict miny, size_t* num_min_ptr, +void emd_find_extrema(double const* x, size_t N, + double* maxx, double* maxy, size_t* num_max_ptr, + double* minx, double* miny, size_t* num_min_ptr, size_t* num_zero_crossings_ptr); // 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 // produce identical results to the Matlab routine 'spline'. -libeemd_error_code emd_evaluate_spline(double const* restrict x, double const* restrict y, - size_t N, double* restrict spline_y, double* spline_workspace); +libeemd_error_code emd_evaluate_spline(double const* x, double const* y, + size_t N, double* spline_y, double* spline_workspace); + +#ifdef __cplusplus +} +#endif #endif // _EEMD_H_