Topic: Why is perfect resampling impossible? (Read 21588 times)previous topic - next topic

0 Members and 1 Guest are viewing this topic.
• Gecko
Why is perfect resampling impossible?
27 August, 2004, 06:40:33 PM
I've taken it for granted that there is no such thing as perfect resampling, but now I ask myself: why?

The sampling theorem says a signal of limited bandwidth f will be perfectly reproduced when sampled with at least 2*f.

From a 44.1kHz file one can perfectly recreate frequencies < 22.05kHz.
From a 48kHz file one can perfectly recreate frequencies < 24kHz.

So why can't I take the perfectly reproduced content of the 44.1kHz file and somehow put it into a 48kHz file? That 48kHz file is more than adequate to reproduce frequencies below 22.05kHz.

The only thing I can come up with is amplitude quantization (AFAIK the sampling theorem only fully works when considering infinite amplitude resolution). Of course I am only talking about upsampling here.

• sven_Bent
Why is perfect resampling impossible?
Reply #1 – 27 August, 2004, 06:54:41 PM
maybe I'm out of moy boundries. but there is my exlanation.

because you dong have infinite resoluted rond wave anymore but a digital "steps" and  the step interval doesn fit the new step interval.

its like resizing af pictures from 80x600 to 1024x768.. some of the pixles/sampels have to consing of the values of to (or more) pixels/sampels which are impossible (its hard to have one value that is two values)
Sven Bent - Denmark

Why is perfect resampling impossible?
Reply #2 – 27 August, 2004, 07:03:55 PM
It's posible to do perfect reampling only if you have an infinite bit depth and all the sound frequrencies are below the max frequency of the new samplerate. For example, it's posible to divide 10/9 but you can't represent the answer correctly using decimals.
"You have the right to remain silent. Anything you say will be misquoted, then used against you."

• Omion
• Developer
Why is perfect resampling impossible?
Reply #3 – 27 August, 2004, 07:13:40 PM

When upsampling, I think you may also need a perfect brick wall filter to get rid of any resampling artifacts above the old nyquist limit. But that requires an infinite amount of time data to calculate correctly.

When downsampling, the problem is backwards: you need the brick wall filter before the resampling to remove any frequencies that may produce artifacts after resampling.

Or something?

Please read any eventual replies to this before calling it the truth, though...
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

• bryant
• Developer (Donating)
Why is perfect resampling impossible?
Reply #4 – 27 August, 2004, 07:27:07 PM
I think maybe you can upsample perfectly (or as accurately as you want). Imagine just converting the digital signal into an analog signal and resampling it (mathematically, of course).

The problem is with downsampling because you have to filter out the information past f/2, and that's where you run into problems. You can make filters that are arbitrarily good in any one characteristic (i.e. stopband ripple) but you can't make one good at everything. It's always a compromise.

Or maybe not...

• Pio2001
• Global Moderator
Why is perfect resampling impossible?
Reply #5 – 27 August, 2004, 07:55:32 PM
Upsampling, the problem is to guess the value of the new samples, that are between the old ones. If you take the nearest neighbour, then lowpass, how can you be sure that the jitter introduced by the time shift, when a value given at time t is translated to its nearest neighbour that stands at t+e, won't introduce some distortion well below the maximum frequency of the recording ? I don't know if it is the case, but I think it might be the main problem.
The same goes if you use linear interpolation. The error is reduced, but you may still introduce audible distortion. Bryant's idea is interesting. If you find an algorithm that can describe a continuous curve that passes through all old values, and have no frequency above the old limit, you win. You just have to take its value at the new sample positions.

I wonder if one would have to solve an equation with as much unknown values as the number of samples of the track.

• Omion
• Developer
Why is perfect resampling impossible?
Reply #6 – 27 August, 2004, 08:03:58 PM
Quote
I wonder if one would have to solve an equation with as much unknown values as the number of samples of the track.
[a href="index.php?act=findpost&pid=237521"][{POST_SNAPBACK}][/a]

It can be done with a fourier transform as long as the file. You'll end up with an amplitude + phase for a whole bunch of frequencies, which you can use to regenerate the sines and cosines in the waveform.

It seems that that would do it (assuming infinite sample precision), but I'm not 100% sure... maybe I'm just bieng too skeptical today.

 Wait a second... doesn't the fourier transform assume the signal is periodic? I think that would screw things up, then. You might need to add an infinite amount of padding at the beginning and end.
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

• idioteque
Why is perfect resampling impossible?
Reply #7 – 27 August, 2004, 08:19:07 PM
Quote
I think maybe you can upsample perfectly (or as accurately as you want). Imagine just converting the digital signal into an analog signal and resampling it (mathematically, of course).

The problem is with downsampling because you have to filter out the information past f/2, and that's where you run into problems. You can make filters that are arbitrarily good in any one characteristic (i.e. stopband ripple) but you can't make one good at everything. It's always a compromise.

Or maybe not...
[a href="index.php?act=findpost&pid=237513"][{POST_SNAPBACK}][/a]

Agreed.  It has always been my impression that the filtering introduces the 'real world' limitations that prevent the theoretical perfect reconstruction.

• Pio2001
• Global Moderator
Why is perfect resampling impossible?
Reply #8 – 27 August, 2004, 08:40:42 PM
Then how do you explain the SB live resampling being bad ? Where do come all these alien sounds in the "udial" killer sample from, when you upsample from 44.1 to 48 kHz ?

• idioteque
Why is perfect resampling impossible?
Reply #9 – 27 August, 2004, 08:44:23 PM

• Pio2001
• Global Moderator
Why is perfect resampling impossible?
Reply #10 – 27 August, 2004, 08:46:59 PM
Quote
 Wait a second... doesn't the fourier transform assume the signal is periodic? I think that would screw things up, then. You might need to add an infinite amount of padding at the beginning and end.
[a href="index.php?act=findpost&pid=237523"][{POST_SNAPBACK}][/a]

No, the Fourier Serial assumes it (sum of sines), not the Fourier Transform (integral of complex functions). Anyway, here we have none of them. It is a Discrete Fourier Transform (DFT), that we compute, thanks to a Fast Fourier Transform (FFT) algorithm. So we'd need an FFT size of the power of 2 superior to the number of samples. That is still a huge amount of calculus. I wonder if the computation time grows faster than the sample size.

• idioteque
Why is perfect resampling impossible?
Reply #11 – 27 August, 2004, 08:49:45 PM
Quote
Then how do you explain the SB live resampling being bad ? Where do come all these alien sounds in the "udial" killer sample from, when you upsample from 44.1 to 48 kHz ?
[a href="index.php?act=findpost&pid=237529"][{POST_SNAPBACK}][/a]

You're talking about a specific implementation which could be flawed for a number of reasons.  I don't know the details of how the sample rate converter is broken in the SB Live so I can't speculate.

I was talking about what the limitations on a practical implementation are.

• Pio2001
• Global Moderator
Why is perfect resampling impossible?
Reply #12 – 27 August, 2004, 08:51:19 PM
Yes, but doesn't the udial sample produce audible aliases whatever 44.1 to 48 kHz converter is used ?

• idioteque
Why is perfect resampling impossible?
Reply #13 – 27 August, 2004, 08:55:55 PM
Quote
Yes, but doesn't the udial sample produce audible aliases whatever 44.1 to 48 kHz converter is used ?
[a href="index.php?act=findpost&pid=237534"][{POST_SNAPBACK}][/a]

I don't know, do you get aliasing with the foobar SRC?

• Garf
• Developer (Donating)
Why is perfect resampling impossible?
Reply #14 – 27 August, 2004, 09:26:34 PM
Quote
Yes, but doesn't the udial sample produce audible aliases whatever 44.1 to 48 kHz converter is used ?
[a href="index.php?act=findpost&pid=237534"][{POST_SNAPBACK}][/a]

No. Any high quality filter will not have any at all. Not audible, and the best ones not visible (on a spectrograph) either.

• Omion
• Developer
Why is perfect resampling impossible?
Reply #15 – 27 August, 2004, 09:44:01 PM
Quote
No, the Fourier Serial assumes it (sum of sines), not the Fourier Transform (integral of complex functions). Anyway, here we have none of them. It is a Discrete Fourier Transform (DFT), that we compute, thanks to a Fast Fourier Transform (FFT) algorithm. So we'd need an FFT size of the power of 2 superior to the number of samples. That is still a huge amount of calculus. I wonder if the computation time grows faster than the sample size.
[a href="index.php?act=findpost&pid=237531"][{POST_SNAPBACK}][/a]

The FFT is O(n log n), so if you double the number of samples, the computation time will more than double. However, it approaches double for extremely large data sets.

So, you're saying that the DFT is not periodic, but needs to be a power of 2? I was under the impression that DFTs could be any length you wanted.

[edit:] Aah, the FFT is a power of 2. But what do you extend it with? I'd think that anything would change the frequency components inside the song.
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

• bleh
Why is perfect resampling impossible?
Reply #16 – 27 August, 2004, 09:45:59 PM
Quote
I wonder if the computation time grows faster than the sample size.
[a href="index.php?act=findpost&pid=237531"][{POST_SNAPBACK}][/a]

The FFT function is O(n*log n) IIRC, so, yes, it does.

edit - beaten to it :|.

Why is perfect resampling impossible?
Reply #17 – 27 August, 2004, 10:12:33 PM
Barring bit-resolution problems, wouldn't it be possible to achieve an as-perfect-as-you-can-get down/upsampling by applying an ideal low-pass filter to the sampled waveform and then sampling again?  In practice that would mean calculating a sinc-pulse value for every sample in the original waveform for each sample in the resulting waveform, but given the bit resolution, you "only" need 2 * (2^n) samples (n = bits per sample in original) to be very close to the noise floor of the original bit-depth (i.e. a sample 2^n samples away has 1/(2^n) effect on a sample).

Not a close-to-real-time solution, but doable on a computer.

Please correct me if I'm wrong.

-BB-

• Elohe
Why is perfect resampling impossible?
Reply #18 – 28 August, 2004, 12:00:56 AM
For upsampling exist a simple tecnic based in the splines, but is computational interesting, it assume than the signal are a function betwen a maximun and minimun, and only calculate a polinomic(  lagrance, newton...) interpolation betwen a consecutive maximun and minimun, it produces a good signal. And if posible to aply a simple armonic restaurator for the los signals, like sbr or plusV, we can recreate the lost signals but with no much fidelity, it can be sound great the upsampling in a extremes cases like 8 -> 48 , the problen if the values of the armonic amplification., a good aproximation is "armonic/((armonic-1)*e)"

• bryant
• Developer (Donating)
Why is perfect resampling impossible?
Reply #19 – 28 August, 2004, 12:40:14 AM
Quote
The same goes if you use linear interpolation. The error is reduced, but you may still introduce audible distortion.
[a href="index.php?act=findpost&pid=237521"][{POST_SNAPBACK}][/a]

You're right, linear interpolation is not good for this. However, there is a very simple formula for the "perfect" interpolation filter:

cf = sin(d*pi) / (d*pi)

where cf is the coefficient for a given sample's weight and d is the distance from that sample to the desired interpolation position (in samples). You simply have to multiply every sample by its coefficient and add them up to get the interpolated value.

The practical problem with this is that it doesn't taper quickly enough as you move away from the center, so in real-world applications you have to weigh the whole filter with a fixed-length windowing function.

• Omion
• Developer
Why is perfect resampling impossible?
Reply #20 – 28 August, 2004, 02:18:20 AM
Quote
Quote
The same goes if you use linear interpolation. The error is reduced, but you may still introduce audible distortion.
[a href="index.php?act=findpost&pid=237521"][{POST_SNAPBACK}][/a]

You're right, linear interpolation is not good for this. However, there is a very simple formula for the "perfect" interpolation filter:

cf = sin(d*pi) / (d*pi)

where cf is the coefficient for a given sample's weight and d is the distance from that sample to the desired interpolation position (in samples). You simply have to multiply every sample by its coefficient and add them up to get the interpolated value.

The practical problem with this is that it doesn't taper quickly enough as you move away from the center, so in real-world applications you have to weigh the whole filter with a fixed-length windowing function.
[a href="index.php?act=findpost&pid=237568"][{POST_SNAPBACK}][/a]

Wow. Just add up a bunch of sinc impulses. It's so simple!

But there's still the problem of what to assume the samples past either end of the song are. The obvious thing to do is assume they're 0, and only calculate the function for the samples actually contained in the file. However, in real life, the song will probably be followed by another song, which will tweak the frequencies slightly.

Imagine a sine wave chopped into two files, where the file boundary is at a waveform max. On resampling the waveforms separately, Gibbs' Phenomenon will show its ugly head and give ripples on either end of the files. This is correct if the files are to be played completely separately, but incorrect if they will be played together.

All in all, though, that would seem to be the perfect filter, barring a few pedantic real-world technicalities. Seeing as there's no way to know what will follow in anybody's playlist, it looks like the "most perfect" possible.
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

Why is perfect resampling impossible?
Reply #21 – 28 August, 2004, 06:39:57 AM
You're also looking at waves at the sampling frequency.  More than likely you'll see more distortion from mastering artifacts than from missing the samples before and after the "lifetime" of the wave.  At 22050+ hz, and with most tracks starting and ending with silence, nobody would be able to detect the difference realistically.

-BB-

• Lyx
Why is perfect resampling impossible?
Reply #22 – 28 August, 2004, 07:51:19 AM
Quote
...and with most tracks starting and ending with silence...

Dont be so fast in asuming that. With mainstream music you may be right, but as soon as you leave the mainstream sector(and with mainstream, i also mean popular acts of subcultures) a significant number of albums have seamless trackchanges. For example, about 1/3 of my music collection has seamless trackchanges.

I think you also misunderstood the intention of the topic a bit - its was more a theoretical question... the search for the perfect resampler. The question was less if one could notice the difference in everyday-listening (most people cannot notice a resampler anyways), but more a technical motivation to "achieve the impossible".

- Lyx
I am arrogant and I can afford it because I deliver.

• Pio2001
• Global Moderator
Why is perfect resampling impossible?
Reply #23 – 28 August, 2004, 09:21:36 AM
Ah thanks, Bryant, it is clearer now.
So the computational limit is how much neughborous samples must be taken into account so that the error is below the definition of the recording.
Unfortunately, the sum of the sinc functions is majored by sum(1/x, x from n to infinite), and it may be as high as this if all contributions are all in phase.
I've not got my math courses anymore, but I think I remember that this sum is infinite for any n.
But the track that we resample is not infinite. Maybe there is a way to ensure that when we stop at a given distance from the new sample, all remaining contributions can't exeed the quantisation noise.

Anyway, all this is only valid if the Nyquist frequency (22050 Hz for example) is strictly inaudible. Have you already tried a sinc resampling for enlarging pictures ? The result is awful, ripple is visible everywhere ! Bicubic resampling looks much better.

• Yaztromo
Why is perfect resampling impossible?
Reply #24 – 28 August, 2004, 10:06:27 AM
Quote
The sampling theorem says a signal of limited bandwidth f will be perfectly reproduced when sampled with at least 2*f.

From a 44.1kHz file one can perfectly recreate frequencies < 22.05kHz.
From a 48kHz file one can perfectly recreate frequencies < 24kHz.

So why can't I take the perfectly reproduced content of the 44.1kHz file and somehow put it into a 48kHz file? That 48kHz file is more than adequate to reproduce frequencies below 22.05kHz.

Don't want to drag this thread off topic but you've brought up a question that i've wondered before.

If what you say is correct, would it make more sense upsampling 44.1khz to 88.2khz, instead of upsampling to 48khz when playing back through cards such as Creative's Audigy 2 series.

Thanks