# Fitting data with two peaks

53 Ansichten (letzte 30 Tage)
Niles Martinsen am 4 Jun. 2012
Bearbeitet: John Kelly am 2 Mär. 2015
Hi
I have some data, which is not too different from the top graph in this picture: <http://www.aanda.org/index.php?option=com_image&format=raw&url=/articles/aa/full/2004/12/aa0526/img14.gif>
In other words, there are two peaks that each represent a Lorentzian. I am not sure how to fit this in MatLAB. Is there a way to fit the data to one function consisting of two Lorentzians, or do I have to split the data set in two, one peak in each?
Ultimately I need to find the x-position of each peak.
Best, Niles.
##### 1 KommentarKeine anzeigenKeine ausblenden
Enrique am 30 Jul. 2014
Niles,
Did you ever figure out how to do this and/or implement any of the solutions suggested below? I am trying to fit two Lorentzians to similar Raman data as yours (is yours a graphene Raman spectrum as well?). In the past I have done this using a single Lorentzian fitting function I found ( Lorentzian Function Fit lorentzfit), but have not tried to implement two Lorentzians. Any suggestion would help a lot.
Thanks,
Enrique

Melden Sie sich an, um zu kommentieren.

### Antworten (5)

Geoff am 4 Jun. 2012
Define a function that accepts the parameters of the two lorenzian curves and computes the full curve.
I don't know how many parameters you need cos I'm no mathematician =) Let's say 2?
dualLorentz = @(x, a1, b1, a2, b2) = lorenz(x, a1, b1) + lorenz(x, a2, b2);
Then, define a function to generate that curve, subtract your actual dataset, square the result and sum it.... While you're at it, parameterise the whole thing (ie a vector p of [a1, b1, a2, b2])
objFn = @(p, x, y) sum( (y - dualLorentz(x, p(1), p(2), p(3), p(4))) .^ 2 );
Then chuck it at fsolve or fminsearch - assuming your dataset is in X and Y:
p0 = % some initial guess at a1, a2, b1, b2 : you can probably be very basic
p = fsolve( @(p) objFn(p, X, Y), p0 );
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Image Analyst am 4 Jun. 2012
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Ryan am 4 Jun. 2012
Bearbeitet: John Kelly am 2 Mär. 2015
You could get a close approximation of peak position with a cubic spline fit and local maxima. You could also try just smoothing the data first as well and then finding the maxima.
Cubic Spline:
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Frederic Moisy am 7 Jun. 2012
Hi, you can try the Ezyfit toolbox:
In particular, there is an example with two peaks (here fitted with the sum of 2 gaussian curves):
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Niles Martinsen am 7 Jun. 2012
If I use this approach http://www.mathworks.se/support/solutions/en/data/1-GNRWCU/index.html, is there a way to obtain the errors on the fitted parameters?
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!
{"ft_lang_label":"__label__en","ft_lang_prob":0.7572211,"math_prob":0.7596914,"size":2560,"snap":"2023-14-2023-23","text_gpt3_token_len":745,"char_repetition_ratio":0.09507042,"word_repetition_ratio":0.030905077,"special_character_ratio":0.275,"punctuation_ratio":0.1498195,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9778751,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-03T17:28:21Z\",\"WARC-Record-ID\":\"<urn:uuid:43d859ff-01a9-46cc-b2c7-bbe6717f6ba2>\",\"Content-Length\":\"161720\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:41be9309-ebd1-4327-889a-e4e9103cf89e>\",\"WARC-Concurrent-To\":\"<urn:uuid:1d25fc1d-da9f-4fb4-8234-e3e15cc03df8>\",\"WARC-IP-Address\":\"104.68.243.15\",\"WARC-Target-URI\":\"https://de.mathworks.com/matlabcentral/answers/40272-fitting-data-with-two-peaks\",\"WARC-Payload-Digest\":\"sha1:CYINJVFM2ADBTOSSJKLGV4IPSL5PXKF5\",\"WARC-Block-Digest\":\"sha1:3HMUYGJXW6BUOK3PTLZIRGGWCIBRTUNS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224649302.35_warc_CC-MAIN-20230603165228-20230603195228-00613.warc.gz\"}"}