help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Filling in a Matrix


From: robert Macy
Subject: Re: Filling in a Matrix
Date: Mon, 10 Nov 2003 08:44:17 -0800

Thanks to all the suggestions to help me smooth in my
matrix.

My final solution was to go very basic and rederive the
smoothing process starting at linear, then quadrature, and
finally cubic.  

I saw the phrase "bi-cubic spline fit" but could not find
any where to get a copy from anybody that yielded any
workable results.  Hence, a reinvented wheel.  


However, here is the path...

Smoothing types:

Single value holds the value until the next value.  Not
very smooth, simply looks like a series of steps.  That's
like convolving the matrix points with a square step whose
width is eaxactly equal to the distance between the points.


Linear ramps from one value to the next and is like
convolving two square pulses together to make a "two
position" sawtooth [uses data from two points].  This makes
a very smooth looking function until...one takes the
derivative of the results after using this fit.

Quadrature parabolically goes from one data point to the
next, but involves more adjacent data points.  This results
in departing from the actual value at a matrix point - a
concept which still bothers me.  The function is like
convolving another square step with your triangle function.
 If you take the derivative after this smoothing, you get a
series of "lumpy" scallop shapes on your result.  

Cubic spline fit involves one more set of points and
follows a cubic function between points.  You get the shape
of the curve by convolving one more square step with your
parabolic shaped curve.  Or, convolve two of the triangle
shapes.  This produces *very* smooth results which then
yield pretty smooth derivatives.  

I suspect the final solution would be to use a sync
function convolved with the matrix data.  Then the data
points would not be changed, but moving between data points
takes into account *all* other data points.  No need.  This
works.  

It's a piece of cake for single vector, but became a bit
complicated when there were two coordinates.  

I made a "square profile" cubic function that slides along
the matrix.   The operation is like working on a little 4
by 4 matrix pulled out of the middle where you're trying to
fill in.  


But here is the kernel:

Note:  a(x,y) is the matrix.  deltax and deltay are the
distances from the next lowest position in the matrix,
defined as xref and yref, to the value real values of x and
y.  

#  simpleminded sliding "cubic" spline fit     - square
sided profile
xpart(1)=(1-deltax)*(1-deltax)*(1-deltax)/6;
xpart(2)=1/6+(1-deltax)*(1+deltax*(1-deltax))/2;
xpart(3)=1/6+deltax*(1+deltax*(1-deltax))/2;
xpart(4)=deltax*deltax*deltax/6;

ypart(1)=(1-deltay)*(1-deltay)*(1-deltay)/6;
ypart(2)=1/6+(1-deltay)*(1+deltay*(1-deltay))/2;
ypart(3)=1/6+deltay*(1+deltay*(1-deltay))/2;
ypart(4)=deltay*deltay*deltay/6;

smallset=[a(xref-1,yref-1),a(xref,yref-1),a(xref+1,yref-1),a(xref+2,yref-1);
          a(xref-1,yref),a(xref,yref),a(xref+1,yref),a(xref+2,yref);
          a(xref-1,yref+1),a(xref,yref+1),a(xref+1,yref+1),a(xref+2,yref+1);
          a(xref-1,yref+2),a(xref,yref+2),a(xref+1,yref+2),a(xref+2,yref+2)];

retval=ypart*smallset*xpart';



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]