I would think clipping could be reasonably (audibly) reconstructed by using 2 or 3 samples before the clipping and after the clipping and fitting the sine curve between. Anyone help me or point me to some easy to grasp formulas for fitting such a curve. I looked at nurbs but it is too much for me to dig out of all the information for what might work here. Surely there is an easy formula to derive the sine formula from points. Thanks -- Phil
reconstructing clipping in audio
Started by ●February 12, 2006
Reply by ●February 13, 20062006-02-13
Phil wrote:> I would think clipping could be reasonably (audibly) reconstructed by > using 2 or 3 samples before the clipping and after the clipping and > fitting the sine curve between. > > Anyone help me or point me to some easy to grasp formulas for fitting > such a curve. > > I looked at nurbs but it is too much for me to dig out of all the > information for what might work here. Surely there is an easy formula > to derive the sine formula from points.Make it a third-order polynomial -- the problem becomes a linear best-fitting problem; and a third-order polynomial should produce a very nice and smooth reconstructed signal. Fitting a sine curve where the frequency and phase are unknowns is a non-linear optimization problem, which I'm sure you'll want to avoid. Carlos --
Reply by ●February 13, 20062006-02-13
I think you can just use a best fit algorithm from linear algebra to predict the clipped/missing samples. You have solutions to the curve before and after the clip so you have enough info to determine the coeficients for an Nth order fit with N equations. Since its audio you can probably do a straight matrix inversion since I assume you only do it a couple thousand times a second. Try: http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html -Clark "Carlos Moreno" <moreno_at_mochima_dot_com@mailinator.com> wrote in message news:ImVHf.9435$5D5.174763@weber.videotron.net...> Phil wrote: > > I would think clipping could be reasonably (audibly) reconstructed by > > using 2 or 3 samples before the clipping and after the clipping and > > fitting the sine curve between. > > > > Anyone help me or point me to some easy to grasp formulas for fitting > > such a curve. > > > > I looked at nurbs but it is too much for me to dig out of all the > > information for what might work here. Surely there is an easy formula > > to derive the sine formula from points. > > Make it a third-order polynomial -- the problem becomes a linear > best-fitting problem; and a third-order polynomial should produce > a very nice and smooth reconstructed signal. Fitting a sine curve > where the frequency and phase are unknowns is a non-linear > optimization problem, which I'm sure you'll want to avoid. > > Carlos > --
Reply by ●February 13, 20062006-02-13
Phil wrote:> I would think clipping could be reasonably (audibly) reconstructed by > using 2 or 3 samples before the clipping and after the clipping and > fitting the sine curve between. > > Anyone help me or point me to some easy to grasp formulas for fitting > such a curve. > > I looked at nurbs but it is too much for me to dig out of all the > information for what might work here. Surely there is an easy formula > to derive the sine formula from points.I guess I'm not sure if your premise is correct: if you're trying to reconstruct clipped audio via a sine, the assumption is that the audio itself was a sine. However, if the audio actually _was_ a sine, it probably wasn't interesting enough to be listening to. I often compare non-linear distortions such as clipping to scrambled eggs: you can't un-scramble eggs; the only thing you can do is not scramble them in the first place. That said, the approach you suggest might be better than nothing. If you really want to do that, you might want to look at the interpolation section of one of the "Numerical Recipies" books, which you can find free online in PDF format at http://www.library.cornell.edu/nr/. =g2 _____________________________________________________________________ Grant R. Griffin Publisher of dspGuru http://www.dspguru.com Iowegian International Corporation http://www.iowegian.com See http://www.iowegian.com/img/contact.gif for e-mail address
Reply by ●February 13, 20062006-02-13
Carlos Moreno wrote:> Phil wrote: > >> I would think clipping could be reasonably (audibly) reconstructed by >> using 2 or 3 samples before the clipping and after the clipping and >> fitting the sine curve between. >> >> Anyone help me or point me to some easy to grasp formulas for fitting >> such a curve. >> >> I looked at nurbs but it is too much for me to dig out of all the >> information for what might work here. Surely there is an easy formula >> to derive the sine formula from points. > > > Make it a third-order polynomial -- the problem becomes a linear > best-fitting problem; and a third-order polynomial should produce > a very nice and smooth reconstructed signal. Fitting a sine curve > where the frequency and phase are unknowns is a non-linear > optimization problem, which I'm sure you'll want to avoid.Test this with a two-tone signal like 10*sin(wt) + sin(10*wt). The peak amplitude will be close to 11; clip at 9. Is the "reconstruction" adequate? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●February 13, 20062006-02-13
Jerry Avins wrote:> Carlos Moreno wrote: > >> Phil wrote: >> >>> I would think clipping could be reasonably (audibly) reconstructed by >>> using 2 or 3 samples before the clipping and after the clipping and >>> fitting the sine curve between. >>> >>> Anyone help me or point me to some easy to grasp formulas for fitting >>> such a curve. >>> >>> I looked at nurbs but it is too much for me to dig out of all the >>> information for what might work here. Surely there is an easy formula >>> to derive the sine formula from points. >> >> >> >> Make it a third-order polynomial -- the problem becomes a linear >> best-fitting problem; and a third-order polynomial should produce >> a very nice and smooth reconstructed signal. Fitting a sine curve >> where the frequency and phase are unknowns is a non-linear >> optimization problem, which I'm sure you'll want to avoid. > > > Test this with a two-tone signal like 10*sin(wt) + sin(10*wt). The peak > amplitude will be close to 11; clip at 9. Is the "reconstruction" adequate?I don't have right now the time to do those tests, but the following quick tests suggest to me that it should work beautifully: Try plotting (e.g., with GNUPlot), for the interval [-2,2], the curves for sin(x) and for x - x^3 / 7 (notice that it's not the first two terms of the Taylor expansion -- probably not the optimal either, but a "guessed" value for the coefficient. Plot also, for the interval [-1,1], cos(x) and 1 - 0.46*x^2 With the above, what I'm saying is that the form of the bumps of a third order polynomial can nicely approximate the bumps of sinusids, and should work nicely for reconstructing clipped peaks. Carlos --
Reply by ●February 13, 20062006-02-13
in article 4bfb5$43f08c0f$4088dbc7$30311@EVERESTKC.NET, Grant Griffin at nospam@yahoo.com wrote on 02/13/2006 08:39:> I often compare non-linear distortions such as clipping to scrambled > eggs: you can't un-scramble eggs; the only thing you can do is not > scramble them in the first place.it might be better compared to burnt toast. not all of the signal is messed up and it might not be too hard to identify which samples *are* clipped (the ones that are 0x7FFFFF or 0x800000), so then you have to scrap off the burnt crap. it's still not as good as if you never burnt it in the first place. assumptions are made because one can certainly conceive of an (unclipped) audio signal that is bandlimited to Nyquist that will have exactly the same samples as the clipped one. but if you first assume that if two or more adjacent samples that are clamped against the rail (0x7FFFFF or 0x800000) they must have been clipped, and then you assume something about the spectrum of the signal (from the unclipped samples immediately before and after the clipped portion), you can create a filter using a couple of methods (LMS is one and LPC is another) the could logically extend the waveform (forward from the "before clipping" data and backward from the "after" data) and crossfade those two extended waveforms to make a seamless patch. this has been talked about (and maybe published) in the AES multiple times. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●February 13, 20062006-02-13
Clipping is the loss of data. You can't recover the data which is lost by the means of the interpolation. However you can do a significant perceptual improvement by the use of the LPC model as the substitute for the clipped samples. Vladimir Vassilevsky DSP and Mixed-Up Signal Design Consultant http://www.abvolt.com Phil wrote:> I would think clipping could be reasonably (audibly) reconstructed by > using 2 or 3 samples before the clipping and after the clipping and > fitting the sine curve between. > > Anyone help me or point me to some easy to grasp formulas for fitting > such a curve. > > I looked at nurbs but it is too much for me to dig out of all the > information for what might work here. Surely there is an easy formula > to derive the sine formula from points. > > Thanks >
Reply by ●February 13, 20062006-02-13
Carlos Moreno wrote:> Jerry Avins wrote: > >> Carlos Moreno wrote: >> >>> Phil wrote: >>> >>>> I would think clipping could be reasonably (audibly) reconstructed by >>>> using 2 or 3 samples before the clipping and after the clipping and >>>> fitting the sine curve between. >>>> >>>> Anyone help me or point me to some easy to grasp formulas for fitting >>>> such a curve. >>>> >>>> I looked at nurbs but it is too much for me to dig out of all the >>>> information for what might work here. Surely there is an easy formula >>>> to derive the sine formula from points. >>> >>> >>> >>> >>> Make it a third-order polynomial -- the problem becomes a linear >>> best-fitting problem; and a third-order polynomial should produce >>> a very nice and smooth reconstructed signal. Fitting a sine curve >>> where the frequency and phase are unknowns is a non-linear >>> optimization problem, which I'm sure you'll want to avoid. >> >> >> >> Test this with a two-tone signal like 10*sin(wt) + sin(10*wt). The >> peak amplitude will be close to 11; clip at 9. Is the "reconstruction" >> adequate? > > > I don't have right now the time to do those tests, but the following > quick tests suggest to me that it should work beautifully: > > Try plotting (e.g., with GNUPlot), for the interval [-2,2], the curves > for sin(x) and for x - x^3 / 7 (notice that it's not the first two > terms of the Taylor expansion -- probably not the optimal either, but > a "guessed" value for the coefficient. > > Plot also, for the interval [-1,1], cos(x) and 1 - 0.46*x^2 > > With the above, what I'm saying is that the form of the bumps of a > third order polynomial can nicely approximate the bumps of sinusids, > and should work nicely for reconstructing clipped peaks.All small waveforms riding on a large one will be lost in clipping. Even with soft clipping, they will vary in amplitude. That is the basis for using intermodulation for linearity testing. jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●February 13, 20062006-02-13
Jerry Avins wrote:> All small waveforms riding on a large one will be lost in clipping. Even > with soft clipping, they will vary in amplitude. That is the basis for > using intermodulation for linearity testing.I see what you mean! I thought you were pointing out the difficulty in detecting the many clipped peaks (for the high frequency) when the lower-frequency might make it seem as if there was only one peak that was clipped. For audio/music, I think it must work fine -- I mean, when you listen to 60s to early 70s recordings, it is so typical to get an unbelievably harsh timbre when the vocals get on a sustained and loud vowel sound -- I bet it is mostly the fundamental frequency being clipped, and I bet that if we "smoothly" extrapolate the missing "main peaks", even though the resulting waveform is not the real one, the sound is going to be infinitely superior (infinitely more "comfortable" to the ear, at least). Just guesstimating, of course... Carlos --






