随机相位因子的产生 [英] Generation of random phase factors

查看:122
本文介绍了随机相位因子的产生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在以下条件下生成大小为1xN的随机相位向量:

How to generate a random phase vector of size 1xN following these conditions:

N = [4,8,16,32]; % number of columns in output phase matrix (P_out)
theta= 1xN random values of theta
P=exp(j*theta)  % Phase factor
P_out= 1xN output row vector for different N values of theeta

选择theta的条件:

Conditions for choosing theta:

  1. 0 <= theta<= 2*pi % Range of theta
  2. 每个theta是最小非零theta的任何整数倍

  1. 0 <= theta<= 2*pi % Range of theta
  2. Each theta is any whole number multiple of smallest non-zero theta

例如,例如N = 4:theta=[45,0,180,225]%随机角度

for e.g., say for N = 4: theta=[45,0,180,225]% random angles

此处theta的每个值都是45的倍数:[45x0 = 45、45x1 = 45、45x4 = 180、45x5 = 225]

here each value of theta is a multiple of 45: [45x0=45, 45x1=45, 45x4=180, 45x5=225]

非常感谢您的帮助, 问候.

Any help is much appreciated, regards.

推荐答案

您可以这样做:

N = 8;                                      % number of angles
A0 = randi(360);                            % random minimum angle in deg
A1 = N*A0;                                  % maximum angle
theta = linspace(A0,A1,N);                  % equidistant angles
theta = theta( randperm( numel(theta) ) );  % shuffle array
P = exp(1i.*theta*pi/180);                  % calculate phase factor

或弧度的直接方向:

A0 = 0.2*pi;
A1 = N*A0;
...
P = exp(1i.*theta);   

如果要为不同的N值设置P组,则需要将数组存储在单元格数组(或结构)中,因为每个数组P的长度都不同.

If you want sets of P for different values of N you need to store the arrays in a cell array (or struct) as every array P has a different length.

您可以使用cellfun来实现.

function P_out = getPhaseFactorSet()

N = {4,8,16,32};                             % number of angles
P_out = cellfun(@getPhaseFactor,N)

end

function P = getPhaseFactor( N )
A0 = randi(360);                             % random minimum angle in deg
A1 = N*A0;                                   % maximum angle
theta = linspace(A0,A1,N);                   % equidistant angles
theta = theta( randperm( numel(theta) ) );   % shuffle array
P{1} = exp(1i.*theta*pi/180);                % calculate phase factor
end

这篇关于随机相位因子的产生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆