Clear Filters
Clear Filters

how to insert noise in a sine function.

82 views (last 30 days)
sanky kumar
sanky kumar on 11 Sep 2013
eg: x = -pi:.1:pi; y = sin(x); plot(x,y) i want to add noise to this signal. help appreciated!

Answers (4)

Image Analyst
Image Analyst on 11 Sep 2013
noisy_y = y + noiseAmplitude * rand(1, length(y));

Shashank Prasanna
Shashank Prasanna on 11 Sep 2013
I'd use randn because white noise or gaussian noise is more natural then uniform random noise.
noisy_y = y + noiseAmplitude * randn(1, length(y));
You don't need this but if you do have the Communication Systems Tbx, there are function that do this automatically for you. Example:
  2 Comments
Image Analyst
Image Analyst on 12 Sep 2013
I'm probably not up on the signal processing lingo but I thought both rand and randn would be white noise. They both add noise to the intensity (y value) independently for each x. The "color" of the noise I thought had to do with what the spectrum of the noise, not its amplitude. In other words it depends on how correlated it is along the x axis, not y axis. So if you had, say uniform noise that varied in offset (like a noisy sine wave or something added to your good signal) then that noise would have a spectrum that's not flat and you'd have colored noise. But if you have noise, regardless of its amplitude spectrum, that doesn't change with time, it's frequency spectrum doesn't change so it's not colored - it's white. That's why Additive White Gaussian Noise (awgn) is white (non-flat distribution) despite the fact that the amplitude noise can have a Gaussian (non-flat) PDF. And, likewise, adding uniformly distributed noise is also white (flat). Correct me if I'm totally confused.
Shashank Prasanna
Shashank Prasanna on 16 Sep 2013
Edited: Shashank Prasanna on 16 Sep 2013
You are right IA, My answer seems to suggest white and gaussian noise are the same, while infact gaussian is one form of white noise. In most engineering applications however they are used interchangeably (albeit as you point out, erroneously). This assumption is almost fundamental and holds well due to central limit theorem. Also, any further analysis (like say regression) assume normally distributed noise.

Sign in to comment.


Jan
Jan on 12 Sep 2013
Edited: Jan on 12 Sep 2013
rand or randn might be sufficient. But 1:length(y) is true noise also and can be 100% natural.
There is no unique definition of noise and therefore asking for "adding noise" is not enough information to find a meaningful answer. Please explain what kind of noise you need and e.g. the purpose of the noise. You can add noise to the Y-values, but to the X-values also, or to both.
Notice that even y = sin(-pi:.1:pi) contains noise already, because due to the limited precision (tiny effect) of double 's and the low sampling rate (huge effect) the resulting vector does not sound like a clean sinus signal when you feed wavplay with it.

W. Owen Brimijoin
W. Owen Brimijoin on 13 Sep 2013
Provided what you are looking for is white noise, then Image Analyst's solution:
noisy_y = y + noiseAmplitude * rand(1, length(y));
...will get you most of the way there, with one caveat. This method will add noise with only a positive sign, thus introducing a DC offset to your signal that's on average noiseAmpitude/2.
I might suggest a simple addition to this line that removes this offset (and I've also reoriented the noise array dimension so that it adds properly):
noisy_y = y + noiseAmplitude * 2*(rand(length(y),1)-.5);
If you are looking for other forms of noise (pink or otherwise), you might try peeking at:
<http://www.mathworks.com/matlabcentral/fileexchange/37376-oscillator-and-signal-generator>
on the FileExchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!