Generate MATLAB Code for 1-D Decimated Wavelet Denoising and Compression
Note
The Wavelet 1-D — Denoising tool is no longer recommended. Use Wavelet Signal Denoiser instead.
Wavelet 1-D Denoising
You can generate MATLAB® code to reproduce app-based 1-D wavelet denoising at the command line. You must perform this operation in the Wavelet 1-D - - Denoising tool. You must first denoise your signal before you can enable the File > Generate MATLAB Code (Denoising Process) operation.
The generated MATLAB code does not include the calculation of the thresholds using
thselect
or wbmpen
.
Denoise Doppler Signal
Enter
waveletAnalyzer
at the MATLAB command prompt.Select Wavelet 1-D in the Wavelet Analyzer.
Load the noisy Doppler example analysis. Select File > Example Analysis > Noisy Signals - Constant Noise Variance > with sym4 at level 5 - - -> Noisy Doppler.
After selecting the analysis, the wavelet decomposition appears.
Click Denoise.
The original details coefficients appear on the left side of the display. In order to time align decomposition levels across all scales, wavelet coefficients are replicated at each scale to account for the missing time points. Therefore, as the scale becomes coarser, the coefficients assume a staircase-like appearance.
In the
Select thresholding method
drop-down menu, select the defaultFixed form threshold
. Use the default soft option. Set the thresholds by level as follows:level 5 — 3.500
level 4 — 3.720
level 3 — 3.000
level 2 — 2.000
level 1 — 3.000
Click Denoise.
Generate the MATLAB code by selecting File > Generate MATLAB Code (Denoising Process).
The operation generates the following MATLAB code.
function sigDEN = func_denoise_dw1d(SIG) % FUNC_DENOISE_DW1-D Saved Denoising Process. % SIG: vector of data % ------------------- % sigDEN: vector of denoised data % Analysis parameters. %--------------------- wname = 'sym4'; level = 5; % Denoising parameters. %---------------------- % meth = 'sqtwolog'; % scal_or_alfa = one; sorh = 's'; % Specified soft or hard thresholding thrParams = [... 3.00000000 ; ... 2.00000000 ; ... 3.00000000 ; ... 3.72000000 ; ... 3.50000000 ... ]; % Denoise using CMDDENOISE. %-------------------------- sigDEN = cmddenoise(SIG,wname,level,sorh,NaN,thrParams);
Save
func_denoise_dw1d.m
in a folder on the MATLAB search path. Execute the following code.load noisdopp; SIG = noisdopp; % func_denoise_dw1d.m is generated code sigDEN = func_denoise_dw1d(SIG);
Export the denoised signal from the app by selecting File > Save > Denoised Signal.
Save the denoised signal as
denoiseddoppler.mat
in a folder on the MATLAB search path. Loaddenoiseddoppler.mat
in the MATLAB workspace. Comparedenoiseddoppler
with your command line result.load denoiseddoppler; plot(sigDEN,'k'); axis tight; hold on; plot(denoiseddoppler,'r'); legend('Command Line','GUI','Location','SouthEast');
Interval Dependent 1-D Wavelet Denoising
Enter
waveletAnalyzer
at the MATLAB command prompt.Select Wavelet 1-D.
At the MATLAB command prompt, type
In the Wavelet 1-D tool, select File > Import from Workspace > Import Signal. When the Import from Workspace dialog box appears, select theload leleccum;
leleccum
variable. Click OK to import the data.Select the
sym4
wavelet, and setLevel
equal to 3. Click Analyze.
When you inspect the original signal and the finest-scale wavelet coefficients, you see that the noise variance is not constant. In this situation, interval-dependent thresholding is useful. To implement interval-dependent denoising:
Click Denoise.
Under Select thresholding method, select
Rigorous SURE
.Select Int. dependent threshold settings.
In the Interval Dependent Threshold Settings for Wavelet 1-D tool, choose Generate Default Intervals. Three intervals are created. Click Propagate to propagate the intervals to all levels.
Click Close, and answer Yes to
Update Thresholds?
.Select Denoise.
Generate the MATLAB code by selecting File > Generate MATLAB Code (Denoising Process).
The operation generates the following MATLAB code.
function sigDEN = func_denoise_dw1d(SIG) % FUNC_DENOISE_DW1D Saved Denoising Process. % SIG: vector of data % ------------------- % sigDEN: vector of denoised data % Analysis parameters. %--------------------- wname = 'sym4'; level = 3; % Denoising parameters. %---------------------- % meth = 'rigrsure'; % scal_or_alfa = one; sorh = 's'; % Specified soft or hard thresholding thrSettings = {... [... 1.000000000000000 2410.000000000000000 5.659608351110114; ... 2410.000000000000000 3425.000000000000000 19.721391195242880; ... 3425.000000000000000 4320.000000000000000 4.907947952868359; ... ]; ... [... 1.000000000000000 2410.000000000000000 5.659608351110114; ... 2410.000000000000000 3425.000000000000000 5.659608351110114; ... 3425.000000000000000 4320.000000000000000 5.659608351110114; ... ]; ... [... 1.000000000000000 2410.000000000000000 5.659608351110114; ... 2410.000000000000000 3425.000000000000000 5.659608351110114; ... 3425.000000000000000 4320.000000000000000 5.659608351110114; ... ]; ... }; % Denoise using CMDDENOISE. %-------------------------- sigDEN = cmddenoise(SIG,wname,level,sorh,NaN,thrSettings);
To avoid confusion with the MATLAB code generated in Denoise Doppler Signal, change the function definition line. Change the function definition to:
Save the MATLAB program asfunction sigDEN = func_IDdenoise_dw1d(SIG)
func_IDdenoise_dw1d.m
in a folder on the MATLAB search path.Save the denoised signal as
denoisedleleccum.mat
with File > Save > Denoised Signal in a folder on the MATLAB search path.
Execute the following code.
load leleccum; load denoisedleleccum; sigDEN = func_IDdenoise_dw1d(leleccum); plot(sigDEN,'k'); hold on; plot(denoisedleleccum,'r'); legend('Command Line','GUI'); norm(sigDEN-denoisedleleccum,2)
See Also
Wavelet Signal
Denoiser | wdenoise