What is the most efficient way to downsample 48KHz sample(Mono) to 8KHz(Mono)? The following are my requirements: 1. This decimating process will run on ARM7TDMI(running at 12MHz), which now only have about 5MIPS available for this. 2. The resulting 8KHz sample rate is just for voice application, which doesn't require very high quality, and I need a as fast as possible speed for this decimating. 3. The decimator factor is 6, do I need the multi-stage filter? for example, first is 3, then 2? How many taps can I use? I hope use as small as possible. 4. How can I get the coefficients(h(n)), using Matlab? How can I select the stopband cutoff frequency, may it is the same as the passband cutoff frequency? and How can I select the Maximum passband attenuation and Minimum stopband attenuation? I don't know how this affect the final quality of voice and the load of computation. I am appreciating any response and help!!! Thanks in advance. Ben.Chen This message was sent using the Comp.DSP web interface on www.DSPRelated.com
Urgent: Most efficient way to downsample 48kHz(MONO) to 8KHz(MONO)?
Started by ●June 29, 2005
Reply by ●June 29, 20052005-06-29
Ben.Chen wrote:> What is the most efficient way to downsample 48KHz sample(Mono) to > 8KHz(Mono)? The following are my requirements: > > 1. This decimating process will run on ARM7TDMI(running at 12MHz), which > now only have about 5MIPS available for this.Do you know how this translates into filter length? Have you done any code prototyping to see?> > 2. The resulting 8KHz sample rate is just for voice application, which > doesn't require very high quality, and I need a as fast as possible speed > for this decimating. > > 3. The decimator factor is 6, do I need the multi-stage filter? for > example, first is 3, then 2? How many taps can I use? I hope use as small > as possible. > > 4a. How can I get the coefficients(h(n)), using Matlab?There's a variety of methods. Presumably the signal processing toolbox has something clever if you're willing to pay for it. I usually just make up a vector expressing my desired frequency response at the higher frequency, then get it's FFT.> 4b. How can I select > the stopband cutoff frequency, may it is the same as the passband cutoff > frequency?That depends on how you define "cutoff frequency". Most definitions would say that the passband ends at 3 or 6dB of attenuation, while the stopband doesn't really start until 30, 40 or 60dB of attenuation. There will be a finite gap between the low passband-ending frequency and the high stopband-ending frequency.> 4c. and How can I select the Maximum passband attenuation and > Minimum stopband attenuation? I don't know how this affect the final > quality of voice and the load of computation. >The more closely you want your filter to appreach the ideal, rectangualar brick wall the more coefficients it'll need to have. Allowing some ripple in the passband and stopband will make the filter shorter, but what will really allow it to be short will be allowing it to drop off slowly from passband to stopband. You may even want to make an elliptic filter of sorts -- if you filter with z^12 - 1 that'll put a zero at 0, 4, 8, etc., kHz -- then you can make an FIR filter that compensates for the rolloff in your desired passband and goes to zero somewhere past 4kHz. I would hazard a guess that for voice quality you could get by with 3dB of passband ripple and a minimum of 40dB of stopband attenuation. When I say "get by", however, that's exactly what I mean -- voices will sound tinny, and you'll be able to hear the band playing faintly and very distorted in the background. Your best bet will be to listen to it. -- ------------------------------------------- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●June 29, 20052005-06-29
"Ben.Chen" <benbenny.chen@163.com> wrote in message news:s7OdnSeqVrtDOF_fRVn-rA@giganews.com...> What is the most efficient way to downsample 48KHz sample(Mono) to > 8KHz(Mono)? The following are my requirements:Well, you probably already know this but the _very_ most effecient way is to simply drop 5 out of every 6 samples! But this will probably sound pretty bad, unless your input audio is already pretty close to bandlimited to 4kHz. Adding low-pass filters of increasing lengh gives better quality at the expense of more MIPS. One thing that will really help you is that you only need to compute the filtered result for the samples you really need, that is 1 out of every 6. Rather than creating a 48kHz filtered waveform, only compute the samples you are going to keep anyway.> 1. This decimating process will run on ARM7TDMI(running at 12MHz), which > now only have about 5MIPS available for this.If you can figure out how long of an FIR filter you can run with 5MIPS, then we can talk further. A simple test where you run some dummy data through a dummy FIR should give you a pretty decent answer in short order.> 2. The resulting 8KHz sample rate is just for voice application, which > doesn't require very high quality, and I need a as fast as possible speed > for this decimating.Google for half-band filters--that might be useful for this application.> 3. The decimator factor is 6, do I need the multi-stage filter? for > example, first is 3, then 2? How many taps can I use? I hope use as small > as possible.You can do it all in one stage (it's simpler to program), but recent discussions have indicated you can get better performance for the same MIPS by breaking it up.> 4. How can I get the coefficients(h(n)), using Matlab? How can I select > the stopband cutoff frequency, may it is the same as the passband cutoff > frequency? and How can I select the Maximum passband attenuation and > Minimum stopband attenuation? I don't know how this affect the final > quality of voice and the load of computation.It's all a tradeoff. You can push your passband farther out (closer to 4kHz) and retain more of the audio bandwidth which is a good thing. But that will inevitably mean that you get worse stop-band rejection, which is a bad thing. Once you know how long your filter can be, listening to the tradeoff between bandwidth and alias suppression is recommended. You can also trade off pass band ripple as Tim mentioned. For a starting point, you could try 3kHz pass band, 4kHz stop band.
Reply by ●June 29, 20052005-06-29
>Ben.Chen wrote: > >> What is the most efficient way to downsample 48KHz sample(Mono) to >> 8KHz(Mono)? The following are my requirements: >> >> 1. This decimating process will run on ARM7TDMI(running at 12MHz),which>> now only have about 5MIPS available for this. > >Do you know how this translates into filter length? Have you done any >code prototyping to see?Sorry, I have not, and I hope the filter length is from 7-10.>> >> 2. The resulting 8KHz sample rate is just for voice application, which >> doesn't require very high quality, and I need a as fast as possiblespeed>> for this decimating. >> >> 3. The decimator factor is 6, do I need the multi-stage filter? for >> example, first is 3, then 2? How many taps can I use? I hope use assmall>> as possible. >> >> 4a. How can I get the coefficients(h(n)), using Matlab? > >There's a variety of methods. Presumably the signal processing toolbox >has something clever if you're willing to pay for it. I usually just >make up a vector expressing my desired frequency response at the higher >frequency, then get it's FFT. > >> 4b. How can I select >> the stopband cutoff frequency, may it is the same as the passbandcutoff>> frequency? > >That depends on how you define "cutoff frequency". Most definitions >would say that the passband ends at 3 or 6dB of attenuation, while the >stopband doesn't really start until 30, 40 or 60dB of attenuation. >There will be a finite gap between the low passband-ending frequency and>the high stopband-ending frequency.Thanks.> >> 4c. and How can I select the Maximum passband attenuation and >> Minimum stopband attenuation? I don't know how this affect the final >> quality of voice and the load of computation. >> >The more closely you want your filter to appreach the ideal, >rectangualar brick wall the more coefficients it'll need to have. >Allowing some ripple in the passband and stopband will make the filter >shorter, but what will really allow it to be short will be allowing it >to drop off slowly from passband to stopband. You may even want to make>an elliptic filter of sorts -- if you filter with z^12 - 1 that'll put a>zero at 0, 4, 8, etc., kHz -- then you can make an FIR filter that >compensates for the rolloff in your desired passband and goes to zero >somewhere past 4kHz. > >I would hazard a guess that for voice quality you could get by with 3dB >of passband ripple and a minimum of 40dB of stopband attenuation. When >I say "get by", however, that's exactly what I mean -- voices will sound>tinny, and you'll be able to hear the band playing faintly and very >distorted in the background. Your best bet will be to listen to it.Did you mean that the above parameters value will result in a very distorted noice in the background? Many thanks!>-- >------------------------------------------- >Tim Wescott >Wescott Design Services >http://www.wescottdesign.com >This message was sent using the Comp.DSP web interface on www.DSPRelated.com
Reply by ●June 29, 20052005-06-29
"Ben.Chen" <benbenny.chen@163.com> wrote in message news:s7OdnSeqVrtDOF_fRVn-rA@giganews.com...> What is the most efficient way to downsample 48KHz sample(Mono) to > 8KHz(Mono)? The following are my requirements:>Well, you probably already know this but the _very_ most effecient way >is to >simply drop 5 out of every 6 samples! But this will probably sound >pretty bad, >unless your input audio is already pretty close to bandlimited to 4kHz. >Adding >low-pass filters of increasing lengh gives better quality at the expense >of more >MIPS.>One thing that will really help you is that you only need to compute the>filtered result for the samples you really need, that is 1 out of every >6. >Rather than creating a 48kHz filtered waveform, only compute the samples >you are >going to keep anyway.Yes, I have done so, and there is a big noise in the background, and the original sample rate of voice may be 11.025KHz or 16KHz or higher, so although I can hear the sound of voice clearly, there are still noise in background. What is the filter length you suppose when the final quality is the same as the telephony voice quality?> 1. This decimating process will run on ARM7TDMI(running at 12MHz),which> now only have about 5MIPS available for this.>>If you can figure out how long of an FIR filter you can run with 5MIPS, >>then we >>can talk further. A simple test where you run some dummy data through a >>dummy >>FIR should give you a pretty decent answer in short order.I suppose the lenght of an FIR filter should be less than 16.> 2. The resulting 8KHz sample rate is just for voice application, which > doesn't require very high quality, and I need a as fast as possiblespeed> for this decimating.Google for half-band filters--that might be useful for this application. What's the difference between half-band and other filters?> 3. The decimator factor is 6, do I need the multi-stage filter? for > example, first is 3, then 2? How many taps can I use? I hope use assmall> as possible.You can do it all in one stage (it's simpler to program), but recent discussions have indicated you can get better performance for the same MIPS by breaking it up. I like one stage to program easily, which doesn't need much memory operations.> 4. How can I get the coefficients(h(n)), using Matlab? How can I select > the stopband cutoff frequency, may it is the same as the passbandcutoff> frequency? and How can I select the Maximum passband attenuation and > Minimum stopband attenuation? I don't know how this affect the final > quality of voice and the load of computation.It's all a tradeoff. You can push your passband farther out (closer to 4kHz) and retain more of the audio bandwidth which is a good thing. But that will inevitably mean that you get worse stop-band rejection, which is a bad thing. Once you know how long your filter can be, listening to the tradeoff between bandwidth and alias suppression is recommended. You can also trade off pass band ripple as Tim mentioned. For a starting point, you could try 3kHz pass band, 4kHz stop band. I am new for Matlab, what should I do for do the above testing? and Have you learned Linear Interpolation? how about of this to do such a job for voice application from 48KHz to 8KHz? I have checked some code for implementation of Linear Interpolation, it only uses two samples to generate a output samples. May I use this method to do this job? Many thanks for your input!!!:) Ben.Chen This message was sent using the Comp.DSP web interface on www.DSPRelated.com
Reply by ●June 29, 20052005-06-29
Ben.Chen wrote: ...> What's the difference between half-band and other filters?Symmetry makes (almost)the coefficients zero, speeding the calculation. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●June 29, 20052005-06-29
Jerry Avins wrote:> Ben.Chen wrote: > > ... > >> What's the difference between half-band and other filters? > > > Symmetry makes (almost)the coefficients zero, speeding the calculation.Fah! Symmetry makes (almost) half of the coefficients zero, speeding the calculation. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●June 30, 20052005-06-30
"Ben.Chen" <benbenny.chen@163.com> wrote in message news:XNWdnRS7J_iYnl7fRVn-vg@giganews.com...> "Ben.Chen" <benbenny.chen@163.com> wrote in message > news:s7OdnSeqVrtDOF_fRVn-rA@giganews.com... >> What is the most efficient way to downsample 48KHz sample(Mono) to >> 8KHz(Mono)? The following are my requirements: > >>Well, you probably already know this but the _very_ most effecient way >>is to >>simply drop 5 out of every 6 samples! But this will probably sound >>pretty bad, >>unless your input audio is already pretty close to bandlimited to 4kHz. >>Adding >>low-pass filters of increasing lengh gives better quality at the expense >>of more >>MIPS. > >>One thing that will really help you is that you only need to compute the > >>filtered result for the samples you really need, that is 1 out of every >>6. >>Rather than creating a 48kHz filtered waveform, only compute the samples >>you are >>going to keep anyway. > > Yes, I have done so, and there is a big noise in the background, and the > original sample rate of voice may be 11.025KHz or 16KHz or higher, so > although I can hear the sound of voice clearly, there are still noise in > background. What is the filter length you suppose when the final quality > is the same as the telephony voice quality?"Yes, I have done so" - does that refer to simply dropping 5 of every 6 samples, or running on a filter only on the samples you are going to keep? If the first, then I would expect lousy sound quality. If the second, the noise shouldn't be too terrible if you've done it right.> >> 1. This decimating process will run on ARM7TDMI(running at 12MHz), > which >> now only have about 5MIPS available for this. > >>>If you can figure out how long of an FIR filter you can run with 5MIPS, >>>then we >>>can talk further. A simple test where you run some dummy data through a >>>dummy >>>FIR should give you a pretty decent answer in short order. > > I suppose the lenght of an FIR filter should be less than 16.Assuming a 8kHz output rate, if you have 5 MIPS, that means you have 625 instructions in which to generate each output sample. I have no idea how efficient an ARM7TDMI is at running an FIR filter, but let's say it takes 20 instructions per tap (probably conversative). That means you could have a ~31 tap FIR. I would suggest you an experiment to see how many instructions it takes for each tap on your processor. Sixteen taps won't give you a very good filter for downsampling by a factor of 6.>> 4. How can I get the coefficients(h(n)), using Matlab? How can I select >> the stopband cutoff frequency, may it is the same as the passband > cutoff >> frequency? and How can I select the Maximum passband attenuation and >> Minimum stopband attenuation? I don't know how this affect the final >> quality of voice and the load of computation. > > It's all a tradeoff. You can push your passband farther out (closer to > 4kHz) > and retain more of the audio bandwidth which is a good thing. But that > will > inevitably mean that you get worse stop-band rejection, which is a bad > thing. > Once you know how long your filter can be, listening to the tradeoff > between > bandwidth and alias suppression is recommended. You can also trade off > pass > band ripple as Tim mentioned. For a starting point, you could try 3kHz > pass > band, 4kHz stop band. > > I am new for Matlab, what should I do for do the above testing?Use Wavread to read a wave file, Filter to process it, and Wavwrite to output the processed file. To design the filter, look up Matlab help on FIR1 and Remez. I am assuming you have the DSP toolbox installed with Matlab. You can also type sptool at the Matlab command prompt to get a nice graphical tool for filter desgin--try that first if it is available to you. Design a filter with a sample rate of 48kHz, cut-off around 3kHz.> and Have > you learned Linear Interpolation? how about of this to do such a job for > voice application from 48KHz to 8KHz? I have checked some code for > implementation of Linear Interpolation, it only uses two samples to > generate a output samples. May I use this method to do this job? Many > thanks for your input!!!:)Yes, I am familiar with linear interpolation, but it is only applicable to interpolating or upsampling. I guess the equivalent in downsampling (formally called decimating) would be to do a 2-sample average for every output. Basically, a simple average make a poor-man's low pass filter. You could try that to heat the effect, but I suspect you will want better quality, so more samples are required. I would recommend first doing the experiment I described above with your processor to see how many taps of an FIR filter it can handle (probably needs to be hand-coded assembly for best performance). Then once you have that target, design a filter in Matlab with that many taps.
Reply by ●July 12, 20052005-07-12
Ben Chen wrote:>> What's the difference between half-band and other filters?Jerry Avins wrote:>Symmetry makes (almost)the coefficients zero, speeding the calculation.One tradeoff is that to achieve the symmetry for a halfband filter, your frequency response must be 0.5 at FS/4. So, for 48kHz, with a single halfband filter, you can't get down to the 4kHz cutoff you would want, as you are forced to accept a frequency response of 0.5 at 12kHz. I just wrote an app that does interpolation using halfband filters (very efficient!), which is why I know this... However, I learned all this by googling, so I could have been googling wrong. Cheers, Chris
Reply by ●July 13, 20052005-07-13
Ben.Chen wrote:> What is the most efficient way to downsample 48KHz sample(Mono) to > 8KHz(Mono)? The following are my requirements: > > 1. This decimating process will run on ARM7TDMI(running at 12MHz), which > now only have about 5MIPS available for this. > > 2. The resulting 8KHz sample rate is just for voice application, which > doesn't require very high quality, and I need a as fast as possible speed > for this decimating. > > 3. The decimator factor is 6, do I need the multi-stage filter? for > example, first is 3, then 2? How many taps can I use? I hope use as small > as possible. > > 4. How can I get the coefficients(h(n)), using Matlab? How can I select > the stopband cutoff frequency, may it is the same as the passband cutoff > frequency? and How can I select the Maximum passband attenuation and > Minimum stopband attenuation? I don't know how this affect the final > quality of voice and the load of computation. >Based on some simulations, I think you should be able to cheaply get 45-55 dB stopband rejection with passband ripple on the order or .1dB and cutoff frequency of 3.6kHz (90%) I'd do it in two stages. A halfband FIR decimate-by-2 stage and then either an IIR filter, followed by dropping 2 out of every 3 samples. OR a LP FIR filter at the final rate I'd go for the FIR-only route if your ARM does not have a FPU. I estimate you'd use about 20 multiplies and 40 additions per input sample. -- Mark Borgerding






