## 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

1. Enter `waveletAnalyzer` at the MATLAB command prompt.

2. Select Wavelet 1-D in the Wavelet Analyzer.

3. 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. 4. Click Denoise.

5. 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 default `Fixed form threshold`. Use the default 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.

6. 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);```
7. 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);```
8. 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. Load `denoiseddoppler.mat` in the MATLAB workspace. Compare `denoiseddoppler` 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

1. Enter `waveletAnalyzer` at the MATLAB command prompt.

2. Select Wavelet 1-D.

3. At the MATLAB command prompt, type

`load leleccum;`
In the Wavelet 1-D tool, select File > Import from Workspace > Import Signal. When the Import from Workspace dialog box appears, select the `leleccum` variable. Click OK to import the data.

4. Select the `sym4` wavelet, and set `Level` 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:

1. Click Denoise.

2. Under Select thresholding method, select `Rigorous SURE`.

3. Select Int. dependent threshold settings.

4. 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.

5. Click Close, and answer Yes to ```Update Thresholds?```.

6. Select Denoise.

7. 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);```

8. To avoid confusion with the MATLAB code generated in Denoise Doppler Signal, change the function definition line. Change the function definition to:

`function sigDEN = func_IDdenoise_dw1d(SIG)`
Save the MATLAB program as `func_IDdenoise_dw1d.m` in a folder on the MATLAB search path.

9. 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)```  