DSPRelated.com
Forums

Seeking good technique for preloading an FIR filter

Started by Larry McFarren February 5, 2004
I've got a oversampled signal which is then run through a high order filter. 
I've set up my DSP program to take advantage of sub-band filtering. 

One problem though is that I am losing the intitial N samples (N is the filter 
length) because I am starting my filtering in a steady-state condition - there 
are a maximum number of samples being multiplied by filter coefficients. 
The missed samples really aren't a problem since they represent a very 
small fraction of a second of my audio data. The preloading method for 
steady-state conditons is in contrast to starting my filtering by feeding in 
one sample at a time - starting from the first audio sample. Preloading the 
filtering permits me to use sub-band (polyphase) filtering.

Anyway, my question is:

Since no samples can be missed when feeding the second stage of my multistage 
filter.Is there a good programming method to take care of these missing 
samples: using several functions, for loops, etc? I haven't found an optimal 
way of doing this.






Larry McFarren wrote:

> I've got a oversampled signal which is then run through a high order filter. > I've set up my DSP program to take advantage of sub-band filtering. > > One problem though is that I am losing the intitial N samples (N is the filter > length) because I am starting my filtering in a steady-state condition - there > are a maximum number of samples being multiplied by filter coefficients. > The missed samples really aren't a problem since they represent a very > small fraction of a second of my audio data. The preloading method for > steady-state conditons is in contrast to starting my filtering by feeding in > one sample at a time - starting from the first audio sample. Preloading the > filtering permits me to use sub-band (polyphase) filtering. > > Anyway, my question is: > > Since no samples can be missed when feeding the second stage of my multistage > filter.Is there a good programming method to take care of these missing > samples: using several functions, for loops, etc? I haven't found an optimal > way of doing this.
I suspect there's a language problem, so I don't know yet what you're really up to. To wit: as far as I know, polyphase and sub-band filtering aren't the same thing. We probably mean different things by at least one of those terms. Only when you stated your question did I realize what you meant by missing samples. You have discovered that the size of a set of validly filtered samples is necessarily smaller than the source. Consider a linear array that is to be smoothed. One likely scheme to to create a new array in which each element is a quarter of the sum of each of its neighbors in the original array and and twice the corresponding element itself. This is feasible for all but the first and last element of the array. To include those elements, some data have to be faked. The best way to do that depends heavily on the particular application. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
On Thu, 05 Feb 2004 23:57:15 GMT, invalid@address.com (Larry McFarren)
wrote:

>I've got a oversampled signal which is then run through a high order filter. >I've set up my DSP program to take advantage of sub-band filtering. > >One problem though is that I am losing the intitial N samples (N is the filter >length) because I am starting my filtering in a steady-state condition - there >are a maximum number of samples being multiplied by filter coefficients. >The missed samples really aren't a problem since they represent a very >small fraction of a second of my audio data. The preloading method for >steady-state conditons is in contrast to starting my filtering by feeding in >one sample at a time - starting from the first audio sample. Preloading the >filtering permits me to use sub-band (polyphase) filtering. > >Anyway, my question is: > >Since no samples can be missed when feeding the second stage of my multistage >filter.Is there a good programming method to take care of these missing >samples: using several functions, for loops, etc? I haven't found an optimal >way of doing this.
Hi Larry, your question is a little hard to understand because we don't know the full details of your filtering scheme. Do you really have a multi-stage filter (cascaded filters)? We have a notion of what a polyphase filter is, but when you say "sub-band filtering" we have to guess just what that might mean. I'm not sure there is a way to "preload" a tapped delay line FIR filter so that its output is valid before the true input samples have been loaded in. No matter what data you initially load into the filter, the filter's output will not be valid (i.e., a filtered version of the input) until N valid input samples are have been "loaded". [-Rick-]
Hi Larry.

FIR filter code usually does the following:
1 Get latest src sample value
2 Pick up circular buffer pointer
3 Save new sample in buffer
4 Loop thru coefficient table & buffer samples doing mult/acc's
5 Return filter o/p rslt, else return 0 if filter idle

Steps 1,2,3 would be executed unconditionally.
You could have a flag "filterActive" which could control whether
Step 4 was done.
This should keep you FIR "warm", at the expense of an overhead of a few
percent of the normal filter calcs in step 4.

Jim Adamthwaite
>I've got a oversampled signal which is then run through a high order filter. >I've set up my DSP program to take advantage of sub-band filtering. > >
After reading my post, it seems that it was too vague to get my question across. Hopefully this one will be better. I'll use an example to better describe what I'm attempting. My first stage takes and signal and interpolates it by zero stuffing 3 samples (L=4). In reality the zeros aren't actually stuffed since a zero tap multiplied by a coefficient is just zero. However, an appropriate FIR filter has been designed around the new oversampled freq. My filter 12 taps. Shown below is a preloaded filter. h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 x2 0 0 0 x1 0 0 0 x0 0 0 0 0 x2 0 0 0 x1 0 0 0 x0 0 0 0 0 x2 0 0 0 x1 0 0 0 x0 0 0 0 0 x2 0 0 0 x1 0 0 0 x0 Now, my filter loop can look like (just psuedocode here): ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ load the filter coeffs into a buffer h[] while (!eof(newsample)..) fread - to get a newsample of the bitstream reorder the sequence - x[2] = x[1], x[1] = x[0], x[0] = newsample for (i=0; i<4; i++) output = x[0] * h[i+8] + x[1] * h[i+4] +x[2] * h[i] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Taken from dspguru.com, http://www.dspguru.com/info/faqs/multrate/interp.htm "Since the interpolation ratio is four (L = 4), there are four "sub-filters" (whose coefficient sets are marked here with matching colors.) These sub-filters are officially called "polyphase filters". I should have said sub-filter instead of sub-band, sorry. Anyway, looking at the example sequence above, it is evident that several multiplications are missing. For example, in the beginning of the filtering there is no provision for: x[0] * h[0] x[0] * h[1] x[0] * h[2] x[0] * h[3] x[0] * h[4] + x[1] * h[0] x[0] * h[5] + x[1] * h[1] x[0] * h[6] + x[1] * h[2] x[0] * h[7] + x[1] * h[3] What is a good way to perform these filter calculations - from a coding standpoint? These operations don't seem to fit in too well to my 'for' loop shown above. Also, can someone explain the significance of missing these signals? If my audio data has silence at the beginning of the track which I'm filtering, it seems to me like it may not be worth the time to add in these missing calculations since the samples only represent a very small slice of time. The filter shown above was just an example. The one that I'm actually working on has N = 48 taps, with L = 8. So, I'll be losing N samples if I don't have a provision for filtering them. Another issue arises when I take the output from this filter and then proceed to perform a 2nd stage of sub-filtering (different filter). Missing samples in my second stage may present a small hiccup in my audio stream, I think. So, I'm thinking that in this stage no samples can be dropped. Any comments? In case you are wondering, I am also trying the 44.1kHz -> 48kHz audio resampling that some of you have been talking about. My strategy is to break up the resampling into 3 stages. Each stage uses sub-filters with the appropriate filter params: Stage 1: L = 8, M = 3 Stage 2: L = 10, M = 7 Stage 3: L = 2, M = 7 Lastly, what is your take multi-stage sub-filtering when the length of the filter is somewhat 'long' ? Should I abandon sub-filtering and 'do it the old way'? Sorry for the long thread. I'm interested to hear you comments.
Rick Lyons wrote:

> On Thu, 05 Feb 2004 23:57:15 GMT, invalid@address.com (Larry McFarren) > wrote: > > >>I've got a oversampled signal which is then run through a high order filter. >>I've set up my DSP program to take advantage of sub-band filtering. >> >>One problem though is that I am losing the intitial N samples (N is the filter >>length) because I am starting my filtering in a steady-state condition - there >>are a maximum number of samples being multiplied by filter coefficients. >>The missed samples really aren't a problem since they represent a very >>small fraction of a second of my audio data. The preloading method for >>steady-state conditons is in contrast to starting my filtering by feeding in >>one sample at a time - starting from the first audio sample. Preloading the >>filtering permits me to use sub-band (polyphase) filtering. >> >>Anyway, my question is: >> >>Since no samples can be missed when feeding the second stage of my multistage >>filter.Is there a good programming method to take care of these missing >>samples: using several functions, for loops, etc? I haven't found an optimal >>way of doing this. > > > Hi Larry, > your question is a little hard to understand > because we don't know the full details of your filtering > scheme. Do you really have a multi-stage filter > (cascaded filters)? We have a notion of what a > polyphase filter is, but when you say "sub-band > filtering" we have to guess just what that might mean. > > I'm not sure there is a way to "preload" a tapped > delay line FIR filter so that its output is valid > before the true input samples have been loaded in. > No matter what data you initially load into > the filter, the filter's output will not > be valid (i.e., a filtered version of the > input) until N valid input samples are have been > "loaded". > > [-Rick-]
Putting it more strongly, the filters output won't be valid unless it is filled with valid samples, so not only the beginning, but also the end of the end of the output stream must be discarded or faked. It's a bit like losing part of a telomere every time a chromosome is replicated. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;