• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required. There are many reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

Upsampling - integer vs non-integer ratios - original samples

Music1969

Major Contributor
Joined
Feb 19, 2018
Messages
4,636
Likes
2,809
Hi all

My upsampling question is centred on what happens with original samples, when using integer vs non-integer ratios (all else being equal with algorithm).

I watched this video by Ayre Acoustics and they mention with non-integer ratios you lose the original samples.

Can someone explain or show this, in the simplest way? If possible

I assumed that no matter what ratio is used, original samples are not affected (all else being equal other than ratios).

I fully understand in practise it probably doesn't matter - no audible difference.

More just wanting to understand better.

 

ElNino

Addicted to Fun and Learning
Joined
Sep 26, 2019
Messages
557
Likes
722
Hi all

My upsampling question is centred on what happens with original samples, when using integer vs non-integer ratios (all else being equal with algorithm).

I watched this video by Ayre Acoustics and they mention with non-integer ratios you lose the original samples.

Can someone explain or show this, in the simplest way? If possible

I assumed that no matter what ratio is used, original samples are not affected (all else being equal other than ratios).

I fully understand in practise it probably doesn't matter - no audible difference.

More just wanting to understand better.


I don't have time to watch the video, but you don't keep the original samples in either case, given a fullrange signal, for any practical digital filter.

What is true is that upsampling by integer ratios involves way less math. To upsample by 2x for example, you just insert zeros between each sample and then apply a low-pass filter. This probably sounds strange and counter-intuitive if you're not used to signal processing, but after you're done filtering, the zeros get "magically" transformed into interpolated values. (Of course it isn't magic, it's just a beautiful result of how the math works.)

Because any practical low-pass filter has a transition band of nonzero width, some of the original samples may get changed during this process, if the input signal is fullrange.

When you upsample by non-integer ratios, the math is many times more complicated, and none of the original samples will be preserved (and of course they wouldn't -- where in the time domain would those samples be?).
 
OP
M

Music1969

Major Contributor
Joined
Feb 19, 2018
Messages
4,636
Likes
2,809
Because any practical low-pass filter has a transition band of nonzero width, some of the original samples may get changed during this process, if the input signal is fullrange.

Noted but lets assume my question is about before low pass filter.

So from what you write with integer ratio the original samples remain - I get that part.

But for non-integer ratio I don't understand:
none of the original samples will be preserved (and of course they wouldn't -- where in the time domain would those samples be?).

This is the crux of my query and probably also what Ayre are saying.

Can you expand a bit on this part.
 

ElNino

Addicted to Fun and Learning
Joined
Sep 26, 2019
Messages
557
Likes
722
This is the crux of my query and probably also what Ayre are saying.

Can you expand a bit on this part.

Think about it this way... at 44.1kHz, the first sample is at zero seconds of the recording, the second sample is at 22.68us into the recording, and the third sample is at 45.35us into the recording. At 96khz (non-integer upsample), the samples are at the following times into the recording: 0, 10.42us, 20.83us, 31.25us, 41.67us, 52.08us...

The job of upsampling is to predict for us what the sample values should be at 0, 10.42us, 20.83us, 31.25us, 41.67us, 52.08us. But we can't just take sample values from the 44.1kHz stream, because they occur at different times. So none of the original sample values are relevant.
 

audio2design

Major Contributor
Joined
Nov 29, 2020
Messages
1,769
Likes
1,830
Hi all

My upsampling question is centred on what happens with original samples, when using integer vs non-integer ratios (all else being equal with algorithm).

I watched this video by Ayre Acoustics and they mention with non-integer ratios you lose the original samples.

Can someone explain or show this, in the simplest way? If possible

I think the answer has been provided, but if you are worried about the sound, just remember that an analog filter does not "preserve" the original value either.
 

tmtomh

Major Contributor
Forum Donor
Joined
Aug 14, 2018
Messages
2,636
Likes
7,492
Hi all

My upsampling question is centred on what happens with original samples, when using integer vs non-integer ratios (all else being equal with algorithm).

I watched this video by Ayre Acoustics and they mention with non-integer ratios you lose the original samples.

Can someone explain or show this, in the simplest way? If possible

I assumed that no matter what ratio is used, original samples are not affected (all else being equal other than ratios).

I fully understand in practise it probably doesn't matter - no audible difference.

More just wanting to understand better.


This is a great question. I used to worry about this until a member here (apologies - I have a mental block and always forget who it was!) showed me that this is not an issue.

Here's a simple way to understand it, based on the way it was shown to me:

1. My original concern was that if I took a 96kHz file and downsampled it to 44.1kHz - non-integer - I could never get the two files to completely null out when I did a null test with them (line up the waveforms, invert one, then mix them together).

2. The member here explained to me that because of the different sample rates you can never do a null test with them that way. Instead, they told me to take that non-integer, downsampled 44.1k version and then resample it back up to 96k, and then run the null test, comparing it with the original. Because the processed version had been downsampled to 44.1kHz, data had been changed/lost forever, and so upsampling it back to 96kHz would not invalidate the test.

The result when I did this was that the original and the downsampled-then-upsampled version nulled out 100%, total silence, up to the 22.05kHz Nyquist limit of the 44.1kHz sample rate.

In other words, the 96kHz original's samples are indeed different - when you non-integer resample to 44.1kHz you do lose data. But the key issue is that the only changed/lost data that cannot be 100% accurately reconstructed is the frequency information that was above/beyond the Nyquist limit of the lower sample-rate format. And since the Nyquist limit of a 44.1kHz sample rate is still comfortably above the audible range of human hearing, as a practical matter non-integer resampling has zero audible impact.

It blew my mind - and as a side benefit it's really convenient because on-the-fly resampling for music streaming systems therefore becomes convenient but not essential for maintaining true high fidelity sound reproduction.
 

MRC01

Major Contributor
Joined
Feb 5, 2019
Messages
3,424
Likes
4,030
Location
Pacific Northwest
Think about it this way... at 44.1kHz, the first sample is at zero seconds of the recording, the second sample is at 22.68us into the recording, and the third sample is at 45.35us into the recording. At 96khz (non-integer upsample), the samples are at the following times into the recording: 0, 10.42us, 20.83us, 31.25us, 41.67us, 52.08us...

The job of upsampling is to predict for us what the sample values should be at 0, 10.42us, 20.83us, 31.25us, 41.67us, 52.08us. But we can't just take sample values from the 44.1kHz stream, because they occur at different times. So none of the original sample values are relevant.
Yet when upsampling from 44.1 to 88.2 kHz, you've got an integer multiple, so each original sample could be used, as they line up exactly at every alternating sample point. For integer multiple rate differences, no interpolation needed.

This is a great question. I used to worry about this until a member here (apologies - I have a mental block and always forget who it was!) showed me that this is not an issue. ...
One valid concern about resampling is that practice may not be as good as theory. All resamplers are not created equal. For example, just yesterday I discovered a bug in my Oppo BDP-83, downsampling from 192 to 96 introduced an easily audible artifact that sounds like tape hiss. This shocked me, as both rates are well above anything necessary and it is an integer multiple.
 
Last edited:
OP
M

Music1969

Major Contributor
Joined
Feb 19, 2018
Messages
4,636
Likes
2,809
The job of upsampling is to predict for us what the sample values should be at 0, 10.42us, 20.83us, 31.25us, 41.67us, 52.08us. But we can't just take sample values from the 44.1kHz stream, because they occur at different times. So none of the original sample values are relevant.
Ahhh this is very helpful.

I feel like I am closer to fully understanding now.

But... regarding your great and simple example: in order to predict sample values at 0, 10.42us, 20.83us, 31.25us, 41.67us (upsampling 44.1 to 96k) - don't you need to use the original sample samples to make those predictions?

To predict something at those different (to original) time points, don't you need to have some other known (original) points? Isn't that the original samples that need to be used?

I'm thinking of interpolation
 
Last edited:
OP
M

Music1969

Major Contributor
Joined
Feb 19, 2018
Messages
4,636
Likes
2,809
Think about it this way... at 44.1kHz, the first sample is at zero seconds of the recording, the second sample is at 22.68us into the recording, and the third sample is at 45.35us into the recording. At 96khz (non-integer upsample), the samples are at the following times into the recording: 0, 10.42us, 20.83us, 31.25us, 41.67us, 52.08us...

The job of upsampling is to predict for us what the sample values should be at 0, 10.42us, 20.83us, 31.25us, 41.67us, 52.08us. But we can't just take sample values from the 44.1kHz stream, because they occur at different times. So none of the original sample values are relevant.

Actually I think I'm getting it now.

The original 44.1kHz samples are used with non-integer ratio upsampling - but only to map (interpolate?) to these new predicted values at 96kHz these time points?

Once mapped / interpolated, the original samples and their time points don't show up since they don't match up in time domain , so no longer relevant, as you say.

Have I got that right?

Or still wrong?
 
Last edited:

mansr

Major Contributor
Joined
Oct 5, 2018
Messages
4,685
Likes
10,700
Location
Hampshire
Yet when upsampling from 44.1 to 88.2 kHz, you've got an integer multiple, so each original sample could be used, as they line up exactly at every alternating sample point.
Only if you have an ideal interpolation filter, which is practically impossible. Any realisable filter will have a non-zero transition band, so the input samples will not be exactly preserved.
Edit: I was wrong.
 
Last edited:

danadam

Addicted to Fun and Learning
Joined
Jan 20, 2017
Messages
957
Likes
1,496
But for non-integer ratio I don't understand:
(I'm not really an expert in the area, so take with a grain of salt)
One rather inefficient way of upsampling with non-integer ratios is:
  1. reduce the ratio: 96'000 / 44'100 -> 320 / 147
  2. upsample by inserting 319 zeros between the samples - so far the original samples are preserved. The resulting sample rate is 14'112'000 (this is the Least Common Multiple of 44'100 and 96'000)
  3. apply filtering
  4. downsample by picking every 147th sample - most of the original samples are lost. The resulting sample rate is 96'000

Indeed the real question is: (why) does it matter?
I thought it was rather clear from the post that it is just curiosity.

I used to worry about this until a member here (apologies - I have a mental block and always forget who it was!) showed me that this is not an issue.
So, we meet again :)
 

ElNino

Addicted to Fun and Learning
Joined
Sep 26, 2019
Messages
557
Likes
722
Ahhh this is very helpful.

I feel like I am closer to fully understanding now.

But... regarding your great and simple example: in order to predict sample values at 0, 10.42us, 20.83us, 31.25us, 41.67us (upsampling 44.1 to 96k) - don't you need to use the original sample samples to make those predictions?

To predict something at those different (to original) time points, don't you need to have some other known (original) points? Isn't that the original samples that need to be used?

I'm thinking of interpolation

You do use all of the original samples to make the prediction in a non-integer upsampler.

The simplest way to understand a non-integer upsampler is to think about it as two steps: an integer upsample and then a decimation. The first part (integer upsample) can use the same math.

Let's say you want to upsample 44.1kHz to 96kHz. You can integer upsample to 4.234 *MHz* (that's 44.1*96kHz). That involves taking the original signal, stuffing in between values with a whole ton of zeros and then low-pass filtering. If you had low-pass filtered with a stop-band at 48kHz, then in the second stage you can just pluck out a bunch of values from that 4.234 MHz signal and you get your 96kHz signal.

In reality, it's not practical to do the two-step process I just described (just because it's wasteful to create an intermediate 4MHz signal), hence the need for more math. But the ultimate result is the same.
 

mansr

Major Contributor
Joined
Oct 5, 2018
Messages
4,685
Likes
10,700
Location
Hampshire
Actually I think I'm getting it now.

The original 44.1kHz samples are used with non-integer ratio upsampling - but only to map (interpolate?) to these new predicted values at 96kHz these time points?

Once mapped / interpolated, the original samples and their time points don't show up since they don't match up in time domain , so no longer relevant, as you say.

Have I got that right?

Or still wrong?
Look at it this way. The sampling theorem tells us that the original, continuous waveform can be reconstructed from the samples. Suppose we do this with the 44.1 kHz sampled signal as input. Now that we have a continuous signal, we can sample this at whatever rate we please, such as 96 kHz, as long as it meets the Nyquist criterion. The sampling theorem, again, tells us that these samples also capture the signal in full. This is why we often call such a process resampling.

In practice, it is possible to take some mathematical shortcuts that lead to the same result with less effort.
 

mansr

Major Contributor
Joined
Oct 5, 2018
Messages
4,685
Likes
10,700
Location
Hampshire
One rather inefficient way of upsampling with non-integer ratios is:
  1. reduce the ratio: 96'000 / 44'100 -> 320 / 147
  2. upsample by inserting 319 zeros between the samples - so far the original samples are preserved. The resulting sample rate is 14'112'000 (this is the Least Common Multiple of 44'100 and 96'000)
  3. apply filtering
  4. downsample by picking every 147th sample - most of the original samples are lost. The resulting sample rate is 96'000
This is exactly correct, including the bit about it being inefficient. To improve the method, we might observe that the last step discards most of the sample values. Therefore, we can save some effort by simply not calculating those values in the first place. Moreover, we might notice that most of the input values to the filtering (step 3) are zero, allowing us to skip most of the arithmetic there too. With these improvements, the remainder takes only a little more effort than integer-ratio upsampling.
 

tcli

Member
Joined
Oct 9, 2021
Messages
36
Likes
34
Location
France
Only if you have an ideal interpolation filter, which is practically impossible. Any realisable filter will have a non-zero transition band, so the input samples will not be exactly preserved.
Any windowed sinc filter will preserve the original samples without having a non-zero transition band when upsampling by an integer factor.
 

ElNino

Addicted to Fun and Learning
Joined
Sep 26, 2019
Messages
557
Likes
722
Any windowed sinc filter will preserve the original samples without having a non-zero transition band when upsampling by an integer factor.

Algebraically, yes. In a practical implementation, there are no ideal sinc filters. If you're willing to throw a lot of resources at it, you can approximate the ideal.
 

tcli

Member
Joined
Oct 9, 2021
Messages
36
Likes
34
Location
France
You don't need an ideal one, any windowed sinc preserve input samples.
This property is particularly important for half band filter ( for x2 upsampler) : you only need to compute half of the output samples, the other half are just the input samples.
 
Top Bottom