필터 지우기
필터 지우기

how to insert noise in a sine function.

조회 수: 75 (최근 30일)
sanky kumar
sanky kumar 2013년 9월 11일
eg: x = -pi:.1:pi; y = sin(x); plot(x,y) i want to add noise to this signal. help appreciated!

답변 (4개)

Image Analyst
Image Analyst 2013년 9월 11일
noisy_y = y + noiseAmplitude * rand(1, length(y));

Shashank Prasanna
Shashank Prasanna 2013년 9월 11일
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
Image Analyst
Image Analyst 2013년 9월 12일
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 2013년 9월 16일
편집: Shashank Prasanna 2013년 9월 16일
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.

댓글을 달려면 로그인하십시오.


Jan
Jan 2013년 9월 12일
편집: Jan 2013년 9월 12일
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 2013년 9월 13일
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

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by