If you're looking to denoise a signal using 'wavedec' and 'waverec', you can follow these primary steps:
- Perform a Multilevel Wavelet Decomposition: Decompose the signal into multiple levels using wavelets.
- Identify a Thresholding Technique: Choose a method for thresholding the wavelet coefficients.
- Threshold and Reconstruct: Apply the chosen thresholding technique to the coefficients and reconstruct the denoised signal.
For a 3-level decomposition, the size of the bookkeeping vector will be 5x1. Hereby attaching 3-level decomposition diagram from documentation for reference. This vector includes the length of the wavelet decomposition vector at each level and the length of the original signal. In a typical decomposition, the first level's coefficients are stored at the end of the Wavelet Decomposition Vector (C). If noise is primarily in the first two levels, you would need to threshold the last two sections of coefficients (cD1 and cD2).
There are several thresholding techniques available, such as Univeral Threshold, SureShring (or 'rigsure') method, Heursure and minimax methods. 'wdenoise' is the built-in denoising function where technique name can be used as an argument . Alternatively, the 'wthresh' function from wavelet toolbox can be used to apply thresholding after manually determining the threshold.
Below is a sample MATLAB code of denoising using 'wavedec' and 'wdenoise' function.
[C, L] = wavedec(signal, level, wname);
denoiseusinginbuiltfunction = wdenoise(signal, level, DenoisingMethod="UniversalThreshold");
plot(signal, 'r', 'DisplayName', 'Noisy Signal');
plot(denoiseusinginbuiltfunction, 'b', 'DisplayName', 'Denoised Signal (Inbuilt)');
title('Noisy vs. Denoised Signal (Inbuilt Function)');
sigma = median(abs(C(L(5)-L(4):L(4)))) / 0.6745;
threshold = sigma * sqrt(2 * log(length(signal)));
start_idx = sum(L(1:i)) + 1;
C(start_idx:end_idx) = wthresh(C(start_idx:end_idx), 's', threshold);
denoised_signal = waverec(C, L, wname);
plot(signal, 'r', 'DisplayName', 'Noisy Signal');
plot(denoised_signal, 'b', 'DisplayName', 'Denoised Signal (Manual)');
title('Noisy vs. Manually Denoised Doppler Signal');
You can also use Wavelet Signal Denoiser app for visualizing and denoising real-valued 1-D signals by running following command
To know more about thresholding, please refer to the following documentation
I hope it helps!