I'm very new to all of this.

Right now I'm just trying to add a bunch of different noises to an input signal and see how they affect my signal.


This is the current output of my code:

 signal,Fs = audioread('~/Documents/Methlab/sp03-0.wav');
 %generate white noise from input signal
 [m,n] = size(signal);
 snr = input('SNR: ');
 power = input('Power[DbW] ');
 whitenoise = wgn(m,n,power)

noiseSignal = addnoise(signal,noise,snr);
%filteredSignal = 

title('Input signal')

title('White noise and signal sum')

If it helps anyone, I'm using this addnoise function to add the noise.

From what I understand if I change power and SNR the white noise should look different based on what I input right? What am I missing ?

I've tried a bunch of powers and SNR combinations. SNR being 0.0004 or 0.9 or power being 30 or 0.0003 had no effect on the signal output.

  • $\begingroup$ There are too many things going on here; it's hard to say what (if anything) is wrong. My suggestion is to look at your vector whitenoise. Does its power change when you change power? If so, the problem is not with Matlab. $\endgroup$
    – MBaz
    Nov 16 '17 at 23:35
  • $\begingroup$ This code is a bit odd. Why are you creating whitenoise ? Why you are using addnoise function instead of built-in awgn function? In which place you are receiving no difference? After VSLMS or before VSLMS? $\endgroup$ Nov 17 '17 at 5:37

So basically you have discrete samples of an audio signal previously recorded and you want to add noise to it. More specifically, you want to add white Gaussian noise (WGN) with a given power to obtain a noisy signal with a specific SNR. That's what the MATLAB function awgn do. You can use it this way:

noiseSignal  = awgn(signal,snr,'measured');

The input snr should be un dBW and the 'measured' config allows MATLAB to automatically measured the power of the input signal (signal should be a vector). The function generated then noise samples (complex or real depending on the signal input), with a power adapted to the SNR value specified, and add them to the signal samples. If you need the noise samples for a reason, you can simply do noise = noiseSignal - signal;.

For more details on the awgn function, you can look at the official documentation.

Furthermore, the noise is generated with pseudo random MATLAB functions, so if you want to always have the same noise samples you will need to have the "same" randomness each time you run the script. For example, you can do that by adding at the beginning of your script,

s = RandStream.create('mt19937ar','seed',529558); prevStream = RandStream.setGlobalStream(s);

and restoring the default randomness by adding RandStream.setGlobalStream(prevStream); at the end of your script.

Finally, typical values for SNR in dB are integers between [-10;30]. A negative SNR just means that the power of the noise is higher than the power of the signal. The values you took for the SNR (0.004 or 0.9 dB) are really closed, and you will not be able to see the difference on the graphic (but if you look at the noise samples you should). Then, based on your code, changing the power variable is useless since the addnoise function seems to modify the noise power to match the SNR value.

Hope it helped.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.