IPB

Welcome Guest ( Log In | Register )

2 Pages V  < 1 2  
Reply to this topicStart new topic
Sample rate conversion
bandpass
post Apr 14 2011, 22:16
Post #26





Group: Members
Posts: 326
Joined: 3-August 08
From: UK
Member No.: 56644



QUOTE (Wombat @ Apr 14 2011, 20:46) *
I still don´t get how any sample can be exactly the same when a lowpass is applied to it in the output!? I hope i only need a small hint smile.gif

Because (by definition) the lowpass doesn't affect frequencies below its cutoff frequency; if all the frequencies in the input signal are below the cutoff frequency, and the filter is implemented in a 'perfect' way, then the signal is unaffected. E.g. an input signal comprising a sine wave swept from 0-22kHz has no frequency component at or above the cutoff (~23kHz), so is unaffected.

Whilst half-band filters may leave samples unaffected, other FIRs may too—sox's filter is not half-band (a half-band upsampling filter always has some imaging remaining).

QUOTE
Is there any sample intact? And how to tell?


Using the 'code' I provided above; it uses a little trick to throw away the interpolated samples from the 96k file thus rendering it back to a 48k file (without filtering, but that's okay in this instance), which is then file-compared to the original. The files are identical barring a few samples at the beginning and end (which are the result of filtering discontinuties).
Go to the top of the page
+Quote Post
Alexey Lukin
post Apr 14 2011, 22:26
Post #27





Group: Members
Posts: 191
Joined: 31-July 08
Member No.: 56508



QUOTE (bandpass @ Apr 14 2011, 17:16) *
Because (by definition) the lowpass doesn't affect frequencies below its cutoff frequency;

It does! — by definition of the cutoff frequency (-3 dB point).

QUOTE (bandpass @ Apr 14 2011, 17:16) *
Whilst half-band filters may leave samples unaffected, other FIRs may too—sox's filter is not half-band (a half-band upsampling filter always has some imaging remaining).

For other filters it's highly unlikely that they will preserve the original samples (which is not a flaw).
However SoX may well be the half-band filter (unless ordered a shifted cutoff frequency).
Go to the top of the page
+Quote Post
Wombat
post Apr 14 2011, 22:27
Post #28





Group: Members
Posts: 1043
Joined: 7-October 01
Member No.: 235



QUOTE (bandpass @ Apr 14 2011, 22:16) *
Using the 'code' I provided above; it uses a little trick to throw away the interpolated samples from the 96k file thus rendering it back to a 48k file (without filtering, but that's okay in this instance), which is then file-compared to the original. The files are identical barring a few samples at the beginning and end (which are the result of filtering discontinuties).

Interesting. So this is more by accident here because we have a 440Hz tone that has no content near the lowpass. On normal music i suppose sox does have to apply it to almost every sample. Will this be the same in this special case when we use a uneven resample to lets say 88.2? I doubt. So all these claims about a resampler is more precise in upsampling by even numbers has some evidence.

Edit: Lol, just read Mr. Lukins answer... So how does it come your trick to throw away the interpolated samples show the original samples!? Does sox use Half-Band. From the frequency plot i doubt this.

This post has been edited by Wombat: Apr 14 2011, 22:30
Go to the top of the page
+Quote Post
Wombat
post Apr 14 2011, 22:49
Post #29





Group: Members
Posts: 1043
Joined: 7-October 01
Member No.: 235



I am getting slowly mad in here or lowpass myself smile.gif

So many real experts and no simple words for an average human being like me.
May we take a snapshot and can someone please answer me 4 questions?

1. Is sox a resampler that upsamples with leaving samples intact when upsampling from 48k to 96k
2. If it isn´t, is there one you are aware of.
3. Is the reasoning that all apply a lowpass on upsampling and so change EVERY single sample correct?
4. Does it play a role at all then to upsample with an even or uneven number?

To my understanding atm it is No-No-Yes-No
Go to the top of the page
+Quote Post
bandpass
post Apr 15 2011, 07:18
Post #30





Group: Members
Posts: 326
Joined: 3-August 08
From: UK
Member No.: 56644



QUOTE (Alexey Lukin @ Apr 14 2011, 22:26) *
QUOTE (bandpass @ Apr 14 2011, 17:16) *
Because (by definition) the lowpass doesn't affect frequencies below its cutoff frequency;

It does! — by definition of the cutoff frequency (-3 dB point).

Yes, but not by much biggrin.gif (And of course, with sinc filters, it's usual to use the -6dB point but I was trying to simplify for Wombat's benefit)

QUOTE
QUOTE (bandpass @ Apr 14 2011, 17:16) *
Whilst half-band filters may leave samples unaffected, other FIRs may too—sox's filter is not half-band (a half-band upsampling filter always has some imaging remaining).

For other filters it's highly unlikely that they will preserve the original samples (which is not a flaw).
However SoX may well be the half-band filter (unless ordered a shifted cutoff frequency).

In fact, I checked 3 resamplers: sox, ssrc, & sndfile-resample. Allowing for the fact the ssrc prepends a couple of spurious samples and sndfile-resample truncates by one sample, all 3 did pretty well on the test: alternate output samples were the same as the input samples (tested at bit-depth 16, input: a 440Hz tone).

According to its design, SoX does not use a half-band filter. Checks on its output (including those at http://src.infinitewave.ca) confirm this as they show no imaging (a characteristic of half-band filters).

QUOTE (Wombat @ Apr 14 2011, 22:27) *
So this is more by accident here because we have a 440Hz tone that has no content near the lowpass.

No accident, it was part of the test design. The test also included tones up to 22kHz and a sweep from 0 to 22kHz—these all passed. A tone of 23kHz did not pass but no real surprises here. (These other tests were performed only on SoX)

QUOTE
On normal music i suppose sox does have to apply it to almost every sample. Will this be the same in this special case when we use a uneven resample to lets say 88.2? I doubt. So all these claims about a resampler is more precise in upsampling by even numbers has some evidence.

The filter is always applied to every sample regardless of the input signal content and sampling rate. However, if resampling to 88.2, there are very few samples in the output that one might expect (or, in general, care) not to have changed (and I haven't tested this case).

With 'normal' music, it is likely that the test would not pass. One situation where it might would be if the music had started life at 96k, and been downsampled to 48k using a filter with a lower cutoff used when subsequently upsampling.
QUOTE
Edit: Lol, just read Mr. Lukins answer... So how does it come your trick to throw away the interpolated samples show the original samples!? Does sox use Half-Band. From the frequency plot i doubt this.

Hopefully covered above and previously.
Go to the top of the page
+Quote Post
bandpass
post Apr 15 2011, 10:39
Post #31





Group: Members
Posts: 326
Joined: 3-August 08
From: UK
Member No.: 56644



Okay, curiousity got the better of me: in the 48k --> 88.2k example below, every 80th sample of the input matches every 147th sample of the output.

CODE
sox -b 16 -n 1.wav synth 10 sin 0:12k
sox -D 1.wav 2.wav rate 88.2k
sox -c 80 -r 600 1.wav 1a.wav remix 1
sox -c 147 -r 600 2.wav 2a.wav remix 1
cmp -l 1a.wav 2a.wav


QUOTE (Wombat @ Apr 14 2011, 22:49) *
1. Is sox a resampler that upsamples with leaving samples intact when upsampling from 48k to 96k
Depending on 3 things: the input signal bandwidth, the selected filter characteristics, and the selected bit-depth, sometimes yes, sometimes no.

Not checked, but I suspect that if you select -q (cubic interpolation) then the answer is always yes (but the interpolated samples will be much noisier than with band-limited interpolation).

QUOTE
2. If it isn´t, is there one you are aware of.
See previous post for a brief mention of some other resamplers.

QUOTE
3. Is the reasoning that all apply a lowpass on upsampling and so change EVERY single sample correct?
No, every sample is processed by the filter but not necessarily changed by it.

QUOTE
4. Does it play a role at all then to upsample with an even or uneven number?
Not especially, as demonstrated by the 88.2 example above.

Just to bring things back into perspective a little, whilst output samples being the same as input samples might indicate that a certain care has been taken in the implementation, the converse is not necessarily true, and that resampler performance for a given application is generally measured in other terms, see e.g. the graphs and discussion at http://src.infinitewave.ca
Go to the top of the page
+Quote Post
Wombat
post Apr 15 2011, 16:24
Post #32





Group: Members
Posts: 1043
Joined: 7-October 01
Member No.: 235



Many thanks bandpass for your efforts. Very interesting explanations and simple held for me to understand smile.gif
Lets hope all your assumptions are true but to me it all makes perfect sense!
Go to the top of the page
+Quote Post
Alexey Lukin
post Apr 15 2011, 17:10
Post #33





Group: Members
Posts: 191
Joined: 31-July 08
Member No.: 56508



I've just verified that SoX never preserves the values of original samples because its bandwidth (-b) parameter cannot be set to 100%, it's limited between 74 and 99.7%.
Go to the top of the page
+Quote Post
Wombat
post Apr 15 2011, 18:11
Post #34





Group: Members
Posts: 1043
Joined: 7-October 01
Member No.: 235



QUOTE (Alexey Lukin @ Apr 15 2011, 17:10) *
I've just verified that SoX never preserves the values of original samples because its bandwidth (-b) parameter cannot be set to 100%, it's limited between 74 and 99.7%.


Now what!? That is what i say from the beginning and bandpass always tells me that with a sample that has no HF content near the cutooff there are untouched samples in the output.
Go to the top of the page
+Quote Post
bandpass
post Apr 15 2011, 22:17
Post #35





Group: Members
Posts: 326
Joined: 3-August 08
From: UK
Member No.: 56644



All I have told you is what I have observed through simple experimentation, and since the experiments involved nothing more than running sox a few times and a file comparison program, you can repeat them and draw your own conclusions.

One final experiment.

Create an input signal:
CODE
sox -b 16 -n 1.wav synth noise gain -4 sinc -22k fade h .01 1 .01

(which looks like this:)


Upsample:
CODE
sox -D 1.wav 2.wav rate 96k

Dump the input and output files to text:
CODE
sox 1.wav -t dat 1.txt
sox 2.wav -t dat 2.txt

and check them in a text editor, or, use a graphical diff program:

(1st column is time, 2nd column is sample value)

For good measure, here are the freq. responses of the filter used in the input signal generation (blue, obtained via sox's --plot option) and the resampling filter (red, obtained via resampling an impulse) which, as can be seen, is not a half-band response:
Go to the top of the page
+Quote Post
Alexey Lukin
post Apr 16 2011, 06:27
Post #36





Group: Members
Posts: 191
Joined: 31-July 08
Member No.: 56508



This is only due to the fact that you used the sinc filter during signal generation. Real music is not like that and its sample values will change.
Go to the top of the page
+Quote Post
bandpass
post Apr 16 2011, 08:41
Post #37





Group: Members
Posts: 326
Joined: 3-August 08
From: UK
Member No.: 56644



QUOTE (Alexey Lukin @ Apr 16 2011, 06:27) *
This is only due to the fact that you used the sinc filter during signal generation.

Not only that—at the risk of repeating myself:
QUOTE (bandpass @ Apr 15 2011, 10:39) *
QUOTE (Wombat @ Apr 14 2011, 22:49) *
1. Is sox a resampler that upsamples with leaving samples intact when upsampling from 48k to 96k

Depending on 3 things: the input signal bandwidth, the selected filter characteristics, and the selected bit-depth, sometimes yes, sometimes no.

QUOTE
Real music is not like that and its sample values will change.

Not necessarily so. It's not a question of whether the music is real or not, it's whether the recording/mastering/etc. has left any headroom in the frequency domain. For example, MP3 usually lowpasses at 16k and some commercially produced music CDs can also be seen to roll-off well before the nyquist.
Go to the top of the page
+Quote Post
Alexey Lukin
post Apr 16 2011, 08:45
Post #38





Group: Members
Posts: 191
Joined: 31-July 08
Member No.: 56508



Agreed.
Go to the top of the page
+Quote Post

2 Pages V  < 1 2
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: 23rd September 2014 - 18:49