Curve fitting for n detected peaks and different intensity

68 Views Asked by At

I am working on spectroscopy data and I am trying to fit a Gaussian curve for each detected peak(shown as a red dot in the graph) but as shown in the graph, the curves are not as expected and I am not sure what's going wrong in the code can anyone help me to fix this. is there any method that can fit the Gaussian curve?

I am trying to do this - expected curves to calculate the area under curve:

expected curves to calculate the area under curve.

def gaussian(x, amp, cen, wid):
    return amp * np.exp(-np.power(x - cen,2.) / (2 * np.power(wid,2.)))

for peak_index in above_noise_peaks:
    #filtered data consists of x and y values
    # filtered_intensity is values of y after buterworth filter

    peak_wavenumber = above_noise_x[peak_index]
    peak_intensity = above_noise_data[peak_index]
    peak_height = filtered_intensity[peak_index] - baseline_corrected_intensity[np.argmax(filtered_data[:, 1] >= peak_wavenumber)]

    peak_heights.append(peak_height)

initial_amplitude = peak_intensity
initial_center = peak_wavenumber
initial_width =  10
popt, _ = optimize.curve_fit(gaussian, filtered_data[:, 1], filtered_intensity, p0=[initial_amplitude, initial_center, initial_width])
fitted_curve = gaussian(filtered_data[:, 1], *popt)
plt.plot(filtered_data[:, 1], fitted_curve, label=f'Gaussian Fit - {intensity_column}', color='orange')

I am getting this

for

initial_amplitude = peak_intensity
initial_center = peak_wavenumber
initial_width =  peak_intensity

I am getting this:

I am getting this

0

There are 0 best solutions below