Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

This example shows how to use wavelets to denoise signals and images. Because wavelets localize features in your data to different scales, you can preserve important signal or image features while removing noise. The basic idea behind wavelet denoising, or wavelet thresholding, is that the wavelet transform leads to a sparse representation for many real-world signals and images. What this means is that the wavelet transform concentrates signal and image features in a few large-magnitude wavelet coefficients. Wavelet coefficients which are small in value are typically noise and you can "shrink" those coefficients or remove them without affecting the signal or image quality. After you threshold the coefficients, you reconstruct the data using the inverse wavelet transform.

To illustrate wavelet denoising, create a noisy "bumps" signal. In this case you have both the original signal and the noisy version.

rng default; [X,XN] = wnoise('bumps',10,sqrt(6)); subplot(211) plot(X); title('Original Signal'); AX = gca; AX.YLim = [0 12]; subplot(212) plot(XN); title('Noisy Signal'); AX = gca; AX.YLim = [0 12];

Denoise the signal down to level 4 using `wdenoise`

with default settings. `wdenoise`

uses the decimated wavelet transform. Plot the result along with the original signal.

xd = wdenoise(XN,4); figure; plot(X,'r') hold on; plot(xd) legend('Original Signal','Denoised Signal','Location','NorthEastOutside') axis tight; hold off;

You can also denoise the signal using the undecimated wavelet transform. Denoise the signal again down to level 4 using the undecimated wavelet transform. Plot the result along with the original signal.

xdMODWT = wden(XN,'modwtsqtwolog','s','mln',4,'sym4'); figure; plot(X,'r') hold on; plot(xdMODWT) legend('Original Signal','Denoised Signal','Location','NorthEastOutside') axis tight; hold off;

You see that in both cases, wavelet denoising has removed a considerable amount of the noise while preserving the sharp features in the signal. This is a challenge for Fourier-based denoising. In Fourier-based denoising, or filtering, you apply a lowpass filter to remove the noise. However, when the data has high-frequency features such as spikes in a signal or edges in an image, the lowpass filter smooths these out.

You can also use wavelets to denoise signals in which the noise is nonuniform. Import and examine a portion of a signal showing electricity consumption over time.

load leleccum; indx = 2000:3450; x = leleccum(indx); plot(x) grid on;

The signal appears to have more noise after approximately sample 500. Accordingly, you want to use different thresholding in the initial part of the signal. You can use `cmddenoise`

to determine the optimal number of intervals to denoise and denoise the signal. In this example, use the 'db3' wavelet and decompose the data down to level 3.

`[SIGDEN,~,thrParams,~,BestNbOfInt] = cmddenoise(x,'db3',3);`

Display the number of intervals and the sample values that delimit the intervals.

BestNbOfInt

BestNbOfInt = 2

thrParams{1}(:,1:2)

`ans = `*2×2*
1 412
412 1451

Two intervals were identified. The sample marking the boundary between the two segments is 412. If you plot the signal and mark the two signal segments, you see that the noise does appear different before and after sample 412.

plot(x) hold on; plot([412 412],[100 550],'r') hold off;

Plot the denoised signal.

```
plot(SIGDEN)
title('Denoised Signal')
```

You can also use wavelets to denoise images. In images, edges are places where the image brightness changes rapidly. Maintaining edges while denoising an image is critically important for perceptual quality. While traditional lowpass filtering removes noise, it often smooths edges and adversely affects image quality. Wavelets are able to remove noise while preserving the perceptually important features. First, obtain the wavelet transform of a noisy image down to level 5 using a biorthogonal spline wavelet.

load(fullfile(matlabroot,'examples','wavelet', 'jump.mat')); wname = 'bior3.5'; level = 5; [C,S] = wavedec2(jump,level,wname);

Obtain denoising (wavelet shrinkage) thresholds. Use the Birge-Massart strategy with a tuning parameter of 3.

thr = wthrmngr('dw2ddenoLVL','penalhi',C,S,3); sorh = 's'; [XDEN,cfsDEN,dimCFS] = wdencmp('lvd',C,S,wname,level,thr,sorh);

Plot the original and denoised images. Note that edges in the image are not smoothed out by the denoising process.

figure; subplot(1,2,1); imagesc(jump); colormap gray; axis off; title('Noisy Image'); subplot(1,2,2); imagesc(XDEN); colormap gray; axis off; title('Denoised Image');