# How to create Gauss noise within the interval

조회 수: 28(최근 30일)
David Kusnirak 2013년 9월 17일
I have an interval with lower boundary at a = -0.005 and upper boundary b = 0.005. I need to create the Gauss white noise within this interval. For uniformly distributed pseudorandom numbers (generated by rand) it is clear e.g.:
r = a + (b-a).*rand(100,1);
however it does not work for randn function.I need some way how to produce the Gaussian noise in given interval. Is there any way how to do it?
thanks

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

### 채택된 답변

Image Analyst 2013년 9월 17일
One (inefficient) way is to just create more than you need and throw away any outside the range. Of course this might make it not purely Gaussian anymore
% Generate the numbers.
mu=2;
sigma = 4;
r = mu + sigma .* randn(1000,1);
% Define range we want
a = -7;
b = 9;
badNumbers = r < a | r > b;
numberOfElementsNow = numel(r)
% Define how many you need
numElementsNeeded = 400;
% Get them
if numElementsNeeded < numberOfElementsNow
r = r(1:numElementsNeeded);
numberOfElementsNow = numel(r)
else
% Tack some more on and try again.
end

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

### 추가 답변(2개)

Daniel Shub 2013년 9월 17일
What you are looking for is typically called a Truncated Gaussian. There is a highly rated FEX:submission
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Laurent 2013년 9월 17일
This is not possible, since the output of randn can be in principle any value between -Inf and +Inf.
Depending on what you want you could set the width of the gaussian to a reasonable value (for example sigma=0.005) and then later clip values outside of your interval to the border values.

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

### 범주

Find more on Polynomials in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by