IPB

Welcome Guest ( Log In | Register )

3 Pages V   1 2 3 >  
Reply to this topicStart new topic
Why is perfect resampling impossible?
Gecko
post Aug 27 2004, 23:40
Post #1





Group: Members
Posts: 948
Joined: 15-December 01
From: Germany
Member No.: 662



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.
Go to the top of the page
+Quote Post
sven_Bent
post Aug 27 2004, 23:54
Post #2





Group: Members
Posts: 691
Joined: 15-December 01
From: Denmark
Member No.: 655



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
Go to the top of the page
+Quote Post
/\/ephaestous
post Aug 28 2004, 00:03
Post #3





Group: Members
Posts: 648
Joined: 25-October 02
From: Colombia
Member No.: 3620



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."
Go to the top of the page
+Quote Post
Omion
post Aug 28 2004, 00:13
Post #4





Group: Developer
Posts: 432
Joined: 22-February 04
From: San Diego, CA
Member No.: 12180



I may be completely wrong about this, but here goes:

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? unsure.gif

Please read any eventual replies to this before calling it the truth, though... wink.gif


--------------------
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2
Go to the top of the page
+Quote Post
bryant
post Aug 28 2004, 00:27
Post #5


WavPack Developer


Group: Developer (Donating)
Posts: 1297
Joined: 3-January 02
From: San Francisco CA
Member No.: 900



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... smile.gif
Go to the top of the page
+Quote Post
Pio2001
post Aug 28 2004, 00:55
Post #6


Moderator


Group: Super Moderator
Posts: 3936
Joined: 29-September 01
Member No.: 73



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.
Go to the top of the page
+Quote Post
Omion
post Aug 28 2004, 01:03
Post #7





Group: Developer
Posts: 432
Joined: 22-February 04
From: San Diego, CA
Member No.: 12180



QUOTE (Pio2001 @ Aug 27 2004, 04:55 PM)
I wonder if one would have to solve an equation with as much unknown values as the number of samples of the track.
*

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. biggrin.gif

[edit] 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.

This post has been edited by Omion: Aug 28 2004, 01:23


--------------------
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2
Go to the top of the page
+Quote Post
idioteque
post Aug 28 2004, 01:19
Post #8





Group: Members
Posts: 120
Joined: 19-May 03
Member No.: 6712



QUOTE (bryant @ Aug 27 2004, 06:27 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...  smile.gif
*


Agreed. It has always been my impression that the filtering introduces the 'real world' limitations that prevent the theoretical perfect reconstruction.
Go to the top of the page
+Quote Post
Pio2001
post Aug 28 2004, 01:40
Post #9


Moderator


Group: Super Moderator
Posts: 3936
Joined: 29-September 01
Member No.: 73



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 ?
Go to the top of the page
+Quote Post
idioteque
post Aug 28 2004, 01:44
Post #10





Group: Members
Posts: 120
Joined: 19-May 03
Member No.: 6712



edit: thread split

This post has been edited by idioteque: Aug 28 2004, 01:54
Go to the top of the page
+Quote Post
Pio2001
post Aug 28 2004, 01:46
Post #11


Moderator


Group: Super Moderator
Posts: 3936
Joined: 29-September 01
Member No.: 73



QUOTE (Omion @ Aug 28 2004, 02:03 AM)
[edit] 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.
*


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.
Go to the top of the page
+Quote Post
idioteque
post Aug 28 2004, 01:49
Post #12





Group: Members
Posts: 120
Joined: 19-May 03
Member No.: 6712



QUOTE (Pio2001 @ Aug 27 2004, 07:40 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 ?
*


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.
Go to the top of the page
+Quote Post
Pio2001
post Aug 28 2004, 01:51
Post #13


Moderator


Group: Super Moderator
Posts: 3936
Joined: 29-September 01
Member No.: 73



Yes, but doesn't the udial sample produce audible aliases whatever 44.1 to 48 kHz converter is used ?
Go to the top of the page
+Quote Post
idioteque
post Aug 28 2004, 01:55
Post #14





Group: Members
Posts: 120
Joined: 19-May 03
Member No.: 6712



QUOTE (Pio2001 @ Aug 27 2004, 07:51 PM)
Yes, but doesn't the udial sample produce audible aliases whatever 44.1 to 48 kHz converter is used ?
*

I don't know, do you get aliasing with the foobar SRC?
Go to the top of the page
+Quote Post
Garf
post Aug 28 2004, 02:26
Post #15


Server Admin


Group: Admin
Posts: 4886
Joined: 24-September 01
Member No.: 13



QUOTE (Pio2001 @ Aug 28 2004, 02:51 AM)
Yes, but doesn't the udial sample produce audible aliases whatever 44.1 to 48 kHz converter is used ?
*


No. Any high quality filter will not have any at all. Not audible, and the best ones not visible (on a spectrograph) either.
Go to the top of the page
+Quote Post
Omion
post Aug 28 2004, 02:44
Post #16





Group: Developer
Posts: 432
Joined: 22-February 04
From: San Diego, CA
Member No.: 12180



QUOTE (Pio2001 @ Aug 27 2004, 05:46 PM)
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.
*

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.

This post has been edited by Omion: Aug 28 2004, 02:52


--------------------
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2
Go to the top of the page
+Quote Post
bleh
post Aug 28 2004, 02:45
Post #17





Group: Members
Posts: 273
Joined: 9-August 03
From: MI, USA
Member No.: 8257



QUOTE (Pio2001 @ Aug 27 2004, 07:46 PM)
I wonder if the computation time grows faster than the sample size.
*

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

edit - beaten to it :|.

This post has been edited by bleh: Aug 28 2004, 02:46
Go to the top of the page
+Quote Post
Bionic-Badger
post Aug 28 2004, 03:12
Post #18





Group: Members
Posts: 14
Joined: 28-August 04
From: USA
Member No.: 16580



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-
Go to the top of the page
+Quote Post
Elohe
post Aug 28 2004, 05:00
Post #19





Group: Members
Posts: 32
Joined: 17-July 03
Member No.: 7826



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)"
Go to the top of the page
+Quote Post
bryant
post Aug 28 2004, 05:40
Post #20


WavPack Developer


Group: Developer (Donating)
Posts: 1297
Joined: 3-January 02
From: San Francisco CA
Member No.: 900



QUOTE (Pio2001 @ Aug 27 2004, 03:55 PM)
The same goes if you use linear interpolation. The error is reduced, but you may still introduce audible distortion.
*

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.
Go to the top of the page
+Quote Post
Omion
post Aug 28 2004, 07:18
Post #21





Group: Developer
Posts: 432
Joined: 22-February 04
From: San Diego, CA
Member No.: 12180



QUOTE (bryant @ Aug 27 2004, 09:40 PM)
QUOTE (Pio2001 @ Aug 27 2004, 03:55 PM)
The same goes if you use linear interpolation. The error is reduced, but you may still introduce audible distortion.
*

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.
*


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

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
Go to the top of the page
+Quote Post
Bionic-Badger
post Aug 28 2004, 11:39
Post #22





Group: Members
Posts: 14
Joined: 28-August 04
From: USA
Member No.: 16580



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-
Go to the top of the page
+Quote Post
Lyx
post Aug 28 2004, 12:51
Post #23





Group: Members
Posts: 3353
Joined: 6-July 03
From: Sachsen (DE)
Member No.: 7609



QUOTE (Bionic-Badger @ Aug 28 2004, 12:39 PM)
...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.
Go to the top of the page
+Quote Post
Pio2001
post Aug 28 2004, 14:21
Post #24


Moderator


Group: Super Moderator
Posts: 3936
Joined: 29-September 01
Member No.: 73



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.
Go to the top of the page
+Quote Post
Yaztromo
post Aug 28 2004, 15:06
Post #25





Group: Members
Posts: 236
Joined: 28-July 03
From: England, UK
Member No.: 8031



QUOTE (Gecko @ Aug 27 2004, 10:40 PM)
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
Go to the top of the page
+Quote Post

3 Pages V   1 2 3 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd December 2014 - 14:04