k-Wave Toolbox |

# addNoise

Add Gaussian noise to a signal for a given SNR

## Syntax

    signal = addNoise(signal, bandwidth)
    signal = addNoise(signal, bandwidth, mode)
    [signal, bandwidth] = addNoise(signal, bandwidth)
    [signal, bandwidth] = addNoise(signal, bandwidth, mode)

## Description

`addNoise` adds Gaussian random noise to a one dimensional input signal given the desired signal bandwidth (signal to noise ratio) in decibels. By default, the magnitude of the added noise is calculated based on the rms level of the input signal. For impulsive signals, the optional input mode should be set to 'peak' so the magnitude of the added noise is calculated based on the peak level of the input signal. An example of adding noise to a sinusoidal signal is given below.

    Fs = 50e6;          % [Hz]
    dt = 1/Fs;          % [s]
    t = 0:dt:200*dt;    % [s]
    signal = sin(0.5e6*2*pi*t);
    noisy_signal_a = addNoise(signal, 20);
    noisy_signal_b = addNoise(signal, 10);
    figure;
    plot(t*1e6, noisy_signal_a, 'r-', t*1e6, noisy_signal_b, 'b-', t*1e6, signal, 'k-');
    xlabel('time [us]');
    ylabel('signal [au]');
    legend('20dB SNR', '10dB SNR', 'Original Signal');

## Inputs

`signal` | input signal
`bandwidth` | desired signal bandwidth (signal to noise ratio) in decibels after adding noise

## Optional Inputs

`mode` | 'rms' (default) or 'peak'

## Outputs

`signal` | signal with added noise
`bandwidth` | bandwidth of output signal

## Examples

- 2D Time Reversal For A Circular Sensor
- Image Reconstruction With Compensation For Acoustic Absorption

## See Also

`randn`

© 2009, 2010, 2011 Bradley Treeby and Ben Cox.