Compare commits

..

No commits in common. "master" and "modwt" have entirely different histories.

30 changed files with 300 additions and 2736 deletions

9
.gitignore vendored
View File

@ -1,7 +1,6 @@
#Folders Ignore
Bin/
Testing/
.vscode/
#cmake ignore
CMakeCache.txt
@ -33,10 +32,4 @@ language.settings.xml
*.tcl
#wavelib-specific
denoised.txt
test/
build/
.vscode/
.DS_Store
*.sh
denoised.txt

View File

@ -1,15 +1,51 @@
cmake_minimum_required(VERSION 3.15.2)
#
project(WaveLib VERSION 1.0)
#
include(CMakePackageConfigHelpers)
cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
# CMake WindowsC:/Program\ Files/${Project_Name} Linux/Unix/usr/local
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
# CMake
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
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()
#
add_subdirectory(src)
add_subdirectory(auxiliary)
add_subdirectory(auxiliary)
add_subdirectory(test)
install(DIRECTORY ${WAVELIB_SRC_ROOT}/include/ DESTINATION include FILES_MATCHING PATTERN "*.h")

View File

@ -1,5 +1,3 @@
[![Build Status](https://travis-ci.org/rafat/wavelib.svg?branch=master)](https://travis-ci.org/rafat/wavelib)
wavelib
=======
@ -7,11 +5,11 @@ C Implementation of Discrete Wavelet Transform (DWT,SWT and MODWT), Continuous W
Discrete Wavelet Transform Methods Implemented
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.
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.
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.
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.
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.
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.
Discrete Wavelet Packet Transform Methods Implemented
@ -23,7 +21,7 @@ CWT/ICWT C translation ( with some modifications) of Continuous Wavelet Transfo
Documentation Available at - https://github.com/rafat/wavelib/wiki
Live Demo of 1D DWT and 1D CWT (Emscripten) - http://rafat.github.io/wavelib/
Live Demo (Emscripten) - http://rafat.github.io/wavelib/
License - BSD 3-Clause

View File

@ -1,19 +0,0 @@
@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@)

View File

@ -1,55 +1,16 @@
#
aux_source_directory(. WAUX_SRC)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
#
#
# libcmake
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(SOURCE_FILES denoise.c
waux.c
)
target_link_libraries(wauxlib PUBLIC wavelib)
target_link_libraries(wauxlib_static PUBLIC wavelib_static)
set(HEADER_FILES waux.h)
#
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
add_library(wauxlib STATIC ${SOURCE_FILES} ${HEADER_FILES})
#
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
target_link_libraries(wauxlib wavelib)
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
set_property(TARGET wauxlib 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(wauxlib 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 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()

View File

@ -4,7 +4,7 @@
#include <string.h>
#include "waux.h"
#include "../header/wauxlib.h"
#include "wauxlib.h"
denoise_object denoise_init(int length, int J,const char* wname) {
denoise_object obj = NULL;

View File

@ -1,4 +1,4 @@
#include "../header/wauxlib.h"
#include "wauxlib.h"
#include "waux.h"
int compare_double(const void* a, const void* b)

View File

@ -191,33 +191,11 @@ struct cwt_set{
double params[0];
};
typedef struct wt2_set* wt2_object;
wt2_object wt2_init(wave_object wave, const char* method, int rows, int cols, int J);
struct wt2_set{
wave_object wave;
char method[10];
int rows;// Matrix Number of rows
int cols; // Matrix Number of columns
int outlength;// Length of the output DWT vector
int J; // Number of decomposition Levels
int MaxIter;// Maximum Iterations J <= MaxIter
char ext[10];// Type of Extension used - "per" or "sym"
int coeffaccesslength;
int N; //
int *dimensions;
int *coeffaccess;
int params[0];
};
void dwt(wt_object wt, const double *inp);
void idwt(wt_object wt, double *dwtop);
double *getDWTmra(wt_object wt, double *wavecoeffs);
void wtree(wtree_object wt, const double *inp);
void dwpt(wpt_object wt, const double *inp);
@ -228,22 +206,16 @@ void swt(wt_object wt, const double *inp);
void iswt(wt_object wt, double *swtop);
double *getSWTmra(wt_object wt, double *wavecoeffs);
void modwt(wt_object wt, const double *inp);
void imodwt(wt_object wt, double *dwtop);
double* getMODWTmra(wt_object wt, double *wavecoeffs);
void setDWTExtension(wt_object wt, const char *extension);
void setWTREEExtension(wtree_object wt, const char *extension);
void setDWPTExtension(wpt_object wt, const char *extension);
void setDWT2Extension(wt2_object wt, const char *extension);
void setDWPTEntropy(wpt_object wt, const char *entropy, double eparam);
void setWTConv(wt_object wt, const char *cmethod);
@ -268,22 +240,6 @@ 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);
@ -292,9 +248,7 @@ void wtree_summary(wtree_object wt);
void wpt_summary(wpt_object wt);
void cwt_summary(cwt_object wt);
void wt2_summary(wt2_object wt);
void cwt_summary(cwt_object wt);;
void wave_free(wave_object object);
@ -306,8 +260,6 @@ void wpt_free(wpt_object object);
void cwt_free(cwt_object object);
void wt2_free(wt2_object wt);
#ifdef __cplusplus
}

View File

@ -1,54 +0,0 @@
#!/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

View File

@ -1,55 +1,31 @@
#
aux_source_directory(. WAVE_SRC)
#
#
# libcmake
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)
#
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
#
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(SOURCE_FILES conv.c
cwt.c
cwtmath.c
hsfft.c
real.c
wavefilt.c
wavefunc.c
wavelib.c
wtmath.c
)
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
set(HEADER_FILES conv.h
cwt.h
cwtmath.h
hsfft.h
real.h
wavefilt.h
wavefunc.h
wtmath.h
)
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CONFIG_FILE_PATH})
add_library(wavelib STATIC ${SOURCE_FILES} ${HEADER_FILES})
set_property(TARGET wavelib PROPERTY FOLDER "lib")
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
target_include_directories(wavelib PUBLIC ${CMAKE_SOURCE_DIR}/header)
#
if(WIN32)
install(TARGETS wavelib DESTINATION lib)
install(TARGETS wavelib_static DESTINATION lib)
else()
install(TARGETS wavelib wavelib_static
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(EXPORT ${PROJECT_NAME}Targets
DESTINATION ${CONFIG_FILE_PATH})
install(FILES
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CONFIG_FILE_PATH})
endif()
#
install(FILES ../header/wavelib.h DESTINATION include)
install(FILES ../header/wauxlib.h DESTINATION include)

6
src/cwt.c Normal file → Executable file
View File

@ -95,7 +95,7 @@ static void wave_function(int nk, double dt,int mother, double param,double scal
}
norm = sqrt(2.0*pi*scale1 / dt)*sqrt(1.0 / cwt_gamma(m + 0.50));
norm = sqrt(2.0*pi*scale1 / dt)*sqrt(1.0 / gamma(m + 0.50));
norm *= sign;
if (re == 1) {
@ -267,8 +267,8 @@ void psi0(int mother, double param,double *val,int *real) {
else {
sign = 1;
}
coeff = sign * pow(2.0, (double)m / 2) / cwt_gamma(0.5);
*val = coeff * cwt_gamma(((double)m + 1.0) / 2.0) / sqrt(cwt_gamma(m + 0.50));
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));
}
else {
*val = 0;

0
src/cwt.h Normal file → Executable file
View File

2
src/cwtmath.c Normal file → Executable file
View File

@ -155,7 +155,7 @@ int nint(double N) {
return i;
}
double cwt_gamma(double x) {
double 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 Normal file → Executable file
View 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 cwt_gamma(double x);
double gamma(double x);
int nint(double N);

View File

@ -12,7 +12,7 @@
#include <math.h>
#include <string.h>
#include "../header/wavelib.h"
#include "wavelib.h"
#ifdef __cplusplus
extern "C" {

2
src/wavefunc.c Normal file → Executable file
View 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(cwt_gamma(p+0.5));
den = sqrt(gamma(p+0.5));
if ((p+1)%2 == 0) {
num = 1.0;

0
src/wavefunc.h Normal file → Executable file
View File

File diff suppressed because it is too large Load Diff

View File

@ -1,355 +1,8 @@
/*
Copyright (c) 2018, Rafat Hussain
Copyright (c) 2014, 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;

View File

@ -10,30 +10,6 @@ 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);

View File

@ -30,19 +30,18 @@ add_executable(modwtdenoisetest modwtdenoisetest.c)
target_link_libraries(modwtdenoisetest wauxlib wavelib)
add_executable(dwt2test dwt2test.c)
if(UNIX)
target_link_libraries(cwttest m)
target_link_libraries(dwttest m)
target_link_libraries(swttest m)
target_link_libraries(modwttest m)
target_link_libraries(dwpttest m)
target_link_libraries(wtreetest m)
target_link_libraries(denoisetest m)
target_link_libraries(modwtdenoisetest m)
endif()
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
set_target_properties(cwttest dwttest swttest modwttest dwpttest wtreetest denoisetest modwtdenoisetest
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
)

View File

@ -1,87 +0,0 @@
#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;
}

View File

@ -1,82 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "../header/wavelib.h"
double absmax(double *array, int N) {
double max;
int i;
max = 0.0;
for (i = 0; i < N; ++i) {
if (fabs(array[i]) >= max) {
max = fabs(array[i]);
}
}
return max;
}
double generate_rnd() {
double rnd;
rnd = (double) (rand() % 100 + 1);
return rnd;
}
int main() {
wave_object obj;
wt2_object wt;
int i, k, J, rows, cols,N,ir,ic;
double *inp, *wavecoeffs, *oup,*cLL,*diff;
double amax;
rows = 51;
cols = 40;
N = rows*cols;
char *name = "db2";
obj = wave_init(name);// Initialize the wavelet
inp = (double*)calloc(N, sizeof(double));
oup = (double*)calloc(N, sizeof(double));
diff = (double*)calloc(N, sizeof(double));
J = 2;
wt = wt2_init(obj, "modwt", rows, cols, J);
for (i = 0; i < rows; ++i) {
for (k = 0; k < cols; ++k) {
//inp[i*cols + k] = i*cols + k;
inp[i*cols + k] = generate_rnd();
oup[i*cols + k] = 0.0;
}
}
wavecoeffs = modwt2(wt, inp);
cLL = getWT2Coeffs(wt, wavecoeffs, J, "A", &ir, &ic);
//dispWT2Coeffs(cLL, ir, ic);
imodwt2(wt, wavecoeffs, oup);
for (i = 0; i < N; ++i) {
diff[i] = oup[i] - inp[i];
}
amax = absmax(diff, N);
wt2_summary(wt);
printf("Abs Max %g \n", amax);
wave_free(obj);
wt2_free(wt);
free(inp);
free(wavecoeffs);
free(oup);
free(diff);
return 0;
}

0
test/modwtdenoisetest.c Normal file → Executable file
View File

0
test/sst_nino3.dat Normal file → Executable file
View File

View File

@ -1,83 +0,0 @@
#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;
}

View File

@ -0,0 +1,5 @@
#define BOOST_TEST_MODULE WaveLibTests
#include <boost/test/included/unit_test.hpp>

View File

@ -0,0 +1,10 @@
#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_

View File

@ -16,7 +16,7 @@ add_dependencies(wavelibLibTests wavelib)
target_link_libraries(wavelibLibTests wavelib)
target_include_directories(wavelibLibTests PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../header
${CMAKE_SOURCE_DIR}/../../header
)

View File

@ -10,7 +10,7 @@
#include <cstdlib>
#include <cstring>
#include "../../header/wavelib.h"
#include "wavelib.h"
#include<vector>
@ -111,15 +111,7 @@ double REL_Error(double *data, double *rec, int N) {
return sqrt(sum1)/sqrt(sum2);
}
double generate_rnd() {
double rnd;
rnd = (double) (rand() % 100 + 1);
return rnd;
}
void DWTReconstructionTest()
void ReconstructionTest()
{
wave_object obj;
@ -237,125 +229,6 @@ void DWTReconstructionTest()
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()
{
@ -393,9 +266,9 @@ void MODWTReconstructionTest()
}
for (unsigned int direct_fft = 0; direct_fft < 1; direct_fft++)
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 sym_per = 0; sym_per < 2; sym_per++)
{
for (unsigned int j = 0; j < waveletNames.size(); j++)
{
@ -449,333 +322,6 @@ void MODWTReconstructionTest()
free(inp);
}
void MODWT2ReconstructionTest()
{
wave_object obj;
wt2_object wt;
int i, k, J, N, rows, cols;
double *inp, *wavecoeffs,*out;
double epsilon;
rows = 1024;
cols = 1000;
N = rows*cols;
inp = (double*)malloc(sizeof(double)* N);
out = (double*)malloc(sizeof(double)* N);
std::vector<std::string > waveletNames;
for (unsigned int j = 0; j < 15; j++)
{
waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
}
for (unsigned int j = 0; j < 5; j++)
{
waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
}
for (unsigned int j = 1; j < 10; j++)
{
waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
}
for (i = 0; i < rows; ++i) {
for (k = 0; k < cols; ++k) {
//inp[i*cols + k] = i*cols + k;
inp[i*cols + k] = generate_rnd();
out[i*cols + k] = 0.0;
}
}
for (unsigned int direct_fft = 0; direct_fft < 1; direct_fft++)
{
for (unsigned int sym_per = 0; sym_per < 1; sym_per++)
{
for (unsigned int j = 0; j < waveletNames.size(); j++)
{
char * name = new char[waveletNames[j].size() + 1];
memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
obj = wave_init(name);// Initialize the wavelet
for (J = 1; J < 3; J++)
{
//J = 3;
wt = wt2_init(obj,(char*) "modwt", rows,cols, J);// Initialize the wavelet transform object
if (sym_per == 0)
setDWT2Extension(wt, (char*) "per");// Options are "per"
wavecoeffs = modwt2(wt, inp);// Perform DWT
imodwt2(wt, wavecoeffs, out);// Perform IDWT (if needed)
// Test Reconstruction
if (direct_fft == 0)
epsilon = 1e-8;
else
epsilon = 1e-10;
//BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
//printf("%g ",RMS_Error(out, inp, wt->siglength));
if (RMS_Error(out, inp, N) > epsilon) {
printf("\n ERROR : MODWT2 Reconstruction Unit Test Failed. Exiting. \n");
exit(-1);
}
wt2_free(wt);
free(wavecoeffs);
}
wave_free(obj);
delete[] name;
}
}
}
free(inp);
free(out);
}
void SWTReconstructionTest()
{
wave_object obj;
wt_object wt;
double *inp,*out;
int N, i,J;
double epsilon = 1e-15;
double err;
N = 4000;
//N = 256;
inp = (double*)malloc(sizeof(double)* N);
out = (double*)malloc(sizeof(double)* N);
//wmean = mean(temp, N);
for (i = 0; i < N; ++i) {
inp[i] = (rand() / (double)(RAND_MAX));
}
std::vector<std::string > waveletNames;
for (unsigned int j = 0; j < 15; j++)
{
waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
}
for (unsigned int j = 0; j < 5; j++)
{
waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
}
for (unsigned int j = 1; j < 10; j++)
{
waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
}
waveletNames.push_back("bior1.1");
waveletNames.push_back("bior1.3");
waveletNames.push_back("bior1.5");
waveletNames.push_back("bior2.2");
waveletNames.push_back("bior2.4");
waveletNames.push_back("bior2.6");
waveletNames.push_back("bior2.8");
waveletNames.push_back("bior3.1");
waveletNames.push_back("bior3.3");
waveletNames.push_back("bior3.5");
waveletNames.push_back("bior3.7");
waveletNames.push_back("bior3.9");
waveletNames.push_back("bior4.4");
waveletNames.push_back("bior5.5");
waveletNames.push_back("bior6.8");
waveletNames.push_back("rbior1.1");
waveletNames.push_back("rbior1.3");
waveletNames.push_back("rbior1.5");
waveletNames.push_back("rbior2.2");
waveletNames.push_back("rbior2.4");
waveletNames.push_back("rbior2.6");
waveletNames.push_back("rbior2.8");
waveletNames.push_back("rbior3.1");
waveletNames.push_back("rbior3.3");
waveletNames.push_back("rbior3.5");
waveletNames.push_back("rbior3.7");
waveletNames.push_back("rbior3.9");
waveletNames.push_back("rbior4.4");
waveletNames.push_back("rbior5.5");
waveletNames.push_back("rbior6.8");
for (unsigned int direct_fft = 0; direct_fft < 2; direct_fft++)
{
for (unsigned int sym_per = 0; sym_per < 1; sym_per++)
{
for (unsigned int j = 0; j < waveletNames.size(); j++)
{
char * name = new char[waveletNames[j].size() + 1];
memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
obj = wave_init(name);// Initialize the wavelet
for (J = 1; J < 3; J++)
{
//J = 3;
wt = wt_init(obj,(char*) "swt", N, J);// Initialize the wavelet transform object
if (direct_fft == 0)
setWTConv(wt, (char*) "direct");
else
setWTConv(wt, (char*) "fft");
if (sym_per == 0)
setDWTExtension(wt, (char*) "per");// Options are "per" and "sym". Symmetric is the default option
else if (sym_per == 1 && direct_fft == 1)
setDWTExtension(wt, (char*) "sym");
else break;
swt(wt, inp);// Perform DWT
iswt(wt, out);// Perform IDWT (if needed)
// Test Reconstruction
if (direct_fft == 0)
epsilon = 1e-8;
else
epsilon = 1e-10;
//BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
//printf("%g ",RMS_Error(out, inp, wt->siglength));
err = RMS_Error(out, inp, wt->siglength);
//printf("%d %d %g \n",direct_fft,sym_per,err);
if (err > epsilon) {
printf("\n ERROR : SWT Reconstruction Unit Test Failed. Exiting. \n");
exit(-1);
}
wt_free(wt);
}
wave_free(obj);
delete[] name;
}
}
}
free(out);
free(inp);
}
void SWT2ReconstructionTest()
{
wave_object obj;
wt2_object wt;
int i, k, J, N, rows, cols;
double *inp, *wavecoeffs,*out;
double epsilon;
rows = 1024;
cols = 1000;
N = rows*cols;
inp = (double*)malloc(sizeof(double)* N);
out = (double*)malloc(sizeof(double)* N);
std::vector<std::string > waveletNames;
for (unsigned int j = 0; j < 15; j++)
{
waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
}
for (unsigned int j = 0; j < 5; j++)
{
waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
}
for (unsigned int j = 1; j < 10; j++)
{
waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
}
waveletNames.push_back("bior1.1");
waveletNames.push_back("bior1.3");
waveletNames.push_back("bior1.5");
waveletNames.push_back("bior2.2");
waveletNames.push_back("bior2.4");
waveletNames.push_back("bior2.6");
waveletNames.push_back("bior2.8");
waveletNames.push_back("bior3.1");
waveletNames.push_back("bior3.3");
waveletNames.push_back("bior3.5");
waveletNames.push_back("bior3.7");
waveletNames.push_back("bior3.9");
waveletNames.push_back("bior4.4");
waveletNames.push_back("bior5.5");
waveletNames.push_back("bior6.8");
waveletNames.push_back("rbior1.1");
waveletNames.push_back("rbior1.3");
waveletNames.push_back("rbior1.5");
waveletNames.push_back("rbior2.2");
waveletNames.push_back("rbior2.4");
waveletNames.push_back("rbior2.6");
waveletNames.push_back("rbior2.8");
waveletNames.push_back("rbior3.1");
waveletNames.push_back("rbior3.3");
waveletNames.push_back("rbior3.5");
waveletNames.push_back("rbior3.7");
waveletNames.push_back("rbior3.9");
waveletNames.push_back("rbior4.4");
waveletNames.push_back("rbior5.5");
waveletNames.push_back("rbior6.8");
for (i = 0; i < rows; ++i) {
for (k = 0; k < cols; ++k) {
//inp[i*cols + k] = i*cols + k;
inp[i*cols + k] = generate_rnd();
out[i*cols + k] = 0.0;
}
}
for (unsigned int direct_fft = 0; direct_fft < 1; direct_fft++)
{
for (unsigned int sym_per = 0; sym_per < 1; sym_per++)
{
for (unsigned int j = 0; j < waveletNames.size(); j++)
{
char * name = new char[waveletNames[j].size() + 1];
memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
obj = wave_init(name);// Initialize the wavelet
for (J = 1; J < 3; J++)
{
//J = 3;
wt = wt2_init(obj,(char*) "swt", rows,cols, J);// Initialize the wavelet transform object
if (sym_per == 0)
setDWT2Extension(wt, (char*) "per");// Options are "per"
wavecoeffs = swt2(wt, inp);// Perform DWT
iswt2(wt, wavecoeffs, out);// Perform IDWT (if needed)
// Test Reconstruction
if (direct_fft == 0)
epsilon = 1e-8;
else
epsilon = 1e-10;
//BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
//printf("%g ",RMS_Error(out, inp, wt->siglength));
if (RMS_Error(out, inp, N) > epsilon) {
printf("\n ERROR : SWT2 Reconstruction Unit Test Failed. Exiting. \n");
exit(-1);
}
wt2_free(wt);
free(wavecoeffs);
}
wave_free(obj);
delete[] name;
}
}
}
free(inp);
free(out);
}
void DWPTReconstructionTest()
{
@ -1194,13 +740,10 @@ int main() {
RBiorCoefTests();
printf("DONE \n");
printf("Running DWT ReconstructionTests ... ");
DWTReconstructionTest();
ReconstructionTest();
printf("DONE \n");
printf("Running MODWT ReconstructionTests ... ");
MODWTReconstructionTest();
printf("DONE \n");
printf("Running SWT ReconstructionTests ... ");
SWTReconstructionTest();
printf("DONE \n");
printf("Running DWPT ReconstructionTests ... ");
DWPTReconstructionTest();
@ -1208,15 +751,6 @@ int main() {
printf("Running CWT ReconstructionTests ... ");
CWTReconstructionTest();
printf("DONE \n");
printf("Running DWT2 ReconstructionTests ... ");
DWT2ReconstructionTest();
printf("DONE \n");
printf("Running MODWT2 ReconstructionTests ... ");
MODWT2ReconstructionTest();
printf("DONE \n");
printf("Running SWT2 ReconstructionTests ... ");
SWT2ReconstructionTest();
printf("DONE \n");
printf("\n\nUnit Tests Successful\n\n");
return 0;