0

我做了一些.m files计算斯托克斯极化参数。有两个脚本:polarisationFromLight它接受三个参数并返回偏振椭圆和斯托克斯参数,polarisationFromStokes它接受斯托克斯参数并绘制偏振椭圆。

我的文件是

极化FromLight.m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                        %
%                                                        %
%  polarisationFromLight.m                               %
%  Matlab Script that gets the x/y component             %
%  and phase end returns the polarisation ellipse        %
%  and the 4 stokes parameters                           %
%                                                        %
%  Author:Thanos Stamatopoulos                           %
%  Date:March 2013                                       %
%                                                        %
%  Neeeds calculateEllipse.m                             %
%         angle.m                                        %
%         deg2rad.m                                      %
%                                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Eox=input('Give me the x amplitude of the wave: ');
Eoy=input('Now give the y amplitude of the wave: ');
phiDeg=input('Finally give the relative phase in degrees between x and y component: ');

if (phiDeg==(90)|phiDeg==-90 && Eox==Eoy)
    angle(90)
else
    %semiminor axis b
    phiRad=deg2rad(phiDeg);
    alpha=Eoy/Eox;
    x=asin(sin(2*alpha)*sin(phiRad))/2;
    beta=tan(x);

    %inclination angle-ellipse's orientation
    psi=atand((2*Eox*Eoy*cosd(phiDeg))/(Eox^2-Eoy^2))/2;

    %draw the ellipse
    p = calculateEllipse(0, 0, 1, beta, psi, 1000);
    plot(p(:,1), p(:,2), '.'),axis equal
end

%calculate the normalised Stokes parameters
I=Eox^2+Eoy^2;
Q=Eox^2-Eoy^2;
U=2*Eox*Eoy*cosd(phiDeg);
V=2*Eox*Eoy*sind(phiDeg);

%plot them on the canvas
text(1.01,.5,['\fontsize{16}\color{red}I= ' num2str(I/I)])
text(1.01,0.4,['\fontsize{16}\color{red}Q= ' num2str(Q/I)])
text(1.01,0.3,['\fontsize{16}\color{red}U= ' num2str(U/I)])
text(1.01,0.2,['\fontsize{16}\color{red}V= ' num2str(V/I)])

%Don't forget the left/hand polarisation
if (V>0)
    text(1.01,.8,['\fontsize{16}\color[rgb]{0 .5 0}Right Handed' ])
elseif(V<0)
    text(1.01,.8,['\fontsize{16}\color[rgb]{0 .5 0}Left Handed' ])
end

极化FromStokes.m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                        %
%                                                        %
%  polarisationFromStokes.m                              %
%  Matlab Script that gets the 4 stokes parameters       %
%  end returns the polarisation ellipse                  %
%                                                        %
%  Author:Thanos Stamatopoulos                           %
%  Date:March 2013                                       %
%                                                        %
%  Neeeds calculateEllipse.m                             %
%         angle.m                                        %
%         rad2deg.m                                      %
%                                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I=input('Give me the I stokes parameter: ');
Q=input('Give me the Q stokes parameter: ');
U=input('Give me the U stokes parameter: ');
V=input('Give me the V stokes parameter: ');

if (V==(1)|V==-1)
    angle(90)
elseif(Q<0)
    %semiminor axis b
    x=asin(V/I)/2;
    beta=tan(x);
    p = calculateEllipse(0, 0, 1, beta, 90, 1000);
    plot(p(:,1), p(:,2), '.'),axis equal
else
    %semiminor axis b
    x=asin(V/I)/2;
    beta=tan(x);

    %inclination angle-ellipse's orientation
    psi=atan(U/Q)/2;
    psiDeg=rad2deg(psi);

    %draw the ellipse
    p = calculateEllipse(0, 0, 1, beta, psiDeg, 1000);
    plot(p(:,1), p(:,2), '.')
    axis equal
    grid on

end

if (V>0)
    text(1.01,.7,['\fontsize{16}\color[rgb]{0 .5 0}Right Handed' ])
elseif(V<0)
    text(1.01,.7,['\fontsize{16}\color[rgb]{0 .5 0}Left Handed' ])
end

text(1.01,.5,['\fontsize{16}\color{red}I= ' num2str(I/I)])
text(1.01,0.4,['\fontsize{16}\color{red}Q= ' num2str(Q/I)])
text(1.01,0.3,['\fontsize{16}\color{red}U= ' num2str(U/I)])
text(1.01,0.2,['\fontsize{16}\color{red}V= ' num2str(V/I)])

功能angle

    function angle=angle(phi)
    t=[0:1:360];
    x=sind(t);
    y=sind(t-phi);
    scatter(x,y,'.')
    axis equal
    grid on

**function calculateellipse**

function [X Y] = calculateEllipse(x, y, a, b, angle, steps)
    %# This functions returns points to draw an ellipse
    %#
    %#  @param x     X coordinate
    %#  @param y     Y coordinate
    %#  @param a     Semimajor axis
    %#  @param b     Semiminor axis
    %#  @param angle Angle of the ellipse (in degrees)
    %#

    error(nargchk(5, 6, nargin));
    if nargin<6, steps = 36; end

    beta = -angle * (pi / 180);
    sinbeta = sin(beta);
    cosbeta = cos(beta);

    alpha = linspace(0, 360, steps)' .* (pi / 180);
    sinalpha = sin(alpha);
    cosalpha = cos(alpha);

    X = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta);
    Y = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta);

    if nargout==1, X = [X Y]; end
end

弧度2度

function deg2rad = deg2rad(degrees)

% RADIANS (DEGREES)
%
% Convert Radians to Degrees.
% Athanasios Stamatopoulos
%

deg2rad = (pi/180)*degrees;

度 2 度

function rad2deg = rad2deg(radians)

%
% Convert Radians to Degrees.
% Athanasios Stamatopoulos 2010
%

rad2deg = radians/(pi/180);

是否可以制作一个用户必须输入每个参数的 GUI,以便绘制偏振椭圆。


编辑

到目前为止,我设计了 GUI

由此.m file产生的是

function varargout = Stokes2Ellipse(varargin)
% STOKES2ELLIPSE M-file for Stokes2Ellipse.fig
%      STOKES2ELLIPSE, by itself, creates a new STOKES2ELLIPSE or raises the existing
%      singleton*.
%
%      H = STOKES2ELLIPSE returns the handle to a new STOKES2ELLIPSE or the handle to
%      the existing singleton*.
%
%      STOKES2ELLIPSE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in STOKES2ELLIPSE.M with the given input arguments.
%
%      STOKES2ELLIPSE('Property','Value',...) creates a new STOKES2ELLIPSE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Stokes2Ellipse_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Stokes2Ellipse_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Stokes2Ellipse

% Last Modified by GUIDE v2.5 12-Mar-2013 09:20:33

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Stokes2Ellipse_OpeningFcn, ...
                   'gui_OutputFcn',  @Stokes2Ellipse_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Stokes2Ellipse is made visible.
function Stokes2Ellipse_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Stokes2Ellipse (see VARARGIN)

% Choose default command line output for Stokes2Ellipse
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Stokes2Ellipse wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Stokes2Ellipse_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function Itext_Callback(hObject, eventdata, handles)
% hObject    handle to Itext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Itext as text
%        str2double(get(hObject,'String')) returns contents of Itext as a double


% --- Executes during object creation, after setting all properties.
function Itext_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Itext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Qtext_Callback(hObject, eventdata, handles)
% hObject    handle to Qtext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Qtext as text
%        str2double(get(hObject,'String')) returns contents of Qtext as a double


% --- Executes during object creation, after setting all properties.
function Qtext_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Qtext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Utext_Callback(hObject, eventdata, handles)
% hObject    handle to Utext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Utext as text
%        str2double(get(hObject,'String')) returns contents of Utext as a double


% --- Executes during object creation, after setting all properties.
function Utext_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Utext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Vtext_Callback(hObject, eventdata, handles)
% hObject    handle to Vtext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Vtext as text
%        str2double(get(hObject,'String')) returns contents of Vtext as a double


% --- Executes during object creation, after setting all properties.
function Vtext_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Vtext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
4

0 回答 0