在Matlab中用mvnrn生成2个高斯相关矩阵

在Matlab中用mvnrn生成2个高斯相关矩阵,matlab,matrix,correlation,gaussian,cross-correlation,Matlab,Matrix,Correlation,Gaussian,Cross Correlation,这是我在这里问的第一个问题,请耐心听我说。我对Matlab并不陌生,但以前从未使用过MVNRND函数,而且我的统计知识也不强。我尝试做的工作总结如下:我尝试创建一个函数,生成2个相关相位屏(NxN矩阵),用于电磁高斯-谢尔模型波束传播模拟。对于X和Y偏振状态,光束需要单独的随机相位屏。到目前为止,我的代码如下 function [phz_x,phz_y]=GSM_phase_screen_2(l_phi_x,l_phi_y,sigma_phi_x, ... sigma_phi_y,gamma,N

这是我在这里问的第一个问题,请耐心听我说。我对Matlab并不陌生,但以前从未使用过MVNRND函数,而且我的统计知识也不强。我尝试做的工作总结如下:我尝试创建一个函数,生成2个相关相位屏(NxN矩阵),用于电磁高斯-谢尔模型波束传播模拟。对于X和Y偏振状态,光束需要单独的随机相位屏。到目前为止,我的代码如下

function [phz_x,phz_y]=GSM_phase_screen_2(l_phi_x,l_phi_y,sigma_phi_x, ...
sigma_phi_y,gamma,N,delta)
%GSM_PHASE_SCREEN_2
%   This code generates two correlated 2-D NxN Gaussian Schell-Model (GSM)
%   phase screens (matrices) of unit variance circular complex Gaussian
%   random numbers for the X and Y polarization states provided l_phi_x,
%   l_phi_y, sigma_phi_x, sigma_phi_y, and gamma. It utilizes the MVNRND
%   Matlab function.  
%
%   l_phi_x:        [m] correlation length in X phase screen
%   l_phi_y:        [m] correlation length in Y phase screen
%   sigma_phi_x:    phase variance in X phase screen
%   sigma_phi_y:    phase variance in Y phase screen
%   gamma:          correlation coefficient
%   N:              number of samples per side of grid
%   delta:          [m] sample grid spacing
%
%   phz_x:          [rad] 2-D phase screen for X polarization state
%   phz_y:          [rad] 2-D phase screen for Y polarization state

% ORIGINAL AUTHOR: Santasri Basu
% MODIFIED BY: Matthew Gridley
%       Added input arguments needed to generate 2 correlated phase
%       screens, updated PSD equations, and replaced RANDN with MVNRND
%

% Setup the Power Spectral Density (PSD)
del_f = 1 / (N*delta); % frequency grid spacing [1/m]
fx = (-N/2 : N/2-1) * del_f;

% Frequency grid
[fx,fy] = meshgrid(fx);

% GSM phase PSD
PSD_phi_x = (sigma_phi_x^2) * pi * (l_phi_x^2) * gamma * ...
    exp(-((pi * l_phi_x)^2) * (fx.^2 + fy.^2));
PSD_phi_y = (sigma_phi_y^2) * pi * (l_phi_y^2) * gamma * ...
    exp(-((pi * l_phi_y)^2) * (fx.^2 + fy.^2));

% Random draws of Fourier series coefficients
% (zero mean Gaussian random numbers)
% 
% the 2 lines of code below need changed to generate the correlated random
% draws using MVNRND and GAMMA
cn_x = (randn(N) + 1i*randn(N)) .* sqrt(PSD_phi_x) * del_f;
cn_y = (randn(N) + 1i*randn(N)) .* sqrt(PSD_phi_y) * del_f;

% Synthesize the phase screens
phz_x = real(ift2(cn_x,1));
phz_y = real(ift2(cn_y,1));

end



function [g, x] = ift2(G, df)
% [g, x] = ift2(G, df)
%   2-D inverse Fourier transform that keeps the origin at the center of 
%   the grid.
%
%   G:   Complex field in frequency space
%   df:  Spacing in frequency space [m^-1]
%   g:   Complex field in coordinate space

% Core function written by Jason Schmidt
% Modified: 17 Apr 2010
% By: Daniel J. Wheeler
%
% x output added functionality by Michael Steinbock 6/8/2014
%

g = ifftshift(ifft2(ifftshift(G))) * (length(G) * df)^2;

%% Calc x:
if nargout == 2
    N = size(G, 1);

    x = (0 : N-1) / (N*delta_f);
end

在上面的代码中,注释下面以“%Random Drawing of Fourier级数系数”开头的两行代码是我需要帮助的地方。我之前用你们看到的代码做了两个矩阵,但意识到它们不是高斯相关的。根据我的学术顾问的建议,我应该使用MVNRND生成这些阶段屏幕。在查看了MVNRND的帮助文件后,我不知道如何使用它。我在这里搜索,试图找到类似的问题和答案,但运气不好,我也搜索了谷歌。任何人都可以帮助更改这两行代码以利用MVNRND。谢谢大家!

输入代码经过大量研究,我找到了如何使用MVNRND来满足我的目的。我的意图是创建4个随机NxN矩阵,以替换下面代码段中randn(N)的4个用法。我需要用MVNRND生成的随机矩阵替换这些矩阵的原因是为了使它们相互关联。在MVNRND中,必须提供协方差矩阵。这就是困扰我的问题

cn_x = (randn(N) + 1i*randn(N)) .* sqrt(PSD_phi_x) * del_f;
cn_y = (randn(N) + 1i*randn(N)) .* sqrt(PSD_phi_y) * del_f;
为了创建它,我有4个不同的随机值,我必须计算组合对的方差(协方差):rx_real、rx_imag、ry_real和ry_imag。一旦我明白了这一点,我就能够创建协方差矩阵

下一个问题是找出MVNRND中需要设置的“cases”值。我需要4个相关的NxN矩阵,所以我确定案例需要是4xN^2矩阵。然后,我能够使用“重塑”命令将MVNRND输出转换为所需的4NXN矩阵

请参阅下面的代码。希望这对其他人有帮助

% Multivariate normal parameters
mu = zeros([1,4]); % Zero mean Gaussian
% Covariance matrix for 4 circular complex Gaussian random numbers:
% rx_real, rx_imag, ry_real, ry_imag
% 
% [<rx_real rx_real> <rx_real rx_imag> <rx_real ry_real> <rx_real ry_imag>;
%  <rx_imag rx_real> <rx_imag rx_imag> <rx_imag ry_real> <rx_imag ry_imag>;
%  <ry_real rx_real> <ry_real rx_imag> <ry_real ry_real> <ry_real ry_imag>;
%  <ry_imag rx_real> <ry_imag rx_imag> <ry_imag ry_real> <ry_imag ry_imag>]
sigma = [1 0 gamma 0;
         0 1 0 gamma;
         gamma 0 1 0; 
         0 gamma 0 1];
cases = N^2; % matrix of random vectors

r = mvnrnd(mu, sigma, cases); % gives a 512^2x4 double matrix

rx_real = reshape(r(:,1),[N N]);
rx_imag = reshape(r(:,2),[N N]);
ry_real = reshape(r(:,3),[N N]);
ry_imag = reshape(r(:,4),[N N]);

% Correlated random draws of Fourier series coefficients
cn_x = (rx_real + 1i*rx_imag) .* sqrt(PSD_phi_x) * del_f;
cn_y = (ry_real + 1i*ry_imag) .* sqrt(PSD_phi_y) * del_f;
%多元正态参数
μ=零([1,4]);%零均值高斯分布
%4个循环复高斯随机数的协方差矩阵:
%rx_real,rx_imag,ry_real,ry_imag
% 
% [   ;
%     ;
%     ;
%     ]
西格玛=[1 0伽马0;
1010伽马;
伽马0 1 0;
0伽马0 1];
案例=N^2;%随机向量矩阵
r=mvnrnd(μ,σ,事例);%给出一个512^2x4的双矩阵
rx_real=重塑(r(:,1),[N]);
rx_imag=重塑(r(:,2),[N]);
r_real=重塑(r(:,3),[N]);
r_imag=重塑(r(:,4),[N]);
%傅里叶级数系数的相关随机抽取
cn_x=(rx_real+1i*rx_imag)。*sqrt(PSD_phi_x)*del_f;
cn_y=(y_real+1i*y_imag)。*sqrt(PSD_phi_y)*del_f;

输入代码经过大量研究,我找到了如何使用MVNRND来满足我的目的。我的意图是创建4个随机NxN矩阵,以替换下面代码段中randn(N)的4个用法。我需要用MVNRND生成的随机矩阵替换这些矩阵的原因是为了使它们相互关联。在MVNRND中,必须提供协方差矩阵。这就是困扰我的问题

cn_x = (randn(N) + 1i*randn(N)) .* sqrt(PSD_phi_x) * del_f;
cn_y = (randn(N) + 1i*randn(N)) .* sqrt(PSD_phi_y) * del_f;
为了创建它,我有4个不同的随机值,我必须计算组合对的方差(协方差):rx_real、rx_imag、ry_real和ry_imag。一旦我明白了这一点,我就能够创建协方差矩阵

下一个问题是找出MVNRND中需要设置的“cases”值。我需要4个相关的NxN矩阵,所以我确定案例需要是4xN^2矩阵。然后,我能够使用“重塑”命令将MVNRND输出转换为所需的4NXN矩阵

请参阅下面的代码。希望这对其他人有帮助

% Multivariate normal parameters
mu = zeros([1,4]); % Zero mean Gaussian
% Covariance matrix for 4 circular complex Gaussian random numbers:
% rx_real, rx_imag, ry_real, ry_imag
% 
% [<rx_real rx_real> <rx_real rx_imag> <rx_real ry_real> <rx_real ry_imag>;
%  <rx_imag rx_real> <rx_imag rx_imag> <rx_imag ry_real> <rx_imag ry_imag>;
%  <ry_real rx_real> <ry_real rx_imag> <ry_real ry_real> <ry_real ry_imag>;
%  <ry_imag rx_real> <ry_imag rx_imag> <ry_imag ry_real> <ry_imag ry_imag>]
sigma = [1 0 gamma 0;
         0 1 0 gamma;
         gamma 0 1 0; 
         0 gamma 0 1];
cases = N^2; % matrix of random vectors

r = mvnrnd(mu, sigma, cases); % gives a 512^2x4 double matrix

rx_real = reshape(r(:,1),[N N]);
rx_imag = reshape(r(:,2),[N N]);
ry_real = reshape(r(:,3),[N N]);
ry_imag = reshape(r(:,4),[N N]);

% Correlated random draws of Fourier series coefficients
cn_x = (rx_real + 1i*rx_imag) .* sqrt(PSD_phi_x) * del_f;
cn_y = (ry_real + 1i*ry_imag) .* sqrt(PSD_phi_y) * del_f;
%多元正态参数
μ=零([1,4]);%零均值高斯分布
%4个循环复高斯随机数的协方差矩阵:
%rx_real,rx_imag,ry_real,ry_imag
% 
% [   ;
%     ;
%     ;
%     ]
西格玛=[1 0伽马0;
1010伽马;
伽马0 1 0;
0伽马0 1];
案例=N^2;%随机向量矩阵
r=mvnrnd(μ,σ,事例);%给出一个512^2x4的双矩阵
rx_real=重塑(r(:,1),[N]);
rx_imag=重塑(r(:,2),[N]);
r_real=重塑(r(:,3),[N]);
r_imag=重塑(r(:,4),[N]);
%傅里叶级数系数的相关随机抽取
cn_x=(rx_real+1i*rx_imag)。*sqrt(PSD_phi_x)*del_f;
cn_y=(y_real+1i*y_imag)。*sqrt(PSD_phi_y)*del_f;

输入代码经过大量研究,我找到了如何使用MVNRND来满足我的目的。我的意图是创建4个随机NxN矩阵,以替换下面代码段中randn(N)的4个用法。我需要用MVNRND生成的随机矩阵替换这些矩阵的原因是为了使它们相互关联。在MVNRND中,必须提供协方差矩阵。这就是困扰我的问题

cn_x = (randn(N) + 1i*randn(N)) .* sqrt(PSD_phi_x) * del_f;
cn_y = (randn(N) + 1i*randn(N)) .* sqrt(PSD_phi_y) * del_f;
为了创建它,我有4个不同的随机值,我必须计算组合对的方差(协方差):rx_real、rx_imag、ry_real和ry_imag。一旦我明白了这一点,我就能够创建协方差矩阵

下一个问题是找出MVNRND中需要设置的“cases”值。我需要4个相关的NxN矩阵,所以我确定案例需要是4xN^2矩阵。然后,我能够使用“重塑”命令将MVNRND输出转换为所需的4NXN矩阵

请参阅下面的代码。希望这对其他人有帮助

% Multivariate normal parameters
mu = zeros([1,4]); % Zero mean Gaussian
% Covariance matrix for 4 circular complex Gaussian random numbers:
% rx_real, rx_imag, ry_real, ry_imag
% 
% [<rx_real rx_real> <rx_real rx_imag> <rx_real ry_real> <rx_real ry_imag>;
%  <rx_imag rx_real> <rx_imag rx_imag> <rx_imag ry_real> <rx_imag ry_imag>;
%  <ry_real rx_real> <ry_real rx_imag> <ry_real ry_real> <ry_real ry_imag>;
%  <ry_imag rx_real> <ry_imag rx_imag> <ry_imag ry_real> <ry_imag ry_imag>]
sigma = [1 0 gamma 0;
         0 1 0 gamma;
         gamma 0 1 0; 
         0 gamma 0 1];
cases = N^2; % matrix of random vectors

r = mvnrnd(mu, sigma, cases); % gives a 512^2x4 double matrix

rx_real = reshape(r(:,1),[N N]);
rx_imag = reshape(r(:,2),[N N]);
ry_real = reshape(r(:,3),[N N]);
ry_imag = reshape(r(:,4),[N N]);

% Correlated random draws of Fourier series coefficients
cn_x = (rx_real + 1i*rx_imag) .* sqrt(PSD_phi_x) * del_f;
cn_y = (ry_real + 1i*ry_imag) .* sqrt(PSD_phi_y) * del_f;
%多元正态参数
μ=零([1,4]);%零均值高斯分布
%4个循环复高斯随机数的协方差矩阵:
%rx_real,rx_imag,ry_real,ry_imag
% 
% [   ;
%     ;
%     ;
%     ]
西格玛=[1 0伽马0;
1010伽马;
伽马0 1 0;
0伽马0 1];
案例=N^2;%ran矩阵