mirror of
https://github.com/simon987/wavelib.git
synced 2025-04-10 14:06:46 +00:00
commit : test->denoisetest for auxiliary
This commit is contained in:
parent
1bde2f9824
commit
59bd91d4fa
@ -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")
|
||||
|
@ -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})
|
||||
|
||||
|
@ -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;
|
||||
|
@ -4,12 +4,8 @@ Copyright (c) 2017, Rafat Hussain
|
||||
#ifndef DENOISE_H_
|
||||
#define DENOISE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#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
|
||||
}
|
||||
|
103
auxiliary/waux.c
Normal file
103
auxiliary/waux.c
Normal file
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
42
auxiliary/waux.h
Normal file
42
auxiliary/waux.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* waux.h
|
||||
*
|
||||
* Created on: Aug 22, 2017
|
||||
* Author: Rafat Hussain
|
||||
*/
|
||||
|
||||
#ifndef AUXILIARY_WAUX_H_
|
||||
#define AUXILIARY_WAUX_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#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_ */
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user