Generation of random phase factors.

18 ビュー (過去 30 日間)
Ved
Ved 2013 年 12 月 8 日
コメント済み: Ved 2013 年 12 月 9 日
How to generate a random phase vector of size MxN following these conditions:
for M=1:5
N = 4; % number of columns in output phase matrix (P_out)
theta= 1xN random values over range of [0:360] degrees
P=exp(j*theta) % Phase factor
P_out= MxN output row vector for random N values of theta
end
Conditions for choosing theta:
  1. 0 <= theta <= 2*pi % Range of theta
  2. Each theta is any whole number multiple of smallest non-zero theta.for e.g.,
say for N = 4: theta=[45,0,180,225]% random angles
here each value of theta is a some whole number multiple of 45: [45x0=45, 45x1=45, 45x4=180, 45x5=225]
So,
P_out=MXN matrix having all different angles in a row.
Any help is much appreciated, regards

採用された回答

Wayne King
Wayne King 2013 年 12 月 8 日
編集済み: Wayne King 2013 年 12 月 8 日
Maybe you want something like this:
N = 4; % number you want
MaxAngle = floor(360/N)-1;
StartAng = randi([0 MaxAngle],1,1);
phaseangles = StartAng:StartAng:N*StartAng;
I've tried to make sure above that you only get angles in [0 360] but you if you really want every phase angle to be a multiple of some starting angle, the more angles you want, the greater that restricts your initial angle choice --unless you don't care about wrapping around the circle.
Of course, Image Analyst's comments about radians vs. degrees apply here as well.
  1 件のコメント
Ved
Ved 2013 年 12 月 9 日
@Wayne King: thank you !

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2013 年 12 月 8 日
編集済み: Image Analyst 2013 年 12 月 8 日
Try this:
numberOfAngles = 4; % or however many you need
theta = 45 * (randi(8, 1, numberOfAngles) - 1)
Of course, multiply by pi/180 if you want it in radians. Also, you can use sind(), cosd(), etc. if you want to use functions that work in degrees instead of radians.
  1 件のコメント
Ved
Ved 2013 年 12 月 9 日
@Image Analyst:Thank you

サインインしてコメントする。


Wayne King
Wayne King 2013 年 12 月 8 日
編集済み: Wayne King 2013 年 12 月 8 日
The way you have set it up, the phase angles are not random
If you really want phase angles randomly chosen to cover the interval (-pi, pi]
theta = -pi+2*pi*rand(10,1);
The above gives you 10 of them.
  1 件のコメント
Ved
Ved 2013 年 12 月 8 日
編集済み: Ved 2013 年 12 月 8 日
@Wayne King: Thank you but could i get non fractional theta values [0 : 360 degrees] and each theta is some whole number multiple of smallest non-zero theta.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by