在Matlab中以任意角度旋转复杂矩阵?

时间:2020-02-26 13:10:03

标签: matlab matrix rotation

我已经在matlab中实现了Hermite-Gaussian函数,以产生不同的模式。沿z方向的光束可以看作是平面中的复矩阵。

HG模式的功能如下。

%Hermite polynomial
function hk = HermitePoly(n)

if n==0 
    hk = 1;
elseif n==1
    hk = [2 0];
else

    hkm2 = zeros(1,n+1);
    hkm2(n+1) = 1;
    hkm1 = zeros(1,n+1);
    hkm1(n) = 2;

    for k=2:n

        hk = zeros(1,n+1);

        for e=n-k+1:2:n
            hk(e) = 2*(hkm1(e+1) - (k-1)*hkm2(e));
        end

        hk(n+1) = -2*(k-1)*hkm2(n+1);

        if k<n
            hkm2 = hkm1;
            hkm1 = hk;
        end
    end  
end
% this is the function of HG modes in z position.
function [HGBeam,X,Y] = Hermite_Gaussian(N,hx,hy,w0,delta,lamda,z) 

   [X Y]=meshgrid((-N/2:N/2-1)*delta);
   [theta,rad] = cart2pol(X,Y);

   k=2*pi/lamda;
   zr=pi*w0^2/lamda;
   wz=w0*sqrt(1+(z/zr)^2);
   qz=z+1i*zr;
   q0=1i*zr;

   if z==0
      rz=Inf;
   else 
      rz=z*(1+(zr/z)^2);
   end

   AmpLGB=sqrt(2/(2^(hx+hy)*pi*factorial(hx)*factorial(hy)*w0^2)).*(q0/qz).*(-conj(qz)/qz)^((hx+hy)/2).*exp(-(rad.*rad)/(wz)^2).*polyval(HermitePoly(hx),sqrt(2)*X/wz).*polyval(HermitePoly(hy),sqrt(2)*Y/wz);   
   PsLGB=exp(-1i*(k*(rad.*rad)/(2*rz)+k*z-(hx+hy+1)*atan(z/zr)));

   HGBeam=AmpLGB.*PsLGB;

end

现在我为HG(2,0)绘制一个示例,如下所示( example1 ):

clc
clear all;
close all;

lambda=809e-9;    % optical wavelength 
w0=0.025;         %optical beam waist 15mm
k=2*pi/lambda;    % optical wavenumber
Zr=pi*w0^2/lambda; % Rayleigh range 

z0=0;          % start position z=0; but careful 0*Inf is undefined, here 0*Inf=NAN

N=1024;       % samples/side length at source plane
D1=0.25;      % side length [m]  at source plane
delta1=D1/N;  % grid spacing [m]
x1=-D1/2:delta1:D1/2-delta1;  % source plane x and y coordinates
y1=x1; 

%% HG modes
HGx=2;  
HGy=0;  

HGintheory=Hermite_Gaussian(N,HGx,HGy,w0,delta1,lambda,z0);

h7=figure(7);
imagesc(x1,y1,abs(HGintheory).^2);
title(sprintf('z=%d; HG(%d,%d)',z0,HGx,HGy))
xlabel('x (m)'); ylabel('y (m)');

光场的图将如下图所示(强度): enter image description here

我们可以使用rot90()函数旋转矩阵HGintheory(添加一行代码:HGintheory=rot90(HGintheory);),然后该字段将旋转90度(强度图的右侧) 。

因为我想处理光场。所以问题是如何在其中旋转复数矩阵HGintheory 任意角度?例如45度?

有人知道如何旋转大尺寸的复杂矩阵吗?如果出现问题或不清楚,请事先指出并谢谢!!

2 个答案:

答案 0 :(得分:1)

您可以将复杂的场分解为两个实场(幅度和相位),同时用imrotate旋转,然后逐像素组合它们。

Hamp=abs(HGintheory);
Hphase=angle(HGintheory);

RotAngle=45;
HampRot=imrotate(Hamp,RotAngle,'bilinear','crop');
HphaseRot=imrotate(Hphase,RotAngle,'bilinear','crop');
HfullRot=HampRot.*exp(1i*HphaseRot);

figure(1);
imagesc(x1,y1,abs(HGintheory).^2);

figure(2);
imagesc(x1,y1,abs(HfullRot).^2);

enter image description here

答案 1 :(得分:0)

您可以使用以下方法旋转初始网格:

[X,Y] = meshgrid(x1,y1)
xyc = [mean(x1), mean(y1)];
angel = 45;
R = [cosd(angel), -sind(angel); sind(angel), cosd(angel)];
XY = xyc' + R * ([X(:) Y(:)]-xyc)';
XR = reshape(XY(1,:),size(X));
YR = reshape(XY(2,:),size(Y));

,然后使用这些转换后的坐标进行绘制:

imagesc(XR,YR,IntensityHGin);