# MATLAB Scripts

Programs that may be useful for other researchers can be found here.

## Centroid.m

This is my (unexpectedly famous) algorithm for calculating the center of mass (centroid) of a resonance peak with minimal noise and high robustness. It is based on performing a high order polynomial fit to the data, thereby generating a continuous spectrum which circumvents issues ssociated with deciding how many discrete pixels that should be included.

The polynomial fit is also very fast and the expression does not have to be integrated numerically. You can easily run the analysis while measuring in real-time unless the temporal resolution should be extreme.

â€‹

You are free to use the MATLAB code for any purpose but please cite the original reference:

A.B. Dahlin, J. Tegenfeldt, F. Höök, Analytical Chemistry 2006.

It should hopefully be clear how the calculation is done if you read through the paper.

## TransferMatrix.m

This program calculates the transmission, reflection and absorption in an arbitrary thin film multilayer system.

When run as is, the program generates the far field angular spectrum (670 nm incident light) of a 50 nm gold film on glass in water. The surface plasmon excitation is seen as a dip in the reflection. The simulation also includes a dielectric coating on the gold film (n = 1.4) with different thickness (hence the series of graphs). This can be thought of as a simulation of a plasmonic biosensor system.

The TransferMatrix program can be used to simulate transmission through and reflection from any kind of thin film multilayer - just change the parameters in the beginning of the file! You can also change to a wavelength spectrum at a fixed angle of incidence. If a material is dispersive you should just include a new refractive index calculation in the wavelength loop.

I use the TransferMatrix program to simulate the transmission of light through thin film multilayers. Although the program naturally does not consider nanostructures it still gives a good estimate of peaks and dips due to Fabry-Pérot interference and simplifies interpretation of experimental spectra.

You are free to use the MATLAB code for any purpose but please cite the reference:

J. Junesch, T. Sannomiya, A.B. Dahlin, ACS Nano 2012.

The supporting information for this paper describes the program. Note that this does not mean that I invented the transfer matrix algorithm! You should cite other articles for that.

## SurfaceWaves.m

This program calculates the dispersion relation for transverse magnetic surface waves in an arbitrary thin film multilayer system. When used as is, it will calculate the dispersion relation of hybridized surface plasmon modes in a metal-insulator-metal system (20 nm Au on both sides of a 50 nm n = 2.24 dielectric in air). The figure below shows the results of solving for the higher energy hybridized bonding mode. The plots generated are for dispersion, propagation length and fields. (The magnetic field gives a 1D plot for TM modes while the electric field is more complicated to visualize since it has two components.)

The algorithm solves the equations by finding the real and imaginary parts of the k-vector by minimization. The program starts with generating a plot of the numerical residual for different values of the k initial guess. You should click in the plot at a location where you see a minimum. Different minima correspond to different modes.

The program will not always converge to a solution. Sorry about that. Sometimes it gets stuck in the loop depending on what system you have simulated. Also, you need to modify the code if you want to solve for TE modes (plasmonic modes are TM).

You are free to use the MATLAB code for any purpose but please cite a suitable reference like:

The supporting information for this paper describes the calculations in detail.