生成随机相位因子

时间:2013-12-08 08:48:04

标签: matlab

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

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的条件:

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

    例如,

    代表N = 4theta=[45,0,180,225]%随机角度

    这里theta的每个值是45的倍数:[45x0 = 45,45x1 = 45,45x4 = 180,45x5 = 225]

  3. 非常感谢任何帮助, 问候。

1 个答案:

答案 0 :(得分:1)

你可以这样做:

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);   

如果您希望P的{​​{1}}集用于N的不同值,则需要将数组存储在单元数组(或结构)中,因为每个数组P具有不同的长度。< / p>

您可以使用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
相关问题