Compare commits
44 Commits
Author | SHA1 | Date | |
---|---|---|---|
51f9d39837 | |||
c4b7655ad4 | |||
3415d6fc03 | |||
172b4af8c4 | |||
38a2cd7ccf | |||
b9c140e5ef | |||
ebd0f89493 | |||
![]() |
adc77ebadf | ||
9b5e9db390 | |||
d001110e30 | |||
312e624dc5 | |||
![]() |
7acb89acfc | ||
![]() |
53b5d140c9 | ||
04d43c09ec | |||
2421f6c543 | |||
24b48f4c9f | |||
8a019e7e88 | |||
edf5790139 | |||
58b5604d3d | |||
afcb53b797 | |||
fc537cea42 | |||
becd7defec | |||
![]() |
a92456d2e2 | ||
![]() |
c7c9ba8b10 | ||
![]() |
d4351d7f1c | ||
![]() |
9d20de8d29 | ||
![]() |
f104d084be | ||
![]() |
8d65cce75f | ||
![]() |
1acc29c724 | ||
![]() |
cef10c1133 | ||
![]() |
f2bf77feb8 | ||
![]() |
36f0d305c1 | ||
![]() |
d76bd20573 | ||
![]() |
1e597aaffa | ||
![]() |
782dc66e20 | ||
![]() |
e49f228771 | ||
![]() |
e49c799ed2 | ||
![]() |
16a54db95b | ||
![]() |
2ef5c81d82 | ||
![]() |
8580e896da | ||
![]() |
00c916c150 | ||
![]() |
6863b24010 | ||
![]() |
0377515f63 | ||
![]() |
b84014f973 |
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
#Folders Ignore
|
||||
Bin/
|
||||
Testing/
|
||||
.vscode/
|
||||
|
||||
#cmake ignore
|
||||
CMakeCache.txt
|
||||
@ -32,4 +33,10 @@ language.settings.xml
|
||||
*.tcl
|
||||
|
||||
#wavelib-specific
|
||||
denoised.txt
|
||||
denoised.txt
|
||||
|
||||
test/
|
||||
build/
|
||||
.vscode/
|
||||
.DS_Store
|
||||
*.sh
|
||||
|
@ -1,51 +1,15 @@
|
||||
cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.15.2)
|
||||
# 设置工程名称和语言
|
||||
project(WaveLib VERSION 1.0)
|
||||
# 添加配置配件编写的函数
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
set(PROJECT_NAME wavelib)
|
||||
project(${PROJECT_NAME} CXX C)
|
||||
|
||||
|
||||
# src root path
|
||||
set(WAVELIB_SRC_ROOT ${PROJECT_SOURCE_DIR} CACHE PATH "Wavelib source root")
|
||||
# binary output by default
|
||||
set(COMMON_BIN_PATH ${CMAKE_BINARY_DIR}/Bin)
|
||||
set(LIBRARY_OUTPUT_PATH ${COMMON_BIN_PATH}/${CMAKE_BUILD_TYPE})
|
||||
set(EXECUTABLE_OUTPUT_PATH ${COMMON_BIN_PATH}/${CMAKE_BUILD_TYPE})
|
||||
# set where to find additional cmake modules if any
|
||||
set(CMAKE_MODULE_PATH ${WAVELIB_SRC_ROOT}/cmake ${CMAKE_MODULE_PATH})
|
||||
|
||||
|
||||
set(WAVELIB_VERSION "1.0.0" CACHE STRING "Wavelib version" FORCE)
|
||||
message(">>> Building Wavelib version: ${WAVELIB_VERSION}")
|
||||
message(">>> EXECUTABLE_OUTPUT_PATH = ${EXECUTABLE_OUTPUT_PATH}")
|
||||
|
||||
option(BUILD_UT "Enable Unit test" ON)
|
||||
|
||||
# cleanup prefix lib for Unix-like OSes
|
||||
set(CMAKE_SHARED_MODULE_PREFIX)
|
||||
|
||||
# install target to this folder by default
|
||||
set(WAVELIB_BINARY_DIR ${WAVELIB_SRC_ROOT}/bin)
|
||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
set(CMAKE_INSTALL_PREFIX "${WAVELIB_BINARY_DIR}" CACHE PATH "default install path" FORCE)
|
||||
endif()
|
||||
|
||||
# make include globaly visible
|
||||
set(PROJECT_WIDE_INCLUDE ${WAVELIB_SRC_ROOT}/include)
|
||||
include_directories(${PROJECT_WIDE_INCLUDE})
|
||||
|
||||
|
||||
|
||||
|
||||
include_directories(${COMMON_BIN_PATH})
|
||||
|
||||
if(BUILD_UT)
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
add_subdirectory(unitTests)
|
||||
endif()
|
||||
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)
|
||||
add_subdirectory(auxiliary)
|
||||
add_subdirectory(test)
|
||||
|
||||
install(DIRECTORY ${WAVELIB_SRC_ROOT}/include/ DESTINATION include FILES_MATCHING PATTERN "*.h")
|
||||
add_subdirectory(auxiliary)
|
10
README.md
10
README.md
@ -1,3 +1,5 @@
|
||||
[](https://travis-ci.org/rafat/wavelib)
|
||||
|
||||
wavelib
|
||||
=======
|
||||
|
||||
@ -5,11 +7,11 @@ C Implementation of Discrete Wavelet Transform (DWT,SWT and MODWT), Continuous W
|
||||
|
||||
Discrete Wavelet Transform Methods Implemented
|
||||
|
||||
DWT/IDWT A decimated Discrete Wavelet Transform implementation using implicit signal extension and up/downsampling so it is a fast implementation. A FFT based implementation is optional but will not be usually needed. Both periodic and symmetric options are available.
|
||||
DWT/IDWT and DWT2/IDWT2 A decimated Discrete Wavelet Transform implementation using implicit signal extension and up/downsampling so it is a fast implementation. A FFT based implementation is optional but will not be usually needed. Both periodic and symmetric options are available.
|
||||
|
||||
SWT/ISWT Stationary Wavelet Transform. It works only for signal lengths that are multiples of 2^J where J is the number of decomposition levels. For signals of other lengths see MODWT implementation.
|
||||
SWT/ISWT and SWT2/ISWT2 Stationary Wavelet Transform. It works only for signal lengths that are multiples of 2^J where J is the number of decomposition levels. For signals of other lengths see MODWT implementation.
|
||||
|
||||
MODWT/IMODWT Maximal Overlap Discrete Wavelet Transform is another undecimated transform. It is implemented for signals of any length but only orthogonal wavelets (Daubechies, Symlets and Coiflets) can be deployed. This implementation is based on the method laid out in "Wavelet Methods For Wavelet Analysis" by Donald Percival and Andrew Walden.
|
||||
MODWT/IMODWT and MODWT2/IMODWT2 Maximal Overlap Discrete Wavelet Transform is another undecimated transform. It is implemented for signals of any length but only orthogonal wavelets (Daubechies, Symlets and Coiflets) can be deployed. This implementation is based on the method laid out in "Wavelet Methods For Wavelet Analysis" by Donald Percival and Andrew Walden.
|
||||
|
||||
Discrete Wavelet Packet Transform Methods Implemented
|
||||
|
||||
@ -21,7 +23,7 @@ CWT/ICWT C translation ( with some modifications) of Continuous Wavelet Transfo
|
||||
|
||||
Documentation Available at - https://github.com/rafat/wavelib/wiki
|
||||
|
||||
Live Demo (Emscripten) - http://rafat.github.io/wavelib/
|
||||
Live Demo of 1D DWT and 1D CWT (Emscripten) - http://rafat.github.io/wavelib/
|
||||
|
||||
License - BSD 3-Clause
|
||||
|
||||
|
19
WaveLibConfig.cmake.in
Normal file
19
WaveLibConfig.cmake.in
Normal file
@ -0,0 +1,19 @@
|
||||
@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@_INCULDE_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 wavelib)
|
||||
set(@PROJECT_NAME@_LIBRARY wavelib)
|
||||
|
||||
set(WauxLib_LIB wauxlib)
|
||||
set(WauxLib_LIBRARY wauxlib)
|
||||
|
||||
# include target information
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
|
||||
check_required_components(@PROJECT_NAME@)
|
@ -1,16 +1,55 @@
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
# 设定源文件文件夹
|
||||
aux_source_directory(. WAUX_SRC)
|
||||
|
||||
set(SOURCE_FILES denoise.c
|
||||
waux.c
|
||||
)
|
||||
# 以下部分为库的编译
|
||||
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||
add_library(wauxlib SHARED ${WAUX_SRC})
|
||||
# 首先添加静态库的生成命令
|
||||
add_library(wauxlib_static STATIC ${WAUX_SRC})
|
||||
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||
set_target_properties(wauxlib_static PROPERTIES OUTPUT_NAME "wauxlib")
|
||||
# 设置输出目标属性以同时输出动态库与静态库
|
||||
set_target_properties(wauxlib PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
set_target_properties(wauxlib_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
# 设置动态库的版本号
|
||||
set_target_properties(wauxlib PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
||||
# 设置动态库的运行搜索地址
|
||||
set_target_properties(wauxlib PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(wauxlib_static PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
|
||||
set(HEADER_FILES waux.h)
|
||||
target_link_libraries(wauxlib PUBLIC wavelib)
|
||||
target_link_libraries(wauxlib_static PUBLIC wavelib_static)
|
||||
|
||||
add_library(wauxlib STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||
# 设置库文件的输出地址
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||
|
||||
target_link_libraries(wauxlib wavelib)
|
||||
# 设置编译选项
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
|
||||
set_property(TARGET wauxlib PROPERTY FOLDER "lib")
|
||||
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
|
||||
|
||||
target_include_directories(wauxlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${CONFIG_FILE_PATH})
|
||||
|
||||
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
# 库的安装命令
|
||||
if(WIN32)
|
||||
install(TARGETS wauxlib DESTINATION lib)
|
||||
install(TARGETS wauxlib_static DESTINATION lib)
|
||||
else()
|
||||
install(TARGETS wauxlib wauxlib_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()
|
@ -4,7 +4,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "waux.h"
|
||||
#include "wauxlib.h"
|
||||
#include "../header/wauxlib.h"
|
||||
|
||||
denoise_object denoise_init(int length, int J,const char* wname) {
|
||||
denoise_object obj = NULL;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "wauxlib.h"
|
||||
#include "../header/wauxlib.h"
|
||||
#include "waux.h"
|
||||
|
||||
int compare_double(const void* a, const void* b)
|
||||
|
@ -191,11 +191,33 @@ struct cwt_set{
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct wt2_set* wt2_object;
|
||||
|
||||
wt2_object wt2_init(wave_object wave, const char* method, int rows, int cols, int J);
|
||||
|
||||
struct wt2_set{
|
||||
wave_object wave;
|
||||
char method[10];
|
||||
int rows;// Matrix Number of rows
|
||||
int cols; // Matrix Number of columns
|
||||
int outlength;// Length of the output DWT vector
|
||||
int J; // Number of decomposition Levels
|
||||
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||
char ext[10];// Type of Extension used - "per" or "sym"
|
||||
int coeffaccesslength;
|
||||
|
||||
int N; //
|
||||
int *dimensions;
|
||||
int *coeffaccess;
|
||||
int params[0];
|
||||
};
|
||||
|
||||
void dwt(wt_object wt, const double *inp);
|
||||
|
||||
void idwt(wt_object wt, double *dwtop);
|
||||
|
||||
double *getDWTmra(wt_object wt, double *wavecoeffs);
|
||||
|
||||
void wtree(wtree_object wt, const double *inp);
|
||||
|
||||
void dwpt(wpt_object wt, const double *inp);
|
||||
@ -206,16 +228,22 @@ void swt(wt_object wt, const double *inp);
|
||||
|
||||
void iswt(wt_object wt, double *swtop);
|
||||
|
||||
double *getSWTmra(wt_object wt, double *wavecoeffs);
|
||||
|
||||
void modwt(wt_object wt, const double *inp);
|
||||
|
||||
void imodwt(wt_object wt, double *dwtop);
|
||||
|
||||
double* getMODWTmra(wt_object wt, double *wavecoeffs);
|
||||
|
||||
void setDWTExtension(wt_object wt, const char *extension);
|
||||
|
||||
void setWTREEExtension(wtree_object wt, const char *extension);
|
||||
|
||||
void setDWPTExtension(wpt_object wt, const char *extension);
|
||||
|
||||
void setDWT2Extension(wt2_object wt, const char *extension);
|
||||
|
||||
void setDWPTEntropy(wpt_object wt, const char *entropy, double eparam);
|
||||
|
||||
void setWTConv(wt_object wt, const char *cmethod);
|
||||
@ -240,6 +268,22 @@ void icwt(cwt_object wt, double *cwtop);
|
||||
|
||||
int getCWTScaleLength(int N);
|
||||
|
||||
double* dwt2(wt2_object wt, double *inp);
|
||||
|
||||
void idwt2(wt2_object wt,double *wavecoeff, double *oup);
|
||||
|
||||
double* swt2(wt2_object wt, double *inp);
|
||||
|
||||
void iswt2(wt2_object wt, double *wavecoeffs, double *oup);
|
||||
|
||||
double* modwt2(wt2_object wt, double *inp);
|
||||
|
||||
void imodwt2(wt2_object wt, double *wavecoeff, double *oup);
|
||||
|
||||
double* getWT2Coeffs(wt2_object wt,double* wcoeffs, int level,char *type, int *rows, int *cols);
|
||||
|
||||
void dispWT2Coeffs(double *A, int row, int col);
|
||||
|
||||
void wave_summary(wave_object obj);
|
||||
|
||||
void wt_summary(wt_object wt);
|
||||
@ -248,7 +292,9 @@ void wtree_summary(wtree_object wt);
|
||||
|
||||
void wpt_summary(wpt_object wt);
|
||||
|
||||
void cwt_summary(cwt_object wt);;
|
||||
void cwt_summary(cwt_object wt);
|
||||
|
||||
void wt2_summary(wt2_object wt);
|
||||
|
||||
void wave_free(wave_object object);
|
||||
|
||||
@ -260,6 +306,8 @@ void wpt_free(wpt_object object);
|
||||
|
||||
void cwt_free(cwt_object object);
|
||||
|
||||
void wt2_free(wt2_object wt);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
54
installer
Executable file
54
installer
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $# == 0 || ${1} == "help" ]]; then
|
||||
echo "Compiles executables/libraries and maintains installed files. Two tools 'Cmake' and 'stow' are empolyed here. For more information, see https://cmake.org and https://www.gnu.org/software/stow/."
|
||||
echo ""
|
||||
echo "School of Earth Sciences, Zhejiang University"
|
||||
echo "Yi Zhang (yizhang-geo@zju.edu.cn)"
|
||||
echo ""
|
||||
echo "Usage: ./config.sh [option] [Cmake options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo "(1) configure: Configure Cmake project(s). This option could take extra Cmake options as in <option>=<value>."
|
||||
echo "(2) build: Build executables/libraries."
|
||||
echo "(3) install: Install executables/libraries to the directory of CMAKE_INSTALL_PREFIX and sym-links them to the target address. This offers a quick and clean remove of the installed files."
|
||||
echo "(4) clean: Clean build/ folder(s)."
|
||||
echo "(5) uninstall: Delete the installed files and sym-links."
|
||||
echo "(6) info: Print out current setups."
|
||||
echo "(7) help: Show help information."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
package=wavelib
|
||||
address=/opt/stow
|
||||
taress=/usr/local
|
||||
option="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${address}/${package}"
|
||||
|
||||
if [[ $# -gt 1 ]]; then
|
||||
for opt in "$@"; do
|
||||
if [[ ${opt} != "configure" ]]; then
|
||||
option="${option} -D${opt}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${1} == "configure" && ! -d "build/" ]]; then
|
||||
mkdir build && cd build && cmake .. ${option}
|
||||
elif [[ ${1} == "configure" ]]; then
|
||||
cd build && rm -rf * && cmake .. ${option}
|
||||
elif [[ ${1} == "build" ]]; then
|
||||
cd build && make
|
||||
elif [[ ${1} == "install" ]]; then
|
||||
cd build && sudo make install
|
||||
sudo stow --dir=${address} --target=${taress} -S ${package}
|
||||
elif [[ ${1} == "clean" ]]; then
|
||||
rm -rf build/
|
||||
elif [[ ${1} == "uninstall" ]]; then
|
||||
sudo stow --dir=${address} --target=${taress} -D ${package}
|
||||
sudo rm -rf ${address}/${package}
|
||||
elif [[ ${1} == "info" ]]; then
|
||||
echo "package name:" ${package}
|
||||
echo "stow address:" ${address}
|
||||
echo "target address:" ${taress}
|
||||
echo "Cmake options:" ${option}
|
||||
fi
|
@ -1,31 +1,55 @@
|
||||
# 设定源文件文件夹
|
||||
aux_source_directory(. WAVE_SRC)
|
||||
|
||||
# 以下部分为库的编译
|
||||
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||
add_library(wavelib SHARED ${WAVE_SRC})
|
||||
# 首先添加静态库的生成命令
|
||||
add_library(wavelib_static STATIC ${WAVE_SRC})
|
||||
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||
set_target_properties(wavelib_static PROPERTIES OUTPUT_NAME "wavelib")
|
||||
# 设置输出目标属性以同时输出动态库与静态库
|
||||
set_target_properties(wavelib PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
set_target_properties(wavelib_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
# 设置动态库的版本号
|
||||
set_target_properties(wavelib PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
||||
# 设置动态库的运行搜索地址
|
||||
set_target_properties(wavelib PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(wavelib_static PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
# 设置库文件的输出地址
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||
|
||||
set(SOURCE_FILES conv.c
|
||||
cwt.c
|
||||
cwtmath.c
|
||||
hsfft.c
|
||||
real.c
|
||||
wavefilt.c
|
||||
wavefunc.c
|
||||
wavelib.c
|
||||
wtmath.c
|
||||
)
|
||||
# 设置编译选项
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
|
||||
set(HEADER_FILES conv.h
|
||||
cwt.h
|
||||
cwtmath.h
|
||||
hsfft.h
|
||||
real.h
|
||||
wavefilt.h
|
||||
wavefunc.h
|
||||
wtmath.h
|
||||
)
|
||||
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
|
||||
|
||||
add_library(wavelib STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||
|
||||
set_property(TARGET wavelib PROPERTY FOLDER "lib")
|
||||
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${CONFIG_FILE_PATH})
|
||||
|
||||
target_include_directories(wavelib PUBLIC ${CMAKE_SOURCE_DIR}/header)
|
||||
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
# 库的安装命令
|
||||
if(WIN32)
|
||||
install(TARGETS wavelib DESTINATION lib)
|
||||
install(TARGETS wavelib_static DESTINATION lib)
|
||||
else()
|
||||
install(TARGETS wavelib wavelib_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 ../header/wavelib.h DESTINATION include)
|
||||
install(FILES ../header/wauxlib.h DESTINATION include)
|
6
src/cwt.c
Executable file → Normal file
6
src/cwt.c
Executable file → Normal file
@ -95,7 +95,7 @@ static void wave_function(int nk, double dt,int mother, double param,double scal
|
||||
}
|
||||
|
||||
|
||||
norm = sqrt(2.0*pi*scale1 / dt)*sqrt(1.0 / gamma(m + 0.50));
|
||||
norm = sqrt(2.0*pi*scale1 / dt)*sqrt(1.0 / cwt_gamma(m + 0.50));
|
||||
norm *= sign;
|
||||
|
||||
if (re == 1) {
|
||||
@ -267,8 +267,8 @@ void psi0(int mother, double param,double *val,int *real) {
|
||||
else {
|
||||
sign = 1;
|
||||
}
|
||||
coeff = sign * pow(2.0, (double)m / 2) / gamma(0.5);
|
||||
*val = coeff * gamma(((double)m + 1.0) / 2.0) / sqrt(gamma(m + 0.50));
|
||||
coeff = sign * pow(2.0, (double)m / 2) / cwt_gamma(0.5);
|
||||
*val = coeff * cwt_gamma(((double)m + 1.0) / 2.0) / sqrt(cwt_gamma(m + 0.50));
|
||||
}
|
||||
else {
|
||||
*val = 0;
|
||||
|
2
src/cwtmath.c
Executable file → Normal file
2
src/cwtmath.c
Executable file → Normal file
@ -155,7 +155,7 @@ int nint(double N) {
|
||||
return i;
|
||||
}
|
||||
|
||||
double gamma(double x) {
|
||||
double cwt_gamma(double x) {
|
||||
/*
|
||||
* This C program code is based on W J Cody's fortran code.
|
||||
* http://www.netlib.org/specfun/gamma
|
||||
|
2
src/cwtmath.h
Executable file → Normal file
2
src/cwtmath.h
Executable file → Normal file
@ -10,7 +10,7 @@ extern "C" {
|
||||
|
||||
void nsfft_exec(fft_object obj, fft_data *inp, fft_data *oup,double lb,double ub,double *w);// lb -lower bound, ub - upper bound, w - time or frequency grid (Size N)
|
||||
|
||||
double gamma(double x);
|
||||
double cwt_gamma(double x);
|
||||
|
||||
int nint(double N);
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wavelib.h"
|
||||
#include "../header/wavelib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
2
src/wavefunc.c
Executable file → Normal file
2
src/wavefunc.c
Executable file → Normal file
@ -111,7 +111,7 @@ void gauss(int N,int p,double lb,double ub,double *psi,double *t) {
|
||||
t[i] = lb + delta * i;
|
||||
}
|
||||
|
||||
den = sqrt(gamma(p+0.5));
|
||||
den = sqrt(cwt_gamma(p+0.5));
|
||||
|
||||
if ((p+1)%2 == 0) {
|
||||
num = 1.0;
|
||||
|
0
src/wavefunc.h
Executable file → Normal file
0
src/wavefunc.h
Executable file → Normal file
1546
src/wavelib.c
1546
src/wavelib.c
File diff suppressed because it is too large
Load Diff
349
src/wtmath.c
349
src/wtmath.c
@ -1,8 +1,355 @@
|
||||
/*
|
||||
Copyright (c) 2014, Rafat Hussain
|
||||
Copyright (c) 2018, Rafat Hussain
|
||||
*/
|
||||
#include "wtmath.h"
|
||||
|
||||
void dwt_per_stride(double *inp, int N, double *lpd,double*hpd,int lpd_len,double *cA, int len_cA, double *cD, int istride, int ostride) {
|
||||
int l, l2, isodd, i, t, len_avg,is,os;
|
||||
|
||||
len_avg = lpd_len;
|
||||
l2 = len_avg / 2;
|
||||
isodd = N % 2;
|
||||
|
||||
for (i = 0; i < len_cA; ++i) {
|
||||
t = 2 * i + l2;
|
||||
os = i *ostride;
|
||||
cA[os] = 0.0;
|
||||
cD[os] = 0.0;
|
||||
for (l = 0; l < len_avg; ++l) {
|
||||
if ((t - l) >= l2 && (t - l) < N) {
|
||||
is = (t - l) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - l) < l2 && (t - l) >= 0) {
|
||||
is = (t - l) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - l) < 0 && isodd == 0) {
|
||||
is = (t - l + N) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - l) < 0 && isodd == 1) {
|
||||
if ((t - l) != -1) {
|
||||
is = (t - l + N + 1) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else {
|
||||
is = (N - 1) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
}
|
||||
else if ((t - l) >= N && isodd == 0) {
|
||||
is = (t - l - N) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - l) >= N && isodd == 1) {
|
||||
is = (t - l - (N + 1)) * istride;
|
||||
if (t - l != N) {
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else {
|
||||
is = (N - 1) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void dwt_sym_stride(double *inp, int N, double *lpd, double*hpd, int lpd_len, double *cA, int len_cA, double *cD, int istride, int ostride) {
|
||||
int i, l, t, len_avg;
|
||||
int is, os;
|
||||
len_avg = lpd_len;
|
||||
|
||||
for (i = 0; i < len_cA; ++i) {
|
||||
t = 2 * i + 1;
|
||||
os = i *ostride;
|
||||
cA[os] = 0.0;
|
||||
cD[os] = 0.0;
|
||||
for (l = 0; l < len_avg; ++l) {
|
||||
if ((t - l) >= 0 && (t - l) < N) {
|
||||
is = (t - l) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - l) < 0) {
|
||||
is = (-t + l - 1) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - l) >= N) {
|
||||
is = (2 * N - t + l - 1) * istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void modwt_per_stride(int M, double *inp, int N, double *filt, int lpd_len, double *cA, int len_cA, double *cD, int istride, int ostride) {
|
||||
int l, i, t, len_avg;
|
||||
int is, os;
|
||||
len_avg = lpd_len;
|
||||
|
||||
|
||||
for (i = 0; i < len_cA; ++i) {
|
||||
t = i;
|
||||
os = i *ostride;
|
||||
is = t *istride;
|
||||
cA[os] = filt[0] * inp[is];
|
||||
cD[os] = filt[len_avg] * inp[is];
|
||||
for (l = 1; l < len_avg; l++) {
|
||||
t -= M;
|
||||
while (t >= len_cA) {
|
||||
t -= len_cA;
|
||||
}
|
||||
while (t < 0) {
|
||||
t += len_cA;
|
||||
}
|
||||
os = i * ostride;
|
||||
is = t * istride;
|
||||
cA[os] += filt[l] * inp[is];
|
||||
cD[os] += filt[len_avg + l] * inp[is];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void swt_per_stride(int M, double *inp, int N, double *lpd, double*hpd, int lpd_len, double *cA, int len_cA, double *cD, int istride, int ostride) {
|
||||
int l, l2, isodd, i, t, len_avg, j;
|
||||
int is, os;
|
||||
len_avg = M * lpd_len;
|
||||
l2 = len_avg / 2;
|
||||
isodd = N % 2;
|
||||
|
||||
for (i = 0; i < len_cA; ++i) {
|
||||
t = i + l2;
|
||||
os = i *ostride;
|
||||
cA[os] = 0.0;
|
||||
cD[os] = 0.0;
|
||||
l = -1;
|
||||
for (j = 0; j < len_avg; j += M) {
|
||||
l++;
|
||||
while (j >= len_cA) {
|
||||
j -= len_cA;
|
||||
}
|
||||
if ((t - j) >= l2 && (t - j) < N) {
|
||||
is = (t - j)*istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - j) < l2 && (t - j) >= 0) {
|
||||
is = (t - j)*istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - j) < 0) {
|
||||
is = (t - j + N)*istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - j) >= N && isodd == 0) {
|
||||
is = (t - j - N)*istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else if ((t - j) >= N && isodd == 1) {
|
||||
if (t - l != N) {
|
||||
is = (t - j - (N + 1))*istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[is];
|
||||
}
|
||||
else {
|
||||
is = (N - 1)*istride;
|
||||
cA[os] += lpd[l] * inp[is];
|
||||
cD[os] += hpd[l] * inp[N - 1];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void idwt_per_stride(double *cA, int len_cA, double *cD, double *lpr, double *hpr, int lpr_len, double *X, int istride, int ostride) {
|
||||
int len_avg, i, l, m, n, t, l2;
|
||||
int is, ms, ns;
|
||||
|
||||
len_avg = lpr_len;
|
||||
l2 = len_avg / 2;
|
||||
m = -2;
|
||||
n = -1;
|
||||
|
||||
for (i = 0; i < len_cA + l2 - 1; ++i) {
|
||||
m += 2;
|
||||
n += 2;
|
||||
ms = m * ostride;
|
||||
ns = n * ostride;
|
||||
X[ms] = 0.0;
|
||||
X[ns] = 0.0;
|
||||
for (l = 0; l < l2; ++l) {
|
||||
t = 2 * l;
|
||||
if ((i - l) >= 0 && (i - l) < len_cA) {
|
||||
is = (i - l) * istride;
|
||||
X[ms] += lpr[t] * cA[is] + hpr[t] * cD[is];
|
||||
X[ns] += lpr[t + 1] * cA[is] + hpr[t + 1] * cD[is];
|
||||
}
|
||||
else if ((i - l) >= len_cA && (i - l) < len_cA + len_avg - 1) {
|
||||
is = (i - l - len_cA) * istride;
|
||||
X[ms] += lpr[t] * cA[is] + hpr[t] * cD[is];
|
||||
X[ns] += lpr[t + 1] * cA[is] + hpr[t + 1] * cD[is];
|
||||
}
|
||||
else if ((i - l) < 0 && (i - l) > -l2) {
|
||||
is = (len_cA + i - l) * istride;
|
||||
X[ms] += lpr[t] * cA[is] + hpr[t] * cD[is];
|
||||
X[ns] += lpr[t + 1] * cA[is] + hpr[t + 1] * cD[is];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void idwt_sym_stride(double *cA, int len_cA, double *cD, double *lpr, double *hpr, int lpr_len, double *X, int istride, int ostride) {
|
||||
int len_avg, i, l, m, n, t, v;
|
||||
int ms, ns, is;
|
||||
len_avg = lpr_len;
|
||||
m = -2;
|
||||
n = -1;
|
||||
|
||||
for (v = 0; v < len_cA; ++v) {
|
||||
i = v;
|
||||
m += 2;
|
||||
n += 2;
|
||||
ms = m * ostride;
|
||||
ns = n * ostride;
|
||||
X[ms] = 0.0;
|
||||
X[ns] = 0.0;
|
||||
for (l = 0; l < len_avg / 2; ++l) {
|
||||
t = 2 * l;
|
||||
if ((i - l) >= 0 && (i - l) < len_cA) {
|
||||
is = (i - l) * istride;
|
||||
X[ms] += lpr[t] * cA[is] + hpr[t] * cD[is];
|
||||
X[ns] += lpr[t + 1] * cA[is] + hpr[t + 1] * cD[is];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void imodwt_per_stride(int M, double *cA, int len_cA, double *cD, double *filt,int lf,double *X,int istride, int ostride) {
|
||||
int len_avg, i, l, t;
|
||||
int is, os;
|
||||
|
||||
len_avg = lf;
|
||||
|
||||
for (i = 0; i < len_cA; ++i) {
|
||||
t = i;
|
||||
os = i * ostride;
|
||||
is = t *istride;
|
||||
X[os] = (filt[0] * cA[is]) + (filt[len_avg] * cD[is]);
|
||||
for (l = 1; l < len_avg; l++) {
|
||||
t += M;
|
||||
while (t >= len_cA) {
|
||||
t -= len_cA;
|
||||
}
|
||||
while (t < 0) {
|
||||
t += len_cA;
|
||||
}
|
||||
is = t *istride;
|
||||
X[os] += (filt[l] * cA[is]) + (filt[len_avg + l] * cD[is]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void idwt2_shift(int shift, int rows, int cols, double *lpr, double *hpr, int lf, double *A,double *H, double *V,double *D, double *oup) {
|
||||
int i, k, N, ir, ic, J, dim1, dim2;
|
||||
int istride, ostride;
|
||||
double *cL, *cH, *X_lp;
|
||||
|
||||
|
||||
N = rows > cols ? 2 * rows : 2 * cols;
|
||||
|
||||
J = 1;
|
||||
dim1 = 2 * rows;
|
||||
dim2 = 2 * cols;
|
||||
|
||||
X_lp = (double*)malloc(sizeof(double)* (N + 2 * lf - 1));
|
||||
cL = (double*)calloc(dim1*dim2, sizeof(double));
|
||||
cH = (double*)calloc(dim1*dim2, sizeof(double));
|
||||
|
||||
ir = rows;
|
||||
ic = cols;
|
||||
istride = ic;
|
||||
ostride = 1;
|
||||
for (i = 0; i < ic; ++i) {
|
||||
idwt_per_stride(A+i, ir, H+i, lpr, hpr, lf, X_lp, istride, ostride);
|
||||
|
||||
for (k = lf / 2 - 1; k < 2 * ir + lf / 2 - 1; ++k) {
|
||||
cL[(k - lf / 2 + 1)*ic + i] = X_lp[k];
|
||||
}
|
||||
|
||||
idwt_per_stride(V+i, ir, D+i, lpr, hpr, lf, X_lp, istride, ostride);
|
||||
|
||||
for (k = lf / 2 - 1; k < 2 * ir + lf / 2 - 1; ++k) {
|
||||
cH[(k - lf / 2 + 1)*ic + i] = X_lp[k];
|
||||
}
|
||||
}
|
||||
ir *= 2;
|
||||
istride = 1;
|
||||
ostride = 1;
|
||||
|
||||
for (i = 0; i < ir; ++i) {
|
||||
idwt_per_stride(cL + i*ic, ic, cH + i*ic, lpr, hpr, lf, X_lp, istride, ostride);
|
||||
|
||||
for (k = lf / 2 - 1; k < 2 * ic + lf / 2 - 1; ++k) {
|
||||
oup[(k - lf / 2 + 1) + i*ic * 2] = X_lp[k];
|
||||
}
|
||||
}
|
||||
ic *= 2;
|
||||
|
||||
|
||||
if (shift == -1) {
|
||||
//Save the last column
|
||||
for (i = 0; i < ir; ++i) {
|
||||
cL[i] = oup[(i + 1)*ic - 1];
|
||||
}
|
||||
// Save the last row
|
||||
memcpy(cH, oup + (ir - 1)*ic, sizeof(double)*ic);
|
||||
for (i = ir - 1; i > 0; --i) {
|
||||
memcpy(oup + i*ic + 1, oup + (i - 1)*ic, sizeof(double)*(ic - 1));
|
||||
}
|
||||
oup[0] = cL[ir - 1];
|
||||
for (i = 1; i < ir; ++i) {
|
||||
oup[i*ic] = cL[i - 1];
|
||||
}
|
||||
|
||||
for (i = 1; i < ic; ++i) {
|
||||
oup[i] = cH[i - 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(X_lp);
|
||||
free(cL);
|
||||
free(cH);
|
||||
|
||||
}
|
||||
|
||||
int upsamp(double *x, int lenx, int M, double *y) {
|
||||
int N, i, j, k;
|
||||
|
||||
|
24
src/wtmath.h
24
src/wtmath.h
@ -10,6 +10,30 @@ Copyright (c) 2014, Rafat Hussain
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void dwt_per_stride(double *inp, int N, double *lpd,double*hpd,int lpd_len,
|
||||
double *cA, int len_cA, double *cD, int istride, int ostride);
|
||||
|
||||
void dwt_sym_stride(double *inp, int N, double *lpd, double*hpd, int lpd_len,
|
||||
double *cA, int len_cA, double *cD, int istride, int ostride);
|
||||
|
||||
void modwt_per_stride(int M, double *inp, int N, double *filt, int lpd_len,
|
||||
double *cA, int len_cA, double *cD, int istride, int ostride);
|
||||
|
||||
void swt_per_stride(int M, double *inp, int N, double *lpd, double*hpd, int lpd_len,
|
||||
double *cA, int len_cA, double *cD, int istride, int ostride);
|
||||
|
||||
void idwt_per_stride(double *cA, int len_cA, double *cD, double *lpr, double *hpr,
|
||||
int lpr_len, double *X, int istride, int ostride);
|
||||
|
||||
void idwt_sym_stride(double *cA, int len_cA, double *cD, double *lpr, double *hpr,
|
||||
int lpr_len, double *X, int istride, int ostride);
|
||||
|
||||
void imodwt_per_stride(int M, double *cA, int len_cA, double *cD, double *filt,
|
||||
int lf,double *X,int istride, int ostride);
|
||||
|
||||
void idwt2_shift(int shift, int rows, int cols, double *lpr, double *hpr, int lf,
|
||||
double *A,double *H, double *V,double *D, double *oup);
|
||||
|
||||
int upsamp(double *x, int lenx, int M, double *y);
|
||||
|
||||
int upsamp2(double *x, int lenx, int M, double *y);
|
||||
|
@ -30,18 +30,19 @@ add_executable(modwtdenoisetest modwtdenoisetest.c)
|
||||
|
||||
target_link_libraries(modwtdenoisetest wauxlib wavelib)
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(cwttest m)
|
||||
target_link_libraries(dwttest m)
|
||||
target_link_libraries(swttest m)
|
||||
target_link_libraries(modwttest m)
|
||||
target_link_libraries(dwpttest m)
|
||||
target_link_libraries(wtreetest m)
|
||||
target_link_libraries(denoisetest m)
|
||||
target_link_libraries(modwtdenoisetest m)
|
||||
endif()
|
||||
add_executable(dwt2test dwt2test.c)
|
||||
|
||||
set_target_properties(cwttest dwttest swttest modwttest dwpttest wtreetest denoisetest modwtdenoisetest
|
||||
target_link_libraries(dwt2test wavelib)
|
||||
|
||||
add_executable(swt2test swt2test.c)
|
||||
|
||||
target_link_libraries(swt2test wavelib)
|
||||
|
||||
add_executable(modwt2test modwt2test.c)
|
||||
|
||||
target_link_libraries(modwt2test wavelib)
|
||||
|
||||
set_target_properties(cwttest dwttest swttest modwttest dwpttest wtreetest denoisetest modwtdenoisetest dwt2test swt2test modwt2test
|
||||
PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
|
||||
)
|
||||
|
87
test/dwt2test.c
Normal file
87
test/dwt2test.c
Normal file
@ -0,0 +1,87 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "../header/wavelib.h"
|
||||
|
||||
double absmax(double *array, int N) {
|
||||
double max;
|
||||
int i;
|
||||
|
||||
max = 0.0;
|
||||
for (i = 0; i < N; ++i) {
|
||||
if (fabs(array[i]) >= max) {
|
||||
max = fabs(array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
double generate_rnd() {
|
||||
double rnd;
|
||||
|
||||
rnd = (double) (rand() % 100 + 1);
|
||||
|
||||
return rnd;
|
||||
}
|
||||
|
||||
int main() {
|
||||
wave_object obj;
|
||||
wt2_object wt;
|
||||
int i, k, J, rows, cols,N;
|
||||
double *inp, *wavecoeffs,*oup,*diff;
|
||||
double *cLL;
|
||||
int ir, ic;
|
||||
double amax;
|
||||
|
||||
rows = 32;
|
||||
cols = 30;
|
||||
N = rows*cols;
|
||||
|
||||
char *name = "db2";
|
||||
obj = wave_init(name);// Initialize the wavelet
|
||||
srand(time(0));
|
||||
inp = (double*)calloc(N, sizeof(double));
|
||||
oup = (double*)calloc(N, sizeof(double));
|
||||
diff = (double*)calloc(N, sizeof(double));
|
||||
|
||||
J = 3;
|
||||
|
||||
wt = wt2_init(obj, "dwt", rows,cols, J);
|
||||
|
||||
for (i = 0; i < rows; ++i) {
|
||||
for (k = 0; k < cols; ++k) {
|
||||
//inp[i*cols + k] = i*cols + k;
|
||||
inp[i*cols + k] = generate_rnd();
|
||||
oup[i*cols + k] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
wavecoeffs = dwt2(wt, inp);
|
||||
|
||||
cLL = getWT2Coeffs(wt, wavecoeffs, 1, "D", &ir, &ic);
|
||||
|
||||
dispWT2Coeffs(cLL, ir, ic);
|
||||
|
||||
idwt2(wt, wavecoeffs, oup);
|
||||
|
||||
for (i = 0; i < rows*cols; ++i) {
|
||||
diff[i] = oup[i] - inp[i];
|
||||
}
|
||||
|
||||
amax = absmax(diff, rows*cols);
|
||||
|
||||
wt2_summary(wt);
|
||||
|
||||
printf("Abs Max %g \n", amax);
|
||||
|
||||
wave_free(obj);
|
||||
wt2_free(wt);
|
||||
free(inp);
|
||||
free(wavecoeffs);
|
||||
free(oup);
|
||||
free(diff);
|
||||
return 0;
|
||||
}
|
82
test/modwt2test.c
Normal file
82
test/modwt2test.c
Normal file
@ -0,0 +1,82 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "../header/wavelib.h"
|
||||
|
||||
double absmax(double *array, int N) {
|
||||
double max;
|
||||
int i;
|
||||
|
||||
max = 0.0;
|
||||
for (i = 0; i < N; ++i) {
|
||||
if (fabs(array[i]) >= max) {
|
||||
max = fabs(array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
double generate_rnd() {
|
||||
double rnd;
|
||||
|
||||
rnd = (double) (rand() % 100 + 1);
|
||||
|
||||
return rnd;
|
||||
}
|
||||
|
||||
int main() {
|
||||
wave_object obj;
|
||||
wt2_object wt;
|
||||
int i, k, J, rows, cols,N,ir,ic;
|
||||
double *inp, *wavecoeffs, *oup,*cLL,*diff;
|
||||
double amax;
|
||||
rows = 51;
|
||||
cols = 40;
|
||||
N = rows*cols;
|
||||
char *name = "db2";
|
||||
obj = wave_init(name);// Initialize the wavelet
|
||||
|
||||
inp = (double*)calloc(N, sizeof(double));
|
||||
oup = (double*)calloc(N, sizeof(double));
|
||||
diff = (double*)calloc(N, sizeof(double));
|
||||
J = 2;
|
||||
|
||||
wt = wt2_init(obj, "modwt", rows, cols, J);
|
||||
|
||||
for (i = 0; i < rows; ++i) {
|
||||
for (k = 0; k < cols; ++k) {
|
||||
//inp[i*cols + k] = i*cols + k;
|
||||
inp[i*cols + k] = generate_rnd();
|
||||
oup[i*cols + k] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
wavecoeffs = modwt2(wt, inp);
|
||||
|
||||
cLL = getWT2Coeffs(wt, wavecoeffs, J, "A", &ir, &ic);
|
||||
|
||||
//dispWT2Coeffs(cLL, ir, ic);
|
||||
|
||||
imodwt2(wt, wavecoeffs, oup);
|
||||
|
||||
for (i = 0; i < N; ++i) {
|
||||
diff[i] = oup[i] - inp[i];
|
||||
}
|
||||
|
||||
amax = absmax(diff, N);
|
||||
|
||||
wt2_summary(wt);
|
||||
|
||||
printf("Abs Max %g \n", amax);
|
||||
|
||||
wave_free(obj);
|
||||
wt2_free(wt);
|
||||
free(inp);
|
||||
free(wavecoeffs);
|
||||
free(oup);
|
||||
free(diff);
|
||||
return 0;
|
||||
}
|
0
test/modwtdenoisetest.c
Executable file → Normal file
0
test/modwtdenoisetest.c
Executable file → Normal file
0
test/sst_nino3.dat
Executable file → Normal file
0
test/sst_nino3.dat
Executable file → Normal file
83
test/swt2test.c
Normal file
83
test/swt2test.c
Normal file
@ -0,0 +1,83 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "../header/wavelib.h"
|
||||
|
||||
double absmax(double *array, int N) {
|
||||
double max;
|
||||
int i;
|
||||
|
||||
max = 0.0;
|
||||
for (i = 0; i < N; ++i) {
|
||||
if (fabs(array[i]) >= max) {
|
||||
max = fabs(array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
double generate_rnd() {
|
||||
double rnd;
|
||||
|
||||
rnd = (double) (rand() % 100 + 1);
|
||||
|
||||
return rnd;
|
||||
}
|
||||
|
||||
int main() {
|
||||
wave_object obj;
|
||||
wt2_object wt;
|
||||
int i, k, J, rows, cols;
|
||||
double *inp, *wavecoeffs, *oup, *cLL,*diff;
|
||||
double amax;
|
||||
int ir, ic, N;
|
||||
rows = 64;
|
||||
cols = 48;
|
||||
|
||||
char *name = "bior3.1";
|
||||
obj = wave_init(name);// Initialize the wavelet
|
||||
N = rows*cols;
|
||||
inp = (double*)calloc(N, sizeof(double));
|
||||
oup = (double*)calloc(N, sizeof(double));
|
||||
diff = (double*)calloc(N, sizeof(double));
|
||||
J = 2;
|
||||
|
||||
wt = wt2_init(obj, "swt", rows, cols, J);
|
||||
|
||||
for (i = 0; i < rows; ++i) {
|
||||
for (k = 0; k < cols; ++k) {
|
||||
//inp[i*cols + k] = i*cols + k;
|
||||
inp[i*cols + k] = generate_rnd();
|
||||
oup[i*cols + k] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
wavecoeffs = swt2(wt, inp);
|
||||
|
||||
cLL = getWT2Coeffs(wt, wavecoeffs, J, "A", &ir, &ic);
|
||||
|
||||
dispWT2Coeffs(cLL, ir, ic);
|
||||
|
||||
iswt2(wt, wavecoeffs, oup);
|
||||
|
||||
for (i = 0; i < N; ++i) {
|
||||
diff[i] = oup[i] - inp[i];
|
||||
}
|
||||
|
||||
amax = absmax(diff, N);
|
||||
|
||||
wt2_summary(wt);
|
||||
|
||||
printf("Abs Max %g \n", amax);
|
||||
|
||||
wave_free(obj);
|
||||
wt2_free(wt);
|
||||
free(inp);
|
||||
free(wavecoeffs);
|
||||
free(oup);
|
||||
free(diff);
|
||||
return 0;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE WaveLibTests
|
||||
|
||||
#include <boost/test/included/unit_test.hpp>
|
@ -1,10 +0,0 @@
|
||||
|
||||
|
||||
#ifndef SWALLOWING_BOOSTTEST_H_
|
||||
#define SWALLOWING_BOOSTTEST_H_
|
||||
|
||||
// we use the header only version of boost unit test
|
||||
#define BOOST_TEST_NO_LIB
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#endif // SWALLOWING_BOOSTTEST_H_
|
@ -16,7 +16,7 @@ add_dependencies(wavelibLibTests wavelib)
|
||||
target_link_libraries(wavelibLibTests wavelib)
|
||||
|
||||
target_include_directories(wavelibLibTests PUBLIC
|
||||
${CMAKE_SOURCE_DIR}/../../header
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../header
|
||||
)
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "wavelib.h"
|
||||
#include "../../header/wavelib.h"
|
||||
|
||||
#include<vector>
|
||||
|
||||
@ -111,7 +111,15 @@ double REL_Error(double *data, double *rec, int N) {
|
||||
return sqrt(sum1)/sqrt(sum2);
|
||||
}
|
||||
|
||||
void ReconstructionTest()
|
||||
double generate_rnd() {
|
||||
double rnd;
|
||||
|
||||
rnd = (double) (rand() % 100 + 1);
|
||||
|
||||
return rnd;
|
||||
}
|
||||
|
||||
void DWTReconstructionTest()
|
||||
{
|
||||
|
||||
wave_object obj;
|
||||
@ -229,6 +237,125 @@ void ReconstructionTest()
|
||||
free(inp);
|
||||
}
|
||||
|
||||
void DWT2ReconstructionTest()
|
||||
{
|
||||
wave_object obj;
|
||||
wt2_object wt;
|
||||
int i, k, J, N, rows, cols;
|
||||
double *inp, *wavecoeffs,*out;
|
||||
double epsilon;
|
||||
|
||||
rows = 1024;
|
||||
cols = 1000;
|
||||
|
||||
N = rows*cols;
|
||||
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
out = (double*)malloc(sizeof(double)* N);
|
||||
|
||||
std::vector<std::string > waveletNames;
|
||||
|
||||
for (unsigned int j = 0; j < 15; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
|
||||
}
|
||||
for (unsigned int j = 0; j < 5; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
|
||||
}
|
||||
for (unsigned int j = 1; j < 10; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
|
||||
}
|
||||
|
||||
waveletNames.push_back("bior1.1");
|
||||
waveletNames.push_back("bior1.3");
|
||||
waveletNames.push_back("bior1.5");
|
||||
waveletNames.push_back("bior2.2");
|
||||
waveletNames.push_back("bior2.4");
|
||||
waveletNames.push_back("bior2.6");
|
||||
waveletNames.push_back("bior2.8");
|
||||
waveletNames.push_back("bior3.1");
|
||||
waveletNames.push_back("bior3.3");
|
||||
waveletNames.push_back("bior3.5");
|
||||
waveletNames.push_back("bior3.7");
|
||||
waveletNames.push_back("bior3.9");
|
||||
waveletNames.push_back("bior4.4");
|
||||
waveletNames.push_back("bior5.5");
|
||||
waveletNames.push_back("bior6.8");
|
||||
|
||||
waveletNames.push_back("rbior1.1");
|
||||
waveletNames.push_back("rbior1.3");
|
||||
waveletNames.push_back("rbior1.5");
|
||||
waveletNames.push_back("rbior2.2");
|
||||
waveletNames.push_back("rbior2.4");
|
||||
waveletNames.push_back("rbior2.6");
|
||||
waveletNames.push_back("rbior2.8");
|
||||
waveletNames.push_back("rbior3.1");
|
||||
waveletNames.push_back("rbior3.3");
|
||||
waveletNames.push_back("rbior3.5");
|
||||
waveletNames.push_back("rbior3.7");
|
||||
waveletNames.push_back("rbior3.9");
|
||||
waveletNames.push_back("rbior4.4");
|
||||
waveletNames.push_back("rbior5.5");
|
||||
waveletNames.push_back("rbior6.8");
|
||||
|
||||
for (i = 0; i < rows; ++i) {
|
||||
for (k = 0; k < cols; ++k) {
|
||||
//inp[i*cols + k] = i*cols + k;
|
||||
inp[i*cols + k] = generate_rnd();
|
||||
out[i*cols + k] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int direct_fft = 0; direct_fft < 1; direct_fft++)
|
||||
{
|
||||
for (unsigned int sym_per = 0; sym_per < 2; sym_per++)
|
||||
{
|
||||
for (unsigned int j = 0; j < waveletNames.size(); j++)
|
||||
{
|
||||
char * name = new char[waveletNames[j].size() + 1];
|
||||
memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
|
||||
obj = wave_init(name);// Initialize the wavelet
|
||||
for (J = 1; J < 3; J++)
|
||||
{
|
||||
//J = 3;
|
||||
|
||||
wt = wt2_init(obj,(char*) "dwt", rows,cols, J);// Initialize the wavelet transform object
|
||||
if (sym_per == 0)
|
||||
setDWT2Extension(wt, (char*) "sym");// Options are "per" and "sym". Symmetric is the default option
|
||||
else
|
||||
setDWT2Extension(wt, (char*) "per");
|
||||
|
||||
wavecoeffs = dwt2(wt, inp);// Perform DWT
|
||||
|
||||
idwt2(wt, wavecoeffs, out);// Perform IDWT (if needed)
|
||||
// Test Reconstruction
|
||||
|
||||
if (direct_fft == 0)
|
||||
epsilon = 1e-8;
|
||||
else
|
||||
epsilon = 1e-10;
|
||||
//BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
|
||||
|
||||
//printf("%g ",RMS_Error(out, inp, wt->siglength));
|
||||
if (RMS_Error(out, inp, N) > epsilon) {
|
||||
printf("\n ERROR : DWT2 Reconstruction Unit Test Failed. Exiting. \n");
|
||||
exit(-1);
|
||||
}
|
||||
wt2_free(wt);
|
||||
free(wavecoeffs);
|
||||
}
|
||||
wave_free(obj);
|
||||
delete[] name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(inp);
|
||||
free(out);
|
||||
}
|
||||
|
||||
void MODWTReconstructionTest()
|
||||
{
|
||||
|
||||
@ -266,9 +393,9 @@ void MODWTReconstructionTest()
|
||||
}
|
||||
|
||||
|
||||
for (unsigned int direct_fft = 0; direct_fft < 2; direct_fft++)
|
||||
for (unsigned int direct_fft = 0; direct_fft < 1; direct_fft++)
|
||||
{
|
||||
for (unsigned int sym_per = 0; sym_per < 2; sym_per++)
|
||||
for (unsigned int sym_per = 0; sym_per < 1; sym_per++)
|
||||
{
|
||||
for (unsigned int j = 0; j < waveletNames.size(); j++)
|
||||
{
|
||||
@ -322,6 +449,333 @@ void MODWTReconstructionTest()
|
||||
free(inp);
|
||||
}
|
||||
|
||||
void MODWT2ReconstructionTest()
|
||||
{
|
||||
wave_object obj;
|
||||
wt2_object wt;
|
||||
int i, k, J, N, rows, cols;
|
||||
double *inp, *wavecoeffs,*out;
|
||||
double epsilon;
|
||||
|
||||
rows = 1024;
|
||||
cols = 1000;
|
||||
|
||||
N = rows*cols;
|
||||
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
out = (double*)malloc(sizeof(double)* N);
|
||||
|
||||
std::vector<std::string > waveletNames;
|
||||
|
||||
for (unsigned int j = 0; j < 15; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
|
||||
}
|
||||
for (unsigned int j = 0; j < 5; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
|
||||
}
|
||||
for (unsigned int j = 1; j < 10; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < rows; ++i) {
|
||||
for (k = 0; k < cols; ++k) {
|
||||
//inp[i*cols + k] = i*cols + k;
|
||||
inp[i*cols + k] = generate_rnd();
|
||||
out[i*cols + k] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int direct_fft = 0; direct_fft < 1; direct_fft++)
|
||||
{
|
||||
for (unsigned int sym_per = 0; sym_per < 1; sym_per++)
|
||||
{
|
||||
for (unsigned int j = 0; j < waveletNames.size(); j++)
|
||||
{
|
||||
char * name = new char[waveletNames[j].size() + 1];
|
||||
memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
|
||||
obj = wave_init(name);// Initialize the wavelet
|
||||
for (J = 1; J < 3; J++)
|
||||
{
|
||||
//J = 3;
|
||||
|
||||
wt = wt2_init(obj,(char*) "modwt", rows,cols, J);// Initialize the wavelet transform object
|
||||
if (sym_per == 0)
|
||||
setDWT2Extension(wt, (char*) "per");// Options are "per"
|
||||
|
||||
wavecoeffs = modwt2(wt, inp);// Perform DWT
|
||||
|
||||
imodwt2(wt, wavecoeffs, out);// Perform IDWT (if needed)
|
||||
// Test Reconstruction
|
||||
|
||||
if (direct_fft == 0)
|
||||
epsilon = 1e-8;
|
||||
else
|
||||
epsilon = 1e-10;
|
||||
//BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
|
||||
|
||||
//printf("%g ",RMS_Error(out, inp, wt->siglength));
|
||||
if (RMS_Error(out, inp, N) > epsilon) {
|
||||
printf("\n ERROR : MODWT2 Reconstruction Unit Test Failed. Exiting. \n");
|
||||
exit(-1);
|
||||
}
|
||||
wt2_free(wt);
|
||||
free(wavecoeffs);
|
||||
}
|
||||
wave_free(obj);
|
||||
delete[] name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(inp);
|
||||
free(out);
|
||||
}
|
||||
|
||||
void SWTReconstructionTest()
|
||||
{
|
||||
|
||||
wave_object obj;
|
||||
wt_object wt;
|
||||
double *inp,*out;
|
||||
int N, i,J;
|
||||
double epsilon = 1e-15;
|
||||
double err;
|
||||
|
||||
N = 4000;
|
||||
|
||||
//N = 256;
|
||||
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
out = (double*)malloc(sizeof(double)* N);
|
||||
//wmean = mean(temp, N);
|
||||
|
||||
for (i = 0; i < N; ++i) {
|
||||
inp[i] = (rand() / (double)(RAND_MAX));
|
||||
}
|
||||
std::vector<std::string > waveletNames;
|
||||
|
||||
for (unsigned int j = 0; j < 15; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
|
||||
}
|
||||
for (unsigned int j = 0; j < 5; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
|
||||
}
|
||||
for (unsigned int j = 1; j < 10; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
|
||||
}
|
||||
|
||||
waveletNames.push_back("bior1.1");
|
||||
waveletNames.push_back("bior1.3");
|
||||
waveletNames.push_back("bior1.5");
|
||||
waveletNames.push_back("bior2.2");
|
||||
waveletNames.push_back("bior2.4");
|
||||
waveletNames.push_back("bior2.6");
|
||||
waveletNames.push_back("bior2.8");
|
||||
waveletNames.push_back("bior3.1");
|
||||
waveletNames.push_back("bior3.3");
|
||||
waveletNames.push_back("bior3.5");
|
||||
waveletNames.push_back("bior3.7");
|
||||
waveletNames.push_back("bior3.9");
|
||||
waveletNames.push_back("bior4.4");
|
||||
waveletNames.push_back("bior5.5");
|
||||
waveletNames.push_back("bior6.8");
|
||||
|
||||
waveletNames.push_back("rbior1.1");
|
||||
waveletNames.push_back("rbior1.3");
|
||||
waveletNames.push_back("rbior1.5");
|
||||
waveletNames.push_back("rbior2.2");
|
||||
waveletNames.push_back("rbior2.4");
|
||||
waveletNames.push_back("rbior2.6");
|
||||
waveletNames.push_back("rbior2.8");
|
||||
waveletNames.push_back("rbior3.1");
|
||||
waveletNames.push_back("rbior3.3");
|
||||
waveletNames.push_back("rbior3.5");
|
||||
waveletNames.push_back("rbior3.7");
|
||||
waveletNames.push_back("rbior3.9");
|
||||
waveletNames.push_back("rbior4.4");
|
||||
waveletNames.push_back("rbior5.5");
|
||||
waveletNames.push_back("rbior6.8");
|
||||
|
||||
for (unsigned int direct_fft = 0; direct_fft < 2; direct_fft++)
|
||||
{
|
||||
for (unsigned int sym_per = 0; sym_per < 1; sym_per++)
|
||||
{
|
||||
for (unsigned int j = 0; j < waveletNames.size(); j++)
|
||||
{
|
||||
char * name = new char[waveletNames[j].size() + 1];
|
||||
memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
|
||||
obj = wave_init(name);// Initialize the wavelet
|
||||
for (J = 1; J < 3; J++)
|
||||
{
|
||||
//J = 3;
|
||||
|
||||
wt = wt_init(obj,(char*) "swt", N, J);// Initialize the wavelet transform object
|
||||
|
||||
if (direct_fft == 0)
|
||||
setWTConv(wt, (char*) "direct");
|
||||
else
|
||||
setWTConv(wt, (char*) "fft");
|
||||
|
||||
if (sym_per == 0)
|
||||
setDWTExtension(wt, (char*) "per");// Options are "per" and "sym". Symmetric is the default option
|
||||
else if (sym_per == 1 && direct_fft == 1)
|
||||
setDWTExtension(wt, (char*) "sym");
|
||||
else break;
|
||||
|
||||
swt(wt, inp);// Perform DWT
|
||||
|
||||
iswt(wt, out);// Perform IDWT (if needed)
|
||||
// Test Reconstruction
|
||||
|
||||
if (direct_fft == 0)
|
||||
epsilon = 1e-8;
|
||||
else
|
||||
epsilon = 1e-10;
|
||||
//BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
|
||||
|
||||
//printf("%g ",RMS_Error(out, inp, wt->siglength));
|
||||
err = RMS_Error(out, inp, wt->siglength);
|
||||
//printf("%d %d %g \n",direct_fft,sym_per,err);
|
||||
if (err > epsilon) {
|
||||
printf("\n ERROR : SWT Reconstruction Unit Test Failed. Exiting. \n");
|
||||
exit(-1);
|
||||
}
|
||||
wt_free(wt);
|
||||
}
|
||||
wave_free(obj);
|
||||
delete[] name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(out);
|
||||
free(inp);
|
||||
}
|
||||
|
||||
void SWT2ReconstructionTest()
|
||||
{
|
||||
wave_object obj;
|
||||
wt2_object wt;
|
||||
int i, k, J, N, rows, cols;
|
||||
double *inp, *wavecoeffs,*out;
|
||||
double epsilon;
|
||||
|
||||
rows = 1024;
|
||||
cols = 1000;
|
||||
|
||||
N = rows*cols;
|
||||
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
out = (double*)malloc(sizeof(double)* N);
|
||||
|
||||
std::vector<std::string > waveletNames;
|
||||
|
||||
for (unsigned int j = 0; j < 15; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
|
||||
}
|
||||
for (unsigned int j = 0; j < 5; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
|
||||
}
|
||||
for (unsigned int j = 1; j < 10; j++)
|
||||
{
|
||||
waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
|
||||
}
|
||||
|
||||
waveletNames.push_back("bior1.1");
|
||||
waveletNames.push_back("bior1.3");
|
||||
waveletNames.push_back("bior1.5");
|
||||
waveletNames.push_back("bior2.2");
|
||||
waveletNames.push_back("bior2.4");
|
||||
waveletNames.push_back("bior2.6");
|
||||
waveletNames.push_back("bior2.8");
|
||||
waveletNames.push_back("bior3.1");
|
||||
waveletNames.push_back("bior3.3");
|
||||
waveletNames.push_back("bior3.5");
|
||||
waveletNames.push_back("bior3.7");
|
||||
waveletNames.push_back("bior3.9");
|
||||
waveletNames.push_back("bior4.4");
|
||||
waveletNames.push_back("bior5.5");
|
||||
waveletNames.push_back("bior6.8");
|
||||
|
||||
waveletNames.push_back("rbior1.1");
|
||||
waveletNames.push_back("rbior1.3");
|
||||
waveletNames.push_back("rbior1.5");
|
||||
waveletNames.push_back("rbior2.2");
|
||||
waveletNames.push_back("rbior2.4");
|
||||
waveletNames.push_back("rbior2.6");
|
||||
waveletNames.push_back("rbior2.8");
|
||||
waveletNames.push_back("rbior3.1");
|
||||
waveletNames.push_back("rbior3.3");
|
||||
waveletNames.push_back("rbior3.5");
|
||||
waveletNames.push_back("rbior3.7");
|
||||
waveletNames.push_back("rbior3.9");
|
||||
waveletNames.push_back("rbior4.4");
|
||||
waveletNames.push_back("rbior5.5");
|
||||
waveletNames.push_back("rbior6.8");
|
||||
|
||||
for (i = 0; i < rows; ++i) {
|
||||
for (k = 0; k < cols; ++k) {
|
||||
//inp[i*cols + k] = i*cols + k;
|
||||
inp[i*cols + k] = generate_rnd();
|
||||
out[i*cols + k] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int direct_fft = 0; direct_fft < 1; direct_fft++)
|
||||
{
|
||||
for (unsigned int sym_per = 0; sym_per < 1; sym_per++)
|
||||
{
|
||||
for (unsigned int j = 0; j < waveletNames.size(); j++)
|
||||
{
|
||||
char * name = new char[waveletNames[j].size() + 1];
|
||||
memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
|
||||
obj = wave_init(name);// Initialize the wavelet
|
||||
for (J = 1; J < 3; J++)
|
||||
{
|
||||
//J = 3;
|
||||
|
||||
wt = wt2_init(obj,(char*) "swt", rows,cols, J);// Initialize the wavelet transform object
|
||||
if (sym_per == 0)
|
||||
setDWT2Extension(wt, (char*) "per");// Options are "per"
|
||||
|
||||
wavecoeffs = swt2(wt, inp);// Perform DWT
|
||||
|
||||
iswt2(wt, wavecoeffs, out);// Perform IDWT (if needed)
|
||||
// Test Reconstruction
|
||||
|
||||
if (direct_fft == 0)
|
||||
epsilon = 1e-8;
|
||||
else
|
||||
epsilon = 1e-10;
|
||||
//BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
|
||||
|
||||
//printf("%g ",RMS_Error(out, inp, wt->siglength));
|
||||
if (RMS_Error(out, inp, N) > epsilon) {
|
||||
printf("\n ERROR : SWT2 Reconstruction Unit Test Failed. Exiting. \n");
|
||||
exit(-1);
|
||||
}
|
||||
wt2_free(wt);
|
||||
free(wavecoeffs);
|
||||
}
|
||||
wave_free(obj);
|
||||
delete[] name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(inp);
|
||||
free(out);
|
||||
}
|
||||
|
||||
void DWPTReconstructionTest()
|
||||
{
|
||||
|
||||
@ -740,10 +1194,13 @@ int main() {
|
||||
RBiorCoefTests();
|
||||
printf("DONE \n");
|
||||
printf("Running DWT ReconstructionTests ... ");
|
||||
ReconstructionTest();
|
||||
DWTReconstructionTest();
|
||||
printf("DONE \n");
|
||||
printf("Running MODWT ReconstructionTests ... ");
|
||||
MODWTReconstructionTest();
|
||||
printf("DONE \n");
|
||||
printf("Running SWT ReconstructionTests ... ");
|
||||
SWTReconstructionTest();
|
||||
printf("DONE \n");
|
||||
printf("Running DWPT ReconstructionTests ... ");
|
||||
DWPTReconstructionTest();
|
||||
@ -751,6 +1208,15 @@ int main() {
|
||||
printf("Running CWT ReconstructionTests ... ");
|
||||
CWTReconstructionTest();
|
||||
printf("DONE \n");
|
||||
printf("Running DWT2 ReconstructionTests ... ");
|
||||
DWT2ReconstructionTest();
|
||||
printf("DONE \n");
|
||||
printf("Running MODWT2 ReconstructionTests ... ");
|
||||
MODWT2ReconstructionTest();
|
||||
printf("DONE \n");
|
||||
printf("Running SWT2 ReconstructionTests ... ");
|
||||
SWT2ReconstructionTest();
|
||||
printf("DONE \n");
|
||||
printf("\n\nUnit Tests Successful\n\n");
|
||||
return 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user