Using polifit in matlab
Show older comments
Hi,
I'm processing some data collected of charges and discharges curves of a battery. To do so, I'm fitting the data to a polynomial using polifit. what I'm doing is the following:
t=time(line,colomn);
V=volt(line,colomn);
sz=size(t,1);
l=150;
n=3;
tab=[];
%charge
for k1=(1+l/2):sz-l/2
x=t((k1-l/2):(k1+l/2),1);
y=V((k1-l/2):(k1+l/2),1);
poly=polyfit(x,y,n);
yf=polyval(pply,t(k1,1));
tab=[tab;t(k1,1) yf];
%But it takes a lot of time doing it. It exist any other way to do the same thing in less time?
%I think that part of the problem come from doing vertcat of each value.
thank you
Accepted Answer
More Answers (1)
Image Analyst
on 2 Jun 2017
2 votes
How much data do you have? Billions of elements? Otherwise it should be really fast. Since the (badly named) l is 150, it looks like the fits are done over only a minuscule 150 points, so that should be blazingly fast to do just a single fit.
It looks like you're trying to fit lots of polynomials in a window sliding along your data. If so, that's basically a Savitzky-Golay filter and can be done efficiently using the function sgolayfilt() in the Signal Processing Toolbox.
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!