Hi. I note that a suitably designed FIR filter with N coefficients can have a time-delay of N/2 (or is it (N-1)/2?). I'm designing low pass filters by the window method. In my application I'm taking whole sample files and filtering after the fact. It is very important for me to be able to say for any sample in my filtered sample what the original time of that sample was in the original file. Hence it looks sensible for me to reinterpret the coefficients of my FIR filter so that when producing an output sample y[i], that my coefficients are applied to samples at times x[i-N/2] to x[i+N/2], and to assume that all samples before the start of my original sample or after its end are zero. Hence I get a filtered version of my original file without any time shift. Is this correct? I haven't yet examined optimal/Remerez FIR filter design in great detail. Is it easy and/or possible to predict the delay inherent in a Remerez filter as it is for one designed by the windowing method? If execution speed is not crucial, are there any other advantages in using a FIR filter designed by the Remerez method compared to simply using a FIR filter with a larger number of coefficients? Thanks in anticipation, Ross-c
FIR filter and time delay
Started by ●February 15, 2006
Reply by ●February 15, 20062006-02-15
Ross Clement (Email address invalid - do not use) wrote:> Hi. I note that a suitably designed FIR filter with N coefficients can > have a time-delay of N/2 (or is it (N-1)/2?). I'm designing low pass > filters by the window method. In my application I'm taking whole sample > files and filtering after the fact. It is very important for me to be > able to say for any sample in my filtered sample what the original time > of that sample was in the original file. Hence it looks sensible for me > to reinterpret the coefficients of my FIR filter so that when producing > an output sample y[i], that my coefficients are applied to samples at > times x[i-N/2] to x[i+N/2], and to assume that all samples before the > start of my original sample or after its end are zero. Hence I get a > filtered version of my original file without any time shift. Is this > correct? > > I haven't yet examined optimal/Remerez FIR filter design in great > detail. Is it easy and/or possible to predict the delay inherent in a > Remerez filter as it is for one designed by the windowing method? If > execution speed is not crucial, are there any other advantages in using > a FIR filter designed by the Remerez method compared to simply using a > FIR filter with a larger number of coefficients? > > Thanks in anticipation, > > Ross-cIf you are using and/or have access to MATLAB along with the Signal Processing Toolbox, then for your application I would recommend filtering with the "filtfilt" command. This command performs true "Zero Phase" (i.e. no delay) filtering by using a forward-reverse filtering implementation. It works with any filter you design (FIR, IIR, linear phase, etc.). If you don't have access to MATLAB, then I would do a search on zero phase filtering. Alternatively, you can pad the data at the ends with intelligently selected values and then take the sections of the filtered output which correspond to your input.
Reply by ●February 15, 20062006-02-15
Thanks. Looking at the page: http://www-ccrma.stanford.edu/~jos/filters/Zero_Phase_Filters.html It seems that my shifting of the coefficients of a FIR filter designed by the windowing method produces a filter where h(n) = h(-n), which fits the definition of a zero phase filter as per that page. The page above doesn't describe zero phase as being produced by a forwards-backwards procedure. Though, I can see how this would work and be useful for filters such as IIR filters with, erm, "inconvenient" phase responses. The phase effects of filtering backward would I presume cancel out those of moving foward while the frequency response would reinforce. Since I'm using very large FIR filters (up to thousands of coefficients), the caveat that phase oscillates between 0 and pi in the stopband is unlikely to cause me any trouble as the response in the stopband will be, I assume, tiny. The page uses a Remez-designed FIR filter as an example and hence I presume the coefficients of a Remez-designed filter are also symmetric so that they can be shifted such that h(n) = h(-n). I sort of have access to matlab. I have windows matlab but work on linux and my uni doesn't seem set up for providing the linux version of matlab. However, I much prefer to "do things myself". I have recently moved "DSP-ward" from a different background recently and prefer to work through things such as filter design "by hand" to make sure that I have an understanding of what is going on. I don't mind writing my own code then discarding it to use library code later on if the library code is going to more numerically accurate than anything I'll ever write, e.g. linear algebra code. As a side question, would you recommend scilab? I've noted people describing the documentation for the DSP toolbox for scilab being well written and well worth reading for the educational side-effects. Cheers, Ross-c
Reply by ●February 15, 20062006-02-15
Ross Clement (Email address invalid - do not use) wrote:> Hi. I note that a suitably designed FIR filter with N coefficients can > have a time-delay of N/2 (or is it (N-1)/2?).All symmetric FIR filters with the same number of taps operating at the same sample rate have the same delay: (N-1)/2.> I'm designing low pass > filters by the window method. In my application I'm taking whole sample > files and filtering after the fact. It is very important for me to be > able to say for any sample in my filtered sample what the original time > of that sample was in the original file.Since the value of a filtered result depends on all of the values of the samples used to calculate it, that is a difficult philosophical as well as practical question.> Hence it looks sensible for me > to reinterpret the coefficients of my FIR filter so that when producing > an output sample y[i], that my coefficients are applied to samples at > times x[i-N/2] to x[i+N/2], and to assume that all samples before the > start of my original sample or after its end are zero. Hence I get a > filtered version of my original file without any time shift. Is this > correct?Sort of. It's as easy to subtract the delay of the filter from the index number of the finished sample. The result will be the same. Note that the output will be wrong when the filter isn't filled with valid data. All filters have start and end transients which become unimportant only with long inputs.> I haven't yet examined optimal/Remerez FIR filter design in great > detail. Is it easy and/or possible to predict the delay inherent in a > Remerez filter as it is for one designed by the windowing method?All symmetric FIR filters with the same number of taps operating at the same sample rate have the same delay: (N-1)/2.> If > execution speed is not crucial, are there any other advantages in using > a FIR filter designed by the Remerez method compared to simply using a > FIR filter with a larger number of coefficients?Less delay? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●February 15, 20062006-02-15
Ross, Looks like you are off to a good start. For more info on forward-backwards (forward-reverse) zero-phase filtering you can check out: http://ccrma.stanford.edu/~jos/filters/Forward_Backwards_Filtering.html http://www.mathworks.com/access/helpdesk/help/toolbox/signal/basic19a.html I've never used Scilab, so I can't comment on that.
Reply by ●February 15, 20062006-02-15
Thanks. I should have taken more note of your page on how to ask questions on comp.dsp and checked out the properties of filters designed by the Remez exchange method before posting. The start and end transients are not too important for my application as speech samples typically have "silence" at the beginning and end +/- the occasional bit of breath noise. Also, as for the philosophical question of the "time" of a sample in the filtered output versus the original output... My thinking is as follows and I would appreciate correction if it is wrong. Imaging that there is a synthetic signal created by the addition of sines (or cosines of course). Imagine that only one such sine wave has a frequency of < 150hz, and all others have frequencies > 150hz. If the full signal was filtered by a perfect (I do know this is impossible) zero-phase lowpass filter with a cutoff of 150hz, then the single relatively low frequency sine should pass through the filter unchanged while all other sines are stopped completely. In this situation the output would be a pure sine wave with observable minima, maxima, and zero crossings. I would like the minima, maxima, and zero crossings of the observed sine wave to be at the same times as the corresponding events of the sine wave used when synthesising the original sound. Therefore I could do things like cut out a portion of the original signal which is one complete cycle of the 150hz component used when synthesising the signal. If I have a known time-delay (e.g. 0) due to filtering then I can cut out such a cycle so that the 150hz component has a phase of 0 in my extracted cycle by observing the minima, maxima, and zero crossings in the filtered signal and mapping the locations of these onto the original signal. I now believe that the term "zero phase filter[ing]" describes exactly what I want. Cheers, Ross-c
Reply by ●February 15, 20062006-02-15
"Ross Clement (Email address invalid - do not use)" <clemenr@wmin.ac.uk> wrote in message news:1140014159.919792.202010@g43g2000cwa.googlegroups.com...> Hi. I note that a suitably designed FIR filter with N coefficients can > have a time-delay of N/2 (or is it (N-1)/2?). I'm designing low pass > filters by the window method. In my application I'm taking whole sample > files and filtering after the fact. It is very important for me to be > able to say for any sample in my filtered sample what the original time > of that sample was in the original file. Hence it looks sensible for me > to reinterpret the coefficients of my FIR filter so that when producing > an output sample y[i], that my coefficients are applied to samples at > times x[i-N/2] to x[i+N/2], and to assume that all samples before the > start of my original sample or after its end are zero. Hence I get a > filtered version of my original file without any time shift. Is this > correct? > > I haven't yet examined optimal/Remerez FIR filter design in great > detail. Is it easy and/or possible to predict the delay inherent in a > Remerez filter as it is for one designed by the windowing method? If > execution speed is not crucial, are there any other advantages in using > a FIR filter designed by the Remerez method compared to simply using a > FIR filter with a larger number of coefficients? > > Thanks in anticipation, > > Ross-cYou have the right idea. For post-processing filtering you can center the filter coefficients at t=0. Doing that will cause no time shift in the output for a *linear phase* i.e. symmetric filter. This requires that the filter be of odd length doesn't it? That is, to line up with the samples being processed. So, for L odd, the coefficients are re-registered in time from the typical: 0 to L-1 where there are L-1 intervals spanned - and with L odd, an equal number on either side of zero: -(L-1)/2 to +(L-1)/2. Whether you use a design program based on the Remez algorithm or some other method shouldn't matter much except filter transition widths and ripple. The length of the filter determines the compute load. I wouldn't compare Remez-generated filters with filters having "a larger number of coefficients" (presumably done using the windowing method??) because there are too many variables to consider. You could use a filter with "a larger number of coefficients" and still not get the performance you need. How you get there is less important than the result. Note: If you want to do the filtering in the frequency domain, then shift the odd-length filter circularly so the center is the zeroeth (or first) term in the array and have (L-1)/2 coefficients at the high end of the array, 1 + (L-1)/2 at the bottom of the array and any zero padding in between. Then the FFT will be purely real and even and the temporal registration of the IFFT of the result will match with the input as you desire. So a filter like this: [1 2 3 2 1 0 0 0 0 0 0 0 0 0 0 0] Would be circularly shifted: [3 2 1 0 0 0 0 0 0 0 0 0 0 0 1 2] before computing its FFT. Fred
Reply by ●February 15, 20062006-02-15
"Ross Clement (Email address invalid - do not use)" <clemenr@wmin.ac.uk> wrote in message news:1140018951.443983.50100@g47g2000cwa.googlegroups.com...> Thanks. Looking at the page: > > http://www-ccrma.stanford.edu/~jos/filters/Zero_Phase_Filters.html > > > Since I'm using very large FIR filters (up to thousands of > coefficients), the caveat that phase oscillates between 0 and pi in the > stopband is unlikely to cause me any trouble as the response in the > stopband will be, I assume, tiny. >Thousands of coefficients is pretty scary unless the sample rate is quite high also. ... there will be lots of temporal leakage and I don't think that's what you want for speech. Oscillating phase????? Maybe you mean that a long linear phase filter that has long delay and, thus, has a high phase slope and goes through 2pi frequently? Well, the delay is flat and that's all you should care about. If you make it zero delay then the phase is zero and the slope is zero and there is no "phase oscillation" of this sort. Fred
Reply by ●February 15, 20062006-02-15
Ross, determining the delay of a filter is equivalent to finding the "center" of its impulse response. For linear phase filters where the coefficients are the same on either side of the half length of the filter this has a pretty clear meaning. For an impulse response of any other shape, what could one consider to be the center? Since filters disperse each sample over time it doesn't have meaning in general to ask which output sample corresponds to the input sample. I suppose one could define it to be the time where the impulse response peaks (which can be between samples) but there is no real basis for such a definition. > Hence it looks sensible for me> to reinterpret the coefficients of my FIR filter so that when producing > an output sample y[i], that my coefficients are applied to samples at > times x[i-N/2] to x[i+N/2], and to assume that all samples before the > start of my original sample or after its end are zero. Hence I get a > filtered version of my original file without any time shift. Is this > correct?I'm not sure what you mean by re-interpret, but with that symmetry you are describing a linear phase filter. Any filter designed to have linear phase will have a constant group delay of half the filter length (for even length filters) which you can make zero for batch processing by shifting the output back in time by that amount. If you have the impulse response of a filter lacking this characteristic, there is a simple method for generating the linear phase filter which has the same magnitude response as the one you start with. You take the FFT of the filter, zero the phase at all frequencies and then take the inverse FFT. Finally you simply rotate the result of that by half its length. It may be necessasary to zero pad the original to twice its length first but I don't remember for sure. Bob -- "Things should be described as simply as possible, but no simpler." A. Einstein
Reply by ●February 15, 20062006-02-15
Thanks Bob. As a folllow-up question, could I use that FFT method to do the following? Imagine that I have a filter implementation, perhaps an IIR filter or even an analogue filter. I then calculate or measure the impulse response of the filter up to a "sufficient" length. I then take the FFT of that, zero the phases, and then inverse FFT and shift to get the coefficients of an FIR filter with approximately the same frequency response as the original IIR or analogue filter, but zero phase? I have no obvious application of this but am curious to know. Cheers, Ross-c






