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 Comments

John D'Errico
John D'Errico on 23 Apr 2017
Edited: John D'Errico on 23 Apr 2017
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.
In my case I know that it is a sine wave and I just don't know exactly what amplitude and frequency describes that sine wave. I understand concept of noise and in my thesis that sine save is a noise which I want to erase.

Sign in to comment.

Answers (1)

Matt J
Matt J on 23 Apr 2017
Edited: Matt J on 23 Apr 2017
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].

Categories

Asked:

on 23 Apr 2017

Commented:

on 23 Apr 2017

Community Treasure Hunt

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

Start Hunting!