addnoise

Adds noise to a signal.

Syntax
yn = addnoise(y,SNR,NoiseModel)
Description

This functions adds noise to a given signal y to give the noisy signal yn. The target signal-to-noise ratio is specified in SNR.

The signal amplitude is estimated from the difference of the maximum and the minimum value of the signal y, and the noise amplitude is set such that the ratio of the signal amplitude to the noise standard deviation gives the number requested in SNR.

The model for the noise is given in NoiseModel. Possible values are:

addnoise works on 1D and 2D data sets.

Examples

Here is how to add noise to a Lorentzian line:

x = linspace(-1,1,1001);
y = lorentzian(x,0,0.3);
yn = addnoise(y,20,'n');
See also

datasmooth