Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Generate noise model[Please help]

Subject: Generate noise model[Please help]

From: Daniel

Date: 19 Aug, 2010 20:04:19

Message: 1 of 8

May i know how to generate Rayleigh noise model using randn function..
Thanks

Subject: Generate noise model[Please help]

From: Walter Roberson

Date: 19 Aug, 2010 20:42:08

Message: 2 of 8

On 10-08-19 03:04 PM, Daniel wrote:
> May i know how to generate Rayleigh noise model using randn function..


http://en.wikipedia.org/wiki/Rayleigh_distribution

and look under "Related Distributions"

Subject: Generate noise model[Please help]

From: Grzegorz

Date: 19 Aug, 2010 20:50:33

Message: 3 of 8

Daniel <romegoh@hotmail.com> wrote in message <2039352140.31930.1282248289923.JavaMail.root@gallium.mathforum.org>...
> May i know how to generate Rayleigh noise model using randn function..
> Thanks

Equation from raylrnd function:

r = sqrt(randn().^2 + randn().^2) .* b;

where b>0 is Rayleigh distribution parameter.

Subject: Generate noise model[Please help]

From: Daniel

Date: 19 Aug, 2010 21:43:33

Message: 4 of 8

Thanks for prompt reply.However,I am sorry because I am really new to matlab, can I have a clear instruction on how to create the model.I have no idea on what I can do with the equation.

Subject: Generate noise model[Please help]

From: Walter Roberson

Date: 19 Aug, 2010 22:15:23

Message: 5 of 8

On 10-08-19 04:43 PM, Daniel wrote:
> Thanks for prompt reply.However,I am sorry because I am really new to matlab, can I have a clear instruction on how to create the model.I have no idea on what I can do with the equation.

RR = @(X) sqrt(X * X.');

randRayleigh = RR(randn(1,2));

Subject: Generate noise model[Please help]

From: ImageAnalyst

Date: 19 Aug, 2010 23:16:32

Message: 6 of 8

On Aug 19, 5:43 pm, Daniel <rome...@hotmail.com> wrote:
> Thanks for prompt reply.However,I am sorry because I am really new to matlab, can I have a clear instruction on how to create the model.I have no idea on what I can do with the equation.

--------------------------------------------------------------------------------
Daniel:
Did they teach you how to generate such a distribution using the well
known method of inverting the CDF of the desired probability function
to get a function that can generate random numbers drawn from that
desired distribution function, given as input numbers that have been
drawn from a uniform distribution? If not, it's something you
*should* know because it's a very useful technique for getting random
numbers from almost any probability density function. I illustrate
this method below. Not exactly sure what you were hoping to do with
it, but this is one thing you can do with the equation.
IMPORTANT: THE NEWSREADER MAY SPLIT SOME LONG LINES INTO TWO, AND
YOU'LL HAVE TO RE-JOIN THOSE LINES TOGETHER INTO A SINGLE LINE.

% Script to generate random numbers drawn from a Rayleigh
distribution.
% Uses the well known method of inverting the CDF of the desired
probability
% function to get a function that can generate random numbers drawn
% from that desired distribution function,
% given as input numbers that have been drawn from a uniform
distribution.
% by ImageAnalyst

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end

% Plot the Rayleigh cumulative distribution function
% over the range 0-20 with a sigma of 5.
x = 0:20;
sigma = 5;
rayleighCDF = 1 - exp(-x.^2 / (2*sigma^2));

subplot(3,1,1);
plot(x, rayleighCDF, 'LineWidth', 3);
caption = sprintf('Rayleigh CDF with sigma = %.2f', sigma);
title(caption, 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

% Ask user for a number of random numbers to generate.
userPrompt = 'Enter an integer number of random numbers to generate';
caNumberOfRandoms = inputdlg(userPrompt, 'Enter an integer',1,
{'1000'});
numberOfRandoms = str2num(cell2mat(caNumberOfRandoms));

% Generate numberOfRandoms uniformly distributed random numbers.
uniformlyDistributedRandomNumbers = rand(numberOfRandoms, 1);
subplot(3,2,3);
bar(uniformlyDistributedRandomNumbers);
xlim([0 numberOfRandoms]);
caption = sprintf('%d Uniformly Distributed Numbers',
numberOfRandoms);
title(caption, 'FontSize', fontSize);

%-----------------------------------------------------------------
% KEY PART, RIGHT HERE!!!!
% Invert the CDF of the Rayleigh function to get a function that can
% generate random numbers drawn from a Rayleigh distribution,
% given numbers drawn from a uniform distribution.
rayleighDistNumbers = sqrt(-log(1-
uniformlyDistributedRandomNumbers)*(2*sigma^2));
%-----------------------------------------------------------------

% Plot the Rayleigh distributed numbers.
subplot(3,2,4);
bar(rayleighDistNumbers);
xlim([0 numberOfRandoms]);
caption = sprintf('%d Rayleigh Distributed Numbers', numberOfRandoms);
title(caption, 'FontSize', fontSize);

% Get histogram of uniformly distributed numbers.
[countsU, binsU] = hist(uniformlyDistributedRandomNumbers, 50);
% Plot the uniformly distributed numbers.
subplot(3,2,5);
bar(binsU, countsU);
caption = sprintf('Histogram of %d Uniformly Distributed Numbers',
numberOfRandoms);
title(caption, 'FontSize', fontSize);

% Get histogram of Rayleigh distributed numbers.
% Observe that it's distribution is not flat like it is
% for the uniformly distributed numbers.
% It will take on the Rayleigh distribution shape.
[countsR, binsR] = hist(rayleighDistNumbers, 50);
subplot(3,2,6);
bar(binsR, countsR);
caption = sprintf('Histogram of %d Rayleigh Distributed Numbers',
numberOfRandoms);
title(caption, 'FontSize', fontSize);

Subject: Generate noise model[Please help]

From: Daniel

Date: 21 Aug, 2010 12:44:06

Message: 7 of 8

I am sorry I think you get me wrong.The problem is about image processing not mathematic.I need to read in an image and generate the Rayleigh noise model from the image given that the noise is model by the pdf as written in the link below http://www.bioen.utah.edu/wiki/index.php?title=Noise_modeling_and_Probability_Theory ...pls help..thx

Subject: Generate noise model[Please help]

From: ImageAnalyst

Date: 21 Aug, 2010 21:38:55

Message: 8 of 8

On Aug 21, 8:44 am, Daniel <rome...@hotmail.com> wrote:
> I am sorry I think you get me wrong.The problem is about image processing not mathematic.I need to read in an image and generate the Rayleigh noise model from the image given that the noise is model by the pdf as written in the link belowhttp://www.bioen.utah.edu/wiki/index.php?title=Noise_modeling_and_Pro......pls help..thx

----------------------------------------------------------
Daniel:
I don't think I got you wrong. I gave you the general method for
getting random numbers taken from whatever distribution you want.
Basically you integrate the pdf to get the cdf, invert it, and plug in
a uniform distribution. And I gave code to do that. That's the basic
recipe that will work for any pdf. Of course it's easier if you know
the analytical form for the noise, like we do for the Rayleigh (I took
it from the website Walter mentioned.) But you could do it
numerically if you had only an empirical pdf function.

What you have not given is how that noise relates to the pixel value.
Is it additive noise, where all the Rayleigh noise comes from the same
distribution with some mean that is independent of the pixel value?
Or is it value-dependent noise, for example the mean of the Rayleigh
distribution should be the pixel value, and so you need to adjust your
noise-generating function for a new mean each time you encounter a new
pixel value? Can you answer that? Because there is no "right" answer
that I know of. I suspect it may be the latter but you could define
it to work however you want - not that that necessarily corresponds
with reality, but you could do it.
ImageAnalyst

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us