Denoise a Signal with the Wavelet Signal Denoiser

This example shows how to use the Wavelet Signal Denoiser app to denoise a real-valued 1-D signal. You can create and compare multiple versions of a denoised signal with the app and export the desired denoised signal to your MATLAB® workspace. To reproduce the denoised signal in your workspace, or to apply the same denoising parameters to other data, you can generate and edit a MATLAB script. This example illustrates one possible workflow.

Import Data into the App

Load data into the MATLAB workspace. The .mat file contains a clean version and a noisy version of a signal. Plot both versions of the signal.

load fdata
plot(fNoisy,'b-')
hold on
plot(fClean,'r-','LineWidth',2)
legend('Noisy Signal','Clean Signal')
grid on

Open the Wavelet Signal Denoiser app. From the MATLAB Toolstrip, open the Apps tab and under Signal Processing and Communications, click Wavelet Signal Denoiser. You can also start the app by typing waveletSignalDenoiser at the MATLAB command prompt.

Load the noisy signal from the workspace into the app by clicking Load Signal in the toolstrip. From the list of workspace variables that can be loaded into the app, select fNoisy and click OK.

The app imports the noisy signal and immediately denoises it using default parameters.

Examine Imported Data

Examine the fNoisy plot. The app plots the original signal, fNoisy, the denoised signal, fNoisy1, and the coarse scale approximation of the signal, Approximation.

1. The Denoised Signals pane lists all versions of the denoised signal. The list currently contains only the signal that the app created using a default name, fNoisy1.

  • You can change the default name by right-clicking it, choosing Rename Denoised Signal from the menu, entering the new name in the dialog box, and clicking OK.

  • You can delete a denoised signal by right-clicking its name and choosing Delete Denoised Signal from the pop-up menu.

2. The Current Wavelet Parameters pane lists the denoising parameters applied to create fNoisy1.

3. Zoom and pan a region of interest. First, place the cursor over the plot to reveal a floating palette.

Then select the desired action from the palette.

  • When you select to either zoom in or out, the mouse wheel controls the zoom..

4. Toggle what signals are visible in the fNoisy plot by:

  • Clicking Signals ▼ in the toolstrip and using the drop-down menu to toggle the visibility of the original and denoised signal plots.

  • Clicking individual signals in the plot legend.

5. Examine the Coefficients plot.

The coefficients in red are used to reconstruct the denoised signal. The Current Wavelet Parameters pane indicates that a 9-level wavelet decomposition was used to denoise the signal.

Zoom and pan a region of interest. First, place the cursor over the plot to reveal a floating palette. Then select the desired action from the palette.

  • When you select to either zoom in or out, the mouse wheel controls the zoom and not the scrollbar.

  • When you zoom in, zoom out, or pan in the D1 coefficients level, the zoom is applied to all levels.

Modify Denoising Parameters

Click the Wavelet tab. Use this toolstrip to adjust and apply denoising parameters for the selected denoised signal.

The values listed are the parameters used to create the denoised signal, fNoisy1. To modify the values of these settings, working from left to right in the toolstrip:

1. In the Wavelet dropdown menu, choose the Daubechies wavelet family, db. Because of this action:

  • The Number dropdown field changes to 1. Change the value to 2.

  • A banner with blue text appears immediately in the fNoisy plot, stating that the wavelet parameter changes are in draft mode. This text appears whenever you have any pending changes to a signal. The banner disappears when you either apply the changes by using the Denoise button, or navigate away from the signal to another signal.

2. From the Method dropdown menu, select Universal Threshold.

3. To define a 10-level wavelet decomposition, change the value of Level to 10.

4. By changing the Method to Universal Threshold, the Rule setting changed automatically from Median to Soft. Change the setting to Hard.

5. Click Level-Dependent.

6. Apply the new values for these settings by clicking Denoise.

The Current Wavelet Parameters pane updates with the new parameters used to denoise the signal, and the app replots the denoised signal, fNoisy1.

Note: All parameters are contextual. Possible values for one parameter can depend on the currently selected value of another parameter. You cannot make an incompatible selection. For example, when the denoising method is FDR, there is only possible thresholding rule: hard. In this instance, no other values are listed in the Rule dropdown menu.

Duplicate a Denoised Signal and Compare Approximations

If you like a particular denoised signal but want to explore more denoising parameters, you can duplicate it. You can then modify the parameters for the duplicate, without losing the original parameters.

1. From the Denoised Signals pane, select fNoisy1. Then on the toolstrip, from the Signal Denoiser tab, click Duplicate.

  • The duplicate signal, fNoisy1Copy, appears highlighted in Denoised Signals.

  • The denoising parameters for the duplicate are listed in Current Wavelet Parameters.

  • The duplicate is plotted as a thick line in the fNoisy plot. The plot legend updates to include the duplicate.

2. On the Wavelet tab, change the Level to 2, and then click Denoise. The app denoises the signal using a two-level wavelet decomposition. In addition, the app:

  • Recalculates and plots the approximation for the duplicate.

  • Updates the Coefficients plot to show the levels for the duplicate.

Because fNoisy1Copy is highlighted, its approximation is plotted. The app always plots the approximation for the currently selected denoised signal. You can demonstrate this behavior as follows. In the plot legend, click fNoisy1 and fNoisy1Copy. The names of both denoised signals fade, and the two signals are no longer plotted. Only the original signal and approximation plots are visible.

The dashed line in the plot represents the approximation. Because fNoisy1Copy is highlighted in the Denoised Signals list, the approximation plotted is the result of a two-level wavelet decomposition. The approximation is relatively noisy. Now selectfNoisy1 in the list. The approximation of a 10-level wavelet decomposition is different.

Restore Original Parameters

You can always return to using the original default parameters by adding a new denoised signal. From the toolstrip, on the Signal Denoiser tab, click Add.

  • The added denoised signal, fNoisy2, appears highlighted in the Denoised Signals list. The default denoising parameters are listed in Current Wavelet Parameters.

  • The new denoised signal is plotted as a thick line. The approximation is calculated and plotted as well. The plot legend updates to include fNoisy2.

Export Results

If you want to apply the same denoising parameters to other data, you can use the app to generate a script that reproduces the selected denoised signal. You can then modify and save the script for your own purposes. To do further analysis, you can export a denoised signal to your workspace.

Export Script

Click fNoisy2 in Denoised Signals. On the Signal Denoiser tab of the toolstrip, from the Export ▼ menu, select Generate MATLAB Script. An untitled script opens in your MATLAB Editor with the following executable code:

fNoisy2 = wdenoise(fNoisy,9, ...
    'Wavelet', 'sym4', ...
    'DenoisingMethod', 'Bayes', ...
    'ThresholdRule', 'Median', ...
    'NoiseEstimate', 'LevelIndependent');

The wdenoise input arguments are populated with the values used to create fNoisy2. Save the script and then run. This will create the variable fNoisy2 in your workspace.

Load the file fdataTS. The file contains noisy data of 100 time series. Each time series has 4096 data points. The data is contained in a type TimeTable variable called fdataTS.

load fdataTS

To apply the denoising parameters to fdataTS, edit the script by replacing fNoisy with fdataTS and fNoisy2 with fdataTSclean. Then run the script.

fdataTSclean = wdenoise(fdataTS,9, ...
    'Wavelet', 'sym4', ...
    'DenoisingMethod', 'Bayes', ...
    'ThresholdRule', 'Median', ...
    'NoiseEstimate', 'LevelIndependent');

Compare the 15th noisy time series with its denoised version.

subplot(2,1,1)
plot(fdataTS.Time,fdataTS.fTS15)
title('Original Time Series')
grid on
subplot(2,1,2)
plot(fdataTSclean.Time,fdataTSclean.fTS15)
title('Denoised Time Series')
grid on

Export Denoised Signal

Click fNoisy2 in Denoised Signals. Then on the toolstrip, from the Signal Denoiser tab, click the green check mark on Export ▼. Since fNoisy2 already exists in your workspace, you can force the export and overwrite the workspace variable. Alternatively, you can cancel the export, rename either the denoised signal in the app or the workspace variable, and export again. A banner appears confirming the signal is exported. To permanently remove the banner, either click X to close or import a new signal into the app.

Because you have the clean signal in your workspace, calculate the sign-to-noise ratio of the denoised signal.

snrWavelet = -20*log10(norm(abs(fClean-fNoisy2))/norm(fClean))
snrWavelet = 35.9623

If you have the Signal Processing Toolbox™ denoise the signal using a moving average filter and Savitzky-Golay filter and compute the SNR of each denoised signal.

fmv = smoothdata(fNoisy,'movmean',25);
snrMovingAverage = -20*log10(norm(abs(fClean-fmv))/norm(fClean))
snrMovingAverage = 26.0040
fsg = smoothdata(fNoisy,'sgolay',25);
snrSavitskyGolay = -20*log10(norm(abs(fClean-fsg))/norm(fClean))
snrSavitskyGolay = 28.8932

You achieve superior results denoising with the sym4 wavelet.