开发者

Any alternate approximation to this method in matlab?

I am trying to convert below matlab/octave function to C(Conven开发者_JAVA技巧tional way - understand the matlab function and code it in C from scratch). It is fitting a data to a gaussian curve using polynomial fitting.

   function y=func(data)
   N=128;
   y1=gausswin(N,4);
   x1=[0:1/N:1-1/N]';
   P=polyfit(x1,y1,12);      
   y=polyval(P,data);

But when I checked the functions polyfit, that seemed a lot of work as it involves lot of calls to further octave library functions. It computes a Vandermonde matrix first, then performs some QR decomposition of it, and computes norm of the vector etc...

  1. What other options/processing I can utilize to have similar functionality(approximation of the actual operation happeneing above) but with some simpler curve fitting or interpolation methods.

Any pointers would be useful.


Besides the point of the practical value of fitting such a polynomial to a gaussian, you can just analyze the behavior of your code:

N=128;
y1=gausswin(N,4);
x1=[0:1/N:1-1/N]';
P=polyfit(x1,y1,12);

The output of this section will always be the same, so you can execute this in MATLAB or Octave and just extract the polynomial P for usage in your C code where you include it as a constant. It's less flexible than rewriting everything in C, but it's also faster.

Otherwise, you might want to take a look at BLAS: BLAS defines an API for libraries used for linear algebra such as LAPACK (which is used by MATLAB). I suspect a lot of these libraries will implement the basic operations you need.

Addition: If you have no little experience with numerical computing or just want a lot of work taken out of your hands, you might want to consider Matlab Coder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜