[英]Rotating complex matrix with arbitrary angle in Matlab?
I have implemented the Hermite-Gaussian function in matlab for producing different modes.我已经在 matlab 中实现了 Hermite-Gaussian 函数来产生不同的模式。 The light beam along z direction can be seen as a complex matrix in the plane.
沿 z 方向的光束可以看作是平面中的复矩阵。
The function for HG modes is as below. 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
Now I plot one example for HG(2,0) as the following ( example1 ):现在我为 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)');
The plot of the light field will be as the following picture in the left side (its intensity):左侧的光场图(强度)如下图所示:
We can use rot90()
function to rotate matrix HGintheory
(which is add one line code: HGintheory=rot90(HGintheory);
) and then the field will rotate 90 degree (right side of the intensity plot).我们可以使用
rot90()
函数来旋转矩阵HGintheory
(即添加一行代码: HGintheory=rot90(HGintheory);
)然后场将旋转 90 度(强度图的右侧)。
Because I want to work with the light field.
因为我想用光场工作。 So the question is how can I rotate the complex matrix
HGintheory
in arbitrary angle ?所以问题是如何以任意角度旋转复矩阵
HGintheory
? For example 45 degree?例如45度?
Does anyone knows how to rotate a complex matrix with big size?有谁知道如何旋转大尺寸的复杂矩阵? If something is wrong or unclear, please pointing out and Thank you in advance!
如果有什么不对或不清楚的地方,请指出并提前谢谢!
You can rotate your initial meshgrid using:您可以使用以下方法旋转初始网格:
[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));
and then use those transformed coordinates to plot:然后使用这些转换后的坐标来绘制:
imagesc(XR,YR,IntensityHGin);
You can decompose your complex field into two real fields (amplitude and phase), rotate both with imrotate
, and combine them afterwards pixel-wise您可以将复杂场分解为两个真实场(幅度和相位),使用
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.