基於matlab的圓偏振光/兩相交流電模擬-導出gif

光學和電學具有諸多相似的地方,本文針對兩個平面偏振光的合成進行討論。

從波動光學中我們可以得到:

  • 相同頻率、相同振幅、相位也完全相同的兩電磁波,合成的依然是平面偏振光;
  • 相同頻率、相同振幅、相位差爲pi/2的兩電磁波,合成的是右旋圓偏振光;
  • 相同頻率、相同振幅、相位差爲-pi/2的兩電磁波,合成的是左旋圓偏振光;
  • 相同頻率、相同振幅、相位差爲0~pi/2的兩電磁波,合成的是橢圓偏振光;

上述四條對於掌握圓二色譜的基本原理有一定幫助。

同時我們知道:

空間相差90度,相位相差90度(利用電容)的兩相交流電可以合成一個旋轉電磁場;

本matlab程序包含兩個子函數:Polarization.m和OutGif.m,前者作圖並輸出gif文件,後者用於設定gif的參數。

可以在這裏下載

%% 偏振光演示
function [] = Polarization(A,f,Tend,Tint,Angle)
if nargin == 0
    A = [1,2];    % 幅值,可改參數哈
    f = [1,1];    % 頻率,可改參數哈
    Tint = 0.01;  % 每幀的時長,可改參數哈
    Tend = 1;     % 運行一秒,可改參數哈
    Angle = pi/2;   % 相位,可改參數哈,注意單位
end
%% 開始作圖
figure('color',[1,1,1]);
w = 2*pi*f;
iter = 0;
x = [];
y = [];
for t = 0:Tint:Tend
    iter = iter+1;
    % 線偏振光
    X = A(1)*sin(w(1)*t);
    plot([0,X],[0,0],'r','LineWIdth',1.5);
    hold on;
    plot([X,X],[0,0],'ro','LineWIdth',1.5,'MarkerFaceColor','r');
    % 另外一個線偏振光
    Y = A(2)*sin(w(2)*t+Angle);
    plot([0,0],[0,Y],'b','LineWIdth',1.5);
    hold on;
    plot([0,0],[Y,Y],'bo','LineWIdth',1.5,'MarkerFaceColor','b');
    % 合成
    plot([0,X],[0,Y],'k','LineWIdth',1.5);
    hold on;
    plot([0,X],[0,Y],'ko','LineWIdth',1.5,'MarkerFaceColor','k');
    % 軌跡
    x = [x X];
    y = [y Y];
    plot(x,y,'k--','LineWIdth',0.5);
    % 其他作圖設置
    hold off
    axis equal
    xlim([-A(1),A(1)]);
    ylim([-A(2),A(2)]);
    axis off
    M = getframe();
    OutGif(M,'POLAR',iter,Tint)
end

end
%% 輸出gif文件(簡易版)
function Status = OutGif(GetFrameOutput,FileName,NumFrame,LoopTime,Path)
if nargin == 3
    LoopTime = 0.3;
    Path = 'C:\Users\ZLY\Desktop';
elseif nargin == 4
    Path = 'C:\Users\ZLY\Desktop';
end
% Status = PathCheck(Path);
imind = frame2im(GetFrameOutput);
[imind,cm] = rgb2ind(imind,256);
T = datestr(now,1);
if NumFrame == 1
    imwrite(imind,cm,strcat(Path,'\',[T,FileName],'.gif'),'gif','LoopCount',inf,'DelayTime',LoopTime);
else
    imwrite(imind,cm,strcat(Path,'\',[T,FileName],'.gif'),'gif','WriteMode','append','DelayTime',LoopTime);
end
end

運行結果:

不同參數對比
    A = [1,2];    % 幅值
    f = [1,1];    % 頻率
    Tint = 0.01;  % 每幀的時長
    Tend = 2;     % 運行時間
    Angle = pi/2; % 相位

 

    A = [1,1];    % 幅值
    f = [1,1];    % 頻率
    Tint = 0.01;  % 每幀的時長
    Tend = 2;     % 運行時間
    Angle = pi/2; % 相位

 

    A = [1,1];    % 幅值
    f = [1,1];    % 頻率
    Tint = 0.01;  % 每幀的時長
    Tend = 2;     % 運行時間
    Angle = -pi/2; % 相位

 

    A = [1,1];    % 幅值
    f = [1,1];    % 頻率
    Tint = 0.01;  % 每幀的時長
    Tend = 2;     % 運行時間
    Angle = pi/3; % 相位

 

    A = [1,1];    % 幅值
    f = [1,2];    % 頻率
    Tint = 0.01;  % 每幀的時長
    Tend = 2;     % 運行時間
    Angle = 0; % 相位

 

    A = [1,1];    % 幅值
    f = [1,2];    % 頻率
    Tint = 0.01;  % 每幀的時長
    Tend = 2;     % 運行時間
    Angle = pi/3; % 相位

 

    A = [1,1];    % 幅值
    f = [1,2];    % 頻率
    Tint = 0.01;  % 每幀的時長
    Tend = 2;     % 運行時間
    Angle = pi/2; % 相位

 

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章