initial upload
This commit is contained in:
parent
42f4bed3be
commit
f1cc0fbe52
4
.gitignore
vendored
4
.gitignore
vendored
@ -50,3 +50,7 @@ modules.order
|
|||||||
Module.symvers
|
Module.symvers
|
||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
|
||||||
|
build/
|
||||||
|
.DS_Store
|
||||||
|
*.sh
|
14
CMakeLists.txt
Normal file
14
CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15.2)
|
||||||
|
# 设置工程名称
|
||||||
|
project(LibEEMD VERSION 1.4.1 LANGUAGES C)
|
||||||
|
# 添加配置配件编写的函数
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
|
||||||
|
# CMake默认的安装路径 Windows下为C:/Program\ Files/${Project_Name} Linux/Unix下为/usr/local
|
||||||
|
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
|
||||||
|
# CMake默认的变异类型为空
|
||||||
|
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||||
|
|
||||||
|
# 添加源文件地址
|
||||||
|
add_subdirectory(src/)
|
674
COPYING
Normal file
674
COPYING
Normal file
@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
36
ChangeLog
Normal file
36
ChangeLog
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
Notable changes from previous release:
|
||||||
|
|
||||||
|
In development:
|
||||||
|
|
||||||
|
Version 1.4.1:
|
||||||
|
* Fix bug in CEEMDAN SNR fixing introduced in 1.4; in some cases
|
||||||
|
(especially N=16) the noise can have zero variance causing an overflow
|
||||||
|
|
||||||
|
Version 1.4:
|
||||||
|
* pyeemd splitted to a separate project
|
||||||
|
* Easier installation on OSX
|
||||||
|
* The GSL error handler is disabled and realistic errors are instead
|
||||||
|
handled by libeemd
|
||||||
|
* In CEEMDAN the SNR is fixed separately for each mode as done by Torres
|
||||||
|
et al
|
||||||
|
|
||||||
|
Version 1.3.1:
|
||||||
|
* Minor documentation improvements
|
||||||
|
* Minor bug fix about possible redefinition of NDEBUG
|
||||||
|
|
||||||
|
Version 1.3:
|
||||||
|
* New default stopping parameters for pyeemd
|
||||||
|
* pyeemd warns if using num_siftings=0
|
||||||
|
* Completely reworked S-number criterion handling
|
||||||
|
* Minor bug fixes
|
||||||
|
* Minor improvements to unit tests
|
||||||
|
|
||||||
|
Version 1.2:
|
||||||
|
* Rudimentary error reporting in the C API
|
||||||
|
* Allow setting number of IMFs to compute
|
||||||
|
|
||||||
|
Version 1.1:
|
||||||
|
* Implementation of CEEMDAN
|
||||||
|
* Allow setting the RNG seed
|
||||||
|
* Documentation improvements
|
||||||
|
* Minor optimizations
|
15
LibEEMDConfig.cmake.in
Normal file
15
LibEEMDConfig.cmake.in
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
set(@PROJECT_NAME@_Version "@PROJECT_VERSION@")
|
||||||
|
set_and_check(@PROJECT_NAME@_INSTALL_PREFIX "${PACKAGE_PREFIX_DIR}")
|
||||||
|
set_and_check(@PROJECT_NAME@_INC_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||||
|
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||||
|
set_and_check(@PROJECT_NAME@_LIB_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||||
|
set_and_check(@PROJECT_NAME@_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||||
|
|
||||||
|
set(@PROJECT_NAME@_LIB eemd)
|
||||||
|
set(@PROJECT_NAME@_LIBRARY eemd)
|
||||||
|
set(@PROJECT_NAME@_FOUND 1)
|
||||||
|
|
||||||
|
# include target information
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
112
README.md
Normal file
112
README.md
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
libeemd – a C library for performing the ensemble empirical mode decomposition
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
libeemd is a C library for performing the ensemble empirical mode decomposition
|
||||||
|
(EEMD), its complete variant (CEEMDAN) or the regular empirical mode
|
||||||
|
decomposition (EMD). The details of what libeemd actually computes are
|
||||||
|
available as a separate [article][], which you should read if you are unsure
|
||||||
|
about what EMD, EEMD and CEEMDAN are.
|
||||||
|
|
||||||
|
[article]: https://dx.doi.org/10.1007/s00180-015-0603-9
|
||||||
|
|
||||||
|
Acquiring libeemd
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
The easiest way to get up-to-date versions of libeemd is to use [Bitbucket][],
|
||||||
|
which is a site built for distributing software using the amazing version
|
||||||
|
control system [Git][]. By using libeemd's [Bitbucket site][webpage] you can see
|
||||||
|
recent changes made to the program, report and track bugs found in the program,
|
||||||
|
access user-generated documentation and even create your own versions of
|
||||||
|
libeemd.
|
||||||
|
|
||||||
|
[bitbucket]: https://bitbucket.org
|
||||||
|
[git]: http://git-scm.com
|
||||||
|
|
||||||
|
Program license
|
||||||
|
---------------
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
[webpage]: https://bitbucket.org/luukko/libeemd
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
To compile libeemd you need:
|
||||||
|
|
||||||
|
* A fairly recent C compiler (something that understands C99)
|
||||||
|
* GNU [Scientific Library (GSL)][GSL]
|
||||||
|
|
||||||
|
If you want to use the easy route and use the `Makefile` distributed with
|
||||||
|
libeemd, you should have:
|
||||||
|
|
||||||
|
* GNU [Make][]
|
||||||
|
* GNU [Compiler Collection (GCC)][GCC]
|
||||||
|
|
||||||
|
[Make]: http://www.gnu.org/software/make/
|
||||||
|
[GCC]: http://gcc.gnu.org/
|
||||||
|
[GSL]: http://www.gnu.org/software/gsl/
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
If you have Make and GCC installed, you can simply run
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
in the top-level directory of libeemd (the one with the `Makefile`). This
|
||||||
|
command compiles libeemd into a static library `libeemd.a`, a dynamic library
|
||||||
|
`libeemd.so`, and copies the header file `eemd.h` to the top-level directory.
|
||||||
|
You can then copy these files to wherever you need them.
|
||||||
|
|
||||||
|
You can use `make install` to install the library files to your system. By
|
||||||
|
default this command installs the files under `/usr` (so you'll need root
|
||||||
|
privileges), but you can specify another installation location like this:
|
||||||
|
|
||||||
|
PREFIX=$HOME/usr make install
|
||||||
|
|
||||||
|
If you set a `PREFIX` you need to make sure other programs will find libeemd
|
||||||
|
in this location. For example, if you set `PREFIX` to `$HOME/usr`, the
|
||||||
|
directory `$HOME/usr/lib` should be in `LIBRARY_PATH` and `LD_LIBRARY_PATH`.
|
||||||
|
|
||||||
|
Using the C interface
|
||||||
|
------------
|
||||||
|
|
||||||
|
To use libeemd in your program include `eemd.h` in your header file and link
|
||||||
|
your program against `libeemd.a` or `libeemd.so` and [GSL][]. The routines
|
||||||
|
exported by libeemd are documented in the header file `eemd.h`.
|
||||||
|
|
||||||
|
To see a short example of libeemd in action, please see the `examples`
|
||||||
|
subdirectory.
|
||||||
|
|
||||||
|
pyeemd, the Python interface to libeemd
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
The official Python interface to libeemd is called [pyeemd][]. You should
|
||||||
|
definitely try it, since data analysis with Python is much more fun than with
|
||||||
|
C. More documentation about [pyeemd][] can be found at [Read the Docs](http://pyeemd.readthedocs.org/).
|
||||||
|
|
||||||
|
[pyeemd]: https://bitbucket.org/luukko/pyeemd
|
||||||
|
|
||||||
|
Rlibeemd, the R interface to libeemd
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
There is also a R interface to libeemd. It is available separately at
|
||||||
|
<https://github.com/helske/Rlibeemd>.
|
||||||
|
|
||||||
|
Developing libeemd
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Please report any issues using the Bitbucket issue tracker. If submitting pull
|
||||||
|
requests, please use `develop` as a target branch.
|
11
README_ZY.txt
Normal file
11
README_ZY.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
To all,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
This is a CMake redistribution of the libeemd library. It is created for easy installation cross different platforms. Please send all questions and regards to the original authors. THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Yi Zhang
|
||||||
|
|
||||||
|
2021-11-20
|
88
src/CMakeLists.txt
Normal file
88
src/CMakeLists.txt
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# 设定源文件文件夹
|
||||||
|
aux_source_directory(lib LIBEEMD_SRC)
|
||||||
|
|
||||||
|
# 以下部分为库的编译
|
||||||
|
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||||
|
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||||
|
add_library(eemd SHARED ${LIBEEMD_SRC})
|
||||||
|
# 首先添加静态库的生成命令
|
||||||
|
add_library(eemd_static STATIC ${LIBEEMD_SRC})
|
||||||
|
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||||
|
set_target_properties(eemd_static PROPERTIES OUTPUT_NAME "eemd")
|
||||||
|
# 设置输出目标属性以同时输出动态库与静态库
|
||||||
|
set_target_properties(eemd PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
|
set_target_properties(eemd_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
|
# 设置动态库的版本号
|
||||||
|
set_target_properties(eemd PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
||||||
|
# 设置库文件的输出地址
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||||
|
|
||||||
|
# 设置编译选项
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||||
|
|
||||||
|
# 添加GSL库的编译命令
|
||||||
|
find_package(GSL REQUIRED)
|
||||||
|
if(GSL_FOUND)
|
||||||
|
message(STATUS "GSL Found.")
|
||||||
|
include_directories(${GSL_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(eemd PUBLIC GSL::gsl)
|
||||||
|
target_link_libraries(eemd_static GSL::gsl)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# 添加openmp的编译命令 设置编译选项
|
||||||
|
find_package(OpenMP REQUIRED)
|
||||||
|
if (OpenMP_C_FOUND)
|
||||||
|
message(STATUS "OpenMP Found.")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_SHARED_LINKER_FLAGS}")
|
||||||
|
target_link_libraries(eemd PUBLIC OpenMP::OpenMP_C)
|
||||||
|
target_link_libraries(eemd_static OpenMP::OpenMP_C)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
|
||||||
|
|
||||||
|
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
INSTALL_DESTINATION ${CONFIG_FILE_PATH}
|
||||||
|
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
||||||
|
|
||||||
|
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY SameMajorVersion)
|
||||||
|
|
||||||
|
# 库的安装命令
|
||||||
|
if(WIN32)
|
||||||
|
install(TARGETS eemd DESTINATION lib)
|
||||||
|
install(TARGETS eemd_static DESTINATION lib)
|
||||||
|
else()
|
||||||
|
install(TARGETS eemd eemd_static
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib)
|
||||||
|
install(EXPORT ${PROJECT_NAME}Targets
|
||||||
|
DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
install(FILES
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
|
DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
endif()
|
||||||
|
# 头文件安装命令
|
||||||
|
install(FILES lib/eemd.h DESTINATION include)
|
||||||
|
|
||||||
|
# 以下部分为例子程序的编译
|
||||||
|
# 设置可执行文件的输出地址
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||||
|
|
||||||
|
# 例子的编译方法
|
||||||
|
macro(add_sample name)
|
||||||
|
# 添加可执行文件 命令行
|
||||||
|
add_executable(${name} examples/${name}.c)
|
||||||
|
# 为安装文件添加动态库的搜索地址 在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(ceemdan_example)
|
4
src/examples/README
Normal file
4
src/examples/README
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
`eemd_example` is a simple example program for the C interface of libeemd. It
|
||||||
|
writes its output to `eemd_example.out`. If you have installed `pyeemd` you can
|
||||||
|
plot the results with the Python script `eemd_example_plot.py`. To compile the
|
||||||
|
example please run `make`.
|
68
src/examples/ceemdan_example.c
Normal file
68
src/examples/ceemdan_example.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* 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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <gsl/gsl_math.h>
|
||||||
|
const double pi = M_PI;
|
||||||
|
|
||||||
|
#include "../lib/eemd.h"
|
||||||
|
|
||||||
|
const size_t ensemble_size = 500;
|
||||||
|
const unsigned int S_number = 4;
|
||||||
|
const unsigned int num_siftings = 50;
|
||||||
|
const double noise_strength = 0.02;
|
||||||
|
const unsigned long int rng_seed = 0;
|
||||||
|
const char outfile[] = "ceemdan_example.out";
|
||||||
|
|
||||||
|
const size_t N = 512;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
libeemd_error_code err;
|
||||||
|
// As an example decompose a Dirac signal as in the original CEEMDAN paper
|
||||||
|
double* inp = malloc(N*sizeof(double));
|
||||||
|
memset(inp, 0x00, N*sizeof(double));
|
||||||
|
inp[N/2] = 1.0;
|
||||||
|
// Allocate memory for output data
|
||||||
|
size_t M = emd_num_imfs(N);
|
||||||
|
double* outp = malloc(M*N*sizeof(double));
|
||||||
|
// Run CEEMDAN
|
||||||
|
err = ceemdan(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
|
||||||
|
FILE* fp = fopen(outfile, "w");
|
||||||
|
for (size_t j=0; j<N; j++) {
|
||||||
|
fprintf(fp, "%f ", inp[j]);
|
||||||
|
}
|
||||||
|
fprintf(fp, "\n");
|
||||||
|
for (size_t i=0; i<M; i++) {
|
||||||
|
for (size_t j=0; j<N; j++) {
|
||||||
|
fprintf(fp, "%f ", outp[i*N+j]);
|
||||||
|
}
|
||||||
|
fprintf(fp, "\n");
|
||||||
|
}
|
||||||
|
printf("Done!\n");
|
||||||
|
// Cleanup
|
||||||
|
fclose(fp);
|
||||||
|
free(inp); inp = NULL;
|
||||||
|
free(outp); outp = NULL;
|
||||||
|
}
|
33
src/examples/ceemdan_example_plot.py
Executable file
33
src/examples/ceemdan_example_plot.py
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
from numpy import loadtxt
|
||||||
|
from pylab import plot, show
|
||||||
|
from pyeemd.utils import plot_imfs
|
||||||
|
|
||||||
|
def main():
|
||||||
|
data = loadtxt("ceemdan_example.out")
|
||||||
|
orig = data[0]
|
||||||
|
imfs = data[1:]
|
||||||
|
plot(orig, label="Original data")
|
||||||
|
plot_imfs(imfs)
|
||||||
|
show()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
74
src/examples/eemd_example.c
Normal file
74
src/examples/eemd_example.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/* 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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#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_example.out";
|
||||||
|
|
||||||
|
// An example signal to decompose
|
||||||
|
const size_t N = 1024;
|
||||||
|
static inline double input_signal(double x) {
|
||||||
|
const double omega = 2*pi/(N-1);
|
||||||
|
return sin(17*omega*x)+0.5*(1.0-exp(-0.002*x))*sin(51*omega*x+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
libeemd_error_code err;
|
||||||
|
// Define input data
|
||||||
|
double* inp = malloc(N*sizeof(double));
|
||||||
|
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 = malloc(M*N*sizeof(double));
|
||||||
|
// Run eemd
|
||||||
|
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
|
||||||
|
FILE* fp = fopen(outfile, "w");
|
||||||
|
for (size_t j=0; j<N; j++) {
|
||||||
|
fprintf(fp, "%f ", inp[j]);
|
||||||
|
}
|
||||||
|
fprintf(fp, "\n");
|
||||||
|
for (size_t i=0; i<M; i++) {
|
||||||
|
for (size_t j=0; j<N; j++) {
|
||||||
|
fprintf(fp, "%f ", outp[i*N+j]);
|
||||||
|
}
|
||||||
|
fprintf(fp, "\n");
|
||||||
|
}
|
||||||
|
printf("Done!\n");
|
||||||
|
// Cleanup
|
||||||
|
fclose(fp);
|
||||||
|
free(inp); inp = NULL;
|
||||||
|
free(outp); outp = NULL;
|
||||||
|
}
|
33
src/examples/eemd_example_plot.py
Executable file
33
src/examples/eemd_example_plot.py
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
from numpy import loadtxt
|
||||||
|
from pylab import plot, show
|
||||||
|
from pyeemd.utils import plot_imfs
|
||||||
|
|
||||||
|
def main():
|
||||||
|
data = loadtxt("eemd_example.out")
|
||||||
|
orig = data[0]
|
||||||
|
imfs = data[1:]
|
||||||
|
plot(orig, label="Original data")
|
||||||
|
plot_imfs(imfs)
|
||||||
|
show()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
901
src/lib/eemd.c
Normal file
901
src/lib/eemd.c
Normal file
@ -0,0 +1,901 @@
|
|||||||
|
/* 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 "eemd.h"
|
||||||
|
|
||||||
|
// If we are using OpenMP for parallel computation, we need locks to ensure
|
||||||
|
// that the same output data is not written by several threads at the same
|
||||||
|
// time.
|
||||||
|
#ifdef _OPENMP
|
||||||
|
typedef omp_lock_t lock;
|
||||||
|
inline static void init_lock(lock* l) { omp_init_lock(l); }
|
||||||
|
inline static void destroy_lock(lock* l) { omp_destroy_lock(l); }
|
||||||
|
inline static void get_lock(lock* l) { omp_set_lock(l); }
|
||||||
|
inline static void release_lock(lock* l) { omp_unset_lock(l); }
|
||||||
|
#else
|
||||||
|
// If we don't use OpenMP, we provide a dummy lock that does nothing. This
|
||||||
|
// avoids littering the code with too many #ifdefs for _OPENMP.
|
||||||
|
typedef char lock;
|
||||||
|
inline static void init_lock(__attribute__((unused)) lock* l) {}
|
||||||
|
inline static void destroy_lock(__attribute__((unused)) lock* l) {}
|
||||||
|
inline static void get_lock(__attribute__((unused)) lock* l) {}
|
||||||
|
inline static void release_lock(__attribute__((unused)) lock* l) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Helper functions for working with data arrays
|
||||||
|
inline static void array_copy(double const* restrict src, size_t n, double* restrict dest) {
|
||||||
|
memcpy(dest, src, n*sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void array_add(double const* src, size_t n, double* dest) {
|
||||||
|
for (size_t i=0; i<n; i++)
|
||||||
|
dest[i] += src[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void array_add_to(double const* src1, double const* src2, size_t n, double* dest) {
|
||||||
|
for (size_t i=0; i<n; i++)
|
||||||
|
dest[i] = src1[i] + src2[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void array_addmul_to(double const* src1, double const* src2, double val, size_t n, double* dest) {
|
||||||
|
for (size_t i=0; i<n; i++)
|
||||||
|
dest[i] = src1[i] + val*src2[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void array_sub(double const* src, size_t n, double* dest) {
|
||||||
|
for (size_t i=0; i<n; i++)
|
||||||
|
dest[i] -= src[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void array_mult(double* dest, size_t n, double val) {
|
||||||
|
for (size_t i=0; i<n; i++)
|
||||||
|
dest[i] *= val;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function for extrapolating data at the ends. For a line passing
|
||||||
|
// through (x0, y0), (x1, y1), and (x, y), return y for a given x.
|
||||||
|
inline static double linear_extrapolate(double x0, double y0,
|
||||||
|
double x1, double y1, double x) {
|
||||||
|
assert(x1 != x0);
|
||||||
|
return y0 + (y1-y0)*(x-x0)/(x1-x0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// In the following part the necessary workspace memory structures for several
|
||||||
|
// EMD operations are defined
|
||||||
|
|
||||||
|
// For sifting we need arrays for storing the found extrema of the signal, and memory required
|
||||||
|
// to form the spline envelopes
|
||||||
|
typedef struct {
|
||||||
|
// Number of samples in the signal
|
||||||
|
size_t N;
|
||||||
|
// Found extrema
|
||||||
|
double* restrict maxx;
|
||||||
|
double* restrict maxy;
|
||||||
|
double* restrict minx;
|
||||||
|
double* restrict miny;
|
||||||
|
// Upper and lower envelope spline values
|
||||||
|
double* restrict maxspline;
|
||||||
|
double* restrict minspline;
|
||||||
|
// Extra memory required for spline evaluation
|
||||||
|
double* restrict spline_workspace;
|
||||||
|
} sifting_workspace;
|
||||||
|
|
||||||
|
sifting_workspace* allocate_sifting_workspace(size_t N) {
|
||||||
|
sifting_workspace* w = malloc(sizeof(sifting_workspace));
|
||||||
|
w->N = N;
|
||||||
|
w->maxx = malloc(N*sizeof(double));
|
||||||
|
w->maxy = malloc(N*sizeof(double));
|
||||||
|
w->minx = malloc(N*sizeof(double));
|
||||||
|
w->miny = malloc(N*sizeof(double));
|
||||||
|
w->maxspline = malloc(N*sizeof(double));
|
||||||
|
w->minspline = malloc(N*sizeof(double));
|
||||||
|
// Spline evaluation requires 5*m-10 doubles where m is the number of
|
||||||
|
// extrema. The worst case scenario is that every point is an extrema, so
|
||||||
|
// use m=N to be safe.
|
||||||
|
const size_t spline_workspace_size = (N > 2)? 5*N-10 : 0;
|
||||||
|
w->spline_workspace = malloc(spline_workspace_size*sizeof(double));
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_sifting_workspace(sifting_workspace* w) {
|
||||||
|
free(w->spline_workspace); w->spline_workspace = NULL;
|
||||||
|
free(w->minspline); w->minspline = NULL;
|
||||||
|
free(w->maxspline); w->maxspline = NULL;
|
||||||
|
free(w->miny); w->miny = NULL;
|
||||||
|
free(w->minx); w->minx = NULL;
|
||||||
|
free(w->maxy); w->maxy = NULL;
|
||||||
|
free(w->maxx); w->maxx = NULL;
|
||||||
|
free(w); w = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// For EMD we need space to do the sifting and somewhere to save the residual from the previous run.
|
||||||
|
// We also leave room for an array of locks to protect multi-threaded EMD.
|
||||||
|
typedef struct {
|
||||||
|
size_t N;
|
||||||
|
// Previous residual for EMD
|
||||||
|
double* restrict res;
|
||||||
|
// What is needed for sifting
|
||||||
|
sifting_workspace* restrict sift_w;
|
||||||
|
// A pointer for shared locks. These locks are used to make EMD thread-safe
|
||||||
|
// even when several threads run EMD with the same output matrix (we'll do
|
||||||
|
// this in EEMD).
|
||||||
|
lock** locks;
|
||||||
|
} emd_workspace;
|
||||||
|
|
||||||
|
emd_workspace* allocate_emd_workspace(size_t N) {
|
||||||
|
emd_workspace* w = malloc(sizeof(emd_workspace));
|
||||||
|
w->N = N;
|
||||||
|
w->res = malloc(N*sizeof(double));
|
||||||
|
w->sift_w = allocate_sifting_workspace(N);
|
||||||
|
w->locks = NULL; // The locks are assumed to be allocated and freed independently
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_emd_workspace(emd_workspace* w) {
|
||||||
|
free_sifting_workspace(w->sift_w);
|
||||||
|
free(w->res); w->res = NULL;
|
||||||
|
free(w); w = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// EEMD needs a random number generator in addition to emd_workspace. We also need a place to store
|
||||||
|
// the member of the ensemble (input signal + realization of noise) to be worked on.
|
||||||
|
typedef struct {
|
||||||
|
size_t N;
|
||||||
|
// The random number generator
|
||||||
|
gsl_rng* r;
|
||||||
|
// The ensemble member signal
|
||||||
|
double* restrict x;
|
||||||
|
// What is needed for running EMD
|
||||||
|
emd_workspace* restrict emd_w;
|
||||||
|
} eemd_workspace;
|
||||||
|
|
||||||
|
eemd_workspace* allocate_eemd_workspace(size_t N) {
|
||||||
|
eemd_workspace* w = malloc(sizeof(eemd_workspace));
|
||||||
|
w->N = N;
|
||||||
|
w->r = gsl_rng_alloc(gsl_rng_mt19937);
|
||||||
|
w->x = malloc(N*sizeof(double));
|
||||||
|
w->emd_w = allocate_emd_workspace(N);
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_rng_seed(eemd_workspace* w, unsigned long int rng_seed) {
|
||||||
|
gsl_rng_set(w->r, rng_seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_eemd_workspace(eemd_workspace* w) {
|
||||||
|
free_emd_workspace(w->emd_w);
|
||||||
|
free(w->x); w->x = NULL;
|
||||||
|
gsl_rng_free(w->r); w->r = NULL;
|
||||||
|
free(w); w = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward declaration of a helper function used internally for making a single
|
||||||
|
// EMD run with a preallocated workspace
|
||||||
|
static libeemd_error_code _emd(double* restrict input, emd_workspace* restrict w,
|
||||||
|
double* restrict output, size_t M,
|
||||||
|
unsigned int S_number, unsigned int num_siftings);
|
||||||
|
|
||||||
|
// Forward declaration of a helper function for applying the sifting procedure to
|
||||||
|
// input until it is reduced to an IMF according to the stopping criteria given
|
||||||
|
// by S_number and num_siftings
|
||||||
|
static libeemd_error_code _sift(double* restrict input, sifting_workspace*
|
||||||
|
restrict w, unsigned int S_number, unsigned int num_siftings, unsigned int*
|
||||||
|
sift_counter);
|
||||||
|
|
||||||
|
// Forward declaration of a helper function for parameter validation shared by functions eemd and ceemdan
|
||||||
|
static inline libeemd_error_code _validate_eemd_parameters(unsigned int ensemble_size, double noise_strength, unsigned int S_number, unsigned int num_siftings);
|
||||||
|
|
||||||
|
// Main EEMD decomposition routine definition
|
||||||
|
libeemd_error_code eemd(double const* restrict input, size_t N,
|
||||||
|
double* restrict output, size_t M,
|
||||||
|
unsigned int ensemble_size, double noise_strength, unsigned int
|
||||||
|
S_number, unsigned int num_siftings, unsigned long int rng_seed) {
|
||||||
|
gsl_set_error_handler_off();
|
||||||
|
// Validate parameters
|
||||||
|
libeemd_error_code validation_result = _validate_eemd_parameters(ensemble_size, noise_strength, S_number, num_siftings);
|
||||||
|
if (validation_result != EMD_SUCCESS) {
|
||||||
|
return validation_result;
|
||||||
|
}
|
||||||
|
// For empty data we have nothing to do
|
||||||
|
if (N == 0) {
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
if (M == 0) {
|
||||||
|
M = emd_num_imfs(N);
|
||||||
|
}
|
||||||
|
// The noise standard deviation is noise_strength times the standard deviation of input data
|
||||||
|
const double noise_sigma = (noise_strength != 0)? gsl_stats_sd(input, 1, N)*noise_strength : 0;
|
||||||
|
// Initialize output data to zero
|
||||||
|
memset(output, 0x00, M*N*sizeof(double));
|
||||||
|
// Each thread gets a separate workspace if we are using OpenMP
|
||||||
|
eemd_workspace** ws = NULL;
|
||||||
|
// The locks are shared among all threads
|
||||||
|
lock** locks;
|
||||||
|
// Don't start unnecessary threads if the ensemble is small
|
||||||
|
#ifdef _OPENMP
|
||||||
|
if (omp_get_num_threads() > (int)ensemble_size) {
|
||||||
|
omp_set_num_threads(ensemble_size);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
unsigned int ensemble_counter = 0;
|
||||||
|
// The following section is executed in parallel
|
||||||
|
libeemd_error_code emd_err = EMD_SUCCESS;
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
#ifdef _OPENMP
|
||||||
|
const int num_threads = omp_get_num_threads();
|
||||||
|
const int thread_id = omp_get_thread_num();
|
||||||
|
#if EEMD_DEBUG >= 1
|
||||||
|
#pragma omp single
|
||||||
|
fprintf(stderr, "Using %d thread(s) with OpenMP.\n", num_threads);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
const int num_threads = 1;
|
||||||
|
const int thread_id = 0;
|
||||||
|
#endif
|
||||||
|
#pragma omp single
|
||||||
|
{
|
||||||
|
ws = malloc(num_threads*sizeof(eemd_workspace*));
|
||||||
|
locks = malloc(M*sizeof(lock*));
|
||||||
|
for (size_t i=0; i<M; i++) {
|
||||||
|
locks[i] = malloc(sizeof(lock));
|
||||||
|
init_lock(locks[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Each thread allocates its own workspace
|
||||||
|
ws[thread_id] = allocate_eemd_workspace(N);
|
||||||
|
eemd_workspace* w = ws[thread_id];
|
||||||
|
// All threads share the same array of locks
|
||||||
|
w->emd_w->locks = locks;
|
||||||
|
// Loop over all ensemble members, dividing them among the threads
|
||||||
|
#pragma omp for
|
||||||
|
for (size_t en_i=0; en_i<ensemble_size; en_i++) {
|
||||||
|
// Check if an error has occured in other threads
|
||||||
|
#pragma omp flush(emd_err)
|
||||||
|
if (emd_err != EMD_SUCCESS) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Initialize ensemble member as input data + noise
|
||||||
|
if (noise_strength == 0.0) {
|
||||||
|
array_copy(input, N, w->x);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// set rng seed based on ensemble member to ensure
|
||||||
|
// reproducibility even in a multithreaded case
|
||||||
|
set_rng_seed(w, rng_seed+en_i);
|
||||||
|
for (size_t i=0; i<N; i++) {
|
||||||
|
w->x[i] = input[i] + gsl_ran_gaussian(w->r, noise_sigma);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Extract IMFs with EMD
|
||||||
|
emd_err = _emd(w->x, w->emd_w, output, M, S_number, num_siftings);
|
||||||
|
#pragma omp flush(emd_err)
|
||||||
|
#pragma omp atomic
|
||||||
|
ensemble_counter++;
|
||||||
|
#if EEMD_DEBUG >= 1
|
||||||
|
fprintf(stderr, "Ensemble iteration %u/%u done.\n", ensemble_counter, ensemble_size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
// Free resources
|
||||||
|
free_eemd_workspace(w);
|
||||||
|
#pragma omp single
|
||||||
|
{
|
||||||
|
free(ws); ws = NULL;
|
||||||
|
for (size_t i=0; i<M; i++) {
|
||||||
|
destroy_lock(locks[i]);
|
||||||
|
free(locks[i]);
|
||||||
|
}
|
||||||
|
free(locks); locks = NULL;
|
||||||
|
}
|
||||||
|
} // End of parallel block
|
||||||
|
if (emd_err != EMD_SUCCESS) {
|
||||||
|
return emd_err;
|
||||||
|
}
|
||||||
|
// Divide output data by the ensemble size to get the average
|
||||||
|
if (ensemble_size != 1) {
|
||||||
|
const double one_per_ensemble_size = 1.0/ensemble_size;
|
||||||
|
array_mult(output, N*M, one_per_ensemble_size);
|
||||||
|
}
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main CEEMDAN decomposition routine definition
|
||||||
|
libeemd_error_code ceemdan(double const* restrict input, size_t N,
|
||||||
|
double* restrict output, size_t M,
|
||||||
|
unsigned int ensemble_size, double noise_strength, unsigned int
|
||||||
|
S_number, unsigned int num_siftings, unsigned long int rng_seed) {
|
||||||
|
gsl_set_error_handler_off();
|
||||||
|
// Validate parameters
|
||||||
|
libeemd_error_code validation_result = _validate_eemd_parameters(ensemble_size, noise_strength, S_number, num_siftings);
|
||||||
|
if (validation_result != EMD_SUCCESS) {
|
||||||
|
return validation_result;
|
||||||
|
}
|
||||||
|
// For empty data we have nothing to do
|
||||||
|
if (N == 0) {
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
// For M == 1 the only "IMF" is the residual
|
||||||
|
if (M == 1) {
|
||||||
|
memcpy(output, input, N*sizeof(double));
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
if (M == 0) {
|
||||||
|
M = emd_num_imfs(N);
|
||||||
|
}
|
||||||
|
const double one_per_ensemble_size = 1.0/ensemble_size;
|
||||||
|
// Initialize output data to zero
|
||||||
|
memset(output, 0x00, M*N*sizeof(double));
|
||||||
|
// Each thread gets a separate workspace if we are using OpenMP
|
||||||
|
eemd_workspace** ws = NULL;
|
||||||
|
// All threads need to write to the same row of the output matrix
|
||||||
|
// so we need only one shared lock
|
||||||
|
lock* output_lock = malloc(sizeof(lock));
|
||||||
|
init_lock(output_lock);
|
||||||
|
// The threads also share the same precomputed noise
|
||||||
|
double* noises = malloc(ensemble_size*N*sizeof(double));
|
||||||
|
// Since we need to decompose this noise by EMD, we also need arrays for storing
|
||||||
|
// the residuals
|
||||||
|
double* noise_residuals = malloc(ensemble_size*N*sizeof(double));
|
||||||
|
// Don't start unnecessary threads if the ensemble is small
|
||||||
|
#ifdef _OPENMP
|
||||||
|
if (omp_get_num_threads() > (int)ensemble_size) {
|
||||||
|
omp_set_num_threads(ensemble_size);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
int num_threads;
|
||||||
|
// The following section is executed in parallel
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
#ifdef _OPENMP
|
||||||
|
num_threads = omp_get_num_threads();
|
||||||
|
const int thread_id = omp_get_thread_num();
|
||||||
|
#if EEMD_DEBUG >= 1
|
||||||
|
#pragma omp single
|
||||||
|
fprintf(stderr, "Using %d thread(s) with OpenMP.\n", num_threads);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
num_threads = 1;
|
||||||
|
const int thread_id = 0;
|
||||||
|
#endif
|
||||||
|
#pragma omp single
|
||||||
|
{
|
||||||
|
ws = malloc(num_threads*sizeof(eemd_workspace*));
|
||||||
|
}
|
||||||
|
// Each thread allocates its own workspace
|
||||||
|
ws[thread_id] = allocate_eemd_workspace(N);
|
||||||
|
eemd_workspace* w = ws[thread_id];
|
||||||
|
// Precompute and store white noise, since for each mode of the data we
|
||||||
|
// need the same mode of the corresponding realization of noise
|
||||||
|
#pragma omp for
|
||||||
|
for (size_t en_i=0; en_i<ensemble_size; en_i++) {
|
||||||
|
// set rng seed based on ensemble member to ensure
|
||||||
|
// reproducibility even in a multithreaded case
|
||||||
|
set_rng_seed(w, rng_seed+en_i);
|
||||||
|
for (size_t j=0; j<N; j++) {
|
||||||
|
noises[N*en_i+j] = gsl_ran_gaussian(w->r, 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // Return to sequental mode
|
||||||
|
// Allocate memory for the residual shared among all threads
|
||||||
|
double* restrict res = malloc(N*sizeof(double));
|
||||||
|
// For the first iteration the residual is the input signal
|
||||||
|
array_copy(input, N, res);
|
||||||
|
// Each mode is extracted sequentially, but we use parallelization in the inner loop
|
||||||
|
// to loop over ensemble members
|
||||||
|
for (size_t imf_i=0; imf_i<M; imf_i++) {
|
||||||
|
// Provide a pointer to the output vector where this IMF will be stored
|
||||||
|
double* const imf = &output[imf_i*N];
|
||||||
|
// Then we go parallel to compute the different ensemble members
|
||||||
|
libeemd_error_code sift_err = EMD_SUCCESS;
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
#ifdef _OPENMP
|
||||||
|
const int thread_id = omp_get_thread_num();
|
||||||
|
#else
|
||||||
|
const int thread_id = 0;
|
||||||
|
#endif
|
||||||
|
eemd_workspace* w = ws[thread_id];
|
||||||
|
unsigned int sift_counter = 0;
|
||||||
|
#pragma omp for
|
||||||
|
for (size_t en_i=0; en_i<ensemble_size; en_i++) {
|
||||||
|
// Check if an error has occured in other threads
|
||||||
|
#pragma omp flush(sift_err)
|
||||||
|
if (sift_err != EMD_SUCCESS) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Provide a pointer to the noise vector and noise residual used by
|
||||||
|
// this ensemble member
|
||||||
|
double* const noise = &noises[N*en_i];
|
||||||
|
double* const noise_residual = &noise_residuals[N*en_i];
|
||||||
|
// Initialize input signal as data + noise.
|
||||||
|
// The noise standard deviation is noise_strength times the
|
||||||
|
// standard deviation of input data divided by the standard
|
||||||
|
// deviation of the noise. This is used to fix the SNR at each
|
||||||
|
// stage.
|
||||||
|
const double noise_sd = gsl_stats_sd(noise, 1, N);
|
||||||
|
const double noise_sigma = (noise_sd != 0)? noise_strength*gsl_stats_sd(res, 1, N)/noise_sd : 0;
|
||||||
|
array_addmul_to(res, noise, noise_sigma, N, w->x);
|
||||||
|
// Sift to extract first EMD mode
|
||||||
|
sift_err = _sift(w->x, w->emd_w->sift_w, S_number, num_siftings, &sift_counter);
|
||||||
|
#pragma omp flush(sift_err)
|
||||||
|
// Sum to output vector
|
||||||
|
get_lock(output_lock);
|
||||||
|
array_add(w->x, N, imf);
|
||||||
|
release_lock(output_lock);
|
||||||
|
// Extract next EMD mode of the noise. This is used as the noise for
|
||||||
|
// the next mode extracted from the data
|
||||||
|
if (imf_i == 0) {
|
||||||
|
array_copy(noise, N, noise_residual);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
array_copy(noise_residual, N, noise);
|
||||||
|
}
|
||||||
|
sift_err = _sift(noise, w->emd_w->sift_w, S_number, num_siftings, &sift_counter);
|
||||||
|
#pragma omp flush(sift_err)
|
||||||
|
array_sub(noise, N, noise_residual);
|
||||||
|
}
|
||||||
|
} // Parallel section ends
|
||||||
|
if (sift_err != EMD_SUCCESS) {
|
||||||
|
return sift_err;
|
||||||
|
}
|
||||||
|
// Divide with ensemble size to get the average
|
||||||
|
array_mult(imf, N, one_per_ensemble_size);
|
||||||
|
// Subtract this IMF from the previous residual to form the new one
|
||||||
|
array_sub(imf, N, res);
|
||||||
|
}
|
||||||
|
// Save final residual
|
||||||
|
get_lock(output_lock);
|
||||||
|
array_add(res, N, output+N*(M-1));
|
||||||
|
release_lock(output_lock);
|
||||||
|
// Free global resources
|
||||||
|
for (int thread_id=0; thread_id<num_threads; thread_id++) {
|
||||||
|
free_eemd_workspace(ws[thread_id]);
|
||||||
|
}
|
||||||
|
free(ws); ws = NULL;
|
||||||
|
free(res); res = NULL;
|
||||||
|
free(noise_residuals); noise_residuals = NULL;
|
||||||
|
free(noises); noises = NULL;
|
||||||
|
destroy_lock(output_lock);
|
||||||
|
free(output_lock); output_lock = NULL;
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline libeemd_error_code _validate_eemd_parameters(unsigned int ensemble_size, double noise_strength, unsigned int S_number, unsigned int num_siftings) {
|
||||||
|
if (ensemble_size < 1) {
|
||||||
|
return EMD_INVALID_ENSEMBLE_SIZE;
|
||||||
|
}
|
||||||
|
if (noise_strength < 0) {
|
||||||
|
return EMD_INVALID_NOISE_STRENGTH;
|
||||||
|
}
|
||||||
|
if (ensemble_size == 1 && noise_strength > 0) {
|
||||||
|
return EMD_NOISE_ADDED_TO_EMD;
|
||||||
|
}
|
||||||
|
if (ensemble_size > 1 && noise_strength == 0) {
|
||||||
|
return EMD_NO_NOISE_ADDED_TO_EEMD;
|
||||||
|
}
|
||||||
|
if (S_number == 0 && num_siftings == 0) {
|
||||||
|
return EMD_NO_CONVERGENCE_POSSIBLE;
|
||||||
|
}
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function for applying the sifting procedure to input until it is
|
||||||
|
// reduced to an IMF according to the stopping criteria given by S_number and
|
||||||
|
// num_siftings. The required number of siftings is saved to sift_counter.
|
||||||
|
static libeemd_error_code _sift(double* restrict input, sifting_workspace*
|
||||||
|
restrict w, unsigned int S_number, unsigned int num_siftings,
|
||||||
|
unsigned int* sift_counter) {
|
||||||
|
const size_t N = w->N;
|
||||||
|
// Provide some shorthands to avoid excessive '->' operators
|
||||||
|
double* const maxx = w->maxx;
|
||||||
|
double* const maxy = w->maxy;
|
||||||
|
double* const minx = w->minx;
|
||||||
|
double* const miny = w->miny;
|
||||||
|
// Initialize counters that keep track of the number of siftings
|
||||||
|
// and the S number
|
||||||
|
*sift_counter = 0;
|
||||||
|
unsigned int S_counter = 0;
|
||||||
|
// Numbers of extrema and zero crossings are initialized to dummy values
|
||||||
|
size_t num_max = (size_t)(-1);
|
||||||
|
size_t num_min = (size_t)(-1);
|
||||||
|
size_t num_zc = (size_t)(-1);
|
||||||
|
size_t prev_num_max = (size_t)(-1);
|
||||||
|
size_t prev_num_min = (size_t)(-1);
|
||||||
|
size_t prev_num_zc = (size_t)(-1);
|
||||||
|
while (num_siftings == 0 || *sift_counter < num_siftings) {
|
||||||
|
(*sift_counter)++;
|
||||||
|
#if EEMD_DEBUG >= 1
|
||||||
|
if (*sift_counter == 10000) {
|
||||||
|
fprintf(stderr, "Something is probably wrong. Sift counter has reached 10000.\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
prev_num_max = num_max;
|
||||||
|
prev_num_min = num_min;
|
||||||
|
prev_num_zc = num_zc;
|
||||||
|
// Find extrema and count zero crossings
|
||||||
|
emd_find_extrema(input, N, maxx, maxy, &num_max, minx, miny, &num_min, &num_zc);
|
||||||
|
// Check if we are finished based on the S-number criteria
|
||||||
|
if (S_number != 0) {
|
||||||
|
const int max_diff = (int)num_max - (int)prev_num_max;
|
||||||
|
const int min_diff = (int)num_min - (int)prev_num_min;
|
||||||
|
const int zc_diff = (int)num_zc - (int)prev_num_zc;
|
||||||
|
if (abs(max_diff)+abs(min_diff)+abs(zc_diff) <= 1) {
|
||||||
|
S_counter++;
|
||||||
|
if (S_counter >= S_number) {
|
||||||
|
const int num_diff = (int)num_min + (int)num_max - 4 - (int)num_zc;
|
||||||
|
if (abs(num_diff) <= 1) {
|
||||||
|
// Number of extrema has been stable for S_number steps
|
||||||
|
// and the number of *interior* extrema and zero
|
||||||
|
// crossings differ by at most one -- we are converged
|
||||||
|
// according to the S-number criterion
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
S_counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fit splines, choose order of spline based on the number of extrema
|
||||||
|
libeemd_error_code max_errcode = emd_evaluate_spline(maxx, maxy, num_max, w->maxspline, w->spline_workspace);
|
||||||
|
if (max_errcode != EMD_SUCCESS) {
|
||||||
|
return max_errcode;
|
||||||
|
}
|
||||||
|
libeemd_error_code min_errcode = emd_evaluate_spline(minx, miny, num_min, w->minspline, w->spline_workspace);
|
||||||
|
if (min_errcode != EMD_SUCCESS) {
|
||||||
|
return min_errcode;
|
||||||
|
}
|
||||||
|
// Subtract envelope mean from the data
|
||||||
|
for (size_t i=0; i<N; i++) {
|
||||||
|
input[i] -= 0.5*(w->maxspline[i] + w->minspline[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function for extracting all IMFs from input using the sifting
|
||||||
|
// procedure defined by _sift. The contents of the input array are destroyed in
|
||||||
|
// the process.
|
||||||
|
static libeemd_error_code _emd(double* restrict input, emd_workspace* restrict w,
|
||||||
|
double* restrict output, size_t M,
|
||||||
|
unsigned int S_number, unsigned int num_siftings) {
|
||||||
|
// Provide some shorthands to avoid excessive '->' operators
|
||||||
|
const size_t N = w->N;
|
||||||
|
double* const res = w->res;
|
||||||
|
lock** locks = w->locks;
|
||||||
|
if (M == 0) {
|
||||||
|
M = emd_num_imfs(N);
|
||||||
|
}
|
||||||
|
// We need to store a copy of the original signal so that once it is
|
||||||
|
// reduced to an IMF we have something to subtract the IMF from to form
|
||||||
|
// the residual for the next iteration
|
||||||
|
array_copy(input, N, res);
|
||||||
|
// Loop over all IMFs to be separated from input
|
||||||
|
unsigned int sift_counter;
|
||||||
|
for (size_t imf_i=0; imf_i<M-1; imf_i++) {
|
||||||
|
if (imf_i != 0) {
|
||||||
|
// Except for the first iteration, restore the previous residual
|
||||||
|
// and use it as an input
|
||||||
|
array_copy(res, N, input);
|
||||||
|
}
|
||||||
|
// Perform siftings on input until it is an IMF
|
||||||
|
libeemd_error_code sift_err = _sift(input, w->sift_w, S_number, num_siftings, &sift_counter);
|
||||||
|
if (sift_err != EMD_SUCCESS) {
|
||||||
|
return sift_err;
|
||||||
|
}
|
||||||
|
// Subtract this IMF from the saved copy to form the residual for
|
||||||
|
// the next round
|
||||||
|
array_sub(input, N, res);
|
||||||
|
// Add the discovered IMF to the output matrix. Use locks to ensure
|
||||||
|
// other threads are not writing to the same row of the output matrix
|
||||||
|
// at the same time
|
||||||
|
get_lock(locks[imf_i]);
|
||||||
|
array_add(input, N, output+N*imf_i);
|
||||||
|
release_lock(locks[imf_i]);
|
||||||
|
#if EEMD_DEBUG >= 2
|
||||||
|
fprintf(stderr, "IMF %zd saved after %u siftings.\n", imf_i+1, sift_counter);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
// Save final residual
|
||||||
|
get_lock(locks[M-1]);
|
||||||
|
array_add(res, N, output+N*(M-1));
|
||||||
|
release_lock(locks[M-1]);
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void emd_find_extrema(double const* restrict x, size_t N,
|
||||||
|
double* restrict maxx, double* restrict maxy, size_t* nmax,
|
||||||
|
double* restrict minx, double* restrict miny, size_t* nmin,
|
||||||
|
size_t* nzc) {
|
||||||
|
// Set the number of extrema and zero crossings to zero initially
|
||||||
|
*nmax = 0;
|
||||||
|
*nmin = 0;
|
||||||
|
*nzc = 0;
|
||||||
|
// Handle empty array as a special case
|
||||||
|
if (N == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Add the ends of the data as both local minima and maxima. These
|
||||||
|
// might be changed later by linear extrapolation.
|
||||||
|
maxx[0] = 0;
|
||||||
|
maxy[0] = x[0];
|
||||||
|
(*nmax)++;
|
||||||
|
minx[0] = 0;
|
||||||
|
miny[0] = x[0];
|
||||||
|
(*nmin)++;
|
||||||
|
// If we had only one data point this is it
|
||||||
|
if (N == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Now starts the main extrema-finding loop. The loop detects points where
|
||||||
|
// the slope of the data changes sign. In the case of flat regions at the
|
||||||
|
// extrema, the center point of the flat region will be considered the
|
||||||
|
// extremal point. While detecting extrema, the loop also counts the number
|
||||||
|
// of zero crossings that occur.
|
||||||
|
enum slope { UP, DOWN, NONE };
|
||||||
|
enum sign { POS, NEG, ZERO };
|
||||||
|
enum slope previous_slope = NONE;
|
||||||
|
enum sign previous_sign = (x[0] < -0)? NEG : ((x[0] > 0)? POS : ZERO);
|
||||||
|
int flat_counter = 0;
|
||||||
|
for (size_t i=0; i<N-1; i++) {
|
||||||
|
if (x[i+1] > x[i]) { // Going up
|
||||||
|
if (previous_slope == DOWN) {
|
||||||
|
// Was going down before -> local minimum found
|
||||||
|
minx[*nmin] = (double)(i)-(double)(flat_counter)/2;
|
||||||
|
miny[*nmin] = x[i];
|
||||||
|
(*nmin)++;
|
||||||
|
}
|
||||||
|
if (previous_sign == NEG && x[i+1] > 0) { // zero crossing from neg to pos
|
||||||
|
(*nzc)++;
|
||||||
|
previous_sign = POS;
|
||||||
|
}
|
||||||
|
else if (previous_sign == ZERO && x[i+1] > 0) {
|
||||||
|
// this needs to be handled as an unfortunate special case
|
||||||
|
previous_sign = POS;
|
||||||
|
}
|
||||||
|
previous_slope = UP;
|
||||||
|
flat_counter = 0;
|
||||||
|
}
|
||||||
|
else if (x[i+1] < x[i]) { // Going down
|
||||||
|
if (previous_slope == UP) {
|
||||||
|
// Was going up before -> local maximum found
|
||||||
|
maxx[*nmax] = (double)(i)-(double)(flat_counter)/2;
|
||||||
|
maxy[*nmax] = x[i];
|
||||||
|
(*nmax)++;
|
||||||
|
}
|
||||||
|
if (previous_sign == POS && x[i+1] < -0) { // zero crossing from pos to neg
|
||||||
|
(*nzc)++;
|
||||||
|
previous_sign = NEG;
|
||||||
|
}
|
||||||
|
else if (previous_sign == ZERO && x[i+1] < -0) {
|
||||||
|
// this needs to be handled as an unfortunate special case
|
||||||
|
previous_sign = NEG;
|
||||||
|
}
|
||||||
|
previous_slope = DOWN;
|
||||||
|
flat_counter = 0;
|
||||||
|
}
|
||||||
|
else { // Staying flat
|
||||||
|
flat_counter++;
|
||||||
|
#if EEMD_DEBUG >= 3
|
||||||
|
fprintf(stderr, "Warning: a flat slope found in data. The results will differ from the reference EEMD implementation.\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add the other end of the data as extrema as well.
|
||||||
|
maxx[*nmax] = N-1;
|
||||||
|
maxy[*nmax] = x[N-1];
|
||||||
|
(*nmax)++;
|
||||||
|
minx[*nmin] = N-1;
|
||||||
|
miny[*nmin] = x[N-1];
|
||||||
|
(*nmin)++;
|
||||||
|
// If we have at least two interior extrema, test if linear extrapolation provides
|
||||||
|
// a more extremal value.
|
||||||
|
if (*nmax >= 4) {
|
||||||
|
const double max_el = linear_extrapolate(maxx[1], maxy[1],
|
||||||
|
maxx[2], maxy[2], 0);
|
||||||
|
if (max_el > maxy[0])
|
||||||
|
maxy[0] = max_el;
|
||||||
|
const double max_er = linear_extrapolate(maxx[*nmax-3], maxy[*nmax-3],
|
||||||
|
maxx[*nmax-2], maxy[*nmax-2], N-1);
|
||||||
|
if (max_er > maxy[*nmax-1])
|
||||||
|
maxy[*nmax-1] = max_er;
|
||||||
|
}
|
||||||
|
if (*nmin >= 4) {
|
||||||
|
const double min_el = linear_extrapolate(minx[1], miny[1],
|
||||||
|
minx[2], miny[2], 0);
|
||||||
|
if (min_el < miny[0])
|
||||||
|
miny[0] = min_el;
|
||||||
|
const double min_er = linear_extrapolate(minx[*nmin-3], miny[*nmin-3],
|
||||||
|
minx[*nmin-2], miny[*nmin-2], N-1);
|
||||||
|
if (min_er < miny[*nmin-1])
|
||||||
|
miny[*nmin-1] = min_er;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t emd_num_imfs(size_t N) {
|
||||||
|
if (N == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (N <= 3) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return (size_t)(log2(N));
|
||||||
|
}
|
||||||
|
|
||||||
|
libeemd_error_code emd_evaluate_spline(double const* restrict x, double const* restrict y,
|
||||||
|
size_t N, double* restrict spline_y, double* restrict spline_workspace) {
|
||||||
|
gsl_set_error_handler_off();
|
||||||
|
const size_t n = N-1;
|
||||||
|
const size_t max_j = (size_t)x[n];
|
||||||
|
if (N <= 1) {
|
||||||
|
return EMD_NOT_ENOUGH_POINTS_FOR_SPLINE;
|
||||||
|
}
|
||||||
|
// perform more assertions only if EEMD_DEBUG is on,
|
||||||
|
// as this function is meant only for internal use
|
||||||
|
#if EEMD_DEBUG >= 1
|
||||||
|
if (x[0] != 0) {
|
||||||
|
return EMD_INVALID_SPLINE_POINTS;
|
||||||
|
}
|
||||||
|
for (size_t i=1; i<N; i++) {
|
||||||
|
if (x[i] <= x[i-1]) {
|
||||||
|
return EMD_INVALID_SPLINE_POINTS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// Fall back to linear interpolation (for N==2) or polynomial interpolation
|
||||||
|
// (for N==3)
|
||||||
|
if (N <= 3) {
|
||||||
|
int gsl_status = gsl_poly_dd_init(spline_workspace, x, y, N);
|
||||||
|
if (gsl_status != GSL_SUCCESS) {
|
||||||
|
fprintf(stderr, "Error reported by gsl_poly_dd_init: %s\n",
|
||||||
|
gsl_strerror(gsl_status));
|
||||||
|
return EMD_GSL_ERROR;
|
||||||
|
}
|
||||||
|
for (size_t j=0; j<=max_j; j++) {
|
||||||
|
spline_y[j] = gsl_poly_dd_eval(spline_workspace, x, N, j);
|
||||||
|
}
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
// For N >= 4, interpolate by using cubic splines with not-a-node end conditions.
|
||||||
|
// This algorithm is described in "Numerical Algorithms with C" by
|
||||||
|
// G. Engeln-Müllges and F. Uhlig, page 257.
|
||||||
|
//
|
||||||
|
// Extra homework assignment for anyone reading this: Implement this
|
||||||
|
// algorithm in GSL, so that next time someone needs these end conditions
|
||||||
|
// they can just use GSL.
|
||||||
|
const size_t sys_size = N-2;
|
||||||
|
double* const c = spline_workspace;
|
||||||
|
double* const diag = c+N;
|
||||||
|
double* const supdiag = diag + sys_size;
|
||||||
|
double* const subdiag = supdiag + (sys_size-1);
|
||||||
|
double* const g = subdiag + (sys_size-1);
|
||||||
|
// Define some constants for easier comparison with Engeln-Mullges & Uhlig
|
||||||
|
// and let the compiler optimize them away.
|
||||||
|
const double h_0 = x[1]-x[0];
|
||||||
|
const double h_1 = x[2]-x[1];
|
||||||
|
const double h_nm1 = x[n]-x[n-1];
|
||||||
|
const double h_nm2 = x[n-1]-x[n-2];
|
||||||
|
// Describe the (N-2)x(N-2) linear system Ac=g with the tridiagonal
|
||||||
|
// matrix A defined by subdiag, diag and supdiag
|
||||||
|
// first row
|
||||||
|
diag[0] = h_0 + 2*h_1;
|
||||||
|
supdiag[0] = h_1 - h_0;
|
||||||
|
g[0] = 3.0/(h_0 + h_1)*((y[2]-y[1]) - (h_1/h_0)*(y[1]-y[0]));
|
||||||
|
// rows 2 to n-2
|
||||||
|
for (size_t i=2; i<=n-2; i++) {
|
||||||
|
const double h_i = x[i+1] - x[i];
|
||||||
|
const double h_im1 = x[i] - x[i-1];
|
||||||
|
|
||||||
|
subdiag[i-2] = h_im1;
|
||||||
|
diag[i-1] = 2*(h_im1 + h_i);
|
||||||
|
supdiag[i-1] = h_i;
|
||||||
|
g[i-1] = 3.0*((y[i+1]-y[i])/h_i - (y[i]-y[i-1])/h_im1);
|
||||||
|
}
|
||||||
|
// final row
|
||||||
|
subdiag[n-3] = h_nm2 - h_nm1;
|
||||||
|
diag[n-2] = 2*h_nm2 + h_nm1;
|
||||||
|
g[n-2] = 3.0/(h_nm1 + h_nm2)*((h_nm2/h_nm1)*(y[n]-y[n-1]) - (y[n-1]-y[n-2]));
|
||||||
|
// Solve to get c_1 ... c_{n-1}
|
||||||
|
gsl_vector_view diag_vec = gsl_vector_view_array(diag, n-1);
|
||||||
|
gsl_vector_view supdiag_vec = gsl_vector_view_array(supdiag, n-2);
|
||||||
|
gsl_vector_view subdiag_vec = gsl_vector_view_array(subdiag, n-2);
|
||||||
|
gsl_vector_view g_vec = gsl_vector_view_array(g, n-1);
|
||||||
|
gsl_vector_view solution_vec = gsl_vector_view_array(c+1, n-1);
|
||||||
|
int gsl_status = gsl_linalg_solve_tridiag(&diag_vec.vector,
|
||||||
|
&supdiag_vec.vector,
|
||||||
|
&subdiag_vec.vector,
|
||||||
|
&g_vec.vector,
|
||||||
|
&solution_vec.vector);
|
||||||
|
if (gsl_status != GSL_SUCCESS) {
|
||||||
|
fprintf(stderr, "Error reported by gsl_linalg_solve_tridiag: %s\n",
|
||||||
|
gsl_strerror(gsl_status));
|
||||||
|
return EMD_GSL_ERROR;
|
||||||
|
}
|
||||||
|
// Compute c[0] and c[n]
|
||||||
|
c[0] = c[1] + (h_0/h_1)*(c[1]-c[2]);
|
||||||
|
c[n] = c[n-1] + (h_nm1/h_nm2)*(c[n-1]-c[n-2]);
|
||||||
|
// The coefficients b_i and d_i are computed from the c_i's, so just
|
||||||
|
// evaluate the spline at the required points. In this case it is easy to
|
||||||
|
// find the required interval for spline evaluation, since the evaluation
|
||||||
|
// points j just increase monotonically from 0 to max_j.
|
||||||
|
size_t i = 0;
|
||||||
|
for (size_t j=0; j<=max_j; j++) {
|
||||||
|
if (j > x[i+1]) {
|
||||||
|
i++;
|
||||||
|
assert(i < n);
|
||||||
|
}
|
||||||
|
const double dx = j-x[i];
|
||||||
|
if (dx == 0) {
|
||||||
|
spline_y[j] = y[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Compute coefficients b_i and d_i
|
||||||
|
const double h_i = x[i+1] - x[i];
|
||||||
|
const double a_i = y[i];
|
||||||
|
const double b_i = (y[i+1]-y[i])/h_i - (h_i/3.0)*(c[i+1]+2*c[i]);
|
||||||
|
const double c_i = c[i];
|
||||||
|
const double d_i = (c[i+1]-c[i])/(3.0*h_i);
|
||||||
|
// evaluate spline at x=j using the Horner scheme
|
||||||
|
spline_y[j] = a_i + dx*(b_i + dx*(c_i + dx*d_i));
|
||||||
|
}
|
||||||
|
return EMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper functions for printing what error codes mean
|
||||||
|
void emd_report_to_file_if_error(FILE* file, libeemd_error_code err) {
|
||||||
|
if (err == EMD_SUCCESS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fprintf(file, "libeemd error: ");
|
||||||
|
switch (err) {
|
||||||
|
case EMD_INVALID_ENSEMBLE_SIZE :
|
||||||
|
fprintf(file, "Invalid ensemble size (zero or negative)\n");
|
||||||
|
break;
|
||||||
|
case EMD_INVALID_NOISE_STRENGTH :
|
||||||
|
fprintf(file, "Invalid noise strength (negative)\n");
|
||||||
|
break;
|
||||||
|
case EMD_NOISE_ADDED_TO_EMD :
|
||||||
|
fprintf(file, "Positive noise strength but ensemble size is one (regular EMD)\n");
|
||||||
|
break;
|
||||||
|
case EMD_NO_NOISE_ADDED_TO_EEMD :
|
||||||
|
fprintf(file, "Ensemble size is more than one (EEMD) but noise strength is zero\n");
|
||||||
|
break;
|
||||||
|
case EMD_NO_CONVERGENCE_POSSIBLE :
|
||||||
|
fprintf(file, "Stopping criteria invalid: would never converge\n");
|
||||||
|
break;
|
||||||
|
case EMD_NOT_ENOUGH_POINTS_FOR_SPLINE :
|
||||||
|
fprintf(file, "Spline evaluation tried with insufficient points\n");
|
||||||
|
break;
|
||||||
|
case EMD_INVALID_SPLINE_POINTS :
|
||||||
|
fprintf(file, "Spline evaluation points invalid\n");
|
||||||
|
break;
|
||||||
|
case EMD_GSL_ERROR :
|
||||||
|
fprintf(file, "Error reported by GSL library\n");
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
fprintf(file, "Error code with unknown meaning. Please file a bug!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void emd_report_if_error(libeemd_error_code err) {
|
||||||
|
emd_report_to_file_if_error(stderr, err);
|
||||||
|
}
|
135
src/lib/eemd.h
Normal file
135
src/lib/eemd.h
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _EEMD_H_
|
||||||
|
#define _EEMD_H_
|
||||||
|
|
||||||
|
#ifndef EEMD_DEBUG
|
||||||
|
#define EEMD_DEBUG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if EEMD_DEBUG == 0
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define NDEBUG
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <gsl/gsl_statistics_double.h>
|
||||||
|
#include <gsl/gsl_rng.h>
|
||||||
|
#include <gsl/gsl_randist.h>
|
||||||
|
#include <gsl/gsl_vector.h>
|
||||||
|
#include <gsl/gsl_linalg.h>
|
||||||
|
#include <gsl/gsl_poly.h>
|
||||||
|
|
||||||
|
#ifdef _OPENMP
|
||||||
|
#include <omp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Possible error codes returned by functions eemd, ceemdan and
|
||||||
|
// emd_evaluate_spline
|
||||||
|
typedef enum {
|
||||||
|
EMD_SUCCESS = 0,
|
||||||
|
// Errors from invalid parameters
|
||||||
|
EMD_INVALID_ENSEMBLE_SIZE = 1,
|
||||||
|
EMD_INVALID_NOISE_STRENGTH = 2,
|
||||||
|
EMD_NOISE_ADDED_TO_EMD = 3,
|
||||||
|
EMD_NO_NOISE_ADDED_TO_EEMD = 4,
|
||||||
|
EMD_NO_CONVERGENCE_POSSIBLE = 5,
|
||||||
|
EMD_NOT_ENOUGH_POINTS_FOR_SPLINE = 6,
|
||||||
|
EMD_INVALID_SPLINE_POINTS = 7,
|
||||||
|
// Other errors
|
||||||
|
EMD_GSL_ERROR = 8
|
||||||
|
} libeemd_error_code;
|
||||||
|
|
||||||
|
// Helper functions to print an error message if an error occured
|
||||||
|
void emd_report_if_error(libeemd_error_code err);
|
||||||
|
void emd_report_to_file_if_error(FILE* file, libeemd_error_code err);
|
||||||
|
|
||||||
|
// Main EEMD decomposition routine as described in:
|
||||||
|
// Z. Wu and N. Huang,
|
||||||
|
// Ensemble Empirical Mode Decomposition: A Noise-Assisted Data Analysis
|
||||||
|
// Method, Advances in Adaptive Data Analysis,
|
||||||
|
// Vol. 1, No. 1 (2009) 1–41
|
||||||
|
//
|
||||||
|
// Parameters 'input' and 'N' denote the input data and its length,
|
||||||
|
// respectively. Output from the routine is written to array 'output', which
|
||||||
|
// needs to be able to store at least N*M doubles, where M is the number of
|
||||||
|
// Intrinsic Mode Functions (IMFs) to compute. If M is set to zero, a value of
|
||||||
|
// M = emd_num_imfs(N) will be used, which corresponds to a maximal number of
|
||||||
|
// IMFs. Note that the final residual is also counted as an IMF in this
|
||||||
|
// respect, so you most likely want at least num_imfs=2. The following
|
||||||
|
// parameters are the ensemble size and the relative noise standard deviation,
|
||||||
|
// respectively. These are followed by the parameters for the stopping
|
||||||
|
// criterion. The stopping parameter can be defined by a S-number (see the
|
||||||
|
// article for details) or a fixed number of siftings. If both are specified,
|
||||||
|
// 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,
|
||||||
|
unsigned int ensemble_size, double noise_strength, unsigned int
|
||||||
|
S_number, unsigned int num_siftings, unsigned long int rng_seed);
|
||||||
|
|
||||||
|
// A complete variant of EEMD as described in:
|
||||||
|
// M. Torres et al,
|
||||||
|
// A Complete Ensemble Empirical Mode Decomposition with Adaptive Noise
|
||||||
|
// IEEE Int. Conf. on Acoust., Speech and Signal Proc. ICASSP-11,
|
||||||
|
// (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,
|
||||||
|
unsigned int ensemble_size, double noise_strength, unsigned int
|
||||||
|
S_number, unsigned int num_siftings, unsigned long int rng_seed);
|
||||||
|
|
||||||
|
// A method for finding the local minima and maxima from input data specified
|
||||||
|
// with parameters x and N. The memory for storing the coordinates of the
|
||||||
|
// extrema and their number are passed as the rest of the parameters. The
|
||||||
|
// 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,
|
||||||
|
size_t* num_zero_crossings_ptr);
|
||||||
|
|
||||||
|
// Return the number of IMFs that can be extracted from input data of length N,
|
||||||
|
// including the final residual.
|
||||||
|
size_t emd_num_imfs(size_t N);
|
||||||
|
|
||||||
|
// This routine evaluates a cubic spline with nodes defined by the arrays x and
|
||||||
|
// y, each of length N. The spline is evaluated using the not-a-node end point
|
||||||
|
// conditions (same as Matlab). The y values of the spline curve will be
|
||||||
|
// evaluated at integer points from 0 to x[N-1], and these y values will be
|
||||||
|
// written to the array spline_y. The endpoint x[N-1] is assumed to be an
|
||||||
|
// integer, and the x values are assumed to be in ascending order, with x[0]
|
||||||
|
// equal to 0. The workspace required is 5*N-10 doubles, except that N==2
|
||||||
|
// requires no extra memory. For N<=3 the routine falls back to polynomial
|
||||||
|
// interpolation, same as Matlab.
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
#endif // _EEMD_H_
|
Loading…
Reference in New Issue
Block a user