MATLAB code for designing collection optics for 2p scopes

The Tsai book chapter from Ron Frostig’s CRC book is a great resource for building your own 2p microscope. In section 3.3.7.2, they describe how to design the collection optics. They use a straightforward single lens design, lay out the optics equations, and show a family of curves for several variables (Fig. 3.14). They do an excellent job of giving the reader an intuitive feel for the engineering compromises inherent in these systems.

I’ve found myself repeatedly going through these calculations for different magnification factors. Or “minification” factors, as is typically the case, since the back aperture of the objective is imaged onto the PMT, which is typically about a third to a quarter of the size.

In order to save time, I wrote a tiny MATLAB program to reproduce Fig 3.14 and overlay points indicating where to place the optics in order to have a particular magnification factor. I used it to generate the figure above.


%% Dist_cl_pmt, dist_obj_cl, f_cl
% Eqn. 3.18 from Tsai et al. 2009 (CRC);
% dist_cl_pmt = (dist_obj_cl * f_cl) / (dist_obj_cl - f_cl)
% Below, for brevity, we use L1 = dist_obj_cl
% Below, for brevity, we use L2 = dist_cl_pmt

% Make a family of curves relating these quantities.
f_cl = 5:5:50; % Collection lens focal lengths, in mm.
L1 = 50:1:250; % dist_obj_cl
mag = 0.24; % Magnification factor.

for f=1:numel(f_cl)
    for L=1:numel(L1)
        L2(f,L) = (L1(L)*f_cl(f))/(L1(L) - f_cl(f));
    end
    L1m(f) = (f_cl(f)/mag) + f_cl(f);
    magloc(f)=locateVal(L1m(f),L1);
    L2m(f) = L2(f,magloc(f));
end

for f=1:numel(f_cl)
    M{f}=num2str(f_cl(f)); % Labels for the different mag lines
end
figure
plot(L1,L2);
xlabel('L_1: Distance from objective back plane to collection lens (mm)')
ylabel('L_2: Distance from collection lens to PMT (mm)')
axis([50 250 0 200])
legend(M,'Location','NorthEast')
legend('boxoff')
title(sprintf('Relation between L_1 and L_2 for different f_C_L, indicating positions for mag=%g',mag))
hold on
plot(L1m,L2m,'o')
hold off