Proper way to add noise to signal

前端 未结 4 1764
情深已故
情深已故 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:07

    This 'should not divide by 0' problem could be easily solved if you add a condition to check if targetSNR is 0 and do these only if it is not 0. When your target SNR is 0, it means it's pure noise.

    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
    if targetSNR ~= 0
       scaleFactor = (pwrSig/pwrNoise)/targetSNR; %find scale factor
       awgnNoise = scaleFactor*awgnNoise; 
       out_signal = signal + awgnNoise; % add noise
    else
       out_signal = awgnNoise; % noise only
    end
    

提交回复
热议问题