Compare commits
63 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 | ||
![]() |
0a4400f369 | ||
![]() |
e16859af59 | ||
![]() |
ec5006b262 | ||
![]() |
924d3a3c9b | ||
![]() |
a7935daae7 | ||
![]() |
32802461e6 | ||
![]() |
0d5118db6f | ||
![]() |
fbbebc90f9 | ||
![]() |
0cbcb8b7d5 | ||
![]() |
c1c6eda13d | ||
![]() |
9219b6020e | ||
![]() |
12d72252c6 | ||
![]() |
1856f4a4f3 | ||
![]() |
2e2b624950 | ||
![]() |
0b5777fc4a | ||
![]() |
4e34b8926b | ||
![]() |
f238fb1ce6 | ||
![]() |
e2f6ddafe0 | ||
![]() |
6e74f8a230 |
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,5 +1,5 @@
|
||||
sudo: false
|
||||
language: cpp
|
||||
language: c
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
@ -11,10 +11,7 @@ compiler:
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- boost-latest
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- libboost1.55-all-dev
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
|
@ -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,18 +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 denoise.h
|
||||
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()
|
@ -1,7 +1,12 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "denoise.h"
|
||||
#include "waux.h"
|
||||
#include "../header/wauxlib.h"
|
||||
|
||||
denoise_object denoise_init(int length, int J,char* wname) {
|
||||
denoise_object denoise_init(int length, int J,const char* wname) {
|
||||
denoise_object obj = NULL;
|
||||
|
||||
obj = (denoise_object)malloc(sizeof(struct denoise_set) +sizeof(double));
|
||||
@ -14,14 +19,15 @@ denoise_object denoise_init(int length, int J,char* wname) {
|
||||
//Set Default Values
|
||||
strcpy(obj->dmethod,"sureshrink");
|
||||
strcpy(obj->ext,"sym");
|
||||
strcpy(obj->level,"first");
|
||||
strcpy(obj->level,"all");
|
||||
strcpy(obj->thresh,"soft");
|
||||
strcpy(obj->wmethod,"dwt");
|
||||
strcpy(obj->cmethod,"direct");
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
void visushrink(double *signal,int N,int J,char *wname,char *method,char *ext,char *thresh,char *level,double *denoised) {
|
||||
void visushrink(double *signal,int N,int J,const char *wname,const char *method,const char *ext,const char *thresh,const char *level,double *denoised) {
|
||||
int filt_len,iter,i,dlen,dwt_len,sgn, MaxIter,it;
|
||||
double sigma,td,tmp;
|
||||
wave_object wave;
|
||||
@ -128,7 +134,7 @@ void visushrink(double *signal,int N,int J,char *wname,char *method,char *ext,ch
|
||||
wt_free(wt);
|
||||
}
|
||||
|
||||
void sureshrink(double *signal,int N,int J,char *wname,char *method,char *ext,char *thresh,char *level,double *denoised) {
|
||||
void sureshrink(double *signal,int N,int J,const char *wname,const char *method,const char *ext,const char *thresh,const char *level,double *denoised) {
|
||||
int filt_len,i,it,len,dlen,dwt_len,min_index,sgn, MaxIter,iter;
|
||||
double sigma,norm,td,tv,te,ct,thr,temp,x_sum;
|
||||
wave_object wave;
|
||||
@ -233,7 +239,6 @@ void sureshrink(double *signal,int N,int J,char *wname,char *method,char *ext,ch
|
||||
risk[i] = ((double)dwt_len - 2 * ((double)i + 1) +dsum[i] +
|
||||
dout[i]*((double)dwt_len - 1 -(double) i))/(double)dwt_len;
|
||||
}
|
||||
printf(" \n");
|
||||
min_index = minindex(risk,dwt_len);
|
||||
thr = sqrt(dout[min_index]);
|
||||
td = thr < tv ? thr : tv;
|
||||
@ -276,44 +281,169 @@ void sureshrink(double *signal,int N,int J,char *wname,char *method,char *ext,ch
|
||||
wt_free(wt);
|
||||
}
|
||||
|
||||
void modwtshrink(double *signal, int N, int J, const char *wname, const char *cmethod, const char *ext, const char *thresh, double *denoised) {
|
||||
int filt_len, iter, i, dlen, sgn, MaxIter, it;
|
||||
double sigma, td, tmp, M, llen;
|
||||
wave_object wave;
|
||||
wt_object wt;
|
||||
double *dout, *lnoise;
|
||||
|
||||
wave = wave_init(wname);
|
||||
|
||||
filt_len = wave->filtlength;
|
||||
|
||||
MaxIter = (int)(log((double)N / ((double)filt_len - 1.0)) / log(2.0));
|
||||
|
||||
if (J > MaxIter) {
|
||||
printf("\n Error - The Signal Can only be iterated %d times using this wavelet. Exiting\n", MaxIter);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
wt = wt_init(wave, "modwt", N, J);
|
||||
|
||||
if (!strcmp(ext, "sym") && !strcmp(cmethod,"fft")) {
|
||||
setWTConv(wt, "fft");
|
||||
setDWTExtension(wt, "sym");
|
||||
}
|
||||
else if (!strcmp(ext, "sym") && !strcmp(cmethod, "direct")) {
|
||||
printf("Symmetric Extension is not available for direct method");
|
||||
exit(-1);
|
||||
}
|
||||
else if (!strcmp(ext, "per") && !strcmp(cmethod, "direct")) {
|
||||
setWTConv(wt, "direct");
|
||||
setDWTExtension(wt, "per");
|
||||
}
|
||||
else if (!strcmp(ext, "per") && !strcmp(cmethod, "fft")) {
|
||||
setWTConv(wt, "fft");
|
||||
setDWTExtension(wt, "per");
|
||||
}
|
||||
else {
|
||||
printf("Signal extension can be either per or sym");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
modwt(wt, signal);
|
||||
|
||||
lnoise = (double*)malloc(sizeof(double)* J);
|
||||
|
||||
//Set sigma
|
||||
|
||||
iter = wt->length[0];
|
||||
dlen = wt->length[J];
|
||||
dout = (double*)malloc(sizeof(double)* dlen);
|
||||
|
||||
for (it = 0; it < J; ++it) {
|
||||
dlen = wt->length[it + 1];
|
||||
for (i = 0; i < dlen; ++i) {
|
||||
dout[i] = fabs(wt->output[iter + i]);
|
||||
}
|
||||
|
||||
sigma = sqrt(2.0) * median(dout, dlen) / 0.6745;
|
||||
lnoise[it] = sigma;
|
||||
iter += dlen;
|
||||
}
|
||||
|
||||
M = pow(2.0,J);
|
||||
llen = log((double)wt->modwtsiglength);
|
||||
// Thresholding
|
||||
|
||||
iter = wt->length[0];
|
||||
for (it = 0; it < J; ++it) {
|
||||
sigma = lnoise[it];
|
||||
dlen = wt->length[it + 1];
|
||||
td = sqrt(2.0 * llen / M) * sigma;
|
||||
|
||||
if (!strcmp(thresh, "hard")) {
|
||||
for (i = 0; i < dlen; ++i) {
|
||||
if (fabs(wt->output[iter + i]) < td) {
|
||||
wt->output[iter + i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(thresh, "soft")) {
|
||||
for (i = 0; i < dlen; ++i) {
|
||||
if (fabs(wt->output[iter + i]) < td) {
|
||||
wt->output[iter + i] = 0;
|
||||
}
|
||||
else {
|
||||
sgn = wt->output[iter + i] >= 0 ? 1 : -1;
|
||||
tmp = sgn * (fabs(wt->output[iter + i]) - td);
|
||||
wt->output[iter + i] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iter += wt->length[it + 1];
|
||||
M /= 2.0;
|
||||
}
|
||||
|
||||
imodwt(wt, denoised);
|
||||
|
||||
free(dout);
|
||||
free(lnoise);
|
||||
wave_free(wave);
|
||||
wt_free(wt);
|
||||
}
|
||||
|
||||
|
||||
void denoise(denoise_object obj, double *signal,double *denoised) {
|
||||
if(!strcmp(obj->dmethod,"sureshrink")) {
|
||||
if (!strcmp(obj->wmethod, "modwt")) {
|
||||
printf("sureshrink method only works with swt and dwt. Please use setDenoiseWTMethod to set the correct method\n");
|
||||
exit(-1);
|
||||
}
|
||||
sureshrink(signal,obj->N,obj->J,obj->wname,obj->wmethod,obj->ext,obj->thresh,obj->level,denoised);
|
||||
} else if(!strcmp(obj->dmethod,"visushrink")) {
|
||||
if (!strcmp(obj->wmethod, "modwt")) {
|
||||
printf("visushrink method only works with swt and dwt. Please use setDenoiseWTMethod to set the correct method\n");
|
||||
exit(-1);
|
||||
}
|
||||
visushrink(signal,obj->N,obj->J,obj->wname,obj->wmethod,obj->ext,obj->thresh,obj->level,denoised);;
|
||||
} else if(!strcmp(obj->dmethod,"modwtshrink")) {
|
||||
if (strcmp(obj->wmethod, "modwt")) {
|
||||
printf("modwtshrink method only works with modwt. Please use setDenoiseWTMethod to set the correct method\n");
|
||||
exit(-1);
|
||||
}
|
||||
modwtshrink(signal,obj->N,obj->J,obj->wname,obj->cmethod,obj->ext,obj->thresh,denoised);;
|
||||
} else {
|
||||
printf("Acceptable Denoising methods are - sureshrink and visushrink\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void setDenoiseMethod(denoise_object obj, char *dmethod) {
|
||||
void setDenoiseMethod(denoise_object obj, const char *dmethod) {
|
||||
if (!strcmp(dmethod, "sureshrink")) {
|
||||
strcpy(obj->dmethod, "sureshrink");
|
||||
}
|
||||
else if (!strcmp(dmethod, "visushrink")) {
|
||||
strcpy(obj->dmethod, "visushrink");
|
||||
}
|
||||
else if (!strcmp(dmethod, "modwtshrink")) {
|
||||
strcpy(obj->dmethod, "modwtshrink");
|
||||
}
|
||||
else {
|
||||
printf("Acceptable Denoising methods are - sureshrink and visushrink\n");
|
||||
printf("Acceptable Denoising methods are - sureshrink, visushrink and modwtshrink\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void setDenoiseWTMethod(denoise_object obj, char *wmethod) {
|
||||
void setDenoiseWTMethod(denoise_object obj, const char *wmethod) {
|
||||
if (!strcmp(wmethod, "dwt")) {
|
||||
strcpy(obj->wmethod, "dwt");
|
||||
}
|
||||
else if (!strcmp(wmethod, "swt")) {
|
||||
strcpy(obj->wmethod, "swt");
|
||||
}
|
||||
else if (!strcmp(wmethod, "modwt")) {
|
||||
strcpy(obj->wmethod, "modwt");
|
||||
}
|
||||
else {
|
||||
printf("Wavelet decomposition method can be either dwt or swt");
|
||||
printf("Wavelet decomposition method can be one of dwt, modwt or swt.\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void setDenoiseWTExtension(denoise_object obj, char *extension) {
|
||||
void setDenoiseWTExtension(denoise_object obj, const char *extension) {
|
||||
if (!strcmp(extension, "sym")) {
|
||||
strcpy(obj->ext, "sym");
|
||||
}
|
||||
@ -326,7 +456,7 @@ void setDenoiseWTExtension(denoise_object obj, char *extension) {
|
||||
}
|
||||
}
|
||||
|
||||
void setDenoiseParameters(denoise_object obj, char *thresh,char *level) {
|
||||
void setDenoiseParameters(denoise_object obj, const char *thresh,const char *level) {
|
||||
|
||||
//Set thresholding
|
||||
if (!strcmp(thresh, "soft")) {
|
||||
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017, Rafat Hussain
|
||||
*/
|
||||
#ifndef DENOISE_H_
|
||||
#define DENOISE_H_
|
||||
|
||||
|
||||
#include "waux.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct denoise_set* denoise_object;
|
||||
|
||||
denoise_object denoise_init(int length, int J,char* wname);
|
||||
|
||||
struct denoise_set{
|
||||
int N; //signal length
|
||||
int J; // Levels of Wavelet decomposition
|
||||
char wname[10]; //Wavelet name
|
||||
char wmethod[10]; //Wavelet decomposition method - dwt or swt
|
||||
char ext[10]; // Signal Extension - sym or per
|
||||
char thresh[10]; // thresholding - soft or hard
|
||||
char level[10]; // Noise Estimation level - first or all
|
||||
char dmethod[20]; //Denoising Method -sureshrink or visushrink
|
||||
//double params[0];
|
||||
};
|
||||
|
||||
void visushrink(double *signal,int N,int J,char *wname,char *method,char *ext,char *thresh,char *level,double *denoised);
|
||||
|
||||
void sureshrink(double *signal,int N,int J,char *wname,char *method,char *ext,char *thresh,char *level,double *denoised);
|
||||
|
||||
void denoise(denoise_object obj, double *signal,double *denoised);
|
||||
|
||||
void setDenoiseMethod(denoise_object obj, char *dmethod);
|
||||
|
||||
void setDenoiseWTMethod(denoise_object obj, char *wmethod);
|
||||
|
||||
void setDenoiseWTExtension(denoise_object obj, char *extension);
|
||||
|
||||
void setDenoiseParameters(denoise_object obj, char *thresh,char *level);
|
||||
|
||||
void denoise_free(denoise_object object);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* DENOISE_H_ */
|
@ -1,3 +1,4 @@
|
||||
#include "../header/wauxlib.h"
|
||||
#include "waux.h"
|
||||
|
||||
int compare_double(const void* a, const void* b)
|
||||
@ -11,7 +12,7 @@ int compare_double(const void* a, const void* b)
|
||||
|
||||
}
|
||||
|
||||
double mean(double* vec, int N) {
|
||||
double mean(const double* vec, int N) {
|
||||
int i;
|
||||
double m;
|
||||
m = 0.0;
|
||||
@ -23,7 +24,7 @@ double mean(double* vec, int N) {
|
||||
return m;
|
||||
}
|
||||
|
||||
double var(double* vec, int N) {
|
||||
double var(const double* vec, int N) {
|
||||
double v,temp,m;
|
||||
int i;
|
||||
v = 0.0;
|
||||
@ -69,7 +70,7 @@ double mad(double *x, int N) {
|
||||
return sigma;
|
||||
}
|
||||
|
||||
int minindex(double *arr, int N) {
|
||||
int minindex(const double *arr, int N) {
|
||||
double min;
|
||||
int index,i;
|
||||
|
||||
@ -116,6 +117,7 @@ void getDWTDetail(wt_object wt, double *detail, int N, int level) {
|
||||
|
||||
if (level > J || level < 1) {
|
||||
printf("The decomposition only has 1,..,%d levels", J);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
iter = wt->length[0];
|
||||
@ -129,7 +131,7 @@ void getDWTDetail(wt_object wt, double *detail, int N, int level) {
|
||||
}
|
||||
}
|
||||
|
||||
void getDWTRecCoeff(double *coeff,int *length,char *ctype,char *ext, int level, int J,double *lpr,
|
||||
void getDWTRecCoeff(double *coeff,int *length,const char *ctype,const char *ext, int level, int J,double *lpr,
|
||||
double *hpr,int lf,int siglength,double *reccoeff) {
|
||||
|
||||
int i,j,k,det_len,N,l,m,n,v,t,l2;
|
||||
@ -273,7 +275,7 @@ void getDWTRecCoeff(double *coeff,int *length,char *ctype,char *ext, int level,
|
||||
}
|
||||
|
||||
|
||||
void autocovar(double* vec,int N, double* acov,int M) {
|
||||
void autocovar(const double* vec,int N, double* acov,int M) {
|
||||
double m,temp1,temp2;
|
||||
int i,t;
|
||||
m = mean(vec,N);
|
||||
@ -300,7 +302,7 @@ void autocovar(double* vec,int N, double* acov,int M) {
|
||||
|
||||
}
|
||||
|
||||
void autocorr(double* vec,int N,double* acorr, int M) {
|
||||
void autocorr(const double* vec,int N,double* acorr, int M) {
|
||||
double var;
|
||||
int i;
|
||||
if (M > N) {
|
||||
|
@ -21,26 +21,21 @@ extern "C" {
|
||||
|
||||
int compare_double(const void* a, const void* b);
|
||||
|
||||
double mean(double* vec, int N);
|
||||
double mean(const double* vec, int N);
|
||||
|
||||
double var(double* vec, int N);
|
||||
double var(const double* vec, int N);
|
||||
|
||||
double median(double *x, int N);
|
||||
|
||||
double mad(double *x, int N);
|
||||
|
||||
int minindex(double *arr, int N);
|
||||
int minindex(const double *arr, int N);
|
||||
|
||||
void getDWTAppx(wt_object wt, double *appx,int N);
|
||||
|
||||
void getDWTDetail(wt_object wt, double *detail, int N, int level);
|
||||
|
||||
void getDWTRecCoeff(double *coeff,int *length,char *ctype,char *ext, int level, int J,double *lpr,
|
||||
double *hpr,int lf,int siglength,double *reccoeff);
|
||||
void autocovar(const double* vec,int N,double* acov, int M);
|
||||
|
||||
void autocovar(double* vec,int N,double* acov, int M);
|
||||
|
||||
void autocorr(double* vec,int N,double* acorr, int M);
|
||||
void autocorr(const double* vec,int N,double* acorr, int M);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -12,13 +12,15 @@ extern "C" {
|
||||
|
||||
typedef struct denoise_set* denoise_object;
|
||||
|
||||
denoise_object denoise_init(int length, int J,char* wname);
|
||||
denoise_object denoise_init(int length, int J,const char* wname);
|
||||
|
||||
struct denoise_set{
|
||||
int N; //signal length
|
||||
int J; // Levels of Wavelet decomposition
|
||||
char wname[10]; //Wavelet name
|
||||
char wmethod[10]; //Wavelet decomposition method - dwt or swt
|
||||
char cmethod[10]; //Cnvolution Method - direct or fft . Available only for modwt.
|
||||
// SWT and DWT only use direct method.
|
||||
char ext[10]; // Signal Extension - sym or per
|
||||
char thresh[10]; // thresholding - soft or hard
|
||||
char level[10]; // Noise Estimation level - first or all
|
||||
@ -26,23 +28,25 @@ struct denoise_set{
|
||||
//double params[0];
|
||||
};
|
||||
|
||||
void visushrink(double *signal,int N,int J,char *wname,char *method,char *ext,char *thresh,char *level,double *denoised);
|
||||
void visushrink(double *signal,int N,int J,const char *wname,const char *method,const char *ext,const char *thresh,const char *level,double *denoised);
|
||||
|
||||
void sureshrink(double *signal,int N,int J,char *wname,char *method,char *ext,char *thresh,char *level,double *denoised);
|
||||
void sureshrink(double *signal,int N,int J,const char *wname,const char *method,const char *ext,const char *thresh,const char *level,double *denoised);
|
||||
|
||||
void modwtshrink(double *signal, int N, int J, const char *wname, const char *cmethod, const char *ext, const char *thresh, double *denoised);
|
||||
|
||||
void denoise(denoise_object obj, double *signal,double *denoised);
|
||||
|
||||
void setDenoiseMethod(denoise_object obj, char *dmethod);
|
||||
void setDenoiseMethod(denoise_object obj, const char *dmethod);
|
||||
|
||||
void setDenoiseWTMethod(denoise_object obj, char *wmethod);
|
||||
void setDenoiseWTMethod(denoise_object obj, const char *wmethod);
|
||||
|
||||
void setDenoiseWTExtension(denoise_object obj, char *extension);
|
||||
void setDenoiseWTExtension(denoise_object obj, const char *extension);
|
||||
|
||||
void setDenoiseParameters(denoise_object obj, char *thresh,char *level);
|
||||
void setDenoiseParameters(denoise_object obj, const char *thresh,const char *level);
|
||||
|
||||
void denoise_free(denoise_object object);
|
||||
|
||||
void getDWTRecCoeff(double *coeff,int *length,char *ctype,char *ext, int level, int J,double *lpr,
|
||||
void getDWTRecCoeff(double *coeff,int *length,const char *ctype,const char *ext, int level, int J,double *lpr,
|
||||
double *hpr,int lf,int siglength,double *reccoeff);
|
||||
|
||||
double mad(double *x, int N);
|
||||
|
83
header/wavelib.h
Normal file → Executable file
83
header/wavelib.h
Normal file → Executable file
@ -26,7 +26,7 @@ typedef struct cplx_t {
|
||||
|
||||
typedef struct wave_set* wave_object;
|
||||
|
||||
wave_object wave_init(char* wname);
|
||||
wave_object wave_init(const char* wname);
|
||||
|
||||
struct wave_set{
|
||||
char wname[50];
|
||||
@ -83,13 +83,14 @@ struct conv_set{
|
||||
|
||||
typedef struct wt_set* wt_object;
|
||||
|
||||
wt_object wt_init(wave_object wave,char* method, int siglength, int J);
|
||||
wt_object wt_init(wave_object wave,const char* method, int siglength, int J);
|
||||
|
||||
struct wt_set{
|
||||
wave_object wave;
|
||||
conv_object cobj;
|
||||
char method[10];
|
||||
int siglength;// Length of the original signal.
|
||||
int modwtsiglength; // Modified signal length for MODWT
|
||||
int outlength;// Length of the output DWT vector
|
||||
int lenlength;// Length of the Output Dimension Vector "length"
|
||||
int J; // Number of decomposition Levels
|
||||
@ -165,7 +166,7 @@ struct wpt_set{
|
||||
|
||||
typedef struct cwt_set* cwt_object;
|
||||
|
||||
cwt_object cwt_init(char* wave, double param, int siglength,double dt, int J);
|
||||
cwt_object cwt_init(const char* wave, double param, int siglength,double dt, int J);
|
||||
|
||||
struct cwt_set{
|
||||
char wave[10];// Wavelet - morl/morlet,paul,dog/dgauss
|
||||
@ -190,34 +191,62 @@ struct cwt_set{
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct wt2_set* wt2_object;
|
||||
|
||||
void dwt(wt_object wt, double *inp);
|
||||
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);
|
||||
|
||||
void wtree(wtree_object wt, double *inp);
|
||||
double *getDWTmra(wt_object wt, double *wavecoeffs);
|
||||
|
||||
void dwpt(wpt_object wt, double *inp);
|
||||
void wtree(wtree_object wt, const double *inp);
|
||||
|
||||
void dwpt(wpt_object wt, const double *inp);
|
||||
|
||||
void idwpt(wpt_object wt, double *dwtop);
|
||||
|
||||
void swt(wt_object wt, double *inp);
|
||||
void swt(wt_object wt, const double *inp);
|
||||
|
||||
void iswt(wt_object wt, double *swtop);
|
||||
|
||||
void modwt(wt_object wt, double *inp);
|
||||
double *getSWTmra(wt_object wt, double *wavecoeffs);
|
||||
|
||||
void modwt(wt_object wt, const double *inp);
|
||||
|
||||
void imodwt(wt_object wt, double *dwtop);
|
||||
|
||||
void setDWTExtension(wt_object wt, char *extension);
|
||||
double* getMODWTmra(wt_object wt, double *wavecoeffs);
|
||||
|
||||
void setWTREEExtension(wtree_object wt, char *extension);
|
||||
void setDWTExtension(wt_object wt, const char *extension);
|
||||
|
||||
void setDWPTExtension(wpt_object wt, char *extension);
|
||||
void setWTREEExtension(wtree_object wt, const char *extension);
|
||||
|
||||
void setDWPTEntropy(wpt_object wt, char *entropy, double eparam);
|
||||
void setDWPTExtension(wpt_object wt, const char *extension);
|
||||
|
||||
void setWTConv(wt_object wt, char *cmethod);
|
||||
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);
|
||||
|
||||
int getWTREENodelength(wtree_object wt, int X);
|
||||
|
||||
@ -227,18 +256,34 @@ int getDWPTNodelength(wpt_object wt, int X);
|
||||
|
||||
void getDWPTCoeffs(wpt_object wt, int X, int Y, double *coeffs, int N);
|
||||
|
||||
void setCWTScales(cwt_object wt, double s0, double dj, char *type, int power);
|
||||
void setCWTScales(cwt_object wt, double s0, double dj, const char *type, int power);
|
||||
|
||||
void setCWTScaleVector(cwt_object wt, double *scale, int J, double s0, double dj);
|
||||
void setCWTScaleVector(cwt_object wt, const double *scale, int J, double s0, double dj);
|
||||
|
||||
void setCWTPadding(cwt_object wt, int pad);
|
||||
|
||||
void cwt(cwt_object wt, double *inp);
|
||||
void cwt(cwt_object wt, const double *inp);
|
||||
|
||||
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);
|
||||
@ -247,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);
|
||||
|
||||
@ -259,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,32 +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
|
||||
wavelib.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_CURRENT_SOURCE_DIR})
|
||||
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)
|
10
src/conv.h
10
src/conv.h
@ -17,18 +17,8 @@ extern "C" {
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
|
||||
typedef struct conv_set* conv_object;
|
||||
|
||||
conv_object conv_init(int N, int L);
|
||||
|
||||
struct conv_set{
|
||||
fft_real_object fobj;
|
||||
fft_real_object iobj;
|
||||
int ilen1;
|
||||
int ilen2;
|
||||
int clen;
|
||||
};
|
||||
|
||||
int factorf(int M);
|
||||
|
||||
int findnext(int M);
|
||||
|
46
src/cwt.c
Executable file → Normal file
46
src/cwt.c
Executable file → Normal file
@ -8,37 +8,8 @@ C. Torrence and G. Compo, and is available at URL: http://atoc.colorado.edu/rese
|
||||
|
||||
#include "cwt.h"
|
||||
|
||||
static int factorial2(int N) {
|
||||
int factorial,i;
|
||||
|
||||
factorial = 1;
|
||||
|
||||
for (i = 1; i <= N;++i) {
|
||||
factorial *= i;
|
||||
}
|
||||
|
||||
return factorial;
|
||||
}
|
||||
|
||||
static double factorial3(int N) {
|
||||
int i;
|
||||
double factorial;
|
||||
|
||||
factorial = 1;
|
||||
|
||||
for (i = 1; i <= N; ++i) {
|
||||
factorial *= i;
|
||||
}
|
||||
|
||||
return factorial;
|
||||
}
|
||||
|
||||
double factorial(int N) {
|
||||
if (N > 40) {
|
||||
printf("This program is only valid for N <= 40 \n");
|
||||
return -1.0;
|
||||
}
|
||||
double fact[41] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000,
|
||||
static const double fact[41] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000,
|
||||
20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000.0, 1124000727777607680000.0,
|
||||
25852016738884976640000.0, 620448401733239439360000.0, 15511210043330985984000000.0, 403291461126605635584000000.0, 10888869450418352160768000000.0,
|
||||
304888344611713860501504000000.0, 8841761993739701954543616000000.0, 265252859812191058636308480000000.0, 8222838654177922817725562880000000.0,
|
||||
@ -46,6 +17,11 @@ double factorial(int N) {
|
||||
371993326789901217467999448150835200000000.0, 13763753091226345046315979581580902400000000.0, 523022617466601111760007224100074291200000000.0,
|
||||
20397882081197443358640281739902897356800000000.0, 815915283247897734345611269596115894272000000000.0 };
|
||||
|
||||
if (N > 40 || N < 0) {
|
||||
printf("This program is only valid for 0 <= N <= 40 \n");
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
return fact[N];
|
||||
|
||||
}
|
||||
@ -119,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) {
|
||||
@ -142,7 +118,7 @@ static void wave_function(int nk, double dt,int mother, double param,double scal
|
||||
}
|
||||
}
|
||||
|
||||
void cwavelet(double *y, int N, double dt, int mother, double param, double s0, double dj, int jtot, int npad,
|
||||
void cwavelet(const double *y, int N, double dt, int mother, double param, double s0, double dj, int jtot, int npad,
|
||||
double *wave, double *scale, double *period, double *coi) {
|
||||
|
||||
int i, j, k, iter;
|
||||
@ -153,6 +129,8 @@ void cwavelet(double *y, int N, double dt, int mother, double param, double s0,
|
||||
fft_object obj, iobj;
|
||||
fft_data *ypad, *yfft,*daughter;
|
||||
|
||||
(void)s0; (void)dj; /* yes, we need these parameters unused */
|
||||
|
||||
pi = 4.0 * atan(1.0);
|
||||
|
||||
if (npad < N) {
|
||||
@ -289,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/cwt.h
Executable file → Normal file
2
src/cwt.h
Executable file → Normal file
@ -7,7 +7,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void cwavelet(double *y, int N, double dt, int mother, double param, double s0, double dj, int jtot, int npad,
|
||||
void cwavelet(const double *y, int N, double dt, int mother, double param, double s0, double dj, int jtot, int npad,
|
||||
double *wave, double *scale, double *period, double *coi);
|
||||
|
||||
void psi0(int mother, double param, double *val, int *real);
|
||||
|
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);
|
||||
|
||||
|
@ -18,7 +18,7 @@ fft_object fft_init(int N, int sgn) {
|
||||
if (out == 1) {
|
||||
obj = (fft_object) malloc (sizeof(struct fft_set) + sizeof(fft_data)* (N-1));
|
||||
obj->lf = factors(N,obj->factors);
|
||||
longvectorN(obj->twiddle,N,obj->factors,obj->lf);
|
||||
longvectorN(obj->twiddle,obj->factors,obj->lf);
|
||||
twi_len = N;
|
||||
obj->lt = 0;
|
||||
} else {
|
||||
@ -32,7 +32,7 @@ fft_object fft_init(int N, int sgn) {
|
||||
}
|
||||
obj = (fft_object) malloc (sizeof(struct fft_set) + sizeof(fft_data)* (M-1));
|
||||
obj->lf = factors(M,obj->factors);
|
||||
longvectorN(obj->twiddle,M,obj->factors,obj->lf);
|
||||
longvectorN(obj->twiddle,obj->factors,obj->lf);
|
||||
obj->lt = 1;
|
||||
twi_len = M;
|
||||
}
|
||||
@ -1831,7 +1831,7 @@ void twiddle(fft_data *vec,int N, int radix) {
|
||||
|
||||
}
|
||||
|
||||
void longvectorN(fft_data *sig,int N, int *array, int tx) {
|
||||
void longvectorN(fft_data *sig, int *array, int tx) {
|
||||
int L,i,Ls,ct,j,k;
|
||||
fft_type theta;
|
||||
L = 1;
|
||||
|
20
src/hsfft.h
20
src/hsfft.h
@ -12,6 +12,8 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../header/wavelib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -22,11 +24,6 @@ extern "C" {
|
||||
#define fft_type double
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct fft_t {
|
||||
fft_type re;
|
||||
fft_type im;
|
||||
} fft_data;
|
||||
/*
|
||||
#define SADD(a,b) ((a)+(b))
|
||||
|
||||
@ -35,19 +32,8 @@ typedef struct fft_t {
|
||||
#define SMUL(a,b) ((a)*(b))
|
||||
*/
|
||||
|
||||
typedef struct fft_set* fft_object;
|
||||
|
||||
fft_object fft_init(int N, int sgn);
|
||||
|
||||
struct fft_set{
|
||||
int N;
|
||||
int sgn;
|
||||
int factors[64];
|
||||
int lf;
|
||||
int lt;
|
||||
fft_data twiddle[1];
|
||||
};
|
||||
|
||||
void fft_exec(fft_object obj,fft_data *inp,fft_data *oup);
|
||||
|
||||
int divideby(int M,int d);
|
||||
@ -60,7 +46,7 @@ int factors(int M, int* arr);
|
||||
|
||||
void twiddle(fft_data *sig,int N, int radix);
|
||||
|
||||
void longvectorN(fft_data *sig,int N, int *array, int M);
|
||||
void longvectorN(fft_data *sig, int *array, int M);
|
||||
|
||||
void free_fft(fft_object object);
|
||||
|
||||
|
@ -9,11 +9,9 @@
|
||||
|
||||
fft_real_object fft_real_init(int N, int sgn) {
|
||||
fft_real_object obj = NULL;
|
||||
fft_type PI, theta;
|
||||
fft_type theta;
|
||||
int k;
|
||||
|
||||
PI = 3.1415926535897932384626433832795;
|
||||
|
||||
obj = (fft_real_object) malloc (sizeof(struct fft_real_set) + sizeof(fft_data)* (N/2));
|
||||
|
||||
obj->cobj = fft_init(N/2,sgn);
|
||||
@ -79,10 +77,9 @@ void fft_c2r_exec(fft_real_object obj,fft_data *inp,fft_type *oup) {
|
||||
|
||||
fft_data* cinp;
|
||||
fft_data* coup;
|
||||
int i,N2,N;
|
||||
int i,N2;
|
||||
fft_type temp1,temp2;
|
||||
N2 = obj->cobj->N;
|
||||
N = N2*2;
|
||||
|
||||
cinp = (fft_data*) malloc (sizeof(fft_data) * N2);
|
||||
coup = (fft_data*) malloc (sizeof(fft_data) * N2);
|
||||
|
@ -14,15 +14,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct fft_real_set* fft_real_object;
|
||||
|
||||
fft_real_object fft_real_init(int N, int sgn);
|
||||
|
||||
struct fft_real_set{
|
||||
fft_object cobj;
|
||||
fft_data twiddle2[1];
|
||||
};
|
||||
|
||||
void fft_r2c_exec(fft_real_object obj,fft_type *inp,fft_data *oup);
|
||||
|
||||
void fft_c2r_exec(fft_real_object obj,fft_data *inp,fft_type *oup);
|
||||
|
@ -3311,7 +3311,6 @@ void copy_reverse(const double *in, int N,double *out)
|
||||
|
||||
void qmf_wrev(const double *in, int N, double *out)
|
||||
{
|
||||
int count = 0;
|
||||
double *sigOutTemp;
|
||||
sigOutTemp = (double*)malloc(N*sizeof(double));
|
||||
|
||||
|
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
2465
src/wavelib.c
2465
src/wavelib.c
File diff suppressed because it is too large
Load Diff
230
src/wavelib.h
230
src/wavelib.h
@ -1,230 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2014, Rafat Hussain
|
||||
*/
|
||||
#ifndef WAVELIB_H_
|
||||
#define WAVELIB_H_
|
||||
|
||||
#include "wtmath.h"
|
||||
#include "cwt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable : 4200)
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
||||
#ifndef cplx_type
|
||||
#define cplx_type double
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct cplx_t {
|
||||
cplx_type re;
|
||||
cplx_type im;
|
||||
} cplx_data;
|
||||
|
||||
typedef struct wave_set* wave_object;
|
||||
|
||||
wave_object wave_init(char* wname);
|
||||
|
||||
struct wave_set{
|
||||
char wname[50];
|
||||
int filtlength;// When all filters are of the same length. [Matlab uses zero-padding to make all filters of the same length]
|
||||
int lpd_len;// Default filtlength = lpd_len = lpr_len = hpd_len = hpr_len
|
||||
int hpd_len;
|
||||
int lpr_len;
|
||||
int hpr_len;
|
||||
double *lpd;
|
||||
double *hpd;
|
||||
double *lpr;
|
||||
double *hpr;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct wt_set* wt_object;
|
||||
|
||||
wt_object wt_init(wave_object wave,char* method, int siglength, int J);
|
||||
|
||||
struct wt_set{
|
||||
wave_object wave;
|
||||
conv_object cobj;
|
||||
char method[10];
|
||||
int siglength;// Length of the original signal.
|
||||
int outlength;// Length of the output DWT vector
|
||||
int lenlength;// Length of the Output Dimension Vector "length"
|
||||
int J; // Number of decomposition Levels
|
||||
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||
char ext[10];// Type of Extension used - "per" or "sym"
|
||||
char cmethod[10]; // Convolution Method - "direct" or "FFT"
|
||||
|
||||
int N; //
|
||||
int cfftset;
|
||||
int zpad;
|
||||
int length[102];
|
||||
double *output;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct wtree_set* wtree_object;
|
||||
|
||||
wtree_object wtree_init(wave_object wave, int siglength, int J);
|
||||
|
||||
struct wtree_set{
|
||||
wave_object wave;
|
||||
conv_object cobj;
|
||||
char method[10];
|
||||
int siglength;// Length of the original signal.
|
||||
int outlength;// Length of the output DWT vector
|
||||
int lenlength;// Length of the Output Dimension Vector "length"
|
||||
int J; // Number of decomposition Levels
|
||||
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||
char ext[10];// Type of Extension used - "per" or "sym"
|
||||
|
||||
int N; //
|
||||
int nodes;
|
||||
int cfftset;
|
||||
int zpad;
|
||||
int length[102];
|
||||
double *output;
|
||||
int *nodelength;
|
||||
int *coeflength;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct wpt_set* wpt_object;
|
||||
|
||||
wpt_object wpt_init(wave_object wave, int siglength, int J);
|
||||
|
||||
struct wpt_set{
|
||||
wave_object wave;
|
||||
conv_object cobj;
|
||||
int siglength;// Length of the original signal.
|
||||
int outlength;// Length of the output DWT vector
|
||||
int lenlength;// Length of the Output Dimension Vector "length"
|
||||
int J; // Number of decomposition Levels
|
||||
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||
char ext[10];// Type of Extension used - "per" or "sym"
|
||||
char entropy[20];
|
||||
double eparam;
|
||||
|
||||
int N; //
|
||||
int nodes;
|
||||
int length[102];
|
||||
double *output;
|
||||
double *costvalues;
|
||||
double *basisvector;
|
||||
int *nodeindex;
|
||||
int *numnodeslevel;
|
||||
int *coeflength;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct cwt_set* cwt_object;
|
||||
|
||||
cwt_object cwt_init(char* wave, double param, int siglength,double dt, int J);
|
||||
|
||||
struct cwt_set{
|
||||
char wave[10];// Wavelet - morl/morlet,paul,dog/dgauss
|
||||
int siglength;// Length of Input Data
|
||||
int J;// Total Number of Scales
|
||||
double s0;// Smallest scale. It depends on the sampling rate. s0 <= 2 * dt for most wavelets
|
||||
double dt;// Sampling Rate
|
||||
double dj;// Separation between scales. eg., scale = s0 * 2 ^ ( [0:N-1] *dj ) or scale = s0 *[0:N-1] * dj
|
||||
char type[10];// Scale Type - Power or Linear
|
||||
int pow;// Base of Power in case type = pow. Typical value is pow = 2
|
||||
int sflag;
|
||||
int pflag;
|
||||
int npad;
|
||||
int mother;
|
||||
double m;// Wavelet parameter param
|
||||
double smean;// Input Signal mean
|
||||
|
||||
cplx_data *output;
|
||||
double *scale;
|
||||
double *period;
|
||||
double *coi;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
|
||||
void dwt(wt_object wt, double *inp);
|
||||
|
||||
void idwt(wt_object wt, double *dwtop);
|
||||
|
||||
void wtree(wtree_object wt, double *inp);
|
||||
|
||||
void dwpt(wpt_object wt, double *inp);
|
||||
|
||||
void idwpt(wpt_object wt, double *dwtop);
|
||||
|
||||
void swt(wt_object wt, double *inp);
|
||||
|
||||
void iswt(wt_object wt, double *swtop);
|
||||
|
||||
void modwt(wt_object wt, double *inp);
|
||||
|
||||
void imodwt(wt_object wt, double *dwtop);
|
||||
|
||||
void setDWTExtension(wt_object wt, char *extension);
|
||||
|
||||
void setWTREEExtension(wtree_object wt, char *extension);
|
||||
|
||||
void setDWPTExtension(wpt_object wt, char *extension);
|
||||
|
||||
void setDWPTEntropy(wpt_object wt, char *entropy, double eparam);
|
||||
|
||||
void setWTConv(wt_object wt, char *cmethod);
|
||||
|
||||
int getWTREENodelength(wtree_object wt, int X);
|
||||
|
||||
void getWTREECoeffs(wtree_object wt, int X, int Y, double *coeffs, int N);
|
||||
|
||||
int getDWPTNodelength(wpt_object wt, int X);
|
||||
|
||||
void getDWPTCoeffs(wpt_object wt, int X, int Y, double *coeffs, int N);
|
||||
|
||||
void setCWTScales(cwt_object wt, double s0, double dj, char *type, int power);
|
||||
|
||||
void setCWTScaleVector(cwt_object wt, double *scale, int J, double s0, double dj);
|
||||
|
||||
void setCWTPadding(cwt_object wt, int pad);
|
||||
|
||||
void cwt(cwt_object wt, double *inp);
|
||||
|
||||
void icwt(cwt_object wt, double *cwtop);
|
||||
|
||||
int getCWTScaleLength(int N);
|
||||
|
||||
void wave_summary(wave_object obj);
|
||||
|
||||
void wt_summary(wt_object wt);
|
||||
|
||||
void wtree_summary(wtree_object wt);
|
||||
|
||||
void wpt_summary(wpt_object wt);
|
||||
|
||||
void cwt_summary(cwt_object wt);
|
||||
|
||||
void wave_free(wave_object object);
|
||||
|
||||
void wt_free(wt_object object);
|
||||
|
||||
void wtree_free(wtree_object object);
|
||||
|
||||
void wpt_free(wpt_object object);
|
||||
|
||||
void cwt_free(cwt_object object);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* WAVELIB_H_ */
|
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);
|
||||
|
@ -1,32 +1,48 @@
|
||||
add_executable(cwttest cwttest.c)
|
||||
|
||||
target_link_libraries(cwttest wavelib m)
|
||||
target_link_libraries(cwttest wavelib)
|
||||
|
||||
add_executable(dwttest dwttest.c)
|
||||
|
||||
target_link_libraries(dwttest wavelib m)
|
||||
target_link_libraries(dwttest wavelib)
|
||||
|
||||
add_executable(swttest swttest.c)
|
||||
|
||||
target_link_libraries(swttest wavelib m)
|
||||
target_link_libraries(swttest wavelib)
|
||||
|
||||
add_executable(modwttest modwttest.c)
|
||||
|
||||
target_link_libraries(modwttest wavelib m)
|
||||
target_link_libraries(modwttest wavelib)
|
||||
|
||||
add_executable(dwpttest dwpttest.c)
|
||||
|
||||
target_link_libraries(dwpttest wavelib m)
|
||||
target_link_libraries(dwpttest wavelib)
|
||||
|
||||
add_executable(wtreetest wtreetest.c)
|
||||
|
||||
target_link_libraries(wtreetest wavelib m)
|
||||
target_link_libraries(wtreetest wavelib)
|
||||
|
||||
add_executable(denoisetest denoisetest.c)
|
||||
|
||||
target_link_libraries(denoisetest wauxlib wavelib m)
|
||||
target_link_libraries(denoisetest wauxlib wavelib)
|
||||
|
||||
set_target_properties(cwttest dwttest swttest modwttest dwpttest wtreetest denoisetest
|
||||
add_executable(modwtdenoisetest modwtdenoisetest.c)
|
||||
|
||||
target_link_libraries(modwtdenoisetest wauxlib wavelib)
|
||||
|
||||
add_executable(dwt2test dwt2test.c)
|
||||
|
||||
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"
|
||||
)
|
||||
)
|
||||
|
@ -56,10 +56,12 @@ int main() {
|
||||
double temp[2400];
|
||||
|
||||
char *wname = "db5";
|
||||
char *method = "dwt";
|
||||
char *ext = "sym";
|
||||
char *thresh = "soft";
|
||||
char *level = "all";
|
||||
char *method = "dwt";// Available - dwt, swt and modwt. modwt works only with modwtshrink. The other two methods work with
|
||||
// visushrink and sureshrink
|
||||
char *ext = "sym";// sym and per work with dwt. swt and modwt only use per extension when called through denoise.
|
||||
// You can use sy extension if you directly call modwtshrink with cmethod set to fft. See modwtdenoisetest.c file
|
||||
char *thresh = "soft";// soft or hard
|
||||
char *level = "all"; // noise estimation at "first" or "all" levels. modwt only has the option of "all"
|
||||
|
||||
ifp = fopen("pieceregular1024.txt", "r");
|
||||
i = 0;
|
||||
@ -104,19 +106,20 @@ int main() {
|
||||
inp[i] = temp[i];
|
||||
}
|
||||
obj = denoise_init(N,J,wname);
|
||||
setDenoiseMethod(obj,"visushrink");// sureshrink is also the default. The other option is visushrink
|
||||
setDenoiseWTMethod(obj,method);// Default is dwt. the other option is swt
|
||||
setDenoiseMethod(obj,"visushrink");// sureshrink is also the default. The other option with dwt and swt is visushrink.
|
||||
// modwt works only with modwtshrink method
|
||||
setDenoiseWTMethod(obj,method);// Default is dwt. the other options are swt and modwt
|
||||
setDenoiseWTExtension(obj,ext);// Default is sym. the other option is per
|
||||
setDenoiseParameters(obj,thresh,level);// Default for thresh is soft. Other option is hard
|
||||
// Default for level is first. The other option is all
|
||||
// Default for level is all. The other option is first
|
||||
|
||||
denoise(obj,inp,oup);
|
||||
|
||||
// Alternative to denoise_object
|
||||
// Just use visushrink and sureshrink functions
|
||||
// Just use visushrink, modwtshrink and sureshrink functions
|
||||
//visushrink(inp,N,J,wname,method,ext,thresh,level,oup);
|
||||
//sureshrink(inp,N,J,wname,method,ext,thresh,level,oup);
|
||||
|
||||
// modwtshrink(sig,N,J,wname,cmethod,ext,thresh,oup); See modwtdenoisetest.c
|
||||
//ofp = fopen("denoiseds.txt", "w");
|
||||
|
||||
|
||||
@ -131,5 +134,6 @@ int main() {
|
||||
free(sig);
|
||||
free(inp);
|
||||
denoise_free(obj);
|
||||
free(oup);
|
||||
return 0;
|
||||
}
|
||||
|
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;
|
||||
}
|
@ -41,6 +41,8 @@ int main() {
|
||||
i++;
|
||||
}
|
||||
N = 256;
|
||||
|
||||
fclose(ifp);
|
||||
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
out = (double*)malloc(sizeof(double)* N);
|
||||
|
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;
|
||||
}
|
123
test/modwtdenoisetest.c
Normal file
123
test/modwtdenoisetest.c
Normal file
@ -0,0 +1,123 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../header/wauxlib.h"
|
||||
|
||||
static double rmse(int N,double *x,double *y) {
|
||||
double rms;
|
||||
int i;
|
||||
|
||||
rms = 0.0;
|
||||
|
||||
for(i = 0; i < N;++i) {
|
||||
rms += (x[i] - y[i]) * (x[i] - y[i]);
|
||||
}
|
||||
|
||||
rms = sqrt(rms/(double)N);
|
||||
|
||||
return rms;
|
||||
}
|
||||
|
||||
static double corrcoef(int N,double *x,double *y) {
|
||||
double cc,xm,ym,tx,ty,num,den1,den2;
|
||||
int i;
|
||||
xm = ym = 0.0;
|
||||
for(i = 0; i < N;++i) {
|
||||
xm += x[i];
|
||||
ym += y[i];
|
||||
}
|
||||
|
||||
xm = xm/N;
|
||||
ym = ym / N;
|
||||
num = den1 = den2 = 0.0;
|
||||
|
||||
for(i = 0; i < N;++i) {
|
||||
tx = x[i] - xm;
|
||||
ty = y[i] - ym;
|
||||
num += (tx*ty);
|
||||
den1 += (tx*tx);
|
||||
den2 += (ty*ty);
|
||||
}
|
||||
|
||||
cc = num / sqrt(den1*den2);
|
||||
|
||||
return cc;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// gcc -Wall -I../header -L../Bin modwtdenoisetest.c -o modwtdenoise -lwauxlib -lwavelib -lm
|
||||
/*
|
||||
modwtshrink can also be called from the denoise object. See denoisetest.c for more information
|
||||
*/
|
||||
double *sig,*inp,*oup;
|
||||
int i,N,J;
|
||||
FILE *ifp;
|
||||
|
||||
double temp[2400];
|
||||
|
||||
char *wname = "db5";
|
||||
char *ext = "per";// The other option sym is only available with "fft" cmethod
|
||||
char *thresh = "soft";
|
||||
char *cmethod = "direct";// The other option is "fft"
|
||||
|
||||
ifp = fopen("pieceregular1024.txt", "r");
|
||||
i = 0;
|
||||
if (!ifp) {
|
||||
printf("Cannot Open File");
|
||||
exit(100);
|
||||
}
|
||||
|
||||
while (!feof(ifp)) {
|
||||
fscanf(ifp, "%lf \n", &temp[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
fclose(ifp);
|
||||
|
||||
N = i;
|
||||
J = 4;
|
||||
|
||||
sig = (double*)malloc(sizeof(double)* N);
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
oup = (double*)malloc(sizeof(double)* N);
|
||||
|
||||
for(i = 0; i < N;++i) {
|
||||
sig[i] = temp[i];
|
||||
}
|
||||
|
||||
ifp = fopen("PieceRegular10.txt", "r");
|
||||
i = 0;
|
||||
if (!ifp) {
|
||||
printf("Cannot Open File");
|
||||
exit(100);
|
||||
}
|
||||
|
||||
while (!feof(ifp)) {
|
||||
fscanf(ifp, "%lf \n", &temp[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
fclose(ifp);
|
||||
|
||||
for(i = 0; i < N;++i) {
|
||||
inp[i] = temp[i];
|
||||
}
|
||||
|
||||
modwtshrink(sig,N,J,wname,cmethod,ext,thresh,oup);
|
||||
|
||||
|
||||
printf("Signal - Noisy Signal Stats \n");
|
||||
printf("RMSE %g\n",rmse(N,sig,inp));
|
||||
printf("Corr Coeff %g\n",corrcoef(N,sig,inp));
|
||||
|
||||
printf("Signal - DeNoised Signal Stats \n");
|
||||
printf("RMSE %g\n",rmse(N,sig,oup));
|
||||
printf("Corr Coeff %g\n",corrcoef(N,sig,oup));
|
||||
|
||||
free(sig);
|
||||
free(inp);
|
||||
free(oup);
|
||||
return 0;
|
||||
}
|
@ -42,6 +42,8 @@ int main() {
|
||||
i++;
|
||||
}
|
||||
N = 177;
|
||||
|
||||
fclose(ifp);
|
||||
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
out = (double*)malloc(sizeof(double)* N);
|
||||
|
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;
|
||||
}
|
@ -41,7 +41,7 @@ int main() {
|
||||
i++;
|
||||
}
|
||||
N = 256;
|
||||
|
||||
fclose(ifp);
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
out = (double*)malloc(sizeof(double)* N);
|
||||
diff = (double*)malloc(sizeof(double)* N);
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
@ -4,11 +4,13 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include "wavelib.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "../../header/wavelib.h"
|
||||
|
||||
#include<vector>
|
||||
|
||||
@ -109,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;
|
||||
@ -117,7 +127,6 @@ void ReconstructionTest()
|
||||
double *inp,*out;
|
||||
int N, i,J;
|
||||
double epsilon = 1e-15;
|
||||
char *type = (char*) "dwt";
|
||||
|
||||
N = 79926;
|
||||
|
||||
@ -228,6 +237,545 @@ 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()
|
||||
{
|
||||
|
||||
wave_object obj;
|
||||
wt_object wt;
|
||||
double *inp,*out;
|
||||
int N, i,J;
|
||||
double epsilon = 1e-15;
|
||||
double err;
|
||||
|
||||
N = 79926;
|
||||
|
||||
//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));
|
||||
}
|
||||
|
||||
|
||||
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 = wt_init(obj,(char*) "modwt", 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;
|
||||
|
||||
modwt(wt, inp);// Perform DWT
|
||||
|
||||
imodwt(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 : DWT Reconstruction Unit Test Failed. Exiting. \n");
|
||||
exit(-1);
|
||||
}
|
||||
wt_free(wt);
|
||||
}
|
||||
wave_free(obj);
|
||||
delete[] name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(out);
|
||||
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()
|
||||
{
|
||||
|
||||
@ -346,10 +894,10 @@ void DWPTReconstructionTest()
|
||||
}
|
||||
|
||||
void CWTReconstructionTest() {
|
||||
int i, j,N, J,subscale,a0,iter;
|
||||
int i, N, J,subscale,a0;
|
||||
double *inp,*oup;
|
||||
double dt, dj,s0, pi,t;
|
||||
double val, epsilon;
|
||||
double epsilon;
|
||||
int it1,it2;
|
||||
cwt_object wt;
|
||||
|
||||
@ -646,14 +1194,29 @@ 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();
|
||||
printf("DONE \n");
|
||||
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