Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to generate a uniformly distributed signal in Matlab?

Status
Not open for further replies.

leoren_tm

Advanced Member level 1
Joined
Dec 19, 2005
Messages
466
Helped
11
Reputation
22
Reaction score
7
Trophy points
1,298
Activity points
4,305
pls help me in matlab..

how can i generate a uniformly distributed signal with a specific mean and STD...

Code:
rand
this funtion generate a uniformely distributed signal with a 0 mean and 1 variance
while
Code:
randn
this function generate a normaly distributed signal, which you could chose its mean and STD..(standard deviation)
 

Re: pls help me in matlab..

MATLAB has subsystem SIMULINK for simulation of different systems.
SIMULINK has "Uniform Random Number" block for your task.
This block is placed in Simulink/Sources section.
 

pls help me in matlab..

Hi

Starting from a zero mean and unity standard deviation random generated numbe n, you can find what you want multiplying by the desired standard deviation std and adding the desired mean m, so that

New_n = n*std+m;

cheers

Sal
 

Re: pls help me in matlab..

gevy said:
MATLAB has subsystem SIMULINK for simulation of different systems.
SIMULINK has "Uniform Random Number" block for your task.
This block is placed in Simulink/Sources section.

not in simulink....

Added after 1 minutes:

Sal said:
Hi

Starting from a zero mean and unity standard deviation random generated numbe n, you can find what you want multiplying by the desired standard deviation std and adding the desired mean m, so that

New_n = n*std+m;

cheers

Sal

wat do meean??? how can i use rand function with that??
 

Re: pls help me in matlab..

A uniform distribution with a given "width" has a fixed variance , its not a parameter you can pick. You can however, set the width of your pdf (which will alter the variance). See picture below.

If you want to increase the variance, you can do it by increasing Delta.

94_1160803435.JPG


As delta --> higher, variance goes up with the square of delta.

I believe typing "rand(1)" returns a number thats uniformly distributed between 0 and 1.
--> delta in this case is 1 , so its variance is 1/12. the mean is 0.5 .

If you wanted a uniform distribution with a variance of 9/12 , you can get the result by " 3*rand(1) "

why? well.. remember, variance scales with the square of the multiplication factor.
(the delta is 3 times larger... but variance is delta^2/12, so the variance increases by a factor of 9). Whats the new mean? its 3*0.5 = 1.5 . What if you wanted the mean to be some other number? simply add the different to 1.5 .


Suppose i wanted the new mean to be 2 (and variance of 9/12) , i would simply add 0.5 to the result.

newNumber = rand(1)*3 + 0.5

this has a pdf that looks like :
74_1160804090.JPG



Sal is right... just that rand(1) doesnt return a 0 mean . But you can use 'rand(1)-0.5' and use what sal suggested.

Good luck
 

Re: pls help me in matlab..

hmm...i was trying to generate a uniformly distributed signal, with a variance of 1.5, and STD of 3.2..
with a 128point...
what i did is use the function..
Code:
wgn
which i can set my parameters...[/quote]
 

Re: pls help me in matlab..

Hi,
Does "wgn" stands for white gaussian noise,

If it is so, then I think this function can be used to generate random number.
(noise is infact a random number).

However since it is white gaussain noise the mean will be zero or some particular constant value.

thanks
sarfraz
 

Re: pls help me in matlab..

huh??the mean will not be zero....
 

Re: pls help me in matlab..

what eecs4ever is saying translates into MATLAB code as

% Generate 50 uniformly distributed random samples

Xunif = rand(1,50); % 50 samples of a uniform dist
% with fX(x) = {1 when 0<=X<=1 and 0 otherwise}

% Define the desired means and variances

mu_Y = -100; % the desired mean of RV Y
var_Y = 5; % the desired variance of RV Y

% Define the mean and variance of fX(x)

mu_Xunif = 0.5;
var_Xunif = 1/12;

% Solve for parameters a and b

a = sqrt(var_Y/var_Xunif);
b = mu_Y - a*mu_Xunif;

% Transform the random samples from fX(x) to random samples for fY(y)
% where the mean and variance of RV Y was defined

Yunif = a*Xunif+b;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top