How to fit multiple peaks/dips

15 views (last 30 days)
Sohel Rana
Sohel Rana on 1 Oct 2021
Commented: Star Strider on 1 Oct 2021
I have a set a data where x-axis is the wavelength and y-axis is the intensity. It is seen from the attached image that there are many peaks/dips and it looks smooth. However, when it is zoomed, a lots of smaller peaks/dips is seen in the actual peak positions. I tried the following functions for the smoothness of the peaks.
(i) smooth: it does not help me so much
(ii) smoothdata: it smoothens so much that my results do not go with the theory
Could anyone please suggest me how to apply gaussian peak fitting/any other fittings for each of the peak?
  2 Comments
Star Strider
Star Strider on 1 Oct 2021
I am not certain what you want to do.
The approach I would take would be to do a Fourier transform (the fft function) of the time domain data, then analyse the results. It may be necessary to filter out the sine curve using the bandstop function in order to see the smaller details with reasonable accuracy. That should tell you enough about the data so that you can analyse the smaller peaks.
If you want to filter out the smaller peaks and keep the sine curve, use the bandpass function (essentially the opposite of the bandstop function) to filter out the noise.
.
Sohel Rana
Sohel Rana on 1 Oct 2021
Thank you for your response. I would like to smooth the curve so that I get only one peak instead of mutiple smaller peaks. As you see when I zoomed one of the peaks, it shows many smaller peaks. However, I only want one good peak instead of these smaller peaks.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 1 Oct 2021
See my code to fit multiple Gaussians. Change the number to the number you expect.
You should also look at findpeaks() to find and count the peaks, and sgloayfilt() to smooth the data.
  2 Comments
Sohel Rana
Sohel Rana on 1 Oct 2021
Thank you for your quick response. Before going thorugh your attached code, I would like to request you to address the following query.
What would be the order and framelen? Should I vary as my own will? I can see you ask about the findpeaks and count. Is there any relation between order, framelen with these peaks numbers?
Image Analyst
Image Analyst on 1 Oct 2021
For something that has peaks, you'd typically use an order of 2 or 3. A lower order (1) gives more smoothing while a higher order will allow the fitted polynomial to "hug" the actual signal more closely, giving less smoothing.
For the framelength You'd typically use at least about 5 or 7 elements. The more you use the more smoothing you get. For a signal such as yours you might want to use as many elements as you have in about a quarter or half of a cycle.
Just experiment around until it's smoothed the way you like it.
If the signal is known to be a noisy since wave, rather than a bunch of offset Gaussians, use frequency filtering to get the dominant cyclical signal, like Star said.

Sign in to comment.


Star Strider
Star Strider on 1 Oct 2021
Thank you for your response. I would like to smooth the curve so that I get only one peak instead of mutiple smaller peaks. As you see when I zoomed one of the peaks, it shows many smaller peaks. However, I only want one good peak instead of these smaller peaks.
My pleasure.
I am not certain what you intend by ‘one peak’ and ‘many small peaks’. There is no one peak in the time domain sine curve., instead several, one for each complete cycle
If you use the bandpass function to pass only the predominant frequency (of the sine curve) and eliminate everything else, you will get the one peak you want, at least in the frequency domain.
.
  3 Comments
Star Strider
Star Strider on 1 Oct 2021
The easiest way to smooth the peak is to use the bandpass filter (preferably with the 'ImpulseResponse', 'iir' option) with the passband set so that it isolates the predominant sine signal and rejects the noise.
.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!