From 59bd91d4fa2af6ac17908b29fd65c022d4424f95 Mon Sep 17 00:00:00 2001 From: Rafat Hussain Date: Tue, 22 Aug 2017 14:42:57 +0530 Subject: [PATCH] commit : test->denoisetest for auxiliary --- CMakeLists.txt | 2 +- auxiliary/CMakeLists.txt | 10 ++-- auxiliary/denoise.c | 100 ------------------------------------- auxiliary/denoise.h | 10 +--- auxiliary/waux.c | 103 +++++++++++++++++++++++++++++++++++++++ auxiliary/waux.h | 42 ++++++++++++++++ test/denoisetest.c | 2 +- 7 files changed, 155 insertions(+), 114 deletions(-) create mode 100644 auxiliary/waux.c create mode 100644 auxiliary/waux.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2271db2..d4f76ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,6 @@ if(BUILD_UT) endif() add_subdirectory(src) -add_subdirectory(denoise) +add_subdirectory(auxiliary) install(DIRECTORY ${WAVELIB_SRC_ROOT}/include/ DESTINATION include FILES_MATCHING PATTERN "*.h") diff --git a/auxiliary/CMakeLists.txt b/auxiliary/CMakeLists.txt index fda632d..ba87b7b 100644 --- a/auxiliary/CMakeLists.txt +++ b/auxiliary/CMakeLists.txt @@ -1,16 +1,18 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCE_FILES denoise.c + waux.c ) set(HEADER_FILES denoise.h + waux.h ) -add_library(denoiselib STATIC ${SOURCE_FILES} ${HEADER_FILES}) +add_library(wauxlib STATIC ${SOURCE_FILES} ${HEADER_FILES}) -target_link_libraries(denoiselib wavelib) +target_link_libraries(wauxlib wavelib) -set_property(TARGET denoiselib PROPERTY FOLDER "lib") +set_property(TARGET wauxlib PROPERTY FOLDER "lib") -target_include_directories(denoiselib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(wauxlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/auxiliary/denoise.c b/auxiliary/denoise.c index da517d4..b5e9311 100644 --- a/auxiliary/denoise.c +++ b/auxiliary/denoise.c @@ -1,106 +1,6 @@ #include "denoise.h" -int compare_double(const void* a, const void* b) -{ - double arg1 = *(const double*)a; - double arg2 = *(const double*)b; - - if (arg1 < arg2) return -1; - if (arg1 > arg2) return 1; - return 0; - -} - -double median(double *x, int N) { - double sigma; - - qsort(x, N, sizeof(double), compare_double); - - if ((N % 2) == 0) { - sigma = (x[N/2 - 1] + x[N/2] ) / 2.0; - } else { - sigma = x[N/2]; - } - - return sigma; -} - -double mad(double *x, int N) { - double sigma; - int i; - - sigma = median(x,N); - - for(i = 0; i < N;++i) { - x[i] = (x[i] - sigma) > 0 ? (x[i] - sigma) : -(x[i] - sigma); - } - - sigma = median(x,N); - - return sigma; -} - -int minindex(double *arr, int N) { - double min; - int index,i; - - min = DBL_MAX; - index = 0; - for(i = 0; i < N;++i) { - if (arr[i] < min) { - min = arr[i]; - index = i; - } - } - - return index; - -} - -void getDWTAppx(wt_object wt, double *appx,int N) { - /* - Wavelet decomposition is stored as - [A(J) D(J) D(J-1) ..... D(1)] in wt->output vector - - Length of A(J) , N = wt->length[0] - */ - int i; - - for (i = 0; i < N; ++i) { - appx[i] = wt->output[i]; - } -} - -void getDWTDetail(wt_object wt, double *detail, int N, int level) { - /* - returns Detail coefficents at the jth level where j = 1,2,.., J - and Wavelet decomposition is stored as - [A(J) D(J) D(J-1) ..... D(1)] in wt->output vector - Use getDWTAppx() to get A(J) - Level 1 : Length of D(J), ie N, is stored in wt->length[1] - Level 2 :Length of D(J-1), ie N, is stored in wt->length[2] - .... - Level J : Length of D(1), ie N, is stored in wt->length[J] - */ - int i, iter, J; - J = wt->J; - - if (level > J) { - printf("The decomposition only has %d levels", J); - } - - iter = wt->length[0]; - - for (i = 1; i < level; ++i) { - iter += wt->length[i]; - } - - for (i = 0; i < N; ++i) { - detail[i] = wt->output[i + iter]; - } -} - void visushrink(double *signal,int N,int J,char *wname,char *method,char *ext,char *thresh,double *denoised) { int filt_len,iter,i,dlen,dwt_len,sgn, MaxIter; double sigma,td,tmp; diff --git a/auxiliary/denoise.h b/auxiliary/denoise.h index b576620..004a84d 100644 --- a/auxiliary/denoise.h +++ b/auxiliary/denoise.h @@ -4,12 +4,8 @@ Copyright (c) 2017, Rafat Hussain #ifndef DENOISE_H_ #define DENOISE_H_ -#include -#include -#include -#include -#include -#include "../header/wavelib.h" + +#include "waux.h" #ifdef __cplusplus extern "C" { @@ -20,8 +16,6 @@ void visushrink(double *signal,int N,int J,char *wname,char *method,char *ext,ch void sureshrink(double *signal,int N,int J,char *wname,char *method,char *ext,char *thresh,double *denoised); -double mad(double *x, int N); - #ifdef __cplusplus } diff --git a/auxiliary/waux.c b/auxiliary/waux.c new file mode 100644 index 0000000..2249b7f --- /dev/null +++ b/auxiliary/waux.c @@ -0,0 +1,103 @@ +#include "waux.h" + +int compare_double(const void* a, const void* b) +{ + double arg1 = *(const double*)a; + double arg2 = *(const double*)b; + + if (arg1 < arg2) return -1; + if (arg1 > arg2) return 1; + return 0; + +} + +double median(double *x, int N) { + double sigma; + + qsort(x, N, sizeof(double), compare_double); + + if ((N % 2) == 0) { + sigma = (x[N/2 - 1] + x[N/2] ) / 2.0; + } else { + sigma = x[N/2]; + } + + return sigma; +} + +double mad(double *x, int N) { + double sigma; + int i; + + sigma = median(x,N); + + for(i = 0; i < N;++i) { + x[i] = (x[i] - sigma) > 0 ? (x[i] - sigma) : -(x[i] - sigma); + } + + sigma = median(x,N); + + return sigma; +} + +int minindex(double *arr, int N) { + double min; + int index,i; + + min = DBL_MAX; + index = 0; + for(i = 0; i < N;++i) { + if (arr[i] < min) { + min = arr[i]; + index = i; + } + } + + return index; + +} + +void getDWTAppx(wt_object wt, double *appx,int N) { + /* + Wavelet decomposition is stored as + [A(J) D(J) D(J-1) ..... D(1)] in wt->output vector + + Length of A(J) , N = wt->length[0] + */ + int i; + + for (i = 0; i < N; ++i) { + appx[i] = wt->output[i]; + } +} + +void getDWTDetail(wt_object wt, double *detail, int N, int level) { + /* + returns Detail coefficents at the jth level where j = 1,2,.., J + and Wavelet decomposition is stored as + [A(J) D(J) D(J-1) ..... D(1)] in wt->output vector + Use getDWTAppx() to get A(J) + Level 1 : Length of D(J), ie N, is stored in wt->length[1] + Level 2 :Length of D(J-1), ie N, is stored in wt->length[2] + .... + Level J : Length of D(1), ie N, is stored in wt->length[J] + */ + int i, iter, J; + J = wt->J; + + if (level > J) { + printf("The decomposition only has %d levels", J); + } + + iter = wt->length[0]; + + for (i = 1; i < level; ++i) { + iter += wt->length[i]; + } + + for (i = 0; i < N; ++i) { + detail[i] = wt->output[i + iter]; + } +} + + diff --git a/auxiliary/waux.h b/auxiliary/waux.h new file mode 100644 index 0000000..b6fd83e --- /dev/null +++ b/auxiliary/waux.h @@ -0,0 +1,42 @@ +/* + * waux.h + * + * Created on: Aug 22, 2017 + * Author: Rafat Hussain + */ + +#ifndef AUXILIARY_WAUX_H_ +#define AUXILIARY_WAUX_H_ + +#include +#include +#include +#include +#include +#include "../header/wavelib.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +int compare_double(const void* a, const void* b); + +double median(double *x, int N); + +double mad(double *x, int N); + +int minindex(double *arr, int N); + +void getDWTAppx(wt_object wt, double *appx,int N); + +void getDWTDetail(wt_object wt, double *detail, int N, int level); + + +#ifdef __cplusplus +} +#endif + + + +#endif /* AUXILIARY_WAUX_H_ */ diff --git a/test/denoisetest.c b/test/denoisetest.c index 4f6e69c..c64377b 100644 --- a/test/denoisetest.c +++ b/test/denoisetest.c @@ -5,7 +5,7 @@ #include "../header/denoise.h" int main() { - // gcc -Wall -I../header -L../Bin denoisetest.c -o denoise -ldenoiselib -lwavelib -lm + // gcc -Wall -I../header -L../Bin denoisetest.c -o denoise -lwauxlib -lwavelib -lm double *inp,*oup; int i,N,J; FILE *ifp,*ofp;