Fitting Cosine function to many different data sets.

9 ビュー (過去 30 日間)
Edward Blocker
Edward Blocker 2019 年 4 月 14 日
コメント済み: Star Strider 2019 年 4 月 17 日
Hi,
I am calibrating a camera and need to fit a cosine curve to each pixel. There 2048x2448 pixels. There's a total of 19 images of different intensities . I am trying to fit each pixel to a cosine function across the different images.
I used a fit function
fit = @(A,B,C,x) A + B.*(cos((x) + C)) ;
and put the paramters i wanted into a matrix whose location correspondeded to which pixel ir refers to.
The problem arises when i have a for loop to do this for all the pixels. It would take 5 years for the code to run .
Is there any tips for optimization? I can easly predict close to what the fit will look like; is there a way to implement this?
Any help/tips are greatly appreciated

採用された回答

Star Strider
Star Strider 2019 年 4 月 17 日
Thi idea I deleted is to use the Angle sum and difference identities (link) to linearise your regression, since linear regressions are significantly faster than nonlinear regressions, especially in MATLAB.
The derivation and detais:
In the context of your model, this becomes:
or:
where:
so after the linear regression is finished, calculating the B and C parameter involves initially
squaring them:
restated:
and if I did my maths correctly:
then knowing B, it is possible to calculate C, ideally as:
The reason I initially deleted it has to do with my not being able to specifically constrain and as functions of each other or of another parameter so that B and C would be unambiguous, so that B and C calculated from either or would yield approximately the same result. I cannot be certain that would hold, and as I mentioned, I cannot devise a way of constraining them as functions of each other or of another parameter so that it would. (You may also be able to eliminate A by subtracting the mean of your signal.)
I am confident that the linear regression will be faster. I cannot claim that the parameter estimates will be as reliable.
  2 件のコメント
Edward Blocker
Edward Blocker 2019 年 4 月 17 日
thanks for the help, I will try it out.
Star Strider
Star Strider 2019 年 4 月 17 日
As always, my pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGaussian Process Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by