简体   繁体   中英

Rotating complex matrix with arbitrary angle in Matlab?

I have implemented the Hermite-Gaussian function in matlab for producing different modes. The light beam along z direction can be seen as a complex matrix in the plane.

The function for HG modes is as below.

%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 ):

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

Because I want to work with the light field. So the question is how can I rotate the complex matrix HGintheory in arbitrary angle ? For example 45 degree?

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

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM