Wow!. From the OP's post and example he's simply looking to linearly
interpolate between the 4 points in his table that bound the measured
data. A simple task. this is really complicating the issue as presented.
Al
Marko Pavlin (home) wrote:
> There's no easy way to interpolate non-orthogonal data. You must first
> orthogonate it, at leas in one axis. Then use simple PWL method. I am
> using same procedure for calculating temperature compensation of
> pressure sensors.
>
> Here's simple 2D aproximation algorithm (in matlab). Check SPAPS
> documentation for more details.
>
> function [coefs,fn,err,breakx,breaky]=bivsp(x,y,z,dx,dy,kx,ky)
> sp = spap2({kx,ky},[dx dy],{x,y},z);
> pp = fn2fm(sp,'pp');
> coefs =fnbrk(pp,'coefs');
> breaks =fnbrk(pp,'breaks');
> l =fnbrk(pp,'l');
> k =fnbrk(pp,'order');
> d =fnbrk(pp,'dim');
> breakx =breaks{:,1};
> breaky =breaks{:,2};
> err=norm(z-spval(sp,{x,y}))^2;
> m = length(breaks);
> breaksx=breaks{:,1};
> breaksy=breaks{:,2};
> v = coefs;
> sizev = [d,l.*k];
> dd = prod(sizev(1:m));
> v=reshape(v,dd*l(m),k(m));
> for i=1:1:l(m) %scan all number of x segments
> sizesegx=k(1)*l(1);
> a(:,:,i)=v((i-1)*sizesegx+1:(i-1)*sizesegx+sizesegx,:);
> end
> v=[];
> for i=1:1:l(m) %scan all number of x segments
> for p=1:1:l(1)
> for j=1:1:k(1) %scan all number of y segments
> u(j,:,i,p)=a((j-1)*l(1)+p,:,i);
> end
> v=[v;reshape(fliplr( flipud(u(:,:,i,p)))',k(1)*k(m),1)'];
> end
> end
> fn=v;
>
>
>
> I hope that helps.
>
> Onestone wrote:
>
> > Somebody's doing fuel maps from the look of this, however fuel maps just
> > aren't linear the way yours are. You may as well just set the start
> > point and the end point thus:-
> > 0 3500
> > 0 12 61
> > 20 17 52
> > 40 18 151
> > 60 23 198
> > 80 44 121
> > 100 56 140
> >
> > Then for example2300(rpm?) at 55kPa can easily be converted as follows:-
> >
> > for 40kpa, 2300rpm point:
> >
> > F1 = (151-18) * 2300/3500. Of course you would precalculate most of this
> > so:-
> > F1 = 133/3500 * 2300. It makes sense to precalulate the increment /rpm,
> > ie 133/3500
> > F1 = 0.038. In 0:16 (unsigned decimal format) this is equal to 0x09BA
> > (2490)
> > F1 = 09BA * 2300 = 0x57.6318 (.038 * 2300 = 87.4)
> >
> > Now repeast this for the second 60(kPa) row where rpm factor = 175/3500
> > = 0.05 = 3277 or 0x0CCD
> > hence F2 = 0x0073.01CC (0.05 * 2300 = 115)
> >
> > Now to interpolate the kpa part do (F2-F1)/(60-40)*(55-40)
> >
> > Again you could speed this up by pre-storing the 60-40 or divide by 20
> > as a binary decimal. Which happens to be 0.05 or 0x0CCD in 0:16 format
> > so:-
> >
> > F2 - F1 = * 15 = 0x001B.9EB4 * 15 (this orders maintains lowest
> > calculation error) = 0x019E.4C8C
> >
> > Now divide by 20 or multiply by 0x0.0CCD = 0x0014.B759DC1C => 20.716.
> >
> > Finally add the 40kPa 2300 rpm value to this, keeping track of the DP =
> > 0x006C.1A71DC1C. returning to the land of 32 bits this is equivalent to
> > 108.103. Honestly a LOT simpler than it looks. With your tables having a
> > hump you would only need to track the sign of results, which is possibly
> > simpler than tracking signed arithmetic. Anyhow it comes down very
> > simply:_
> >
> > For each kPa point store the difference between 0RPM value and 3500RPM
> > value divided by 3500 as a binary decimal.
> > This gives you 6 values in your scenario, call them K0 - K5, call the
> > pressures at these values P'0 - P'5
> >
> > read RPM (R), read kPa (P)(obviously if I have guessed wrongly
> > substitute whatever the axes represent)
> > if P exactly matches one of the stored values Kn simply multiply RPM by
> > Kn else
> > multply R * K(P'n<P) = Ix
> > multiply R * K(P'm>P) = Iy
> >
> > next calculate Ix + (Iy - Ix) * (P-P'n)/(P'm-P'n)
> >
> > Might look a bit long winded, but by prestoring a lot of the calculable
> > values you can run the calcualtions very fast.
> >
> > Al
> >
> >
> >
> >
> > Rolf Bredemeier wrote:
> >
> > > Hi,
> > >
> > > i'm searching for an example for 2d linear interpolation.
> > > The data is in an array unsigned char [10][400].
> > >
> > > Here is my "worksheet", may be, it help's to explain for i looking on:
> > > http://www.nur-solutions.de/tmp/2dinterpol.gif
> > >
> > > There is the way to solve the prob. for x-value 55 and y-value 800 =
> > > 59,35
> > >
> > > I need no floting point, unsigned char is only what i need.
> > >
> > > Best regards, Rolf
> > >
> > >
> > > Yahoo! Groups Sponsor
> > > ADVERTISEMENT
> > >
> >
> <http://us.ard.yahoo.com/SIG=129f2ditf/M=298184.6018725.7038619.3001176/D=groups/S=1706554205:HM/EXP=1110610019/A=2593423/R=0/SIG=11el9gslf/*http://www.netflix.com/Default?mqso=60190075>
>
> >
> > >
> > >
> > >
> > >
> ------------------------------------------------------------------------
> > > Yahoo! Groups Links
> > >
> > > * To visit your group on the web, go to:
> > > http://groups.yahoo.com/group/lpc2000/
> > >
> > > * To unsubscribe from this group, send an email to:
> > > lpc2000-unsubscribe@yahoogroups.com
> > > <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
> > >
> > > * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > > Service <http://docs.yahoo.com/info/terms/>.
> > >
> > >
> >
> >
> > *Yahoo! Groups Sponsor*
> > ADVERTISEMENT
> > click here
> >
> <http://us.ard.yahoo.com/SIG=129hbc9up/M=298184.6018725.7038619.3001176/D=groups/S=1706554205:HM/EXP=1110648344/A=2593423/R=0/SIG=11el9gslf/*http://www.netflix.com/Default?mqso=60190075>
>
> >
> >
> >
> > *Yahoo! Groups Links*
> >
> > * To visit your group on the web, go to:
> > http://groups.yahoo.com/group/lpc2000/
> >
> > * To unsubscribe from this group, send an email to:
> > lpc2000-unsubscribe@yahoogroups.com
> > <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
> >
> > * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > Service <http://docs.yahoo.com/info/terms/>.
> >
> >
>
>
> Yahoo! Groups Sponsor
> ADVERTISEMENT
> <http://us.ard.yahoo.com/SIG=129agk7ev/M=298184.6018725.7038619.3001176/D=groups/S=1706554205:HM/EXP=1110650793/A=2593423/R=0/SIG=11el9gslf/*http://www.netflix.com/Default?mqso=60190075>
>
>
>
> ------------------------------------------------------------------------
> Yahoo! Groups Links
>
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/lpc2000/
>
> * To unsubscribe from this group, send an email to:
> lpc2000-unsubscribe@yahoogroups.com
> <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>Message
Re: [lpc2000] 2d linear Interpolation
2005-03-11 by Onestone
Attachments
- No local attachments were found for this message.