I work in a lab making quantum dots, and was recently tasked with finding a way to extract some figures of merit from old data in an automated way. In particular, I'm looking to extract the peak position, and FWHM from a Gaussian fit of said peak. I believe this would normally be relatively trivial, however the data has an unusual shape, which is not playing nicely with Mathematica's built-in functions. An example of the data, zoomed into the ROI is available here

My current procedure is as follows:

  1. Smooth data using Savitsky-Golay (Code obtained from here)
  2. Background Subtract using EstimatedBackground
  3. Use PeakDetect to find the relevant peaks

Unfortunately, the background estimation, and peak detection appear to be very sensitive to the values of $\sigma$ which is chosen. I made a simple Manipulate object to show what I mean: (Example, Yellow=Smoothed Data, Blue=Estimated Background, Green=Background Subtracted, and Orange=Results from PeakDetect)


{EstimatedBackground[smoothed[[;; , 2]], i], 
   smoothed[[;; , 2]], 
   smoothed[[;; , 2]] - EstimatedBackground[smoothed[[;; , 2]], i], 
     smoothed[[;; , 2]] - EstimatedBackground[smoothed[[;; , 2]], i], 
     n]*smoothed[[;; , 2]]},
 DataRange -> {400, 800}, 
  PlotRange -> All
{i, 0, 100}, {n, 0, 100}

I find that a good $\sigma$ value for the Background Subtraction for this particular dataset is ~30 and a good $\sigma$ for the Peak Detection is ~25.

To be clear, the left side of the plot is not of interest to me. It's an example of a standard semiconductor absorbance spectrum (like this), and my peak of interest is simply superimposed on it. Ideally I would simply subtract out the left side using a known function, but it's complicated since it's the result of multiple compounds in a given sample.

In short:

  1. Is there a better way to do this, which will result in more generalizable code?
  2. If my approach is the best way to do this (which I doubt) how can it be improved to require minimal human intervention?
  • $\begingroup$ Apologies, I wasn't aware that you had to do that for cloud objects. I'll edit to reflect that. $\endgroup$ Dec 5, 2019 at 16:00
  • 1
    $\begingroup$ Thank you for adding the code! $\endgroup$
    – MarcoB
    Dec 5, 2019 at 16:04
  • $\begingroup$ @BesselF I get a 403 error when trying to access your cloud code example... (but the data link works OK) $\endgroup$ Dec 5, 2019 at 18:47
  • $\begingroup$ I reposted the Manipulate link that should be accessible. Let me know if it doesn't work. $\endgroup$ Dec 5, 2019 at 19:01


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.