Spectral or peak alignment
Show older comments

Hello: I have two spectra, Spectrum A and Spectrum B. Spectrum A is the reference spectrum and spectrum B is one I just collected. I'm trying to match spectrum B with the reference spectrum A. However, I realized that the peaks in B are a bit shifted.
My question is how do I correctly align B to the reference A using matlab?
How do I correct for the peak shifts in my spectrum so that they align correctly to the reference spectrum using matlab or any other program or algorithm?
Thank you.
2 Comments
dpb
on 9 Jul 2017
'Pends on what kind of shift you're talking about...is it simply a phase shift of the whole spectrum or a shrinkage/expansion?
Attach at least figure; data would be better...
Curious Mind
on 9 Jul 2017
Accepted Answer
More Answers (2)
Star Strider
on 9 Jul 2017
1 vote
One option is to use the Signal Processing Toolbox alignsignals (link) function. That is not its intended use, but it could work. (It is relatively recent. The documentation does not say when it was introduced.)
14 Comments
Image Analyst
on 9 Jul 2017
Cool - I didn't know about that function! Thanks for mentioning it.
Star Strider
on 9 Jul 2017
My pleasure!
Star Strider
on 9 Jul 2017
@Francis Kwofie —
The two spectra do not look ‘shifted’ in wavenumber, but varying slightly in amplitude, probably reflecting sample collection or preparation and instrument calibration.
I do not see a problem.
Curious Mind
on 9 Jul 2017
Edited: Curious Mind
on 9 Jul 2017
Star Strider
on 9 Jul 2017
@Francis Kwofie —
I would just use your data as you have them, write off the differences as normal variations and noise, and leave it at that. This is what statistics (specifically statistical tests and confidence intervals) are for.
The best you can probably do is to run the same sample on both instruments, and create a calibration curve. Running different samples on different instruments and expecting the results to match exactly is probably not realistic.
Curious Mind
on 10 Jul 2017
Star Strider
on 10 Jul 2017
I honestly have no idea. This is far outside my areas of expertise.
My Answer was posted long before you posted your image, and I thought that ‘alignment’ referred only to the peaks position in reference to your independent variable. Thus my thought to use the alignsignals function.
The only approach I can think of (and I cannot guarantee that it is valid) is to develop some sort of nonlinear fit between the amplitudes of the two signals, if they share exactly the same values of the independent variable, and use it to equalise the spectra. The polyfit and polyval functions could be one way to do this. (Fit one spectrum to the other, using only the dependent variables of both data sets, not the independent variables. I would keep the polynomial order at 7 or less. Then use the same function to ‘correct’ other spectra you may want to analyse.)
Curious Mind
on 10 Jul 2017
Image Analyst
on 10 Jul 2017
I work with some world class spectroscopists. I could ask them tomorrow. But first I'd like to know if all the peaks are shifted in the same direction. And if so, does alignsignals translate it so that the peaks align to your satisfaction or not.
Curious Mind
on 10 Jul 2017
Image Analyst
on 10 Jul 2017
I asked my best spectroscopist about your spectra, and he said it could be many things. He said by far the most likely reason is the chemistry of your sample. He said that differences in the chemistry between the two samples could shift the peaks in different directions and by different amounts, and that your spectra look perfectly reasonable with that in mind. The peaks will, or may, shift slightly due to the water content, the environment the sample is in, the species and concentrations of various chemicals in the sample, etc. He said the shifts are most likely not due to any problem with your spectrometer instrument, but rather to legitimate differences in the chemistry of the sample itself. He said that any kind of warping of one signal to match the other would be inadvisable Such manipulations might hide/mask/obscure any effect that is truly due to the actual chemistry, and advised you to NOT do that. He said that his best advice would for you to personally consult with an experienced spectroscopist.
dpb
on 10 Jul 2017
What kind of spectroscopy of what sample?
In gamma spec, a slight energy calibration difference will shorten/lengthen on reference spectrum vis a vis another. An alignment there by a linear ratio vs channel will bring the two in line but it is linear by the gain difference. A truly nonlinear response wouldn't occur that way.
Curious Mind
on 10 Jul 2017
Curious Mind
on 10 Jul 2017
Image Analyst
on 9 Jul 2017
0 votes
Look up xcorr in the help and see this entry "Find a Signal in a Measurement". It says "You receive some data and would like to know if it matches a longer stream you have measured. Cross-correlation allows you to make that determination, even when the data are corrupted by noise."
and then it gives an example. Try it.
1 Comment
Curious Mind
on 9 Jul 2017
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!