Resampling

Started by October 31, 2005
```Dear,

I want to resample a real signal from for instance 1024 -> 1027 samples.
I prefer not to do it in the temporal domain, in order to avoid large
upsampling and downsampling steps. I have read that one possibility could
be zero padding in frequency, but for this example I must use a IDFT and
not IFFT to transform the signal to time domain. I have heard something
about chirp-z transform, but I don't understand how to use it in this
application. Someone has solved this problem or has any other idea?
Thanks.

Inaki

```
```in article P7GdnWqkjuwcy_veRVn-hA@giganews.com, Inaki Val at
nahemoth@gmail.com wrote on 10/31/2005 12:38:

> I want to resample a real signal from for instance 1024 -> 1027 samples.
> I prefer not to do it in the temporal domain, in order to avoid large
> upsampling and downsampling steps.

where do these guys pick up these misconceptions?  is there some textbook
somewhere that is saying that you first upsample by an integer factor of
1027, then pick out 1 sample in every 1024 thus throwing away the other
1023?  does it not occur to people that, if all you're gonna do with the
other 1023 samples is throw them away, maybe you don't have to compute them
in the first place?

> I have read that one possibility could
> be zero padding in frequency, but for this example I must use a IDFT and
> not IFFT to transform the signal to time domain.

the magic of the FFT.  a cure for all ills.

> I have heard something about chirp-z transform,

and if the FFT doesn't cure it, then the Chirp certainly will, and if the
Chirp doesn't do the trick, the transforming into wavelets will.

you can do anything with the right tools.

--

r b-j                  rbj@audioimagination.com

"Imagination is more important than knowledge."

```
```robert bristow-johnson wrote:
> in article P7GdnWqkjuwcy_veRVn-hA@giganews.com, Inaki Val at
> nahemoth@gmail.com wrote on 10/31/2005 12:38:
>
> > I want to resample a real signal from for instance 1024 -> 1027 samples.
> > I prefer not to do it in the temporal domain, in order to avoid large
> > upsampling and downsampling steps.
>
> where do these guys pick up these misconceptions?  is there some textbook
> somewhere that is saying that you first upsample by an integer factor of
> 1027, then pick out 1 sample in every 1024 thus throwing away the other
> 1023?  does it not occur to people that, if all you're gonna do with the
> other 1023 samples is throw them away, maybe you don't have to compute them
> in the first place?
>
> > I have read that one possibility could
> > be zero padding in frequency, but for this example I must use a IDFT and
> > not IFFT to transform the signal to time domain.
>
> the magic of the FFT.  a cure for all ills.
>
> > I have heard something about chirp-z transform,
>
> and if the FFT doesn't cure it, then the Chirp certainly will, and if the
> Chirp doesn't do the trick, the transforming into wavelets will.
>
> you can do anything with the right tools.
>
> --
>
> r b-j                  rbj@audioimagination.com
>
> "Imagination is more important than knowledge."

Like the song says:

...and if that FFT don't work,
... and if that ...

Ahem, sorry.

```
```robert bristow-johnson wrote:
> > I want to resample a real signal from for instance 1024 -> 1027 samples.
> > I prefer not to do it in the temporal domain, in order to avoid large
> > upsampling and downsampling steps.
>
> where do these guys pick up these misconceptions?  is there some textbook
> somewhere that is saying that you first upsample by an integer factor of
> 1027, then pick out 1 sample in every 1024 thus throwing away the other
> 1023?  does it not occur to people that, if all you're gonna do with the
> other 1023 samples is throw them away, maybe you don't have to compute them
> in the first place?

You don't have to compute all of them in the first place, but you do
have to compute smoothed intermediate samples at a wide variety of
possible points in between the input ones.  Do you have a way of
computing only those that are needed?

Guess it should be possible... for example, if you had coefficienct for
an FIR filter intended to run at the least-common-multiple sample rate,
you could with some logic (not unlike the phase accumulator in a DDS)
select the coefficients matching the actual input samples necessary for
computing the desired output sample.  So you don't need to compute LCM
samples, but you do need a coefficient table sized by LCM.  Is there a
simpler way?

```
```Inaki Val wrote:
>
> Dear,
>
>  I want to resample a real signal from for instance 1024 -> 1027 samples.

Try Secret Rabbit Code:

http://www.mega-nerd.com/SRC/

> I prefer not to do it in the temporal domain, in order to avoid large
> upsampling and downsampling steps.

SRC does it in the time domain using the technique popularised by
Julius O. Smith (links on SRC web pages). It avoids any large
upsampling.

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
```
```
Erik de Castro Lopo wrote:
> Inaki Val wrote:
>> Dear,
>>
>>  I want to resample a real signal from for instance 1024 -> 1027 samples.
>
> Try Secret Rabbit Code:
>
>     http://www.mega-nerd.com/SRC/

Does it really allow such precision?  On occasion I'd have loved to be
able to stretch something containing tens of millions of samples by
precisely a few hundred or even a few tens of samples.

Bob
--

"Things should be described as simply as possible, but no simpler."

A. Einstein
```
```in article 1130785305.942008.159020@g14g2000cwa.googlegroups.com,
cs_posting@hotmail.com at cs_posting@hotmail.com wrote on 10/31/2005 14:01:

> robert bristow-johnson wrote:
>>> I want to resample a real signal from for instance 1024 -> 1027 samples.
>>> I prefer not to do it in the temporal domain, in order to avoid large
>>> upsampling and downsampling steps.
>>
>> where do these guys pick up these misconceptions?  is there some textbook
>> somewhere that is saying that you first upsample by an integer factor of
>> 1027, then pick out 1 sample in every 1024 thus throwing away the other
>> 1023?  does it not occur to people that, if all you're gonna do with the
>> other 1023 samples is throw them away, maybe you don't have to compute them
>> in the first place?
>
> You don't have to compute all of them in the first place, but you do
> have to compute smoothed intermediate samples at a wide variety of
> possible points in between the input ones.

why?

> Do you have a way of computing only those that are needed?

you only need to compute the samples that fall precisely on the output
sample times.

> Guess it should be possible... for example, if you had coefficienct for
> an FIR filter intended to run at the least-common-multiple sample rate,
> you could with some logic (not unlike the phase accumulator in a DDS)
> select the coefficients matching the actual input samples necessary for
> computing the desired output sample.  So you don't need to compute LCM
> samples, but you do need a coefficient table sized by LCM.

i might agree with this last statement.

>  Is there a simpler way?

it might not be simpler for many simple SRC ratios, but a coefficient table
that is large enough (how large?) coupled with some kind of interpolation
(perhaps linear interpolation) is the simplest way for arbitrary or varying
sample rate ratio.

--

r b-j                  rbj@audioimagination.com

"Imagination is more important than knowledge."

```
```robert bristow-johnson wrote:
> >>> I want to resample a real signal from for instance 1024 -> 1027 samples.

> > You don't have to compute all of them in the first place, but you do
> > have to compute smoothed intermediate samples at a wide variety of
> > possible points in between the input ones.
>
> why?
>
> > Do you have a way of computing only those that are needed?
>
> you only need to compute the samples that fall precisely on the output
> sample times.

Yes, but the samples you need (at output frequency) will fall at a
range of times between (and rarely coincident with) an input sample.

> it might not be simpler for many simple SRC ratios, but a coefficient table
> that is large enough (how large?) coupled with some kind of interpolation
> (perhaps linear interpolation) is the simplest way for arbitrary or varying
> sample rate ratio.

It's not so much that you can't use linear interpolation, as that you
need to low-pass filter the resampled signal to get rid of high
frequency error components (phase jitter, distortion, etc) above it's
nyquist limit.  Easiest way to do that is digitally, at several times
out output sample rate, though it probably doesn't have to be the LCM
of sample rates.  That filter can accomplish better than linear
interpolation for you too, if the FIR includes several input samples.
You do have to clock the filter quite a bit faster than the sample
rate, but most of the inputs except for those at input sample rate will
be zero.

```
```robert bristow-johnson wrote:

> in article P7GdnWqkjuwcy_veRVn-hA@giganews.com, Inaki Val at
> nahemoth@gmail.com wrote on 10/31/2005 12:38:
>
>
>>I want to resample a real signal from for instance 1024 -> 1027 samples.
>>I prefer not to do it in the temporal domain, in order to avoid large
>>upsampling and downsampling steps.
>
>
> where do these guys pick up these misconceptions?  is there some textbook
> somewhere that is saying that you first upsample by an integer factor of
> 1027, then pick out 1 sample in every 1024 thus throwing away the other
> 1023?  does it not occur to people that, if all you're gonna do with the
> other 1023 samples is throw them away, maybe you don't have to compute them
> in the first place?
>
>
>>I have read that one possibility could
>>be zero padding in frequency, but for this example I must use a IDFT and
>>not IFFT to transform the signal to time domain.
>
>
> the magic of the FFT.  a cure for all ills.
>
>
>>I have heard something about chirp-z transform,
>
>
> and if the FFT doesn't cure it, then the Chirp certainly will, and if the
> Chirp doesn't do the trick, the transforming into wavelets will.
>
> you can do anything with the right tools.
>
Goodness you're cranky this week.

Look for polyphase conversion on the web, Secret Rabbit Code (I have
_no_ idea what this may have to do with Sample Rate Conversion) is a
good example.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
```
```Tim Wescott wrote:
>
> Look for polyphase conversion on the web, Secret Rabbit Code (I have
> _no_ idea what this may have to do with Sample Rate Conversion) is a
> good example.

I think I have an answer to this :-).

I was working on the Rabbit and someone asked a question
on the Linux Audio Developers mailing list about writing
a program like Fruity Loops. I replied that that I was
working on something that they would find useful. A friend
of mine who knew I was working on a sample rate converter
said (sssh, secret rabbit code):