# Use a convolution of two gaussians as a custom fit

3 views (last 30 days)
Bill Francois on 3 Jun 2015
Commented: Bill Francois on 11 Jun 2015
Hi I want to create a function that is the convolution product of two gaussian probability density functions:
f1=normpdf(x,(1-tau)*m,(1-tau*sigma))
and
f2=normpdf(x,tau*m,tau*P*sigma)
where P, sigma and m will be given, and tau will be the fit parameter.
I want to obtain the convolution product: a fuction of x that is the sum from i=0 to x of
f1(i)*f2(x-i)
And use it as a custom fit model with parameter tau.
How can I do this?
I have tried using the conv function:
function[c]=gaussienneconv3(P,tau,sigma,mu,x)
c=conv(normpdf(x,(1-tau)*mu,(1-tau)*sigma),normpdf(x,tau*mu,P*tau*sigma));
end
And then fit wit cftool and a custom fit model but even when I adjusted the size of the data vectors the fit tool did not work with this expression (he said all the points were NaN)
Then I tried with a sum expression:
function[d]=gaussienneconv4(tau,P,sigma,mu,x)
compteur=0;
for i=0:1:x
compteur=compteur+gaussienneconv1(tau,sigma,mu,i)*gaussienneconv2(P,tau,sigma,mu,x-i);
end;
d=compteur;
end
But in this case the fit tool worked but gave me a very bad fit, with a negative R-square, even when using some data computed so that they should have given me an accurate value.
Bill
Bill Francois on 11 Jun 2015
Can anyone please help me with this issue? I am sure it is very easy for you, but I do not manage to make this fit work and it is a major problem in my biology research project.

### Categories

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!