Proper way to add noise to signal

前端 未结 4 1768
情深已故
情深已故 2020-12-01 08:34

In many areas I have found that while adding noise, we mention some specification like zero mean and variance. I need to add AWGN, colored noise, uniform noise of varying SN

4条回答
  •  盖世英雄少女心
    2020-12-01 09:21

    You can use randn() to generate a noise vector 'awgnNoise' of the length you want. Then, given a specified SNR value, calculate the power of the orignal signal and the power of the noise vector 'awgnNoise'. Get the right amplitude scaling factor for the noise vector and just scale it.

    The following code is an example to corrupt signal with white noise, assuming input signal is 1D and real valued.

    function out_signal = addAWGN(signal, targetSNR)
    sigLength = length(signal); % length
    awgnNoise = randn(size(signal)); % orignal noise
    pwrSig = sqrt(sum(signal.^2))/sigLength; % signal power
    pwrNoise = sqrt(sum(awgnNoise.^2))/sigLength; % noise power
    
    scaleFactor = (pwrSig/pwrNoise)/targetSNR; %find scale factor
    awgnNoise = scaleFactor*awgnNoise; 
    out_signal = signal + awgnNoise; % add noise
    

    Be careful about the sqrt(2) factor when you deal with complex signal, if you want to generate the real and imag part separately.

提交回复
热议问题