Adding a customized wavelet to DWT
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.
https://www.mathworks.com/matlabcentral/answers/75397-adding-custom-wavelets-to-cwt
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’);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.
https://www.mathworks.com/matlabcentral/answers/75397-adding-custom-wavelets-to-cwt
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’); 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.
https://www.mathworks.com/matlabcentral/answers/75397-adding-custom-wavelets-to-cwt
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’); wavelet, signal processing MATLAB Answers — New Questions