how to insert noise in a sine function.
102 次查看(过去 30 天)
显示 更早的评论
eg: x = -pi:.1:pi; y = sin(x); plot(x,y) i want to add noise to this signal. help appreciated!
0 个评论
回答(4 个)
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
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
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
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.
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!