02-04-2026 09:59 AM
This is kind of an abstract question I realize; However, I thought I would give it a try as you folks have been very kind to me in the past.
Does anybody have a LabVIEW VI example that would input a raw optical spectrum then compute dominant wavelength?
I also realize I can use other tool functions such as DLL based software that comes with the spectrometer.
Lux PY ETC.
I was hoping for something that just mathematically computes dominant or centroid wavelength from a raw spectrum. (In LabVIEW solely)
Attaching a text file with a spectrum just in case
02-04-2026 10:15 AM
What is the dominant wavelength in your data? Is it the max or the other peak?
LabVIEW has built in Max/Min functions for arrays and a built in peak-finder. Have you tried those?
02-04-2026 10:48 AM - edited 02-04-2026 10:53 AM
@LED47 wrote:
I was hoping for something that just mathematically computes dominant or centroid wavelength from a raw spectrum. (In LabVIEW solely)
You have two peaks. Do you want to process the entire data or just the broader peak on the right?
I assume with "centroid" you are looking for the wavelength that splits the spectrum in two separate equal areas. For that you would just do a normalized integral, then use threshold array for find the point where the integral is 0.5.
Can we assume that the data does not have an offset? Your x-values are not spaced equally.
02-04-2026 10:54 AM
I would want to process the entire data.
I would want dominant wavelength I only put centroid in there because I didn't know what I was talking about.
But I could use the centroid value If you had an example of that in Labview that would be very helpful?
Yes we can assume the data does not have an offset
02-04-2026 11:09 AM - edited 02-04-2026 11:22 AM
If you search for the max peak, in your case the data is clipped or has a nearly flat top (bandwidth), from ~438 to ~444 nm
so you have to decide if you what you want to measure ....
but maybe look for the peaks in the top?
02-04-2026 11:29 AM - edited 02-04-2026 12:00 PM
Yes, the term "centroid" typically relates to geometry, so I was just trying to figure out what you mean. It defines the center of gravity, so here it would split the graph into two equal areas.
Here's code that would roughly do that (result is ~550.733. What value do you expect).
02-04-2026 11:42 AM
Thank you... I'll give that a try and let you know how it goes
02-04-2026 11:57 AM
I work with lasers professionally and also use spectrometers regularly.
Other people have mentioned this somewhat, but it looks like the spectrum you have captured is clipped at around the 440 nm mark, because the signal is very close to what is almost certainly the max limit of a 16-bit spectrometer. It would be more obvious if the data was 65565 the entire time because that's exactly (2^16)-1, but the spectrometer has likely been calibrated with a "dark level" per pixel that's being subtracted to give you the jagged peak you see there. Likely the 440 nm signal you see is 2-10 times more powerful than you can see and is much more dominant, to the point where the wider "hump" in the 500-700 range is really much shorter than it is depicted as on the spectrum and so it is currently over-emphasized. I would add something to your data capture code to look for anything above 95% of the max allowed by the detector and if found, lower the exposure time or gain until it's no longer saturating the sensor.
Honestly, I am kind of wondering if you have a primarily 440 nm laser source and the remainder of the spectrum that you see there is just background light from the room you're in. If so, you likely need to put some light blocking around your test setup.
You haven't yet mentioned the overall goal of your task. Is this homework? Grad student/PhD work? Commercial application?
This is a case where, if it is a practical application rather than an academic one, trying to just use math to get a "centroid" may not produce a helpful result. In my line of work we often are tasked to put as much power in one narrow wavelength band as possible while ignoring the remainder because it's unhelpful, so it might be to the point where your real measurements should be split into at least two. First, find the peak power, then find the rough width of that peak, then calculate the centroid only on an area that's double the peak width or so. Then, if needed, check for any other light not around the main peak, and calculate how much light is there in a separate calculation.
02-04-2026 12:35 PM
We really don't know what the data represents. Could it be that the sharp peak is an excitation wavelength and the broad peak are the emissions from quantum dots? In this case only the broad peak would really be interesting.
You said that the instrument reports the correct result. What would that be for the current data?
So, please explain the experiment in detail.
02-04-2026 12:37 PM
The overall system I'm developing is LED platelet function test.
Yes it's a 440 nanometer laser, The data I sent you is saturated...
It's a commercial project.
I do subtract the dark spectrum.
A lot of ambient light in this site at the moment..
Currently I do run Lux Py both dominant wavelength and centroid wavelength..
I would really want to use dominant wavelength and see if I could get a small VI that would give me that without having to bring in Lux Py
I need dominant wavelength at every point that I'm measuring on the platelet wafer and if I'm running Lux Py that's increasing the test time