2014-10-17 4 views
0

이것은 내가 여기에서 질문한 첫 번째 질문이므로 나와 함께하시기 바랍니다. 나는 Matlab에 익숙하지 않지만 이전에는 MVNRND 함수를 사용한 적이 없으며 통계 지식이 강하지 않습니다. 내가하려고하는 것의 요약은 다음과 같습니다 : 전자기 가우스 Schell 모델 빔 전파 시뮬레이션에 사용될 2 개의 상관 상 스크린 (NxN 행렬)을 생성하는 함수를 생성하려고합니다. 빔은 X 및 Y 편광 상태에 대해 별도의 랜덤 위상 스크린을 필요로합니다. 내가 지금까지 가지고있는 코드는 아래와 같습니다. 내가 도움을 필요로하는 곳에 위의 코드에서 Matlab에서 MVNRND를 사용하여 2 개의 가우스 상관 행렬 만들기

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 

,로 시작하는 주석 아래 두 줄의 코드가 "% 랜덤 푸리에 급수 계수의립니다"입니다. 이전에 보았던 코드로 두 개의 행렬을 만들었지 만, 가우스 상관 관계가 아니라는 것을 깨달았습니다. 저의지도 교수 추천에서 MVNRND를 사용하여 이러한 단계 화면을 생성해야합니다. MVNRND에 대한 도움말 파일을 검토 한 후이 용도로 사용하는 방법에 대해 분실했습니다. 나는 행운을 빌어 비슷한 질문과 답변을 찾기 위해 여기를 수색했으며, 나는 또한 구글을 수색했다. 누구나 MVNRND를 사용하기 위해이 두 줄의 코드를 변경하는 데 도움을 줄 수 있습니까? 고맙습니다!

+0

2 개의 랜덤 행렬이 서로 관련되어야한다는 것을 분명히 밝히고 싶습니다. – balistikboy

답변

2

많은 연구 끝에, MVNRND를 사용하여 내 용도에 맞게 사용 방법을 알아 냈습니다. 내 의도는 아래의 코드 조각에서 randn (N)의 4 가지 용도를 대체 할 4 개의 임의의 NxN 메트릭스를 작성하는 것이 었습니다. MVNRND를 임의의 matricies로 대체해야하는 이유는 상관 관계가 있기 때문입니다. MVNRND에서 공분산 행렬을 제공해야합니다. 이것은 나를 우스꽝스럽게하고 있었던 것이다. rx_real, rx_imag, ry_real 및 ry_imag :

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; 

를 만들려면, I는 I이 결합 쌍의 분산 (공분산)을 계산해야하는 4 개 가지 임의의 값을 갖는다. 일단 그 점을 알아 냈 으면 공분산 행렬을 만들 수있었습니다.

다음 호는 MVNRND의 '사례'값을 설정해야 하는지를 파악하고있었습니다. 4 개의 상관 된 NxN 행렬이 필요했기 때문에 4xN^2 행렬이 필요한 경우를 결정했습니다. 그런 다음 MVNRND 출력을 필요한 NxN 4 개의 매트릭스로 변환하기 위해 'reshape'명령을 사용할 수있었습니다.

아래 코드를 참조하십시오. 희망이 다른 사람을 도와주세요!

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