Adding a customized wavelet to DWT

17 次查看(过去 30 天)
Tung
Tung 2024-5-6
评论: Tung 2024-5-30
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');

回答(1 个)

Paras Gupta
Paras Gupta 2024-5-16
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.
  1 个评论
Tung
Tung 2024-5-30
Thank you very much for the needed answer.
I have a few following-up questions.
  1. I understand that Matlab was able to create a customerized mother wavelet. How can I add scales to my wavelet to make it into type 1 and type 2?
  2. I tried the same code using continuous wavelet transform but it also does not work. Matlab told me that they expect WAVNAME to match "morse", "bump", "amor". Does that mean Matlab does not support CWT with cusomerized wavelet?
There seems to be lots of interests in this type of question. I found several threads on Mathworks where people ask similar questions (I can't find a satisfactory answers in those threads-unforuntately). So, it would be a great service to the community to have this figure out.
Thank you again.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Discrete Multiresolution Analysis 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by