DSPRelated.com
Forums

Upsample/FIR/downsample

Started by Unknown August 3, 2007
On Aug 8, 2:28 pm, robert bristow-johnson <r...@audioimagination.com>
wrote:
> On Aug 8, 4:21 pm, R.Lyons@_BOGUS_ieee.org (Rick Lyons) wrote: > > > > > On Wed, 08 Aug 2007 17:31:32 -0000, robert bristow-johnson > > > <r...@audioimagination.com> wrote: > > > >it depends on if you are ultimately upsampling (M<L) or downsampling > > >(M>L). that's why i said > > > > h = fir1(N-1, min(1/M,1/L), kaiser(N,7.8562)); > > ... > > Regarding the fir1's freq argument, when > > I looked at mpowell's original decimation > > code, and the interpolation code example in MATLAB's > > hardcopy User's Manual, I originally thought > > mpowell made an error in his > > > h = fir1(N,1/M,kaiser(N+1,7.8562)) > > > where M = 160. > > > It took me a while to figure it out (and it > > surprised me a little), with MATLAB's formating > > the fir1's freq argument should always be 1/160 > > REGARDLESS of whether your interpolating or > > decimating!! > > i don't think i agree, Rick. if you're UPsampling (switch the values > for M and L around, M=147 and L=160) then you want the cutoff > frequency to be Nyquist/L, no? > > e.g. converting a sound file from CD sampling rate (44.1 kHz) to DAT > or DAW or "studio" sampling rate (48 kHz).
Wouldn't all the reconstruction filters on the way between two sample rates have the same cutoff; e.g. min(f1/2, f2/2) ? In the upsampling case one wants to make sure that any new samples don't introduce any new image spectral content. And in the downsampling case, one wants to low pass filter first so that there will be no content at or above Fs/2 of the destination sample rate. I prefer to think of resampling as reconstruction, with all the polyphase and up/down intermediate rate stuff as just (major) implementation optimizations. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
On Aug 9, 2:14 am, "Ron N." <rhnlo...@yahoo.com> wrote:
> On Aug 8, 2:28 pm, robert bristow-johnson <r...@audioimagination.com> > wrote: > > > On Aug 8, 4:21 pm, R.Lyons@_BOGUS_ieee.org (Rick Lyons) wrote: > > > > On Wed, 08 Aug 2007 17:31:32 -0000, robert bristow-johnson > > > > <r...@audioimagination.com> wrote: > > > > >it depends on if you are ultimately upsampling (M<L) or downsampling > > > >(M>L). that's why i said > > > > > h = fir1(N-1, min(1/M,1/L), kaiser(N,7.8562)); >
...
> > Wouldn't all the reconstruction filters on the > way between two sample rates have the same cutoff; > e.g. min(f1/2, f2/2) ?
yes, i think so. that why i said h = fir1(N-1, min(1/M,1/L), kaiser(N,7.8562)); (N = L*n_taps in either case.)
> In the upsampling case one wants to make sure that > any new samples don't introduce any new image > spectral content. And in the downsampling case, > one wants to low pass filter first so that there > will be no content at or above Fs/2 of the > destination sample rate.
i think we're in agreement.
> I prefer to think of resampling as reconstruction, > with all the polyphase and up/down intermediate rate > stuff as just (major) implementation optimizations.
in my long treatise on this thread, i tried to put it in those terms. but i find it easier to think of resampling as emulating, in a purely digital environment, what happens in the ideal if you were to, at the first sampling rate, output your samples to an ideal D/A with an ideal anti-imaging filter, and then resampling at the new sampling instances spaced apart by the reciprocal of the new sampling rate. that's the easier way for me to imagine it and the details of what needs to happen. r b-j
On Wed, 08 Aug 2007 21:28:07 -0000, robert bristow-johnson
<rbj@audioimagination.com> wrote:

>On Aug 8, 4:21 pm, R.Lyons@_BOGUS_ieee.org (Rick Lyons) wrote: >> On Wed, 08 Aug 2007 17:31:32 -0000, robert bristow-johnson >> >> <r...@audioimagination.com> wrote: >> >> >> >it depends on if you are ultimately upsampling (M<L) or downsampling >> >(M>L). that's why i said >> >> > h = fir1(N-1, min(1/M,1/L), kaiser(N,7.8562)); >> >... >> Regarding the fir1's freq argument, when >> I looked at mpowell's original decimation >> code, and the interpolation code example in MATLAB's >> hardcopy User's Manual, I originally thought >> mpowell made an error in his >> >> h = fir1(N,1/M,kaiser(N+1,7.8562)) >> >> where M = 160. >> >> It took me a while to figure it out (and it >> surprised me a little), with MATLAB's formating >> the fir1's freq argument should always be 1/160 >> REGARDLESS of whether your interpolating or >> decimating!! > >i don't think i agree, Rick. if you're UPsampling (switch the values >for M and L around, M=147 and L=160) then you want the cutoff >frequency to be Nyquist/L, no? > >e.g. converting a sound file from CD sampling rate (44.1 kHz) to DAT >or DAW or "studio" sampling rate (48 kHz). so now the intermediate >upsampled frequency is the same 7.058 MHz (44.1kHz*160), but now you >want your cutoff to be half of the source sampling rate (22.05 kHz), >not half of the destination sampling rate (which is higher, 24 kHz). >your 7 MHz intermediate signal will have images at 44.1, 88.2 and so >on. there might be something between 22.05 and 24 kHz that you don't >like. > >when up-converting, there should be no loss of information, but there >will be holes in the spectrum of the intermediate over-sampled >signal. when down-converting, to prevent aliasing, you must filter >your input signal to even less of its Nyquist (to that of the final >Nyquist). > >i think it should be the Nyquist*min(1/L,1/M), and in fir1() (and all >other things MATLAB), "Nyquist"=1. > >that's my story, and i'm stickin to it. > >r b-j
Well, if your text: "min(1/L,1/M)" means "the minimum of 1/147 or 1/160", then min(1/L,1/M) always equals 1/160, right. All I was tryin' to say was that the fir1's freq argument should always be 1/160 whether we're interpolating by 160/147 or decimating by 147/160. As far as I can tell we're in agreement. [-Rick-]
On Aug 9, 12:22 pm, R.Lyons@_BOGUS_ieee.org (Rick Lyons) wrote:
> On Wed, 08 Aug 2007 21:28:07 -0000, robert bristow-johnson > > > > <r...@audioimagination.com> wrote: > >On Aug 8, 4:21 pm, R.Lyons@_BOGUS_ieee.org (Rick Lyons) wrote: > >> On Wed, 08 Aug 2007 17:31:32 -0000, robert bristow-johnson > > >> <r...@audioimagination.com> wrote: > > >> >it depends on if you are ultimately upsampling (M<L) or downsampling > >> >(M>L). that's why i said > > >> > h = fir1(N-1, min(1/M,1/L), kaiser(N,7.8562)); > > >... > >> Regarding the fir1's freq argument, when > >> I looked at mpowell's original decimation > >> code, and the interpolation code example in MATLAB's > >> hardcopy User's Manual, I originally thought > >> mpowell made an error in his > > >> h = fir1(N,1/M,kaiser(N+1,7.8562)) > > >> where M = 160. > > >> It took me a while to figure it out (and it > >> surprised me a little), with MATLAB's formating > >> the fir1's freq argument should always be 1/160 > >> REGARDLESS of whether your interpolating or > >> decimating!! > > >i don't think i agree, Rick. if you're UPsampling (switch the values > >for M and L around, M=147 and L=160) then you want the cutoff > >frequency to be Nyquist/L, no? > > >e.g. converting a sound file from CD sampling rate (44.1 kHz) to DAT > >or DAW or "studio" sampling rate (48 kHz). so now the intermediate > >upsampled frequency is the same 7.058 MHz (44.1kHz*160), but now you > >want your cutoff to be half of the source sampling rate (22.05 kHz), > >not half of the destination sampling rate (which is higher, 24 kHz). > >your 7 MHz intermediate signal will have images at 44.1, 88.2 and so > >on. there might be something between 22.05 and 24 kHz that you don't > >like. > > >when up-converting, there should be no loss of information, but there > >will be holes in the spectrum of the intermediate over-sampled > >signal. when down-converting, to prevent aliasing, you must filter > >your input signal to even less of its Nyquist (to that of the final > >Nyquist). > > >i think it should be the Nyquist*min(1/L,1/M), and in fir1() (and all > >other things MATLAB), "Nyquist"=1. > > >that's my story, and i'm stickin to it. > > >r b-j > > Well, if your text: > > "min(1/L,1/M)" > > means "the minimum of 1/147 or 1/160", then > min(1/L,1/M) always equals 1/160, right?
yah.
> All I was tryin' to say was that the fir1's > freq argument should always be 1/160 whether > we're interpolating by 160/147 or decimating > by 147/160. > > As far as I can tell we're in agreement.
yup. i might have misread or misunderstood what you said earlier. but the length of the filter should always be N = n_taps*L, so the design of the filter is a little different in the cases of conversion ratios, L/M, of 160/147 vs. 147/160. r b-j
On Thu, 09 Aug 2007 16:44:47 -0000, robert bristow-johnson
<rbj@audioimagination.com> wrote:

  (snipped)
>> >> Well, if your text: >> >> "min(1/L,1/M)" >> >> means "the minimum of 1/147 or 1/160", then >> min(1/L,1/M) always equals 1/160, right? > >yah. > >> All I was tryin' to say was that the fir1's >> freq argument should always be 1/160 whether >> we're interpolating by 160/147 or decimating >> by 147/160. >> >> As far as I can tell we're in agreement. > >yup. i might have misread or misunderstood what you said earlier. >but the length of the filter should always be N = n_taps*L, so the >design of the filter is a little different in the cases of conversion >ratios, L/M, of 160/147 vs. 147/160. > >r b-j
Yep, no question about that. [-Rick-]