### Install wavelib Library and Configuration Source: https://github.com/rafat/wavelib/blob/master/src/CMakeLists.txt This section defines the installation rules for the 'wavelib' static library and its CMake configuration files. It specifies destinations for the library archives, include files, and configuration scripts, enabling easy integration into other projects. ```cmake install(TARGETS wavelib EXPORT wavelib-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(EXPORT wavelib-targets FILE wavelib-config.cmake NAMESPACE wavelib:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wavelib) ``` -------------------------------- ### CMakeLists.txt: Install wauxlib Library and Headers Source: https://github.com/rafat/wavelib/blob/master/auxiliary/CMakeLists.txt Defines the installation rules for the 'wauxlib' library. It specifies the destination directories for the library archives and include files. ```cmake install(TARGETS wauxlib EXPORT wavelib-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ``` -------------------------------- ### DWPT/IDWPT Transform Example in C Source: https://github.com/rafat/wavelib/wiki/DWPT-Example-Code This C code demonstrates the Discrete Wavelet Packet Transform (DWPT) and Inverse Discrete Wavelet Packet Transform (IDWPT) using the wavelib library. It initializes a wavelet, performs the transform on an input signal, reconstructs the signal using the inverse transform, and calculates the difference to assess reconstruction accuracy. Dependencies include standard C libraries and the wavelib header. ```c #include #include #include #include #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; } int main() { int i, J, N; wave_object obj; wpt_object wt; double *inp, *oup, *diff; char *name = "db4"; obj = wave_init(name);// Initialize the wavelet N = 788 + 23; inp = (double*)malloc(sizeof(double)* N); oup = (double*)malloc(sizeof(double)* N); diff = (double*)malloc(sizeof(double)* N); for (i = 1; i < N + 1; ++i) { //inp[i - 1] = -0.25*i*i*i + 25 * i *i + 10 * i; inp[i - 1] = i; } J = 4; wt = wpt_init(obj, N, J);// Initialize the wavelet transform Tree object setDWPTExtension(wt, "per");// Options are "per" and "sym". Symmetric is the default option setDWPTEntropy(wt, "logenergy", 0); dwpt(wt, inp); // Discrete Wavelet Packet Transform idwpt(wt, oup); // Inverse Discrete Wavelet Packet Transform for (i = 0; i < N; ++i) { diff[i] = (inp[i] - oup[i])/inp[i]; } wpt_summary(wt); // Tree Summary printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value. free(inp); free(oup); free(diff); wave_free(obj); wpt_free(wt); return 0; } ``` -------------------------------- ### C++ SWT/ISWT Signal Processing Example Source: https://github.com/rafat/wavelib/wiki/SWT-Example-Code This C++ code demonstrates the usage of the Stationary Wavelet Transform (SWT) and its inverse (ISWT) for signal processing. It includes signal initialization, transform execution, and reconstruction verification. Dependencies include standard C libraries and the 'wavelib' header. ```c++ #include #include #include #include #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; } int main() { wave_object obj; wt_object wt; double *inp, *out, *diff; int N, i, J; FILE *ifp; double temp[1200]; char *name = "bior3.5"; obj = wave_init(name);// Initialize the wavelet ifp = fopen("signal.txt", "r"); i = 0; if (!ifp) { printf("Cannot Open File"); exit(100); } while (!feof(ifp)) { fscanf(ifp, "%lf \n", &temp[i]); i++; } N = 256; inp = (double*)malloc(sizeof(double)* N); out = (double*)malloc(sizeof(double)* N); diff = (double*)malloc(sizeof(double)* N); //wmean = mean(temp, N); for (i = 0; i < N; ++i) { inp[i] = temp[i]; //printf("%g \n",inp[i]); } J = 1; wt = wt_init(obj, "swt", N, J);// Initialize the wavelet transform object setWTConv(wt, "direct"); swt(wt, inp);// Perform SWT //SWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients for (i = 0; i < wt->outlength; ++i) { printf("%g ",wt->output[i]); } iswt(wt, out);// Perform ISWT (if needed) // Test Reconstruction for (i = 0; i < wt->siglength; ++i) { diff[i] = out[i] - inp[i]; } printf("\n MAX %g \n", absmax(diff, wt->siglength));// If Reconstruction succeeded then the output should be a small value. wt_summary(wt);// Prints the full summary. wave_free(obj); wt_free(wt); free(inp); free(out); free(diff); return 0; } ``` -------------------------------- ### CWT/ICWT Example using Morlet Wavelet in C Source: https://github.com/rafat/wavelib/wiki/CWT-Example-Code This C code snippet demonstrates a full cycle of CWT and ICWT. It initializes the CWT object with the 'morlet' wavelet, reads input data from a file, performs the CWT, prints statistical information and specific wavelet coefficients, reconstructs the signal using ICWT, and calculates the RMS error and variance of the reconstruction. It requires the wavelib header and data file 'sst_nino3.dat'. ```c #include #include #include #include #include "../header/wavelib.h" int main() { int i, N, J,subscale,a0,iter,nd,k; double *inp,*oup; double dt, dj,s0, param,mn; double td,tn,den, num, recon_mean, recon_var; cwt_object wt; FILE *ifp; double temp[1200]; char *wave = "morlet"; // Set Morlet wavelet. Other options "paul" and "dog" char *type = "pow"; N = 504; param = 6.0; subscale = 4; dt = 0.25; s0 = dt; dj = 1.0 / (double)subscale; J = 11 * subscale; // Total Number of scales a0 = 2;//power ifp = fopen("sst_nino3.dat", "r"); i = 0; if (!ifp) { printf("Cannot Open File"); exit(100); } while (!feof(ifp)) { fscanf(ifp, "%lf \n", &temp[i]); i++; } fclose(ifp); wt = cwt_init(wave, param, N,dt, J); inp = (double*)malloc(sizeof(double)* N); oúp = (double*)malloc(sizeof(double)* N); for (i = 0; i < N; ++i) { inp[i] = temp[i] ; } setCWTScales(wt, s0, dj, type, a0); cwt(wt, inp); printf("\n MEAN %g \n", wt->smean); mn = 0.0; for (i = 0; i < N; ++i) { mn += sqrt(wt->output[i].re * wt->output[i].re + wt->output[i].im * wt->output[i].im); } cwt_summary(wt); printf("\n abs mean %g \n", mn / N); printf("\n\n"); printf("Let CWT w = w(j, n/2 - 1) where n = %d\n\n", N); nd = N/2 - 1; printf("%-15s%-15s%-15s%-15s \n","j","Scale","Period","ABS(w)^2"); for(k = 0; k < wt->J;++k) { iter = nd + k * N; printf("%-15d%-15lf%-15lf%-15lf \n",k,wt->scale[k],wt->period[k], wv->output[iter].re * wt->output[iter].re + wt->output[iter].im * wt->output[iter].im); } icwt(wt, oup); num = den = recon_var = recon_mean = 0.0; printf("\n\n"); printf("Signal Reconstruction\n"); printf("%-15s%-15s%-15s \n","i","Input(i)","Output(i)"); for (i = N - 10; i < N; ++i) { printf("%-15d%-15lf%-15lf \n", i,inp[i] , oup[i]); } for (i = 0; i < N; ++i) { //printf("%g %g \n", oup[i] ,inp[i] - wt->smean); td = inp[i] ; tn = oup[i] - td; num += (tn * tn); den += (td * td); recon_mean += oup[i]; } recon_var = sqrt(num / N); recon_mean /= N; printf("\nRMS Error %g \n", sqrt(num) / sqrt(den)); printf("\nVariance %g \n", recon_var); printf("\nMean %g \n", recon_mean); free(inp); free(oup); cwt_free(wt); return 0; } ``` -------------------------------- ### MODWT2 and IMODWT2 2D Wavelet Transform Example (C) Source: https://github.com/rafat/wavelib/wiki/MODWT2-Example-Code This C code demonstrates the application of MODWT2 and IMODWT2 for 2D signals. It includes helper functions for calculating the maximum absolute difference and generating random data. The example initializes a wavelet object, performs the forward transform, extracts approximation coefficients, reconstructs the signal using the inverse transform, and prints the maximum absolute difference. ```c #include #include #include #include #include #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; } ``` -------------------------------- ### MODWT/IMODWT Example in C Source: https://github.com/rafat/wavelib/wiki/MODWT-Example-Code This C code snippet demonstrates how to perform a Maximum Overlap Discrete Wavelet Transform (MODWT) and its inverse (IMODWT) on a signal. It includes signal loading, transform initialization, forward and inverse transforms, and a reconstruction error check. Dependencies include standard C libraries and the wavelib header. ```c #include #include #include #include #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; } int main() { wave_object obj; wt_object wt; double *inp, *out, *diff; int N, i, J; FILE *ifp; double temp[1200]; char *name = "db4"; obj = wave_init(name); wave_summary(obj); ifp = fopen("signal.txt", "r"); i = 0; if (!ifp) { printf("Cannot Open File"); exit(100); } while (!feof(ifp)) { fscanf(ifp, "%lf \n", &temp[i]); i++; } N = 177; inp = (double*)malloc(sizeof(double)* N); out = (double*)malloc(sizeof(double)* N); diff = (double*)malloc(sizeof(double)* N); //wmean = mean(temp, N); for (i = 0; i < N; ++i) { inp[i] = temp[i]; //printf("%g \n",inp[i]); } J = 2; wt = wt_init(obj, "modwt", N, J);// Initialize the wavelet transform object modwt(wt, inp);// Perform MODWT //MODWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients for (i = 0; i < wt->outlength; ++i) { printf("%g ",wt->output[i]); } imodwt(wt, out);// Perform ISWT (if needed) // Test Reconstruction for (i = 0; i < wt->siglength; ++i) { diff[i] = out[i] - inp[i]; } printf("\n MAX %g \n", absmax(diff, wt->siglength));// If Reconstruction succeeded then the output should be a small value. wt_summary(wt);// Prints the full summary. wave_free(obj); wt_free(wt); free(inp); free(out); free(diff); return 0; } ``` -------------------------------- ### CMake Project Setup and Configuration Source: https://github.com/rafat/wavelib/blob/master/CMakeLists.txt Initializes the CMake project, sets the project name to 'wavelib', specifies the primary language as C, and includes necessary modules. It also defines source and build paths, and configures build type specific output directories. ```cmake cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR) set(PROJECT_NAME wavelib) project(${PROJECT_NAME} C) include(GNUInstallDirs) # 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}/header) include_directories(${PROJECT_WIDE_INCLUDE}) include_directories(${COMMON_BIN_PATH}) if(BUILD_UT) include(CTest) enable_testing() enable_language(CXX) add_subdirectory(unitTests) endif() add_subdirectory(src) add_subdirectory(auxiliary) add_subdirectory(test) install(DIRECTORY ${WAVELIB_SRC_ROOT}/header/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h") ``` -------------------------------- ### WTREE Initialization and Coefficient Extraction in C Source: https://github.com/rafat/wavelib/wiki/WTREE-Example-Code Initializes a WTREE object with a specified wavelet, performs a transform, and extracts coefficients from a specific node. It includes memory allocation and deallocation for input and output arrays, along with wavelet and WTREE object cleanup. ```c #include #include #include #include #include "../header/wavelib.h" int main() { int i, J, N, len; int X, Y; wave_object obj; wtree_object wt; double *inp, *oup; char *name = "db3"; obj = wave_init(name);// Initialize the wavelet N = 147; inp = (double*)malloc(sizeof(double)* N); for (i = 1; i < N + 1; ++i) { inp[i - 1] = -0.25*i*i*i + 25 * i *i + 10 * i; } J = 3; wt = wtree_init(obj, N, J);// Initialize the wavelet transform object setWTREEExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option wtree(wt, inp); wtree_summary(wt); X = 3; Y = 5; len = getWTREENodelength(wt, X); printf("\n %d", len); printf("\n"); o = (double*)malloc(sizeof(double)* len); printf("Node [%d %d] Coefficients : \n",X,Y); getWTREECoeffs(wt, X, Y, oup, len); for (i = 0; i < len; ++i) { printf("%g ", oup[i]); } printf("\n"); free(inp); free(oup); wave_free(obj); wtree_free(wt); return 0; } ``` -------------------------------- ### DWT2/IDWT2 Example in C Source: https://github.com/rafat/wavelib/wiki/DWT2-Example-Code This C code demonstrates the 2D Discrete Wavelet Transform (DWT2) and its inverse (IDWT2). It initializes a wavelet object, performs the transform on a generated input array, extracts and displays coefficients, reconstructs the signal, and calculates the maximum absolute difference between the original and reconstructed signals. It relies on the wavelib library. ```C #include #include #include #include #include #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; } ``` -------------------------------- ### SWT2/ISWT2 Wavelet Transform Example in C Source: https://github.com/rafat/wavelib/wiki/SWT2-Example-Code This C code demonstrates the application of SWT2 for forward wavelet transform and ISWT2 for inverse transform. It utilizes the wavelib library, initializing a wavelet object, generating random input data, performing the transform, extracting approximation coefficients (cLL), and calculating the absolute maximum difference between the original and reconstructed signals. Dependencies include standard C libraries and the wavelib header. ```C #include #include #include #include #include #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; } ``` -------------------------------- ### Wavelet Tree Decomposition (WTREE) Example Source: https://github.com/rafat/wavelib/wiki/Home Demonstrates the Fully Decimated Wavelet Tree Decomposition (WTREE). This method is highly redundant and retains all coefficients at each node, making it less suitable for compression or denoising. ```c // Example code for WTREE would go here. // Refer to the WTREE Example Code link for details. ``` -------------------------------- ### 1D Discrete Wavelet Packet Transform (DWPT/IDWPT) Example Source: https://github.com/rafat/wavelib/wiki/Home Provides an example of the 1D Discrete Wavelet Packet Transform (DWPT) and its Inverse (IDWPT). This transform is a derivative of WTREE, retaining coefficients based on entropy methods, resulting in a non-redundant transform. ```c // Example code for 1D DWPT/IDWPT would go here. // Refer to the DWPT Example Code link for details. ``` -------------------------------- ### DWT/IDWT Transformation with wavelib in C++ Source: https://github.com/rafat/wavelib/wiki/DWT-Example-Code Performs Discrete Wavelet Transform (DWT) and Inverse Discrete Wavelet Transform (IDWT) on a signal using the wavelib library. It initializes wavelet objects, reads a signal from 'signal.txt', applies DWT, then IDWT, and checks the reconstruction accuracy. Dependencies include standard C libraries and the wavelib header. ```c++ #include #include #include #include #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; } int main() { wave_object obj; wt_object wt; double *inp,*out,*diff; int N, i,J; FILE *ifp; double temp[1200]; char *name = "db4"; obj = wave_init(name);// Initialize the wavelet ifp = fopen("signal.txt", "r"); i = 0; if (!ifp) { printf("Cannot Open File"); exit(100); } while (!feof(ifp)) { fscanf(ifp, "%lf \n", &temp[i]); i++; } N = 256; inp = (double*)malloc(sizeof(double)* N); out = (double*)malloc(sizeof(double)* N); diff = (double*)malloc(sizeof(double)* N); //wmean = mean(temp, N); for (i = 0; i < N; ++i) { inp[i] = temp[i]; //printf("%g \n",inp[i]); } J = 3; wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option setWTConv(wt, "direct"); dwt(wt, inp);// Perform DWT //DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients for (i = 0; i < wt->outlength; ++i) { printf("%g ",wt->output[i]); } idwt(wt, out);// Perform IDWT (if needed) // Test Reconstruction for (i = 0; i < wt->siglength; ++i) { diff[i] = out[i] - inp[i]; } printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value. wt_summary(wt);// Prints the full summary. wave_free(obj); wt_free(wt); free(inp); free(out); free(diff); return 0; } ``` -------------------------------- ### 2D Discrete Wavelet Transform (DWT2/IDWT2) Example Source: https://github.com/rafat/wavelib/wiki/Home Demonstrates the 2D Discrete Wavelet Transform (DWT2) and its Inverse (IDWT2). This is a decimated implementation using implicit signal extension and up/downsampling. ```c // Example code for 2D DWT/IDWT would go here. // Refer to the DWT2 Example Code link for details. ``` -------------------------------- ### 1D Discrete Wavelet Transform (DWT/IDWT) Example Source: https://github.com/rafat/wavelib/wiki/Home Demonstrates the usage of the 1D Discrete Wavelet Transform (DWT) and its Inverse (IDWT) implementation. It covers implicit signal extension, up/downsampling, and options for periodic and symmetric boundary conditions. ```c // Example code for 1D DWT/IDWT would go here. // Refer to the DWT Example Code link for details. ``` -------------------------------- ### 1D Continuous Wavelet Transform (CWT/ICWT) Example Source: https://github.com/rafat/wavelib/wiki/Home Illustrates the usage of the 1D Continuous Wavelet Transform (CWT) and its generalized Inverse Transform (ICWT). This implementation is based on work by C. Torrence and G. Compo. ```c // Example code for 1D CWT/ICWT would go here. // Refer to the CWT Example Code link for details. ``` -------------------------------- ### 2D Stationary Wavelet Transform (SWT2/ISWT2) Example Source: https://github.com/rafat/wavelib/wiki/Home Shows the implementation of the 2D Stationary Wavelet Transform (SWT2) and its Inverse (ISWT2). Similar to the 1D version, it requires signal dimensions to be multiples of 2^J. ```c // Example code for 2D SWT/ISWT would go here. // Refer to the SWT2 Example Code link for details. ``` -------------------------------- ### 1D Stationary Wavelet Transform (SWT/ISWT) Example Source: https://github.com/rafat/wavelib/wiki/Home Illustrates the implementation of the 1D Stationary Wavelet Transform (SWT) and its Inverse (ISWT). Note that SWT requires signal lengths to be multiples of 2^J, where J is the decomposition level. ```c // Example code for 1D SWT/ISWT would go here. // Refer to the SWT Example Code link for details. ``` -------------------------------- ### Wavelet Tree Coefficient Storage Example (C) Source: https://github.com/rafat/wavelib/wiki/wtree-object Illustrates the storage order of coefficients in the `wt->output` vector for a two-level decomposition. Coefficients are stored level by level, from the highest decomposition level downwards, from left to right within each level. ```c // wt->output stores node coefficents beginning with Jth level from left to right. // For a two level decomposition, as shown in the figure, the coefficients are stored as - // [{2,0} {2,1} {2,2} {2,3} {1,0} {1,1}] ``` -------------------------------- ### 2D Maximal Overlap Discrete Wavelet Transform (MODWT2/IMODWT2) Example Source: https://github.com/rafat/wavelib/wiki/Home Illustrates the 2D Maximal Overlap Discrete Wavelet Transform (MODWT2) and its Inverse (IMODWT2). This undecimated transform supports signals of any size and orthogonal wavelets. ```c // Example code for 2D MODWT/IMODWT would go here. // Refer to the MODWT2 Example Code link for details. ``` -------------------------------- ### 1D Maximal Overlap Discrete Wavelet Transform (MODWT/IMODWT) Example Source: https://github.com/rafat/wavelib/wiki/Home Shows how to use the 1D Maximal Overlap Discrete Wavelet Transform (MODWT) and its Inverse (IMODWT). This transform handles signals of any length and supports orthogonal wavelets like Daubechies, Symlets, and Coiflets. ```c // Example code for 1D MODWT/IMODWT would go here. // Refer to the MODWT Example Code link for details. ``` -------------------------------- ### Download Wavelib Zip Archive Source: https://github.com/rafat/wavelib/wiki/Home This provides a direct link to download the wavelib project as a zip file, typically used for offline access or specific version retrieval. ```bash https://github.com/rafat/wavelib/archive/master.zip ``` -------------------------------- ### Configure wavelibLibTests Executable Source: https://github.com/rafat/wavelib/blob/master/unitTests/wavelibBoostTests/CMakeLists.txt Defines the wavelibLibTests executable and its source files. It also sets up the test command, dependencies, and linked libraries. ```cmake set(SOURCE_FILES tst_dwt.cpp ) add_executable(wavelibLibTests ${SOURCE_FILES} ) add_test(NAME wavelibLibTests WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test COMMAND wavelibLibTests) add_dependencies(wavelibLibTests wavelib) target_link_libraries(wavelibLibTests wavelib) target_include_directories(wavelibLibTests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../header ) install(TARGETS wavelibLibTests RUNTIME DESTINATION bin LIBRARY DESTINATION tests ARCHIVE DESTINATION tests ) ``` -------------------------------- ### Build wavelib static library with GCC on Linux Source: https://github.com/rafat/wavelib/wiki/Usage Compiles all C source files into object files and then archives them into a static library named 'libwavelib.a'. This library can then be linked to your projects. ```bash gcc -c *.c ar rcs libwavelib.a *.o ``` -------------------------------- ### Define wavelib Static Library Source: https://github.com/rafat/wavelib/blob/master/src/CMakeLists.txt This snippet defines the 'wavelib' as a static library, listing all its C source files and header files. It's a fundamental step in building the library. ```cmake include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCE_FILES conv.c cwt.c cwtmath.c hfft.c real.c wavefilt.c wavefunc.c wavelib.c wtmath.c ) set(HEADER_FILES conv.h cwt.h cwtmath.h hfft.h real.h wavefilt.h wavefunc.h wtmath.h ) add_library(wavelib STATIC ${SOURCE_FILES} ${HEADER_FILES}) ``` -------------------------------- ### Clone Wavelib Git Repository Source: https://github.com/rafat/wavelib/wiki/Home This command clones the wavelib project from its GitHub repository, allowing you to access the source code. ```bash git clone https://github.com/rafat/wavelib ``` -------------------------------- ### Get WTREE Coefficients Source: https://github.com/rafat/wavelib/wiki/wtree-object Retrieves the coefficients for a specific node at a given decomposition level. ```APIDOC ## getWTREECoeffs ### Description Retrieves the coefficients for a specific node `{X, Y}` at decomposition level `X`. ### Function Signature ```c void getWTREECoeffs(wtree_object wt, int X, int Y, double *coeffs, int N); ``` ### Parameters #### Path Parameters - **wt** (wtree_object) - The wtree object. - **X** (int) - The decomposition level (0 < X <= J). - **Y** (int) - The node index at level `X` (0 < Y < 2**J). - **coeffs** (double *) - A pointer to a buffer where the coefficients will be stored. The size of this buffer should be `N`, obtained from `getWTREENodelength(wt, X)`. - **N** (int) - The length of the coefficients buffer, typically obtained using `getWTREENodelength(wt, X)`. ``` -------------------------------- ### Get WTREE Node Length Source: https://github.com/rafat/wavelib/wiki/wtree-object Retrieves the length of the coefficients at a specific decomposition level. ```APIDOC ## getWTREENodelength ### Description Returns the number of coefficients at a specified node level `X` of the decomposition. ### Function Signature ```c int getWTREENodelength(wtree_object wt, int X); ``` ### Parameters #### Path Parameters - **wt** (wtree_object) - The wtree object. - **X** (int) - The decomposition level (0 < X <= J). ### Returns An integer representing the length of the coefficients at level `X`. ``` -------------------------------- ### Getting DWPT Coefficient Length at a Level Source: https://github.com/rafat/wavelib/wiki/wpt-object Retrieves the length of coefficients at a specified decomposition level. ```APIDOC ## getDWPTNodelength ### Description Returns the length of the coefficients at a specific level of the decomposition. ### Method C function ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **wt** (wtree_object) - The WPT or WTREE object. - **X** (int) - The decomposition level (0 < X <= J). ### Request Example ```c int getDWPTNodelength(struct wtree_object *wt, int X); ``` ### Response #### Success Response (200) - **return value** (int) - The length of the coefficients at level X. #### Response Example ```c // Get the length of coefficients at level 2 int length_at_level_2 = getDWPTNodelength(my_wpt_object, 2); ``` ``` -------------------------------- ### Build wavelib DLL with GCC on Cygwin Source: https://github.com/rafat/wavelib/wiki/Usage Compiles C source files with PIC and then creates a Dynamic Link Library (DLL) named 'libwavelib.dll'. This DLL can be used by Windows applications. ```bash gcc -c -fPIC *.c gcc -shared -o libwavelib.dll *.o ``` -------------------------------- ### Build wavelib shared library with GCC on Linux Source: https://github.com/rafat/wavelib/wiki/Usage Compiles C source files with Position Independent Code (PIC) and then creates a shared library 'libwavelib.so.1.0'. Symlinks are created for easier access. ```bash gcc -fPIC -c *.c gcc -shared -Wl,-soname,libwavelib.so.1 -o libwavelib.so.1.0 *.o ln -sf libwavelib.so.1.0 libwavelib.so ln -sf libwavelib.so.1.0 libwavelib.so.1 ``` -------------------------------- ### Getting DWPT Coefficients at a Node Source: https://github.com/rafat/wavelib/wiki/wpt-object Retrieves the specific coefficients at a given node within the WPT structure. ```APIDOC ## getDWPTCoeffs ### Description Retrieves the coefficients from a specific node {X,Y} at a given level X of the decomposition. The node must be one of the retained nodes. ### Method C function ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **wt** (wtree_object) - The WPT or WTREE object. - **X** (int) - The decomposition level (0 < X <= J). - **Y** (int) - The index of the node at level X (0 < Y < 2**J). - **coeffs** (double *) - A pointer to a pre-allocated buffer to store the coefficients. - **N** (int) - The expected length of the coefficients at node {X,Y}, obtained from `getDWPTNodelength(wt, X)`. ### Request Example ```c void getDWPTCoeffs(struct wtree_object *wt, int X, int Y, double *coeffs, int N); ``` ### Response #### Success Response (200) The `coeffs` buffer is populated with the requested coefficients. No explicit return value. #### Response Example ```c // Assuming N is obtained from getDWPTNodelength int node_length = getDWPTNodelength(my_wpt_object, 1); double *node_coefficients = (double *)malloc(node_length * sizeof(double)); if (node_coefficients != NULL) { getDWPTCoeffs(my_wpt_object, 1, 0, node_coefficients, node_length); // Use node_coefficients here free(node_coefficients); } ``` ``` -------------------------------- ### Get DWPT Node Coefficient Length Source: https://github.com/rafat/wavelib/wiki/wpt-object Retrieves the length of coefficients at a specific level of decomposition within the DWPT object. The level X must be between 1 and J (inclusive). ```c // Returns the length of the coefficients node at the level X of decomposition. // 0 < X <= J. All coefficients at each level have the same length. int getDWPTNodelength(wtree_object wt, int X); ``` -------------------------------- ### Define Executable and Link wavelib (CMake) Source: https://github.com/rafat/wavelib/blob/master/test/CMakeLists.txt This snippet demonstrates how to define a CMake executable target from a C source file and link it against the 'wavelib' library. This pattern is repeated for multiple test cases. ```cmake add_executable(cwttest cwttest.c) target_link_libraries(cwttest wavelib) ``` ```cmake add_executable(dwttest dwttest.c) target_link_libraries(dwttest wavelib) ``` ```cmake add_executable(swttest swttest.c) target_link_libraries(swttest wavelib) ``` ```cmake add_executable(modwttest modwttest.c) target_link_libraries(modwttest wavelib) ``` ```cmake add_executable(dwpttest dwpttest.c) target_link_libraries(dwpttest wavelib) ``` ```cmake add_executable(wtreetest wtreetest.c) target_link_libraries(wtreetest wavelib) ``` ```cmake add_executable(dwt2test dwt2test.c) target_link_libraries(dwt2test wavelib) ``` ```cmake add_executable(swt2test swt2test.c) target_link_libraries(swt2test wavelib) ``` ```cmake add_executable(modwt2test modwt2test.c) target_link_libraries(modwt2test wavelib) ``` -------------------------------- ### CMakeLists.txt: Build wauxlib Static Library Source: https://github.com/rafat/wavelib/blob/master/auxiliary/CMakeLists.txt Configures the build process for the 'wauxlib' static library. It specifies source files, header files, and sets the library's folder and include directories. ```cmake include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCE_FILES denoise.c waux.c ) set(HEADER_FILES waux.h) add_library(wauxlib STATIC ${SOURCE_FILES} ${HEADER_FILES}) target_link_libraries(wauxlib wavelib) set_property(TARGET wauxlib PROPERTY FOLDER "lib") target_include_directories(wauxlib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) ```