- Wavelet Family Types - https://www.mathworks.com/help/wavelet/ref/wavemngr.html#mw_a07c3cc5-59a0-46c7-8ec0-c26073cf6550
- Note on 'pat2cwav' function's output type - https://www.mathworks.com/help/wavelet/ref/pat2cwav.html#mw_7826d681-27a7-4ecf-87cc-09b8d1f1d16d
- Supported wavelet types by 'wdenoise' - https://www.mathworks.com/help/wavelet/ref/wdenoise.html#d126e140636
Adding a customized wavelet to DWT
16 views (last 30 days)
Show older comments
Hi everyone
I am trying to add a customized wavelet to Matlab in order to do wavelet transform (in particular, denoising a signal with wavelets). I found the following old discussion but the link to the official page provided there is broken.
I tried the solutions suggested by other users. For some reason, it did not work. Could you please take a look and let me know where it went wrong?
For your conveninence, I have attached below my code.
Thank you!
--
% Experimental data
data = [0.001 0.0013 -0.002 -0.006 -0.010 -0.011 -0.0108 ...
-0.007 -0.0107 -0.0261 -0.0461 -0.059 -0.052 -0.023 0.026 ...
0.102 0.150 0.1143 0.0347 -0.025 -0.059 -0.0725 -0.06512 ...
-0.045 -0.023 -0.012 -0.010 -0.008 -0.007 -0.005 -0.0014 -0.0007 -0.00063]
% Duration of the data
duration = 3.2 * 10^-3;
time = linspace(0, duration, length(data));
time_scaled = 1/duration * time;
% Scaling the data for better fit
scaled_data = 21 * data;
% Find the fitted wavelet
[wavelet_ap, wavelet_time, nc] = pat2cwav(scaled_data, 'polynomial', 20, 'continuous');
mother_wavelet = wavelet_ap;
mother_wavelet_time = wavelet_time;
plot(time_scaled, scaled_data, mother_wavelet_time, mother_wavelet, '--')
% Save the wavelet
save('test_wavelet.m', 'mother_wavelet', 'mother_wavelet_time');
wavelet_name = 'apwavetest5';
wavemngr('add', 'ApWaveTest5', wavelet_name, 4, '', 'test_wavelet.m', [0 1])
% Test the new wavelet on simulated data
N = 1000;
t = linspace(0, 10, N);
x = sin(t)+2*cos(t).^2;
xn = x + 0.2 * randn(1, N);
% Denoise the simulated signal with the new wavelet
xn1 = wdenoise(xn,7, ...
Wavelet= wavelet_name, ...
DenoisingMethod='Bayes', ...
ThresholdRule='Median', ...
NoiseEstimate='LevelIndependent');
0 Comments
Answers (1)
Paras Gupta
on 16 May 2024
Hi Tung,
I understand that you are facing an error while running the MATLAB script provided in the question to build a custom wavelet and denoise a signal with the created wavelet. The script provided seems to successfully build the wavelet using the 'pat2cwav' function and add the wavelet using the 'wavemngr' function. The error occurs when the 'wdenoise' function is invoked.
It is to be noted that the 'wdenoise' function only supports wavelets of type 1 (orthogonal) or type 2 (biorthogonal). However, since the 'pat2cwav' function outputs wavelets of type 4 (wavelet without a scaling function), the 'wdenoise' function errors out.
You can refer to the following documentations for more information on the same:
Hope this helps you with your work.
See Also
Categories
Find more on Discrete Multiresolution Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!