Thread Subject: MZDDE matlab to Zemax MTF calculation

Subject: MZDDE matlab to Zemax MTF calculation

From: Michael

Date: 20 Jun, 2011 20:08:04

Message: 1 of 4

Hello Everyone,

Here is a small excerpt from a program I am working on which is intended to calculate the change in MTF of a lens system as source is move away.

Zemax preferences set to allow extension to push lenses
zemax txt file encoding set to ANSI

Question how do I run/save the MTF calculation using the zemax file wavelenghts with weights ect..?

StartPosition =5000; %inital source position
EndPosition = 10000;
Interval =5000;

% DEFAULT.TXT file was previously saved manually from zemax
% How do I automatically run MTF calculations using the wavelenth and
% weights ect from the original zemax file and save a new file

zmxOTF = ReadZemaxOTF('C:\Documents and Settings\mlisowski\My Documents\MATLAB\DEFAULT.TXT');
PlotZemaxOTF(zmxOTF)

for position=StartPosition:Interval:EndPosition
zSetSurfaceData(0,3,(position+Interval));
zPushLens(2)
zGetRefresh
% Need to reevaluate and save new MTF file using zemax define wavelength
% and weights ect
zmxOTF = ReadZemaxOTF('C:\Documents and Settings\mlisowski\My Documents\MATLAB\DEFAULT.TXT');
PlotZemaxOTF(zmxOTF)
end

Subject: MZDDE matlab to Zemax MTF calculation

From: Michael

Date: 21 Jun, 2011 12:00:20

Message: 2 of 4

Hello,

Everyone. I am still trying to work through my earlier issue. After reviewing the documentation for MZDDE I think the function I am looking for is zGetMTF or PMTF. However, the zGetMTF requires a settings file.

Anyone know how to create or get this file from the current system loaded into the LDE.

Here is an example of what I need:
Polychromatic say 486 530 550 630, weights 10 40 40 10
fields 0 10 20 degrees, weights 1 1 1
freq 0-300
sampling 128 x128

Subject: MZDDE matlab to Zemax MTF calculation

From: Michael

Date: 21 Jun, 2011 12:47:04

Message: 3 of 4

Hello Everyone,

I was correct thet the zGetTextFile was what I needed. I have set the function to save the settings to a file "MySettingsFile"; however, at first glance this does not appear to be a simple txt file does anyone know how to read this file so I can view the contents and make sure it is functioning (running according to the the default parameters with weigths ect..

zmxOTFa=zGetTextFile('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile', 'Mtf', 'C:\Documents and Settings\mlisowski\My Documents\MATLAB\MySettingsFile', 0)

Subject: MZDDE matlab to Zemax MTF calculation

From: Michael

Date: 21 Jun, 2011 20:00:19

Message: 4 of 4

Helllo Everyone,

I still have the of how to verify the contents of MySettings file.

But the main reason for my post is the code below. It appears to be functional (I am still verifing the output is the same as what . However, I would appreciate any feed back on how this could be streamlined or if there are any errors that would cause errors.

%% Intro
% Created M. Lisowksi
% June 22, 2011
% File Designed to Calculate the Frequency (cy/mm) at which
% a minimun desired contrast level is reached as the source position is moved
% polychromatic and 3 field point
%
%
%% Establish Link
link = zDDEInit;

if link~=0
    warndlg('Link not established','!! Warning !!')
end

zGetRefresh
%% Verify Correct File
Time=8;
zSetTimeout(Time);
%zGetFile
%zGetRefresh
%% Set Inital Parameters
StartPosition =5000;
zSetSurfaceData(0,3,StartPosition);

Status=zPushLens(3);
if Status ~=0
  errordlg('Lens not updated','File Error');
end

zGetRefresh;
if Status ~=0
  errordlg('Lens not refreshed','File Error');
end

EndPosition = 10000;
Interval =1000;
NumStep= abs((StartPosition-EndPosition)/Interval);
ContrastLevel=0.5;
%% Inital MTF Data
Reply=zGetTextFile('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile', 'Mtf', ...
    'C:\Documents and Settings\mlisowski\My Documents\MATLAB\MySettingsFile', 0);
if Reply ==0
    errordlg('MTF not Calculated','File Error')
end

zmxOTF = ReadZemaxOTF('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile');
AvezmxOTF=zeros(length(zmxOTF.data),3);
[m,n] = size(AvezmxOTF);
FreqContrastLevel=zeros(NumStep,n+1);%need #step
counter=1;
PlotZemaxOTF(zmxOTF)

%% Evaluate
for position= StartPosition:Interval:EndPosition
     %% Processing
     disp('Processing....Please wait')
     %% Average Tangnetial and Sagital for all filed points
     
     for i=1:length(zmxOTF.data)
         AvezmxOTF(i,1)= (zmxOTF.data(i,1)+ zmxOTF.data(i,2))/2;
         AvezmxOTF(i,2)= (zmxOTF.data(i,3)+ zmxOTF.data(i,4))/2;
         AvezmxOTF(i,3)= (zmxOTF.data(i,5)+ zmxOTF.data(i,6))/2;
         
     end
         overContrast_level = AvezmxOTF > ContrastLevel;
      
         index_level=zeros(1,n);
      %% Find Contrast Frequency
         for temp=1:1:n
            index_level(1,temp)= nnz(overContrast_level(1:end,temp));
            if index_level(1,temp)<= 1 %test closest value
                warndlg('Contrast never greater than Specified Limit','!! Warning !!')
                index_level(1,temp)=1;
            elseif index_level(1,temp)<= (m-1)
                diff1= AvezmxOTF(index_level(1,temp),temp)-0.5;
                diff2= 0.5 - AvezmxOTF(index_level(1,temp)+1,temp);
                if diff2<diff1
                    index_level(1,temp)=index_level(1,temp)+1;
                end
            else
                warndlg('Contrast never less than Specified Limit','!! Warning !!')
            end
            
         end
       %% Output Matrix
         FreqContrastLevel(counter,1)=position;
         for temp=1:1:n
             FreqContrastLevel(counter,temp+1)=zmxOTF.abscis(index_level(1,temp));
         end

%% Plot Data
% PlotZemaxOTF(zmxOTF)
%% Setup Next Loop
counter=counter+1;

if position < EndPosition
    zSetSurfaceData(0,3,(position+Interval));
    
    Status=zPushLens(10);
    if Status ~=0
        errordlg('Lens not updated','File Error');
    end
    
    zGetRefresh;
    if Status ~=0
        errordlg('Lens not refreshed','File Error');
    end
    
    Reply=zGetTextFile('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile', 'Mtf', ...
        'C:\Documents and Settings\mlisowski\My Documents\MATLAB\MySettingsFile', 0);
    if Reply ==0
        errordlg('MTF not Calculated','File Error')
    end
    %zPushLens(10);
    %zGetRefresh;
    zmxOTF = ReadZemaxOTF('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile');
    AvezmxOTF=zeros(length(zmxOTF.data),3);
    [m,n] = size(AvezmxOTF);
end
end
 %% Plot Results
PlotZemaxOTF (zmxOTF)
PlotZemaxOTFContrast (FreqContrastLevel, zmxOTF)

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
toolbox Michael 20 Jun, 2011 16:09:08
zemax Michael 20 Jun, 2011 16:09:08
rssFeed for this Thread

Contact us at files@mathworks.com