DSPRelated.com
Forums

Waveform interpolation

Started by bitrex August 9, 2015
Suppose I have some sampled signal data in a ROM on a microcontroller or 
something, and I'm reading it out to a DAC.  Let's say that for some 
reason, I'd like to begin reading this data at some random position, go 
for a while, and then stop at a random stopping point and jump to 
another random position in the ROM and continue reading, and so on, to 
obtain pseudorandom variations on the waveform data.

What sort of interpolation algorithm might be appropriate to use in a 
situation like this to smooth the discontinuity between the two jump points?
On 09/08/2015 20:02, bitrex wrote:

> Suppose I have some sampled signal data in a ROM on a microcontroller or > something, and I'm reading it out to a DAC. Let's say that for some > reason, I'd like to begin reading this data at some random position, go > for a while, and then stop at a random stopping point and jump to > another random position in the ROM and continue reading, and so on, to > obtain pseudorandom variations on the waveform data.
Does it have to be random to random position? Zero crossing and in the same direction will get you something that the ear can barely hear.
> What sort of interpolation algorithm might be appropriate to use in a > situation like this to smooth the discontinuity between the two jump > points?
Force the wavefrom jump to be at a zero crossing and pick up from a zero crossing with the same sign gradient. -- Regards, Martin Brown
On 8/9/2015 3:02 PM, bitrex wrote:
> Suppose I have some sampled signal data in a ROM on a microcontroller or > something, and I'm reading it out to a DAC. Let's say that for some > reason, I'd like to begin reading this data at some random position, go > for a while, and then stop at a random stopping point and jump to > another random position in the ROM and continue reading, and so on, to > obtain pseudorandom variations on the waveform data. > > What sort of interpolation algorithm might be appropriate to use in a > situation like this to smooth the discontinuity between the two jump > points?
What Martin said, or you can use a fade-in, fade-out perhaps, or a cross-fade where the two fades work at the same time. I think the answer to this question depends greatly on the waveform and its use. -- Rick
bitrex wrote:
> Suppose I have some sampled signal data in a ROM on a microcontroller or > something, and I'm reading it out to a DAC. Let's say that for some > reason, I'd like to begin reading this data at some random position, go > for a while, and then stop at a random stopping point and jump to > another random position in the ROM and continue reading, and so on, to > obtain pseudorandom variations on the waveform data. > > What sort of interpolation algorithm might be appropriate to use in a > situation like this to smooth the discontinuity between the two jump > points?
DAW programs use a "crossfade" - you ramp the first signal down at X db/sec while ramping the second signal up at the same X db/sec. The amount of time for the crossfade would then be determined by the fade-slope - X. If X is 6 db/sec, then 96 dB is 16 seconds. You probably want more slope than that. This to address discontinuities caused by a square "butt splice", just as in tape splicing when you'd use an angled cut. Adding dither may be required, depending. -- Les Cargill
On Sun, 9 Aug 2015 15:02:56 -0400, bitrex
<bitrex@de.lete.earthlink.net> wrote:

>Suppose I have some sampled signal data in a ROM on a microcontroller or >something, and I'm reading it out to a DAC. Let's say that for some >reason, I'd like to begin reading this data at some random position, go >for a while, and then stop at a random stopping point and jump to >another random position in the ROM and continue reading, and so on, to >obtain pseudorandom variations on the waveform data. > >What sort of interpolation algorithm might be appropriate to use in a >situation like this to smooth the discontinuity between the two jump points?
Assuming that your "position" (ie, time) variable has finer resolution than your lookup table, you can use simple linear interpolation. Linear interpolation between two points can never result in an output bigger than either point, whereas an ideal filter can. So for better approximation of a good sample reconstruction filter, you need to account for more than two table points, and use something like a cubic or higher order spline interpolation. That may not matter in your situation. https://dl.dropboxusercontent.com/u/53724080/Circuits/Filters/Wayback_Machine/Interpolation_Error.JPG -- John Larkin Highland Technology, Inc lunatic fringe electronics jlarkin att highlandtechnology dott com http://www.highlandtechnology.com
On Sun, 09 Aug 2015 14:36:42 -0700, John Larkin
<jlarkin@highlandtechnology.com> wrote:

>On Sun, 9 Aug 2015 15:02:56 -0400, bitrex ><bitrex@de.lete.earthlink.net> wrote: > >>Suppose I have some sampled signal data in a ROM on a microcontroller or >>something, and I'm reading it out to a DAC. Let's say that for some >>reason, I'd like to begin reading this data at some random position, go >>for a while, and then stop at a random stopping point and jump to >>another random position in the ROM and continue reading, and so on, to >>obtain pseudorandom variations on the waveform data. >> >>What sort of interpolation algorithm might be appropriate to use in a >>situation like this to smooth the discontinuity between the two jump points? > >Assuming that your "position" (ie, time) variable has finer resolution >than your lookup table, you can use simple linear interpolation. > >Linear interpolation between two points can never result in an output >bigger than either point, whereas an ideal filter can. So for better >approximation of a good sample reconstruction filter, you need to >account for more than two table points, and use something like a cubic >or higher order spline interpolation. That may not matter in your >situation. > >https://dl.dropboxusercontent.com/u/53724080/Circuits/Filters/Wayback_Machine/Interpolation_Error.JPG
Or maybe I misunderstood the problem. If you want to smooth the jump between the two waveform segments (and not between points within a waveform) a lowpass filter might work. Or a fader type algorithm, depending on your requirements. The point interpolator would still help, to better map the table output to the time variable. -- John Larkin Highland Technology, Inc lunatic fringe electronics jlarkin att highlandtechnology dott com http://www.highlandtechnology.com
John Larkin wrote:
> On Sun, 09 Aug 2015 14:36:42 -0700, John Larkin > <jlarkin@highlandtechnology.com> wrote: > >> On Sun, 9 Aug 2015 15:02:56 -0400, bitrex >> <bitrex@de.lete.earthlink.net> wrote: >> >>> Suppose I have some sampled signal data in a ROM on a microcontroller or >>> something, and I'm reading it out to a DAC. Let's say that for some >>> reason, I'd like to begin reading this data at some random position, go >>> for a while, and then stop at a random stopping point and jump to >>> another random position in the ROM and continue reading, and so on, to >>> obtain pseudorandom variations on the waveform data. >>> >>> What sort of interpolation algorithm might be appropriate to use in a >>> situation like this to smooth the discontinuity between the two jump points? >> >> Assuming that your "position" (ie, time) variable has finer resolution >> than your lookup table, you can use simple linear interpolation. >> >> Linear interpolation between two points can never result in an output >> bigger than either point, whereas an ideal filter can. So for better >> approximation of a good sample reconstruction filter, you need to >> account for more than two table points, and use something like a cubic >> or higher order spline interpolation. That may not matter in your >> situation. >> >> https://dl.dropboxusercontent.com/u/53724080/Circuits/Filters/Wayback_Machine/Interpolation_Error.JPG > > > Or maybe I misunderstood the problem. If you want to smooth the jump > between the two waveform segments (and not between points within a > waveform) a lowpass filter might work. Or a fader type algorithm, > depending on your requirements. The point interpolator would still > help, to better map the table output to the time variable. > >
A "crossfade" is the general solution to the problem. It carries over from tape editing. Simple. http://stash.reaper.fm/14554/crossfade_shape_examples.png -- Les Cargill
On 8/9/15 6:36 PM, Les Cargill wrote:
> John Larkin wrote: >> On Sun, 09 Aug 2015 14:36:42 -0700, John Larkin >> <jlarkin@highlandtechnology.com> wrote: >> >>> On Sun, 9 Aug 2015 15:02:56 -0400, bitrex >>> <bitrex@de.lete.earthlink.net> wrote: >>> >>>> Suppose I have some sampled signal data in a ROM on a >>>> microcontroller or >>>> something, and I'm reading it out to a DAC. Let's say that for some >>>> reason, I'd like to begin reading this data at some random position, go >>>> for a while, and then stop at a random stopping point and jump to >>>> another random position in the ROM and continue reading, and so on, to >>>> obtain pseudorandom variations on the waveform data. >>>> >>>> What sort of interpolation algorithm might be appropriate to use in a >>>> situation like this to smooth the discontinuity between the two jump >>>> points? >>> >>> Assuming that your "position" (ie, time) variable has finer resolution >>> than your lookup table, you can use simple linear interpolation. >>> >>> Linear interpolation between two points can never result in an output >>> bigger than either point, whereas an ideal filter can. So for better >>> approximation of a good sample reconstruction filter, you need to >>> account for more than two table points, and use something like a cubic >>> or higher order spline interpolation. That may not matter in your >>> situation. >>> >>> https://dl.dropboxusercontent.com/u/53724080/Circuits/Filters/Wayback_Machine/Interpolation_Error.JPG >>> >> >> >> Or maybe I misunderstood the problem. If you want to smooth the jump >> between the two waveform segments (and not between points within a >> waveform) a lowpass filter might work. Or a fader type algorithm, >> depending on your requirements. The point interpolator would still >> help, to better map the table output to the time variable. >> >> > > A "crossfade" is the general solution to the problem. It carries over > from tape editing. Simple. >
i'll jump on board with the crossfading thing. so rex, this is what you should do if you want the least "glitchy" waveform splices or jumps. it requires having a buffer of ancillary metadata alongside of your sampled signal data. this metadata buffer would not need to be as large as the waveform sample data, but what it would contain is pitch detection data for it's associated portion of the waveform data. if this is stored in ROM like the sample data, it might be pre-calculated. that might not be so good. pitch or period estimators can reasonably easy to design using AMDF (or better yet ASDF - Average Squared Difference Function) or some kinda autocorrelation function. (pitch detection algs are a whole 'nother topic.) without the metadata, with some contemporaneous work, you can correlate the spot where you are expecting to splice from to various possible spots around the "random" place you intend to splice to. using ancillary metadata, you are always aware of the period length (if it's not periodic, it's the splice displacement that is the "best splice" by some measure, like how good the correlation is). then between the splice-from spot to the proposed splice-to spot, compute the mean period of all of the waveform data between the two spots, then adjust the splice-to spot a little earlier or later to make it an integer number of mean periods. now, in all cases, whether the splice is good or bad, *crossfade* from the splice-from spot to the splice-to spot. there are issues regarding that. if the correlation between the two spots is very good, then you want a complementary-voltage splice. but if the splice is very bad (but it's the best you can do with the data in the neighborhoods of the two spots) like if it was white noise, then the splice should be a complementary-power splice. and you can go in between the two extremes. i said something about this a couple years ago on the music-dsp list. i can dig it up if you want. Olli Niemato had some similar results. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
On 8/9/2015 9:25 PM, robert bristow-johnson wrote:
> On 8/9/15 6:36 PM, Les Cargill wrote: >> John Larkin wrote: >>> On Sun, 09 Aug 2015 14:36:42 -0700, John Larkin >>> <jlarkin@highlandtechnology.com> wrote: >>> >>>> On Sun, 9 Aug 2015 15:02:56 -0400, bitrex >>>> <bitrex@de.lete.earthlink.net> wrote: >>>> >>>>> Suppose I have some sampled signal data in a ROM on a >>>>> microcontroller or >>>>> something, and I'm reading it out to a DAC. Let's say that for some >>>>> reason, I'd like to begin reading this data at some random >>>>> position, go >>>>> for a while, and then stop at a random stopping point and jump to >>>>> another random position in the ROM and continue reading, and so on, to >>>>> obtain pseudorandom variations on the waveform data. >>>>> >>>>> What sort of interpolation algorithm might be appropriate to use in a >>>>> situation like this to smooth the discontinuity between the two jump >>>>> points? >>>> >>>> Assuming that your "position" (ie, time) variable has finer resolution >>>> than your lookup table, you can use simple linear interpolation. >>>> >>>> Linear interpolation between two points can never result in an output >>>> bigger than either point, whereas an ideal filter can. So for better >>>> approximation of a good sample reconstruction filter, you need to >>>> account for more than two table points, and use something like a cubic >>>> or higher order spline interpolation. That may not matter in your >>>> situation. >>>> >>>> https://dl.dropboxusercontent.com/u/53724080/Circuits/Filters/Wayback_Machine/Interpolation_Error.JPG >>>> >>>> >>> >>> >>> Or maybe I misunderstood the problem. If you want to smooth the jump >>> between the two waveform segments (and not between points within a >>> waveform) a lowpass filter might work. Or a fader type algorithm, >>> depending on your requirements. The point interpolator would still >>> help, to better map the table output to the time variable. >>> >>> >> >> A "crossfade" is the general solution to the problem. It carries over >> from tape editing. Simple. >> > > i'll jump on board with the crossfading thing. so rex, this is what you > should do if you want the least "glitchy" waveform splices or jumps. it > requires having a buffer of ancillary metadata alongside of your sampled > signal data. this metadata buffer would not need to be as large as the > waveform sample data, but what it would contain is pitch detection data > for it's associated portion of the waveform data. if this is stored in > ROM like the sample data, it might be pre-calculated. that might not be > so good. > > pitch or period estimators can reasonably easy to design using AMDF (or > better yet ASDF - Average Squared Difference Function) or some kinda > autocorrelation function. (pitch detection algs are a whole 'nother > topic.) > > without the metadata, with some contemporaneous work, you can correlate > the spot where you are expecting to splice from to various possible > spots around the "random" place you intend to splice to. > > using ancillary metadata, you are always aware of the period length (if > it's not periodic, it's the splice displacement that is the "best > splice" by some measure, like how good the correlation is). then > between the splice-from spot to the proposed splice-to spot, compute the > mean period of all of the waveform data between the two spots, then > adjust the splice-to spot a little earlier or later to make it an > integer number of mean periods. > > > now, in all cases, whether the splice is good or bad, *crossfade* from > the splice-from spot to the splice-to spot. there are issues regarding > that. if the correlation between the two spots is very good, then you > want a complementary-voltage splice. but if the splice is very bad (but > it's the best you can do with the data in the neighborhoods of the two > spots) like if it was white noise, then the splice should be a > complementary-power splice. and you can go in between the two extremes. > i said something about this a couple years ago on the music-dsp list. > i can dig it up if you want. Olli Niemato had some similar results. > >
Thank for the input - this will take some time to digest but it looks like I definitely have something to work with here.
In comp.dsp bitrex <bitrex@de.lete.earthlink.net> wrote:
> Suppose I have some sampled signal data in a ROM on a microcontroller or > something, and I'm reading it out to a DAC. Let's say that for some > reason, I'd like to begin reading this data at some random position, go > for a while, and then stop at a random stopping point and jump to > another random position in the ROM and continue reading, and so on, to > obtain pseudorandom variations on the waveform data.
You don't say what kind of data, and it might matter. Assuming that the full bandwidth is in use, you should be able to just switch. For audio, there is much less at the higher frequencies, which makes it more noticable when you add high frequencies with a discontinuous jump. This is also the reason why audio is fairly compressible. To answer the question, you need to know, approximately, the power spectrum of the signal. That is, how much there is in the high frequencies to mask the discontinuity.
> What sort of interpolation algorithm might be appropriate to > use in a situation like this to smooth the discontinuity between > the two jump points?
-- glen