DSPRelated.com
Forums

Convert to higher sample rate

Started by B April 13, 2014
On Sun, 13 Apr 2014 21:16:55 GMT, no-one@notreal.invalid (Robert
Scott) wrote:

>On Sun, 13 Apr 2014 15:46:12 +0200, =?ISO-8859-1?Q?Marcel_M=FCller?= ><news.5.maazl@spamgourmet.org> wrote: > >>Place zeros in between and apply a low pass filter with high stopband >>attenuation at the higher sampling rate but with a cutoff frequency >>slightly above the Nyquist frequency of your original sampling rate. >> > >Wouldn't it be better to duplicate each sample and then low pass >filter? Inserting zeroes between each sample will introduce a large >component at the lower sample rate, which places more demands on the >low pass filter. Duplicating each sample will not introduce nearly as >much higher frequency content that needs to be filtered. Or better >yet, in between each sample insert the average of the neighboring >samples. You still need to low pass filter, but the filter has much >less work to do, and therefore can be a less critical filter. > >Robert Scott >Hopkins, MN >
As has been mentioned, duplicating samples is a Zero-Order Hold (ZOH) operation that has a frequency response that isn't flat anywhere. This means that you will have to correct for the response of the ZOH in your interpolating filter if you want the final frequency response to be flat in the original spectrum. Putting zeroes in between samples instead of repeating them avoids this, but either way will work. Eric Jacobsen Anchor Hill Communications http://www.anchorhill.com
>oh, c'mon. > >upsample a 5 minute song from 48 kHz to 96 kHz in a straightforward >manner with the FFT. that might be interesting.
oh c'mon yourself :-) This octave:4> z = rand(72*60*44100, 1); a = fft(z); takes about 10 seconds for the whole CD (one FFT, add another 10 seconds to get back to time domain). _____________________________ Posted through www.DSPRelated.com
On 4/13/14 7:20 PM, mnentwig wrote:
>> oh, c'mon. >> >> upsample a 5 minute song from 48 kHz to 96 kHz in a straightforward >> manner with the FFT. that might be interesting. > > oh c'mon yourself :-) > > This > > octave:4> z = rand(72*60*44100, 1); a = fft(z); > > takes about 10 seconds for the whole CD (one FFT, add another 10 seconds to > get back to time domain). >
the problem is not (in modern times) about execution time. what kind of numerical issues might you expect with a 256 Meg FFT? cos(2*pi/268435456) = what ?? -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
robert bristow-johnson <rbj@audioimagination.com> wrote:
> On 4/13/14 7:20 PM, mnentwig wrote:
(snip)
>> oh c'mon yourself :-)
>> This
>> octave:4> z = rand(72*60*44100, 1); a = fft(z);
>> takes about 10 seconds for the whole CD (one FFT, add another > 10 seconds to get back to time domain).
> the problem is not (in modern times) about execution time.
> what kind of numerical issues might you expect with a 256 Meg FFT?
> cos(2*pi/268435456) = what ??
Interesting question. As I understand it (not having actually tested it) the FFT is numerically much better than the DCT. That is, many small roundings are better than one big one. log2(77*60*44100) is about 28. Worst case is one additional bit per stage, so 53 bit floating point should be plenty. I believe (again, I haven't tested it) that on the average only one half bit is needed per stage. -- glen
>> what kind of numerical issues might you expect with a 256 Meg FFT?
I have used regularly FFTs up to Octave's 2G limit for simulations. Usually the dynamic range is 300 dB in double precision, give or take some. Now I can't tell you how much exactly is lost. But I agree, one should keep an eye (or an ear?) on it. I haven't heard about large FFTs being problematic. I might risk a bet that it's still better than anything you can cook up with a "reasonable" impulse response length, not at a level that you can hear but if you look at -150 dBc. With some very loose assumptions (that is, if the "repeat all" button on the CD player is pressed and the signal is cyclic), the FFT's Fourier sum -is- the correct solution to the oversampling problem. Brute force - if it doesn't work, I'm not t using enough of it. Wouldn't propose this for an ASIC, though. _____________________________ Posted through www.DSPRelated.com
On Sun, 13 Apr 2014 16:49:35 -0400, robert bristow-johnson wrote:

> On 4/13/14 4:35 PM, Tim Wescott wrote: >> On Sun, 13 Apr 2014 21:16:55 +0000, Robert Scott wrote: >> >>> On Sun, 13 Apr 2014 15:46:12 +0200, =?ISO-8859-1?Q?Marcel_M=FCller?= >>> <news.5.maazl@spamgourmet.org> wrote: >>> >>>> Place zeros in between and apply a low pass filter with high stopband >>>> attenuation at the higher sampling rate but with a cutoff frequency >>>> slightly above the Nyquist frequency of your original sampling rate. >>>> >>>> >>> Wouldn't it be better to duplicate each sample and then low pass >>> filter? >>> Inserting zeroes between each sample will introduce a large component >>> at the lower sample rate, which places more demands on the low pass >>> filter. Duplicating each sample will not introduce nearly as much >>> higher frequency content that needs to be filtered. Or better yet, in >>> between each sample insert the average of the neighboring samples. >>> You still need to low pass filter, but the filter has much less work >>> to do, and therefore can be a less critical filter. >> >> If you view the operations in the frequency domain, the zero-insertion >> method replicates the original spectrum exactly, as many times as there >> are zeros inserted (so if you go up 4x you have 4x the bandwidth, and >> four identical spectra, with three of them shifted). The sample- >> replication, on the other hand, introduces significant frequency >> shaping, >> with a honkin' big null at Nyquist and its harmonics. > > which is nice. *very* useful for audio, because nearly all of the > energy in audio is in the bottom 5 or 6 octaves. > > hint: this fact can be put to use for designing the LPF even if you > *don't* stuff with replicated samples (and zero-stuff it). > >> In the end analysis, the "replicate samples" method is essentially the >> same thing as the "insert zeros" method followed by a boxcar filter. >> That, in turn, means that the "replicate samples" method is really just >> the "insert zeros" method with the boxcar filter imposed on the >> designer. > > "imposed"? you might want to put it that the boxcar filter (with those > nice honkin' bit nulls at n*Fs for |n|>0) is *aiding* the designer. it's > all in the semantics.
I would say that it's all in the designers intent. If they can use the nulls, then its an aid. If they don't want the nulls, or if they want the nulls elsewhere, it's an imposition.
> hint: this fact can be put to use for designing the LPF even if you > *don't* stuff with replicated samples (and zero-stuff it).
Will, that's pretty much what I said in the sentence below.
>> So you can always get the effect of the "replicate samples" method in >> the "insert zeros" method, but you can't always get the reverse. > > i don't get the big difference. the only difference between the two are > whether or not there is a zero-order hold (which is an LTI filter) in > there or not. it might affect how the other LPF is designed.
It's not a huge difference, for me it's more of a "why bother?"
> the only reason i would bother to do either is if the LPF i am using to > eliminate the images (which would be much better eliminated if the ZOH > *was* in there) with an IIR filter. otherwise, i would just polyphase > the damn thing.
I agree on that point. The whole zero-stuff-and-filter is a nice conceptual framework, but it's less work to polyphase filter the thing (even, BTW, if you do an IIR filter: if you use the right form of filter you can update the states once for each input sample, then pull out a "polyphased" version with different weights on the states for each output sample). -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
On 4/14/14 1:15 PM, Tim Wescott wrote:
> On Sun, 13 Apr 2014 16:49:35 -0400, robert bristow-johnson wrote: > >> On 4/13/14 4:35 PM, Tim Wescott wrote: >>> On Sun, 13 Apr 2014 21:16:55 +0000, Robert Scott wrote: >>> >>>> On Sun, 13 Apr 2014 15:46:12 +0200, =?ISO-8859-1?Q?Marcel_M=FCller?= >>>> <news.5.maazl@spamgourmet.org> wrote: >>>> >>>>> Place zeros in between and apply a low pass filter with high stopband >>>>> attenuation at the higher sampling rate but with a cutoff frequency >>>>> slightly above the Nyquist frequency of your original sampling rate. >>>>> >>>>> >>>> Wouldn't it be better to duplicate each sample and then low pass >>>> filter? >>>> Inserting zeroes between each sample will introduce a large component >>>> at the lower sample rate, which places more demands on the low pass >>>> filter. Duplicating each sample will not introduce nearly as much >>>> higher frequency content that needs to be filtered. Or better yet, in >>>> between each sample insert the average of the neighboring samples. >>>> You still need to low pass filter, but the filter has much less work >>>> to do, and therefore can be a less critical filter. >>> >>> If you view the operations in the frequency domain, the zero-insertion >>> method replicates the original spectrum exactly, as many times as there >>> are zeros inserted (so if you go up 4x you have 4x the bandwidth, and >>> four identical spectra, with three of them shifted). The sample- >>> replication, on the other hand, introduces significant frequency >>> shaping, >>> with a honkin' big null at Nyquist and its harmonics. >> >> which is nice. *very* useful for audio, because nearly all of the >> energy in audio is in the bottom 5 or 6 octaves. >> >> hint: this fact can be put to use for designing the LPF even if you >> *don't* stuff with replicated samples (and zero-stuff it). >> >>> In the end analysis, the "replicate samples" method is essentially the >>> same thing as the "insert zeros" method followed by a boxcar filter. >>> That, in turn, means that the "replicate samples" method is really just >>> the "insert zeros" method with the boxcar filter imposed on the >>> designer. >> >> "imposed"? you might want to put it that the boxcar filter (with those >> nice honkin' bit nulls at n*Fs for |n|>0) is *aiding* the designer. it's >> all in the semantics. > > I would say that it's all in the designers intent. If they can use the > nulls, then its an aid. If they don't want the nulls, or if they want > the nulls elsewhere, it's an imposition.
lemme see, other than the image centered at f=0 (the original), why *wouldn't* you welcome nulls smack dab in the middle of all of the other images? when you resample, all of those images (that survive) potentially fold over into your original baseband and mess things up. they become the "N" when you calculate the S/N of your resampling operation.
>> hint: this fact can be put to use for designing the LPF even if you >> *don't* stuff with replicated samples (and zero-stuff it). > > Will, that's pretty much what I said in the sentence below. >
well, i dunno if you know precisely what i meant. you have MATLAB or Octave, right? lemme send you something.
>>> So you can always get the effect of the "replicate samples" method in >>> the "insert zeros" method, but you can't always get the reverse. >> >> i don't get the big difference. the only difference between the two are >> whether or not there is a zero-order hold (which is an LTI filter) in >> there or not. it might affect how the other LPF is designed. > > It's not a huge difference, for me it's more of a "why bother?" > >> the only reason i would bother to do either is if the LPF i am using to >> eliminate the images (which would be much better eliminated if the ZOH >> *was* in there) with an IIR filter. otherwise, i would just polyphase >> the damn thing. > > I agree on that point. The whole zero-stuff-and-filter is a nice > conceptual framework,
yes.
> but it's less work to polyphase filter the thing > (even, BTW, if you do an IIR filter: if you use the right form of filter > you can update the states once for each input sample, then pull out a > "polyphased" version with different weights on the states for each output > sample).
i don't see how you can do that with an IIR. if you upsample, initially by zero-stuffing or sample-replication, your *IIR* has to run on every upsampled sample (even with zero input). with the FIR, you know what terms will be zero and you can avoid adding those terms. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
On Mon, 14 Apr 2014 14:15:41 -0400
robert bristow-johnson <rbj@audioimagination.com> wrote:

> On 4/14/14 1:15 PM, Tim Wescott wrote: > > On Sun, 13 Apr 2014 16:49:35 -0400, robert bristow-johnson wrote: > > > >> On 4/13/14 4:35 PM, Tim Wescott wrote: > >>> On Sun, 13 Apr 2014 21:16:55 +0000, Robert Scott wrote: > >>> > >> > >>> In the end analysis, the "replicate samples" method is essentially the > >>> same thing as the "insert zeros" method followed by a boxcar filter. > >>> That, in turn, means that the "replicate samples" method is really just > >>> the "insert zeros" method with the boxcar filter imposed on the > >>> designer. > >> > >> "imposed"? you might want to put it that the boxcar filter (with those > >> nice honkin' bit nulls at n*Fs for |n|>0) is *aiding* the designer. it's > >> all in the semantics. > > > > I would say that it's all in the designers intent. If they can use the > > nulls, then its an aid. If they don't want the nulls, or if they want > > the nulls elsewhere, it's an imposition. > > lemme see, other than the image centered at f=0 (the original), why > *wouldn't* you welcome nulls smack dab in the middle of all of the other > images? when you resample, all of those images (that survive) > potentially fold over into your original baseband and mess things up. > they become the "N" when you calculate the S/N of your resampling operation. >
I can't imagine not wanting the nulls themselves, but sinc(f)'s got some awfully round knees. If I'm having to fancy up my post-filtering to try to restore those mid-ranges that got their heads pushed down, there's every chance that's more work than doing it the mathematically simpler way. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.
On Mon, 14 Apr 2014 14:15:41 -0400, robert bristow-johnson wrote:

>> but it's less work to polyphase filter the thing (even, BTW, if you do >> an IIR filter: if you use the right form of filter you can update the >> states once for each input sample, then pull out a "polyphased" version >> with different weights on the states for each output sample). > > > i don't see how you can do that with an IIR. if you upsample, initially > by zero-stuffing or sample-replication, your *IIR* has to run on every > upsampled sample (even with zero input). with the FIR, you know what > terms will be zero and you can avoid adding those terms.
I've posted on this before. It can be done. Let say that your zero-stuffed signal has its non-zero elements at n = 4 * k, where k is the sample index of the original signal. Then, if you have an IIR filter, the value of both the states and the outputs at n = 4 * k, n = 4 * k + 1, n = 4 * k + 2, and n = 4 * k + 3 are wholly determined by the state of the filter at n = 4 * k - 1 and the signal value at k. Moreover, the outputs and states at those four samples will all be linear combinations of the input and the state at n = 4 * k. I'm not sure about the best way to express this, but in state-space it'd be expressed as x_k = A * x_{k-1} + B * u_k, y_k = C * x_{k-1} + D * u_k where x_k is a state vector (m x m for m states), B is a m x 1 input vector, C is a 4 x m output vector, and D is a 4 x 1 feed-forward vector. y_k in this case would then contain the outputs of the filter at 4*k, 4*k +1, etc. I don't know if the filter could be constructed to actually take less computation than running the IIR at the higher rate (I suspect yes), but it certainly can be done. Given a full-speed filter described by A', B', C' and D', the polyphase IIR filter would be described by A = (A')^4 B = B' [ C' ] C = [ C' * A' ] [ C' * (A')^2 ] [ C' * (A')^3 ] and [ D' ] D = [ 0 ] [ 0 ] [ 0 ] (Note that this hasn't been tested -- I'm just working off the top of my head here. But I know that I'm f***ing brilliant, so I'm right). ( :) ) -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
On 4/14/14 2:24 PM, Rob Gaddi wrote:
> On Mon, 14 Apr 2014 14:15:41 -0400 > robert bristow-johnson<rbj@audioimagination.com> wrote: > >> On 4/14/14 1:15 PM, Tim Wescott wrote: >>> On Sun, 13 Apr 2014 16:49:35 -0400, robert bristow-johnson wrote: >>> >>>> On 4/13/14 4:35 PM, Tim Wescott wrote: >>>>> On Sun, 13 Apr 2014 21:16:55 +0000, Robert Scott wrote: >>>>> >>>> >>>>> In the end analysis, the "replicate samples" method is essentially the >>>>> same thing as the "insert zeros" method followed by a boxcar filter. >>>>> That, in turn, means that the "replicate samples" method is really just >>>>> the "insert zeros" method with the boxcar filter imposed on the >>>>> designer. >>>> >>>> "imposed"? you might want to put it that the boxcar filter (with those >>>> nice honkin' big nulls at n*Fs for |n|>0) is *aiding* the designer. it's >>>> all in the semantics. >>> >>> I would say that it's all in the designers intent. If they can use the >>> nulls, then its an aid. If they don't want the nulls, or if they want >>> the nulls elsewhere, it's an imposition. >> >> lemme see, other than the image centered at f=0 (the original), why >> *wouldn't* you welcome nulls smack dab in the middle of all of the other >> images? when you resample, all of those images (that survive) >> potentially fold over into your original baseband and mess things up. >> they become the "N" when you calculate the S/N of your resampling operation. >> > > I can't imagine not wanting the nulls themselves, but sinc(f)'s got some > awfully round knees. If I'm having to fancy up my post-filtering to > try to restore those mid-ranges that got their heads pushed down, > there's every chance that's more work than doing it the mathematically > simpler way. >
well, one thing about the magic of optimal FIR filter design is that you get to specify the target frequency response in such a way to compensate (to whatever extent possible) for those awfully rounded knees. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."