FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > DSP

DSP comp.dsp newsgroup, mailing list

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-30-2004, 06:50 PM
David Reid
Guest
 
Posts: n/a
Default Sample Rate Conversion by non integer factor

How can this be done? My application is converting the sample rate of
44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or 1.3)
and playing back at 44.1kHz, so that the speed sounds different. This is
being done in C++.

So far, what i've read seems to only apply to SRC by integer factors. One
method is:

Upsampling: Interpolate zeroes (in time domain?), low pass filter with Fc at
new Nyquist freq

Downsampling: Low pass filter + decimation (of every nth sample, n being the
conversion factor)

OR

FFT -> low pass filter with Fc at new Nyquist frequency -> IFFT.

How does this change to be able to change the sample rate by a Real factor?
Please correct any and all errors i've made above.

Thanks for any and all help.


Reply With Quote
  #2 (permalink)  
Old 06-30-2004, 07:39 PM
Jon Harris
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

Perceptually, converting by any rational factor can be accomplished by combining
integer upsampling and downsampling, e.g. for 0.75, upsample by 3, downsample by
4. There are efficiency tricks that can do this all in one step with much less
computation (try searching on polyphase filters).

"David Reid" <dreid_nospam@remove_no_spam_mechtronix.ca> wrote in message
news:W6CEc.179470$[email protected] m...
> How can this be done? My application is converting the sample rate of
> 44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or 1.3)
> and playing back at 44.1kHz, so that the speed sounds different. This is
> being done in C++.
>
> So far, what i've read seems to only apply to SRC by integer factors. One
> method is:
>
> Upsampling: Interpolate zeroes (in time domain?), low pass filter with Fc at
> new Nyquist freq
>
> Downsampling: Low pass filter + decimation (of every nth sample, n being the
> conversion factor)
>
> OR
>
> FFT -> low pass filter with Fc at new Nyquist frequency -> IFFT.
>
> How does this change to be able to change the sample rate by a Real factor?
> Please correct any and all errors i've made above.
>
> Thanks for any and all help.
>
>



Reply With Quote
  #3 (permalink)  
Old 06-30-2004, 07:40 PM
Suodatin Pussi
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

David Reid wrote:

> How can this be done? My application is converting the sample rate of
> 44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or 1.3)
> and playing back at 44.1kHz, so that the speed sounds different. This is
> being done in C++.
>
> So far, what i've read seems to only apply to SRC by integer factors. One
> method is:
>
> Upsampling: Interpolate zeroes (in time domain?), low pass filter with Fc at
> new Nyquist freq
>

Going up I would use a cutoff at the old nyquist since the signal does
not contain any more information than that.
When going down I would check if the new sample freq is lower than the
old one and use that nyquist for a lowpass filter cutoff.

> Downsampling: Low pass filter + decimation (of every nth sample, n being the
> conversion factor)
>


Check the 'Data resampling' topic of janey posted on 06/16/2004

> OR
>
> FFT -> low pass filter with Fc at new Nyquist frequency -> IFFT.

FFT (Overlap-add) would also work fine but you do not need a real
lowpass filter just trow away bins. And transform back using lesser bins
or more bins padded with zeros.

>
> How does this change to be able to change the sample rate by a Real factor?
> Please correct any and all errors i've made above.

Real=Up/Down

fs*0.75= 3 up and 4 down
fs*1.3 = 13 up 10 down
etc.
>
> Thanks for any and all help.
>
>


Reply With Quote
  #4 (permalink)  
Old 06-30-2004, 09:12 PM
Suodatin Pussi
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

Suodatin Pussi wrote:

> David Reid wrote:
>
>> How can this be done? My application is converting the sample rate of
>> 44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or 1.3)
>> and playing back at 44.1kHz, so that the speed sounds different. This is
>> being done in C++.

When using integer up and down values and a fir interpolation filter:
Let say you need to go from fs=44.1kHz to fs=32khz. That would be 320 up
and 441 down (44.1x320/441=32). The lowest samplerate allows only for
freqs upto 32/2=16kHz. So your interpolation or lowpassfilter will have
its cutoff at 16kHz or lower (for example at 0.93*16kHz) you need some
room for the roll-off of your fir filter. The fir filter should have a
relatively high order because filtering is done at samplerate of
44.1*320 kHz. So check if you can construct such a filter.

After you have constructed the appropriate filter. Take a sample from
your original signal and add 320-1 zeros. repeat that for all samples.
So you will get a sample, 319 zeros, next sample, 319 zeros etc..
Be aware that the total energy of your signal drops. You have to gain
you signal with a factor 320.
Now you would fir filter it at the new samplerate 44.1*320 using the
lowpass (interpolation) filter. But as you see there are a lot of
useless calculations because multiplying a zero sample value with a
filter coeff would result in zero output. So you only need to muliply
each sample at your inputbuffer with the correponsding 320th filter
coefficient. This saves a lot of calculations. Shift your filter 1
sample and look again. Now you see that each sample correponds with the
every 320th coefffient starting at the 319th coeff. etc..

After filtering you need to downsample. Down 441 means that you take the
0 sample, the 441th sample, the 882th etc. So downsampling is nothing
more than trowing all those samples away you just calculated. You could
have skipped these calculations at the upsampling stage. Saving some
more calculations. It's all about organizing your calculations. The main
problem is to get a good fir interpolation filter

Try to draw it out on a sheet of paper and use some more reasonable up
and downfactors like up 3 and down 4.

Before I write down a similar procedure using overlap-add. I first have
to check it myself. There are a few tricky things. earlier I said that
you could trow away bins or padd zeros (for going down or up). But thats
not all, you also need to reorganize the bin content and store them at
the (new) appropriate locations.

sorry for the typos, I have to watch football now. damn portugal scores.


Reply With Quote
  #5 (permalink)  
Old 06-30-2004, 11:04 PM
Erik de Castro Lopo
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

David Reid wrote:
>
> How can this be done? My application is converting the sample rate of
> 44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or 1.3)
> and playing back at 44.1kHz, so that the speed sounds different. This is
> being done in C++.
>
> So far, what i've read seems to only apply to SRC by integer factors.


Well obviously you have never heard of Secret Rabbit Code .

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

or Julius O. Smith (see URL below).

> How does this change to be able to change the sample rate by a Real factor?
> Please correct any and all errors i've made above.


The best explanation is here:

http://ccrma-www.stanford.edu/~jos/resample/

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo [email protected] (Yes it's valid)
+-----------------------------------------------------------+
"I've nothing against OO, I do have something against C++. Its a dogs
dinner. Anyone who's (tried) to read Stroustrups book on C++ like I had
the misfortune of doing knows that the man is very intelligent but has
about as much clarity of thought as Timothy Leary on a bad day."
-- NJR in comp.os.linux.development.apps
Reply With Quote
  #6 (permalink)  
Old 06-30-2004, 11:07 PM
David Reid
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

Hey, thanks for the replies. Your explanations seem very useful. However,
i don't think i will be using them....for the following reason.

My manager came to see why it was taking so long for me to get this thing
working and we had a debate about the proper way to do resampling. He
suggested a technique, which i don't know where it came from but for some
reason it works (i just implemented it). It goes against pretty much all
that i've read on the web, and what i've read on this news group. I will
post the question and algorithm for everyone to respond to in another post,
if your interested.

david

"Suodatin Pussi" <[email protected]> wrote in
message news:40e3105c$0$42417$e4fe514c[email protected]..
> Suodatin Pussi wrote:
>
> > David Reid wrote:
> >
> >> How can this be done? My application is converting the sample rate of
> >> 44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or

1.3)
> >> and playing back at 44.1kHz, so that the speed sounds different. This

is
> >> being done in C++.

> When using integer up and down values and a fir interpolation filter:
> Let say you need to go from fs=44.1kHz to fs=32khz. That would be 320 up
> and 441 down (44.1x320/441=32). The lowest samplerate allows only for
> freqs upto 32/2=16kHz. So your interpolation or lowpassfilter will have
> its cutoff at 16kHz or lower (for example at 0.93*16kHz) you need some
> room for the roll-off of your fir filter. The fir filter should have a
> relatively high order because filtering is done at samplerate of
> 44.1*320 kHz. So check if you can construct such a filter.
>
> After you have constructed the appropriate filter. Take a sample from
> your original signal and add 320-1 zeros. repeat that for all samples.
> So you will get a sample, 319 zeros, next sample, 319 zeros etc..
> Be aware that the total energy of your signal drops. You have to gain
> you signal with a factor 320.
> Now you would fir filter it at the new samplerate 44.1*320 using the
> lowpass (interpolation) filter. But as you see there are a lot of
> useless calculations because multiplying a zero sample value with a
> filter coeff would result in zero output. So you only need to muliply
> each sample at your inputbuffer with the correponsding 320th filter
> coefficient. This saves a lot of calculations. Shift your filter 1
> sample and look again. Now you see that each sample correponds with the
> every 320th coefffient starting at the 319th coeff. etc..
>
> After filtering you need to downsample. Down 441 means that you take the
> 0 sample, the 441th sample, the 882th etc. So downsampling is nothing
> more than trowing all those samples away you just calculated. You could
> have skipped these calculations at the upsampling stage. Saving some
> more calculations. It's all about organizing your calculations. The main
> problem is to get a good fir interpolation filter
>
> Try to draw it out on a sheet of paper and use some more reasonable up
> and downfactors like up 3 and down 4.
>
> Before I write down a similar procedure using overlap-add. I first have
> to check it myself. There are a few tricky things. earlier I said that
> you could trow away bins or padd zeros (for going down or up). But thats
> not all, you also need to reorganize the bin content and store them at
> the (new) appropriate locations.
>
> sorry for the typos, I have to watch football now. damn portugal scores.
>
>



Reply With Quote
  #7 (permalink)  
Old 06-30-2004, 11:36 PM
Suodatin Pussi
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

David Reid wrote:

> Hey, thanks for the replies. Your explanations seem very useful. However,
> i don't think i will be using them....for the following reason.
>
> My manager came to see why it was taking so long for me to get this thing
> working and we had a debate about the proper way to do resampling. He
> suggested a technique, which i don't know where it came from but for some
> reason it works (i just implemented it). It goes against pretty much all
> that i've read on the web, and what i've read on this news group. I will
> post the question and algorithm for everyone to respond to in another post,
> if your interested.
>
> david

Sure, share it with us, if you're allowed to, it seems to be a very
quick method.
Reply With Quote
  #8 (permalink)  
Old 06-30-2004, 11:57 PM
David Reid
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

I have actually. i've also heard of Open source audio library on
sourceforge.net. i think the implementation for the class afLibConverter
(used for sample rate conversion) is a reimplementation of the Secret Rabbit
Code functions in C++.

Anyway, I've posted the algorithm. don't care if i can't share it. dont
really like this company much....


"Erik de Castro Lopo" <[email protected]> wrote in message
news:[email protected]..
> David Reid wrote:
> >
> > How can this be done? My application is converting the sample rate of
> > 44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or

1.3)
> > and playing back at 44.1kHz, so that the speed sounds different. This

is
> > being done in C++.
> >
> > So far, what i've read seems to only apply to SRC by integer factors.

>
> Well obviously you have never heard of Secret Rabbit Code .
>
> http://www.mega-nerd.com/SRC/
>
> or Julius O. Smith (see URL below).
>
> > How does this change to be able to change the sample rate by a Real

factor?
> > Please correct any and all errors i've made above.

>
> The best explanation is here:
>
> http://ccrma-www.stanford.edu/~jos/resample/
>
> Erik
> --
> +-----------------------------------------------------------+
> Erik de Castro Lopo [email protected] (Yes it's valid)
> +-----------------------------------------------------------+
> "I've nothing against OO, I do have something against C++. Its a dogs
> dinner. Anyone who's (tried) to read Stroustrups book on C++ like I had
> the misfortune of doing knows that the man is very intelligent but has
> about as much clarity of thought as Timothy Leary on a bad day."
> -- NJR in comp.os.linux.development.apps



Reply With Quote
  #9 (permalink)  
Old 06-30-2004, 11:59 PM
Jon Harris
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

Let me guess--linear interpolation? If not, please post.

"David Reid" <dreid_nospam@remove_no_spam_mechtronix.ca> wrote in message
news:0UFEc.185159$[email protected] m...
> Hey, thanks for the replies. Your explanations seem very useful. However,
> i don't think i will be using them....for the following reason.
>
> My manager came to see why it was taking so long for me to get this thing
> working and we had a debate about the proper way to do resampling. He
> suggested a technique, which i don't know where it came from but for some
> reason it works (i just implemented it). It goes against pretty much all
> that i've read on the web, and what i've read on this news group. I will
> post the question and algorithm for everyone to respond to in another post,
> if your interested.
>
> david



Reply With Quote
  #10 (permalink)  
Old 07-01-2004, 09:54 PM
Ronald H. Nicholson Jr.
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

In article <W6CEc.179470$[email protected]> ,
David Reid <dreid_nospam@remove_no_spam_mechtronix.ca> wrote:
>How can this be done? My application is converting the sample rate of
>44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or 1.3)
>and playing back at 44.1kHz, so that the speed sounds different.


Interpolation can give you any point between sample points, and
thus will work for any arbitrary or even time varying sample ratios.

Sinc interpolation will produce much less distortion than linear
or low order polynomial interpolation (see the "reconstruction"
theorems), although linear interpolation may work if the frequency
content of the original signal is way below the sample rate.

An interpolation method with suitable approximations for the
windowed-Sinc function will allow you to trade off compute time against
S/N ratio. You can play with the type of window, width of window and
various approximation tricks for the windowed-Sinc function. The various
polyphase resampling methods are just table-lookup driven optimization
tricks which one can use with DSP's that are too slow (or as an
optimization when needed for power reduction or something). On a fast
PC you may not need to do this, as a well tuned math library can often
calculate the window and Sinc tap coefficients in real time.


IMHO. YMMV.
--
Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/
#include <canonical.disclaimer> // only my own opinions, etc.
Reply With Quote
  #11 (permalink)  
Old 07-01-2004, 11:32 PM
Jon Harris
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

"Ronald H. Nicholson Jr." <[email protected]> wrote in message
news:cc1q5u$8k1$[email protected]..
> In article <W6CEc.179470$[email protected]> ,
>
> On a fast
> PC you may not need to do this, as a well tuned math library can often
> calculate the window and Sinc tap coefficients in real time.


Just curious, how well does this work with a Kaiser window (my favorite choice
for this type of thing)? It's got that nasty Bessel function in it!


Reply With Quote
  #12 (permalink)  
Old 07-01-2004, 11:38 PM
Erik de Castro Lopo
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

David Reid wrote:
>
> I have actually. i've also heard of Open source audio library on
> sourceforge.net. i think the implementation for the class afLibConverter
> (used for sample rate conversion) is a reimplementation of the Secret Rabbit
> Code functions in C++.


Actually, I beleive that afLibConverter uses a modified version
of Julius O. Smith's original C code and simply provides a C++
wrapper around it.

Secret Rabbit Code is the reimplementation and last time I compared
my code (the Rabbit) with implementations based on the JOS code, my
code ran faster and had better signal to noise and a wider passband.
I've been meaning write up these results but I simply haven't had
the time.

> Anyway, I've posted the algorithm. don't care if i can't share it. dont
> really like this company much....


Que??

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo [email protected] (Yes it's valid)
+-----------------------------------------------------------+
When aiming for the common denominator, be prepared for the
occasional division by zero.
Reply With Quote
  #13 (permalink)  
Old 07-02-2004, 06:36 AM
balaji
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

I have implemented a polynomial interpolator and it works fine for
Audio Sample rate conversion. You can the material here
http://www.student.oulu.fi/~oniemita/DSP/INDEX.HTM

[email protected] (Ronald H. Nicholson Jr.) wrote in message news:<cc1q5u$8k1$[email protected]>...
> In article <W6CEc.179470$[email protected]> ,
> David Reid <dreid_nospam@remove_no_spam_mechtronix.ca> wrote:
> >How can this be done? My application is converting the sample rate of
> >44.1kHz wave files to sample rate X (eg change SR by factor of 0.75, or 1.3)
> >and playing back at 44.1kHz, so that the speed sounds different.

>
> Interpolation can give you any point between sample points, and
> thus will work for any arbitrary or even time varying sample ratios.
>
> Sinc interpolation will produce much less distortion than linear
> or low order polynomial interpolation (see the "reconstruction"
> theorems), although linear interpolation may work if the frequency
> content of the original signal is way below the sample rate.
>
> An interpolation method with suitable approximations for the
> windowed-Sinc function will allow you to trade off compute time against
> S/N ratio. You can play with the type of window, width of window and
> various approximation tricks for the windowed-Sinc function. The various
> polyphase resampling methods are just table-lookup driven optimization
> tricks which one can use with DSP's that are too slow (or as an
> optimization when needed for power reduction or something). On a fast
> PC you may not need to do this, as a well tuned math library can often
> calculate the window and Sinc tap coefficients in real time.
>
>
> IMHO. YMMV.

Reply With Quote
  #14 (permalink)  
Old 07-02-2004, 09:20 AM
Erik de Castro Lopo
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

balaji wrote:
>
> I have implemented a polynomial interpolator and it works fine for
> Audio Sample rate conversion. You can the material here
> http://www.student.oulu.fi/~oniemita/DSP/INDEX.HTM


Have you measured the signal to noise ratio? If so, what was
it and how did you measure it?

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo [email protected] (Yes it's valid)
+-----------------------------------------------------------+
"And MS thinks Linux is vulnerable to forking? 95, 95 OEM SR2, 98, 98SE,
ME, NT, 2000, Bob, .NET, CE, Datacenter, Server, Adv. Server, and now
Web Server, sheesh." -- BTS on LinuxToday.com
Reply With Quote
  #15 (permalink)  
Old 07-02-2004, 11:50 AM
Andor
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

Jon Harris wrote:
> "Ronald H. Nicholson Jr." wrote:
> >
> > On a fast
> > PC you may not need to do this, as a well tuned math library can often
> > calculate the window and Sinc tap coefficients in real time.

>
> Just curious, how well does this work with a Kaiser window (my favorite choice
> for this type of thing)? It's got that nasty Bessel function in it!


Have you tried Knab's alternative to the Kaiser window [1]? It is also
a one-parameter window family, but is defined using exp instead of the
Bessel I_0 function and is claimed to be very close to the Kaiser
window.

Regards,
Andor

[1] John J Knab, "An Alternate Kaiser Window"
IEEE Transactions on Acoustics, Speech, and Signal Processing, Vol.
ASSP-27, No.5, October 1979
Reply With Quote
  #16 (permalink)  
Old 07-02-2004, 06:03 PM
Jon Harris
Guest
 
Posts: n/a
Default Re: Sample Rate Conversion by non integer factor

"Andor" <[email protected]> wrote in message
news:[email protected] om...
> Jon Harris wrote:
> > "Ronald H. Nicholson Jr." wrote:
> > >
> > > On a fast
> > > PC you may not need to do this, as a well tuned math library can often
> > > calculate the window and Sinc tap coefficients in real time.

> >
> > Just curious, how well does this work with a Kaiser window (my favorite

choice
> > for this type of thing)? It's got that nasty Bessel function in it!

>
> Have you tried Knab's alternative to the Kaiser window [1]? It is also
> a one-parameter window family, but is defined using exp instead of the
> Bessel I_0 function and is claimed to be very close to the Kaiser
> window.
>
> Regards,
> Andor
>
> [1] John J Knab, "An Alternate Kaiser Window"
> IEEE Transactions on Acoustics, Speech, and Signal Processing, Vol.
> ASSP-27, No.5, October 1979


That's the first I've heard of it. Thanks for the tip!


Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate sample rate ... Kappa FPGA 23 11-24-2008 02:16 PM
Sample Rate Conversion Confusion Morgan P?lsson DSP 7 06-29-2004 08:47 PM
DSP sample rate question Jon Dohnson DSP 6 06-09-2004 09:50 PM
SOS! how to factor x^341 -1 in GF(3)? how to do GF(3) stuff in matlab? how to factor polynomial on GF(3)? walala DSP 3 12-23-2003 03:05 PM
C6711 sample rate H.Greving DSP 3 12-22-2003 11:58 AM


All times are GMT +1. The time now is 02:46 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved