DSPRelated.com
Forums

Scaling FIR for samplerate

Started by jeff227 December 7, 2006
Sorry for the "DSP 101" questions but I'm a newbie...

Is there a way to scale FIR filter coefficients so I can have the same
cutoff and transition bandwidth regardless of sample rate (provided the
sample rate is always within Nyquist limits)?

I am designing an audio processor that needs to have the same filter
response regardless of user-selected sample rate (44.1KHz, 48KHz, 96KHz,
etc.).

How would one accomplish this with FIR filters?  

Do I need variable tap lengths as well as re-calculated coefficients for
every possible samplerate or can one set of fixed-length coefficients be
somehow scaled?
jeff227 skrev:
> Sorry for the "DSP 101" questions but I'm a newbie... > > Is there a way to scale FIR filter coefficients so I can have the same > cutoff and transition bandwidth regardless of sample rate (provided the > sample rate is always within Nyquist limits)?
No, not FIR filters. The normalized cut-off frequency fc/fs is the main design factor. Once you change either fc or fs you have to do the whole design all over again. In the case of IIR filters, matters are a bit different. You can get away with a frequency transform of a normalized prototype if you go from lower to higher sample rates, possibly at the expense of using a higher-than-necessary filter order. If you want to decrease the sampling frequency, the whole design has to be re-computed, as you likely will need a higher filter order to meet the spec.
> I am designing an audio processor that needs to have the same filter > response regardless of user-selected sample rate (44.1KHz, 48KHz, 96KHz, > etc.). > > How would one accomplish this with FIR filters?
One filter for each rate. It's not hard to do once you know the specs.
> Do I need variable tap lengths as well as re-calculated coefficients for > every possible samplerate or can one set of fixed-length coefficients be > somehow scaled?
You need to do the design all over for each sample rate. Rune
jeff227 wrote:
> Sorry for the "DSP 101" questions but I'm a newbie... > > Is there a way to scale FIR filter coefficients so I can have the same > cutoff and transition bandwidth regardless of sample rate (provided the > sample rate is always within Nyquist limits)? > > I am designing an audio processor that needs to have the same filter > response regardless of user-selected sample rate (44.1KHz, 48KHz, 96KHz, > etc.). > > How would one accomplish this with FIR filters? > > Do I need variable tap lengths as well as re-calculated coefficients for > every possible samplerate or can one set of fixed-length coefficients be > somehow scaled?
The salient frequencies of digital filters are all relative to the sample rate, so I'm afraid you're at a dead end. It's also likely that the filter order needed for a fixed absolute response will be proportional to the sample rate. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������

jeff227 wrote:

> Sorry for the "DSP 101" questions but I'm a newbie... > > Is there a way to scale FIR filter coefficients so I can have the same > cutoff and transition bandwidth regardless of sample rate (provided the > sample rate is always within Nyquist limits)?
You can do it by direct scaling. 1. Compute the FIR to the highest sample rate you need. 2. If you want to recalculate the filter to the different sample rate, interpolate the coefficients in the time domain so the impulse response will look same. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
>You can do it by direct scaling. > >1. Compute the FIR to the highest sample rate you need. >2. If you want to recalculate the filter to the different sample rate, >interpolate the coefficients in the time domain so the impulse response >will look same.
Thank you, but it looks like even that approach requires an "adaptive" array length (proportional to samplerate) and some carefully designed interpolation code. Yuck. My "simple" problem seems to be getting worse. I can't use IIR because of the excessive ringing and phase shifts. If I use FIR I need multiple filters and delay lines for every possible samplerate. There are numerous audio editors and VST/DirectX plugins available that use FIRs and work at any samplerate (including odd rates). HOW ARE THEY DOING THAT?!? Any ideas appreciated!
jeff227 wrote:
> >You can do it by direct scaling. > > > >1. Compute the FIR to the highest sample rate you need. > >2. If you want to recalculate the filter to the different sample rate, > >interpolate the coefficients in the time domain so the impulse response > >will look same. > > > Thank you, but it looks like even that approach requires an "adaptive" > array length (proportional to samplerate) and some carefully designed > interpolation code. >
If you are willing to waste some FIR filter length, then design your filter length for the highest sample rate, and zero pad the unused FIR taps as the sample rate goes down and the filter becomes shorter. Instead of interpolating in the time domain, you might be able to fft your filter, change the length of the fft vector, and then ifft this new length of vector back to the time domain. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Ron N. skrev:
> jeff227 wrote: > > >You can do it by direct scaling. > > > > > >1. Compute the FIR to the highest sample rate you need. > > >2. If you want to recalculate the filter to the different sample rate, > > >interpolate the coefficients in the time domain so the impulse response > > >will look same. > > > > > > Thank you, but it looks like even that approach requires an "adaptive" > > array length (proportional to samplerate) and some carefully designed > > interpolation code. > > > > If you are willing to waste some FIR filter length, then design your > filter length for the highest sample rate, and zero pad the unused > FIR taps as the sample rate goes down and the filter becomes > shorter.
This might work for the truncated-sinc filter, but once you introduce window functions, the window coefficients have to be re-calculated for the new filter lengths and you are back to square one, you have to design the whole filter from the spec. Rune
jeff227 wrote:

> ... I can't use IIR because of the excessive ringing and phase shifts.
Phase shift and ringing are not closely connected.
> If I use FIR I need > multiple filters and delay lines for every possible sample rate.
A filter's frequency response implies a certain impulse response. Achieving the same impulse response at different sample rates necessarily involves a different number of delay elements. ... Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:
> jeff227 wrote: > > > ... I can't use IIR because of the excessive ringing and phase shifts. > > Phase shift and ringing are not closely connected. > > > If I use FIR I need > > multiple filters and delay lines for every possible sample rate. > > A filter's frequency response implies a certain impulse response. > Achieving the same impulse response at different sample rates > necessarily involves a different number of delay elements.
It involves a maximum number of delay elements (given some bounds on the sample rates). You can always use coefficients of zero for a shorter impulse response, without actually changing the number of delay elements or taps in the filter implementation. The OP asked for "ease" of filter generation, not efficiency of operation. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
On Thu, 07 Dec 2006 13:01:08 -0600, jeff227 wrote:

> Yuck. My "simple" problem seems to be getting worse. I can't use IIR > because of the excessive ringing and phase shifts.
IIRs don't *have* to have ringing: that's a design decision. (Look up "maximally flat".)
> If I use FIR I need > multiple filters and delay lines for every possible samplerate.
Yep.
> There are numerous audio editors and VST/DirectX plugins available that > use FIRs and work at any samplerate (including odd rates). HOW ARE THEY > DOING THAT?!?
They almost certainly have different implementations for each sample rate. In some circumstances (depends on what the plugin is doing, obviously), it is reasonable to do the filter-design (compute the impulse response) at run-time, whenever the sample rate changes. Another approach that is sometimes used is to run your filter at one "gold standard" sample rate (say 96kHz) and sample-rate-convert on input and output. That's probably harder to do in a plug-in environment than in one where you control all of the horizontals and verticals. It also guarantees that you use the largest number of MIPS possible, if that is a concern... Cheers, -- Andrew