PeakPika

Tolbert Lab, UCLA

2025

MATLAB
Project Description

PeakPika is a scientific computing package for fitting spectral peaks, originally developed to analyze the vibronic progressions of polarons in semiconducting polymers. Users specify approximate peak positions and apply constraints, such as shared peak widths or fixed interpeak spacing, before the package numerically optimizes the fit.

PeakPika generates reports containing optimized peak parameters, including peak centers, heights, and standard deviations, along with the root-mean-square deviation (RMSD) as a measure of fit quality. The package also provides tools for spectral preprocessing, including background subtraction, normalization, trimming, unit conversion, and masking. In research applications, PeakPika was used to automate parameter sweeps and investigate whether alternative fits could achieve comparable or lower RMSD values. The fixed interpeak spacing constraint for peak series could also be relaxed to test whether the fitted peaks remained consistent with assignment to the same vibronic progression.

Cleaned UV-Vis spectrum Cleaned UV-Vis spectrum
Optimized peak fit including 1 peak series and 4 individual peaks Optimized peak fit including 1 peak series and 4 individual peaks
Technical Architecture

PeakPika is implemented in MATLAB and ingests spectral data from CSV files. The package represents fitting components using two object types: individual peaks and peak series. Peak series initialize groups of peaks with shared widths and uniform spacing between peak centers. During optimization, users can independently specify whether these width and spacing constraints should be maintained or relaxed.

Users construct and configure fitting components programmatically, with individual peaks and peak series organized within a larger fitting container. Following optimization, the package exports fitted spectral data, optimized peak parameters, and fit statistics to CSV files for further analysis.

Engineering Highlights
Preserving Spectral Sampling

Spectroscopic data can be represented using different horizontal-axis units, including wavelength (\(\lambda\), nm) and wavenumber (\(\tilde{\nu}\), cm⁻¹). Because these quantities are related nonlinearly, uniformly spaced samples in one representation become nonuniformly spaced when converted to another.

\( \tilde{\nu}\;(\mathrm{cm}^{-1}) = \dfrac{10^7}{\lambda\;(\mathrm{nm})} \)

To preserve point correspondence between experimental spectra and fitted peaks, PeakPika initializes each peak using the original spectrum's x-axis coordinates. Subsequent unit conversions transform both the measured data and fitted peaks together, ensuring that corresponding points retain identical x-axis values. Similarly, trimming and masking operations replace excluded values with NaN rather than removing data points, preserving the shared coordinate grid at the cost of retaining some additional data in memory. Rows containing NaN values are excluded during RMSD calculation to prevent masked regions from influencing fit optimization.

Coordinated Parameter Optimization

The primary computational challenge in developing PeakPika was optimizing multiple overlapping spectral peaks under weakly constrained conditions. Because overlapping peaks have interdependent parameters, optimizing them without coordinating their adjustments can produce unstable or physically implausible fits.

To address this challenge, I developed a coordinated, derivative-free optimization algorithm using user-defined step sizes for each parameter type. During each optimization cycle, the algorithm evaluates candidate parameter adjustments for each peak and selects the single adjustment that most improves the overall fit for that peak. Updates are performed sequentially across peaks, allowing each peak an opportunity to optimize before subsequent rounds of adjustment. This approach helps prevent individual peaks from dominating the spectrum before neighboring peaks can adjust.

Because the algorithm can converge to local minima, PeakPika supports automated parameter searches across multiple initial configurations. These searches help identify alternative solutions with comparable or lower RMSD values and assess the sensitivity of the resulting fit to its initial conditions.

Collaborators

PeakPika was designed, developed, and maintained by me as part of my PhD research at the University of California, Los Angeles (UCLA), under the guidance of my principal investigator, Professor Sarah Tolbert.