Forums

Which Scilab curve fitting approach is most applicable.

Started by Richard Owlett November 12, 2007
Ultimate Goal:
Get a feel for pitfalls associated with changing sample rate.
Immediate Goal:
Create an artificial test signal which I intuitively understand.

Starting point:
Audio CD of text being read. It was originally recorded for cassette 
tape distribution circa 1974. Identical Material later distributed on 
CD. Assume from looking at FFT that original was likely low pass limited 
at 8-10 kHz.

I've had glancing contact with using splines to do curve fitting. I 
would like to use an algorithm which forces the fit to pass thru the 
"known" points. I would then "sample" at 4 - 16 times the current 44.1 kHz.

Suggestions?
Richard Owlett wrote:
> Ultimate Goal: > Get a feel for pitfalls associated with changing sample rate. > Immediate Goal: > Create an artificial test signal which I intuitively understand. > > Starting point: > Audio CD of text being read. It was originally recorded for cassette > tape distribution circa 1974. Identical Material later distributed on > CD. Assume from looking at FFT that original was likely low pass limited > at 8-10 kHz. > > I've had glancing contact with using splines to do curve fitting. I > would like to use an algorithm which forces the fit to pass thru the > "known" points. I would then "sample" at 4 - 16 times the current 44.1 kHz. > > Suggestions?
Splines are probably the right choice if you must pass through known points, and Scilab provides spline functions. If I'm not mistaken a spline on data that's evenly spaced ends up being a linear transformation -- if the spline function in Scilab takes a prohibitively long time you may be able to speed things up by calculating & running the correct polyphase filter. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Tim Wescott wrote:

> Richard Owlett wrote: > >> Ultimate Goal: >> Get a feel for pitfalls associated with changing sample rate. >> Immediate Goal: >> Create an artificial test signal which I intuitively understand. >> >> Starting point: >> Audio CD of text being read. It was originally recorded for cassette >> tape distribution circa 1974. Identical Material later distributed on >> CD. Assume from looking at FFT that original was likely low pass >> limited at 8-10 kHz. >> >> I've had glancing contact with using splines to do curve fitting. I >> would like to use an algorithm which forces the fit to pass thru the >> "known" points. I would then "sample" at 4 - 16 times the current 44.1 >> kHz. >> >> Suggestions? > > > Splines are probably the right choice if you must pass through known > points, and Scilab provides spline functions.
Thanks for attempting to reply. My question evidently not phrased well. Doing "help spline" in Scilab gives 10 hits - 5 apparently not relevant as being 3 dimensional. I find the descriptive information on the others to be excessively terse. And the examples don't give hints as which functions are suitable for which problems. Part of my problem is that I'm weak in math theory, so I'm looking for something approaching a cookbook solution.
> > If I'm not mistaken a spline on data that's evenly spaced ends up being > a linear transformation
Not sure what "linear transformation" means in context. I would take it as the math that describes a 2-port LTI network to which linear superposition applies.
> -- if the spline function in Scilab takes a > prohibitively long time you may be able to speed things up by > calculating & running the correct polyphase filter. >
I've got LOTS of time and insignificant understanding of digital filters - polyphase or not ;/ In fact upsampling by stuffing in 0's is so counterintuitive to lead me to funny farm.
On Nov 12, 1:48 pm, Richard Owlett <rowl...@atlascomm.net> wrote:
> Tim Wescott wrote: > > Richard Owlett wrote: > > >> Ultimate Goal: > >> Get a feel for pitfalls associated with changing sample rate. > >> Immediate Goal: > >> Create an artificial test signal which I intuitively understand. > > >> Starting point: > >> Audio CD of text being read. It was originally recorded for cassette > >> tape distribution circa 1974. Identical Material later distributed on > >> CD. Assume from looking at FFT that original was likely low pass > >> limited at 8-10 kHz. > > >> I've had glancing contact with using splines to do curve fitting. I > >> would like to use an algorithm which forces the fit to pass thru the > >> "known" points. I would then "sample" at 4 - 16 times the current 44.1 > >> kHz. > > >> Suggestions? > > > Splines are probably the right choice if you must pass through known > > points, and Scilab provides spline functions. > > Thanks for attempting to reply. My question evidently not phrased well. > > Doing "help spline" in Scilab gives 10 hits - 5 apparently not relevant > as being 3 dimensional. I find the descriptive information on the others > to be excessively terse. And the examples don't give hints as which > functions are suitable for which problems. > > Part of my problem is that I'm weak in math theory, so I'm looking for > something approaching a cookbook solution. > > > > > If I'm not mistaken a spline on data that's evenly spaced ends up being > > a linear transformation > > Not sure what "linear transformation" means in context. I would take it > as the math that describes a 2-port LTI network to which linear > superposition applies. > > > -- if the spline function in Scilab takes a > > prohibitively long time you may be able to speed things up by > > calculating & running the correct polyphase filter. > > I've got LOTS of time and insignificant understanding of digital filters > - polyphase or not ;/ In fact upsampling by stuffing in 0's is so > counterintuitive to lead me to funny farm.- Hide quoted text - > > - Show quoted text -
Do you just need to do cubic interpolation do you need to have smooth derivatives at the knots? A cubic interpolation between 4 points is easy. A cubic spline that makes sure the the first derivative is smooth at knots and the second derivative is continuous. Splines may be a liitle more that what you really need. They require solving a system of equations. One for every point. I don't think that is practical for music. Cubic interpolation using 4 points is MUCH easier. Peter Nachtwey
pnachtwey wrote:
> On Nov 12, 1:48 pm, Richard Owlett <rowl...@atlascomm.net> wrote: >> Tim Wescott wrote: >>> Richard Owlett wrote: >>>> Ultimate Goal: >>>> Get a feel for pitfalls associated with changing sample rate. >>>> Immediate Goal: >>>> Create an artificial test signal which I intuitively understand. >>>> Starting point: >>>> Audio CD of text being read. It was originally recorded for cassette >>>> tape distribution circa 1974. Identical Material later distributed on >>>> CD. Assume from looking at FFT that original was likely low pass >>>> limited at 8-10 kHz. >>>> I've had glancing contact with using splines to do curve fitting. I >>>> would like to use an algorithm which forces the fit to pass thru the >>>> "known" points. I would then "sample" at 4 - 16 times the current 44.1 >>>> kHz. >>>> Suggestions? >>> Splines are probably the right choice if you must pass through known >>> points, and Scilab provides spline functions. >> Thanks for attempting to reply. My question evidently not phrased well. >> >> Doing "help spline" in Scilab gives 10 hits - 5 apparently not relevant >> as being 3 dimensional. I find the descriptive information on the others >> to be excessively terse. And the examples don't give hints as which >> functions are suitable for which problems. >> >> Part of my problem is that I'm weak in math theory, so I'm looking for >> something approaching a cookbook solution. >> >> >> >>> If I'm not mistaken a spline on data that's evenly spaced ends up being >>> a linear transformation >> Not sure what "linear transformation" means in context. I would take it >> as the math that describes a 2-port LTI network to which linear >> superposition applies. >> >>> -- if the spline function in Scilab takes a >>> prohibitively long time you may be able to speed things up by >>> calculating & running the correct polyphase filter. >> I've got LOTS of time and insignificant understanding of digital filters >> - polyphase or not ;/ In fact upsampling by stuffing in 0's is so >> counterintuitive to lead me to funny farm.- Hide quoted text - >> >> - Show quoted text - > > > Do you just need to do cubic interpolation do you need to have smooth > derivatives at the knots? A cubic interpolation between 4 points is > easy. A cubic spline that makes sure the the first derivative is > smooth at knots and the second derivative is continuous. Splines may > be a liitle more that what you really need. They require solving a > system of equations. One for every point. I don't think that is > practical for music. Cubic interpolation using 4 points is MUCH > easier. > > Peter Nachtwey > >
A spline is certainly overkill. But Pentiums and math packages make overkill easy: ptd = 0:10; ptd = [ptd; sin(ptd)]; // make a 'signal' to smooth pt = smooth(ptd, 0.05); // smooth it with splines clf; // clear the current figure plot2d(ptd(1,:), ptd(2,:)); // plot the 'jaggy' signal plot2d(pt(1,:), pt(2,:), style = 2); // plot the smoothed signal -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Tim Wescott wrote:
> pnachtwey wrote: > >> On Nov 12, 1:48 pm, Richard Owlett <rowl...@atlascomm.net> wrote: >> >>> Tim Wescott wrote: >>> >>>> Richard Owlett wrote: >>>> >>>>> Ultimate Goal: >>>>> Get a feel for pitfalls associated with changing sample rate. >>>>> Immediate Goal: >>>>> Create an artificial test signal which I intuitively understand. >>>>> Starting point: >>>>> Audio CD of text being read. It was originally recorded for cassette >>>>> tape distribution circa 1974. Identical Material later distributed on >>>>> CD. Assume from looking at FFT that original was likely low pass >>>>> limited at 8-10 kHz. >>>>> I've had glancing contact with using splines to do curve fitting. I >>>>> would like to use an algorithm which forces the fit to pass thru the >>>>> "known" points. I would then "sample" at 4 - 16 times the current 44.1 >>>>> kHz. >>>>> Suggestions? >>>> >>>> Splines are probably the right choice if you must pass through known >>>> points, and Scilab provides spline functions. >>> >>> Thanks for attempting to reply. My question evidently not phrased well. >>> >>> Doing "help spline" in Scilab gives 10 hits - 5 apparently not relevant >>> as being 3 dimensional. I find the descriptive information on the others >>> to be excessively terse. And the examples don't give hints as which >>> functions are suitable for which problems. >>> >>> Part of my problem is that I'm weak in math theory, so I'm looking for >>> something approaching a cookbook solution. >>> >>> >>> >>>> If I'm not mistaken a spline on data that's evenly spaced ends up being >>>> a linear transformation >>> >>> Not sure what "linear transformation" means in context. I would take it >>> as the math that describes a 2-port LTI network to which linear >>> superposition applies. >>> >>>> -- if the spline function in Scilab takes a >>>> prohibitively long time you may be able to speed things up by >>>> calculating & running the correct polyphase filter. >>> >>> I've got LOTS of time and insignificant understanding of digital filters >>> - polyphase or not ;/ In fact upsampling by stuffing in 0's is so >>> counterintuitive to lead me to funny farm.- Hide quoted text - >>> >>> - Show quoted text - >> >> >> >> Do you just need to do cubic interpolation do you need to have smooth >> derivatives at the knots? A cubic interpolation between 4 points is >> easy. A cubic spline that makes sure the the first derivative is >> smooth at knots and the second derivative is continuous. Splines may >> be a liitle more that what you really need. They require solving a >> system of equations. One for every point. I don't think that is >> practical for music.
Ahhh. But I had stated I was working with someone reading text. None of the problems associated wide wide variation of pitch and/or source(s).
>> Cubic interpolation using 4 points is MUCH >> easier. >> >> Peter Nachtwey >> >> > A spline is certainly overkill. But Pentiums and math packages make > overkill easy:
and *FAST* ;}
> > ptd = 0:10; ptd = [ptd; sin(ptd)]; // make a 'signal' to smooth > pt = smooth(ptd, 0.05); // smooth it with splines > clf; // clear the current figure > plot2d(ptd(1,:), ptd(2,:)); // plot the 'jaggy' signal > plot2d(pt(1,:), pt(2,:), style = 2); // plot the smoothed signal >
I had tried smooth() before. *APPARENTLY* unsuccessfully. I was wrong. It not only had worked, but had done exactly what I was trying to accomplish. It was an educationally worthwhile "failure" :> The key was that the CD sampling rate was high enough compared to the signal's highest frequencies that I had had to use very high magnification to observe the difference between the raw data and the smoothed data. Tim's sample code was a better match for my problem than the sample in Scilab's Help system. Thank you.
Have a look:
http://yehar.com/dsp/deip.pdf
-mn
mnentwig wrote:
> Have a look: > http://yehar.com/dsp/deip.pdf > -mn
Just had a chance to glance at the table of contents. It looks worthwhile. From the title page: "Polynomial Interpolators for High-Quality Resampling of Oversampled Audio" by Olli Niemitalo, August 2001. Abstract This paper discusses piece-wise polynomial interpolators used in audio resampling and presents new low-order designs that are optimized for high-quality resampling of oversampled audio. Source code and useful tables for using the interpolators are included.