Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Implementing splines in a microcontroller
Date: Sun, 22 Nov 2009 16:38:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 61
Message-ID: <hebpdb$j29$1@fred.mathworks.com>
References: <he1kh0$26s$1@fred.mathworks.com> <he1o3c$mqq$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1258907883 19529 172.30.248.37 (22 Nov 2009 16:38:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 22 Nov 2009 16:38:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2100208
Xref: news.mathworks.com comp.soft-sys.matlab:587035


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <he1o3c$mqq$1@fred.mathworks.com>...
> "Tom E" <tom.elliot@students.fhv.at> wrote in message <he1kh0$26s$1@fred.mathworks.com>...
> > Hi folks,
> > 
> > I have a reasonably simple task to do for uni:
> > Take an image
> > Extract the edges
> > Display this using a microcontroller.
> > 
> > Because the display method is as a vector, I have chosen to interpret the edges as splines.
> > 
> > So far I have managed to extract the edges and convert to a series of splines.
> > 
> > Now i've come to the problem of how to implement the resultant data in a microcontroller. I don't really understand how splines are stored in matlab. As far as I understand, splines are a series of curves, all joined together (Bezier curves, paths, however you'd like to call them).
> > 
> > So given a spline in ppform, or B-form, how do I know what the equations are for each of the curves?
> 
> Spline is a polynomial on each subinterval (piecewise polynomials). On each interval, the polynomial is computed with respect to the relative abscissa to its left bound  (leftbound := 0). The coefficients of the polynomials are ranged in each columns of the field COEFS (highest to lowest order - same as used by polyval/polyfit). Consecutive subintervals are separated by the subdivision of the entire interval stored in the field BREAKS.
> 
> Bruno

Hi Bruno,

I'm having trouble understanding your response - unfortunately I'm not as adept at MATLAB as i'd like.

>On each interval, the polynomial is computed with respect to the relative abscissa to its left bound  (leftbound := 0).

Does this mean that if the first polynomial is active from 1 - 4 and the second polynomial is active from 4 - 5, then the second polynomial must be calculated with the abscissa values of (4 - 4) and (5 - 4)?

I have attempted to redraw the spline by extracting the polynomials from the BREAKS and COEFS fields of the struct, however the result is not what I would expect:
------ CODE --------------------------------------------------
clc
clear all;
close all;

x = 0:10;
y = sin(x);
xx = 0:.25:10;
yy1 = spline(x,y,xx);
yy2 = cscvn([x; y]);
subplot(3,1,1);
plot(x,y,'o',xx,yy1)
subplot(3,1,2);
fnplt(yy2,'r');

xvals = 0;
lastval = 0;
for aspline = 1:length(yy2.breaks) - 1 
    xvals = yy2.breaks(aspline);
    subplot(3,1,3);
    yy2coefs = yy2.coefs(aspline,:);
    yy2polyval = polyval(yy2coefs,xvals - lastval);
    plot(xvals, yy2polyval,'-x'), hold on;
    lastval = xvals;
end
------ CODE --------------------------------------------------

could someone please explain to me what i'm missing? I obviously don't correctly understand the way splines are stored.

Thanks,
Tom