LsqFit.jl Residuals Interpretation

I have a question regarding interpreting the results of a residual plot. Basically light is decaying inside a cell and we are doing an exponential fit to get the decay time (In layman terms) (Cavity RingDown). There are 20 fits that we are averaging together to get our decay time. Here is what the plot looks like.

image

The grey is the overlap of the 20 decays and the blue line is the fit. Based on that data we get a residuals plot that looks like this.

image

The first 20-30 microseconds are random and looks like a good fit, but towards 30-60 microseconds it starts to have a pattern which from my understanding is not good when it comes to residual plots. Why is this happening or what could be causing this?

Code:

function fitCRD(waveform::Vector{Float64}, n::Int64, startpt::Int64, endpt::Int64; s, model = crd_model, p0 = [0.5, 7.5])
	m = reshape(waveform, :, n) # reshape
	m2 = m[1:endpt, :] # discard second half of period
	time = Array(1:1:size(m2)[1]) .* s^-1 .* 1e6 # compute time values
	τ = ones(Float64, n) # pre-allocate τ array
	A = ones(Float64, n) # pre-allocate A array
	for i in 1:n
		m2[:, i] = m2[:, i] .- mean(m2[(endpt-25):endpt, i]) # baseline correct
		global nlfit = curve_fit(crd_model, time, m2[:, i], p0); # fit
		τ[i] = nlfit.param[2]; 
		A[i] = nlfit.param[1];
	end
	return (τ = τ, A = A, data = m2, t = time, n = n)
end;

Thanks,
W

That pattern is due to having discrete data points of a very low magnitude (since you’re presumably counting photons).

The first 20-30 microseconds are random and looks like a good fit

It really is not a good fit at all. There’s an obvious second exponential in your data, so try modifying your function accordingly. The second exponential term will likely have a fairly small amplitude, but will still improve the fit by quite a bit. I’d also recommend using a goodness of fit metric like \chi^2.

1 Like

Hello,

Thanks for this timely response. We are using an oscilloscope to measure the decays by a photodiode, so our measurements are in volts. But yes the numbers do get really low so that makes sense.

There are 20 waveforms being displayed on the scope. We are reading all the waveforms, breaking them up into individual decays, then doing a fit on each one.

Thanks,
W

Looks to me like an exponentially clamped oscillation, like a damped harmonic oscillator.

Do try a bi-exponential fit with

f(t) = A\cdot e^{-t/\tau_1}+B\cdot e^{-t/\tau_2}

I’m sure there’s some literature around for fitting multiple exponentials for CRDS signals and why that might make sense.

Looks to me like an exponentially clamped oscillation, like a damped harmonic oscillator.

Possible, but I doubt it. The apparent oscillation is a typical artifact when fitting a bi-exponential signal with a single exponential.