필터 지우기
필터 지우기

Fitting a convolution

조회 수: 21 (최근 30일)
Niles Martinsen
Niles Martinsen 2012년 6월 7일
Hi
I have the following piece of code:
------------------------------------------------------------------------------------------
dataX = -4:1:4;
dataY = [0 -1 -10 -40 -55 10 40 10 1];
figure(1)
plot(dataX, dataY, '*');
x = -2:0.01:2;
plot(-4:0.01:4, 1*conv(exp(-x).*heaviside(x),sin(x)), dataX, dataY, '*')
mdl = @(a, x)(a(1)*conv(exp(-x).*heaviside(x),sin(x)));
par=[1];
[fitted_par, r, J, cov, mse] = nlinfit(dataX, dataY, mdl, par);
------------------------------------------------------------------------------------------
What I am trying to do is to fit the function (a convolution) to the data set. However, I get an error due to vector size mismatch. I'm not sure what is going on here: The fitting routine should not care about how many data points I have?
Regards, Niels.

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 6월 8일
Try
mdl = @(a, x)a*conv(exp(-x).*heaviside(x),sin(x),'same');
[fitted_par, r, J, cov, mse] = nlinfit(dataX, dataY, mdl, 1);
  댓글 수: 1
Niles Martinsen
Niles Martinsen 2012년 6월 8일
Hi
Thanks for replying. It runs now, but the fit gives me the amplitude 48.17, which is a horrible guess. Is something wrong with the program, or is it just a difficult function to fit?
Best regards,
Niels.

댓글을 달려면 로그인하십시오.


Niles Martinsen
Niles Martinsen 2012년 6월 8일
Andrei's suggestion works, but when I increase the resolution of x, then the convolution changes as well. Is this just a property on conv, or have I made an error?

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by