fminsearch problem with denoising
이전 댓글 표시
Greetings everyone.
I'm trying to use fminsearch to find minumum of specific function. I have noisy function like this:
f = @(x) (sqrt(-x^2+6*x-5)+1+0.01*sin(100*x))*(x>=1&&x<3)
and I'd like to get rid of that sinus function (I assume that I don't know what that sinus is like and I want to find it). So I figured out that I'll do something like this:
function f = objectivefnc1(x)
f = @(x) (sqrt(-x^2+6*x-5)+1+0.01*sin(100*x)-(sqrt(-x^2+6*x-5)+1+x(1)*sin(x(2)*x)))*(x>=1&&x<3)
I thought that I could find amplitude and frequency of that sinus and then subtract it from original function. I need denoised function in further steps of my master thesis. I have another script which looks like this:
x0 = [0.25, 0.25];
fun = @objectivefnc1;
[x,fval] = fminsearch(fun, x0);
But it shows some kind of error like this:
Conversion to double from function_handle is not possible.
My questions are:
- How can I get rid of that error?
- Is it going to work or I'm making some mistakes?
Thank you for your help!
댓글 수: 2
John D'Errico
2017년 4월 23일
편집: John D'Errico
2017년 4월 23일
Why do you think that your noise is purely and simply a sine wave, of some unknown frequency? That is not noise. As well, it would seem to be quite rare for noise to be a single, pure sine wave. My guess is you may be misunderstanding the concept of noise.
Kacper Koziel
2017년 4월 23일
답변 (1개)
Several mistakes. Your objective function needs to return a number. The number is to be an error value, representing the difference between your measured y-values and the ones you predict using a guess, p, of the unknown parameters. fminsearch will try to minimize this error. You must also be careful to use different symbols for your unknown parameters p and the x-values where you sample the function:
function error = objectivefnc1(p, x,y)
model = ( sqrt(-x.^2+6*x-5) + 1 + p(1)*sin(p(2)*x) ).*(x>=1 & x<3)
error=norm(y-model);
end
fun = @(p) objectivefnc1(p, xData,yData);
[p,fval] = fminsearch(fun, [0.01, 100]);
Finally, you must choose a better initial guess than p0=[0.25,0.25], if you know that the true parameters are closer to p=[0.01,100].
카테고리
도움말 센터 및 File Exchange에서 Measurements and Feature Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!