Hello experts, I need to implement a multirate bandstop fir filter on the PC, but not in Matlab, for realtime processing. I already have a bandpass filter based on the classical design [1] and [2]. As stated in this article or by Rabiner/Crochiere, the group delay of a cosine modulated bandpass filter varies with the modulation frequency. As such, I can't directly use the bandstop design given in [1] and [2] because I need to compensate for the bandpass group delay and I don't have a formula for it. Could someone point me a reference for that formula, or to another multirate bandstop design? Sorry if I was not clear enough, my first post here. Regards, Romain [1] www.mds.com/tech/filter/multirate_article.pdf [2] Crochiere, Rabiner. Multirate digital signal processing, 1983

# Implementation of a multirate bandstop fir filter

Started by ●September 22, 2010

Reply by ●October 7, 20102010-10-07

Hi, In this 2005' thread http://www.dsprelated.com/showmessage/33089/3.php (summed up below), D. Kirkland began to give the solution I am looking for. Could someone tell me how to adjust the filter length so that the overall group delay is an integer number of samples? May be the solution is obvious (I know group delay is constant for FIR filters), but I have hard time finding it for modulated multirate FIR filters. Please ask for details if I am not clear/precise enough. Thank you in advance, Cheers Romain -- original thread A solution is to use a Multirate design. Essentially you would form a band pass version of the signal you are tryiing to filter out, and subtract it from the original signal. The steps would be: 1) Shift 50 Hz down to 0 Hz 2) Decimate - do this is steps if necessary 3) Final Filter to get the proper band edges you desire 4) Interpolate back to original sampling frequency 5) shift 0Hz back to 50 Hz 6) Subtract the resulting signal from the original. Of course you must take care to handle the group delays properly, and you want to design the filters so the overall group delay is an integer number of samples - so you can delay the original signal by an integer number. On 09/22/2010 08:14 PM, Romain Bossart wrote:> Hello experts, > > I need to implement a multirate bandstop fir filter on the PC, but not > in Matlab, for realtime processing. > > I already have a bandpass filter based on the classical design [1] and > [2]. As stated in this article or by Rabiner/Crochiere, the group delay > of a cosine modulated bandpass filter varies with the modulation > frequency. As such, I can't directly use the bandstop design given in > [1] and [2] because I need to compensate for the bandpass group delay > and I don't have a formula for it. > > Could someone point me a reference for that formula, or to another > multirate bandstop design? > > Sorry if I was not clear enough, my first post here. > > Regards, > Romain > > [1] www.mds.com/tech/filter/multirate_article.pdf > [2] Crochiere, Rabiner. Multirate digital signal processing, 1983 >

Reply by ●October 7, 20102010-10-07

On Oct 7, 2:05�pm, Romain Bossart <romain.bossart.nos...@free.fr.remove> wrote:> Hi, > > In this 2005' threadhttp://www.dsprelated.com/showmessage/33089/3.php(summed > up below), D. Kirkland began to give the solution I am looking for. Could > someone tell me how to adjust the filter length so that the overall group delay > is an integer number of samples? May be the solution is obvious (I know group > delay is constant for FIR filters), but I have hard time finding it for > modulated multirate FIR filters. > > Please ask for details if I am not clear/precise enough. > > Thank you in advance, > Cheers > > Romain > > -- original thread > > A solution is to use a Multirate design. Essentially you would form a > band pass version of the signal you are tryiing to filter out, and > subtract it from the original signal. The steps would be: > > 1) Shift 50 Hz down to 0 Hz > 2) Decimate - do this is steps if necessary > 3) Final Filter to get the proper band edges you desire > 4) Interpolate back to original sampling frequency > 5) shift 0Hz back to 50 Hz > 6) Subtract the resulting signal from the original. > > Of course you must take care to handle the group delays properly, and > you want to design the filters so the overall group delay is an integer > number of samples - so you can delay the original signal by an integer > number. > > On 09/22/2010 08:14 PM, Romain Bossart wrote: > > > > > Hello experts, > > > I need to implement a multirate bandstop fir filter on the PC, but not > > in Matlab, for realtime processing. > > > I already have a bandpass filter based on the classical design [1] and > > [2]. As stated in this article or by Rabiner/Crochiere, the group delay > > of a cosine modulated bandpass filter varies with the modulation > > frequency. As such, I can't directly use the bandstop design given in > > [1] and [2] because I need to compensate for the bandpass group delay > > and I don't have a formula for it. > > > Could someone point me a reference for that formula, or to another > > multirate bandstop design? > > > Sorry if I was not clear enough, my first post here. > > > Regards, > > Romain > > > [1]www.mds.com/tech/filter/multirate_article.pdf > > [2] Crochiere, Rabiner. Multirate digital signal processing, 1983- Hide quoted text - > > - Show quoted text -What is your original sample rate? Dirk

Reply by ●October 8, 20102010-10-08

On Oct 7, 2:05�pm, Romain Bossart <romain.bossart.nos...@free.fr.remove> wrote:> Hi, > > In this 2005' threadhttp://www.dsprelated.com/showmessage/33089/3.php(summed > up below), D. Kirkland began to give the solution I am looking for. Could > someone tell me how to adjust the filter length so that the overall group delay > is an integer number of samples? May be the solution is obvious (I know group > delay is constant for FIR filters), but I have hard time finding it for > modulated multirate FIR filters. > > Please ask for details if I am not clear/precise enough. > > Thank you in advance, > Cheers > > Romain > > -- original thread > > A solution is to use a Multirate design. Essentially you would form a > band pass version of the signal you are tryiing to filter out, and > subtract it from the original signal. The steps would be: > > 1) Shift 50 Hz down to 0 Hz > 2) Decimate - do this is steps if necessary > 3) Final Filter to get the proper band edges you desire > 4) Interpolate back to original sampling frequency > 5) shift 0Hz back to 50 Hz > 6) Subtract the resulting signal from the original. > > Of course you must take care to handle the group delays properly, and > you want to design the filters so the overall group delay is an integer > number of samples - so you can delay the original signal by an integer > number. > > On 09/22/2010 08:14 PM, Romain Bossart wrote: > > > > > Hello experts, > > > I need to implement a multirate bandstop fir filter on the PC, but not > > in Matlab, for realtime processing. > > > I already have a bandpass filter based on the classical design [1] and > > [2]. As stated in this article or by Rabiner/Crochiere, the group delay > > of a cosine modulated bandpass filter varies with the modulation > > frequency. As such, I can't directly use the bandstop design given in > > [1] and [2] because I need to compensate for the bandpass group delay > > and I don't have a formula for it. > > > Could someone point me a reference for that formula, or to another > > multirate bandstop design? > > > Sorry if I was not clear enough, my first post here. > > > Regards, > > Romain > > > [1]www.mds.com/tech/filter/multirate_article.pdf > > [2] Crochiere, Rabiner. Multirate digital signal processing, 1983- Hide quoted text - > > - Show quoted text -Test post.

Reply by ●October 8, 20102010-10-08

On Oct 7, 2:05�pm, Romain Bossart <romain.bossart.nos...@free.fr.remove> wrote:> Hi, > > In this 2005' threadhttp://www.dsprelated.com/showmessage/33089/3.php(summed > up below), D. Kirkland began to give the solution I am looking for. Could > someone tell me how to adjust the filter length so that the overall group delay > is an integer number of samples? May be the solution is obvious (I know group > delay is constant for FIR filters), but I have hard time finding it for > modulated multirate FIR filters. > > Please ask for details if I am not clear/precise enough. > > Thank you in advance, > Cheers > > Romain > > -- original thread > > A solution is to use a Multirate design. Essentially you would form a > band pass version of the signal you are tryiing to filter out, and > subtract it from the original signal. The steps would be: > > 1) Shift 50 Hz down to 0 Hz > 2) Decimate - do this is steps if necessary > 3) Final Filter to get the proper band edges you desire > 4) Interpolate back to original sampling frequency > 5) shift 0Hz back to 50 Hz > 6) Subtract the resulting signal from the original. > > Of course you must take care to handle the group delays properly, and > you want to design the filters so the overall group delay is an integer > number of samples - so you can delay the original signal by an integer > number. > > On 09/22/2010 08:14 PM, Romain Bossart wrote: > > > Hello experts, > > > I need to implement a multirate bandstop fir filter on the PC, but not > > in Matlab, for realtime processing. > > > I already have a bandpass filter based on the classical design [1] and > > [2]. As stated in this article or by Rabiner/Crochiere, the group delay > > of a cosine modulated bandpass filter varies with the modulation > > frequency. As such, I can't directly use the bandstop design given in > > [1] and [2] because I need to compensate for the bandpass group delay > > and I don't have a formula for it. > > > Could someone point me a reference for that formula, or to another > > multirate bandstop design? > > > Sorry if I was not clear enough, my first post here. > > > Regards, > > Romain >Since I wrote the post you are referring to, I'll try to answer you. I can't comment on the case for modulated filter banks. In my case, you essentially have to design the filter length (assuming symmetrical FIR filters) so that the group delay is a multiple of the following decimation factor. So if you are decimating by 5 the group delay has to be a multiple of 5 e.g. 5, 10 ,15 .... This would mean your filter length would be 11, 21, 31, ... An alternative is to insert zeros in front of the filter to adjust the group delay. So for example. the filter 1,2,1 has a group delay of 1 sample. The filter 0, 0, 1, 2, 1 has a group delay of 3 samples. When doing the interpolation you don't have to worry about the group delay as much - you still want it to be an integer i.e. use an odd length filter (symmetric FIR). Hope that helps. Cheers, David

Reply by ●October 8, 20102010-10-08

On Oct 7, 2:05 pm, Romain Bossart <romain.bossart.nos...@free.fr.remove> wrote:> Hi, > > In this 2005' threadhttp://www.dsprelated.com/showmessage/33089/3.php(summed > up below), D. Kirkland began to give the solution I am looking for. Could > someone tell me how to adjust the filter length so that the overall group delay > is an integer number of samples? May be the solution is obvious (I know group > delay is constant for FIR filters), but I have hard time finding it for > modulated multirate FIR filters. > > Please ask for details if I am not clear/precise enough. > > Thank you in advance, > Cheers > > Romain > > -- original thread > > A solution is to use a Multirate design. Essentially you would form a > band pass version of the signal you are tryiing to filter out, and > subtract it from the original signal. The steps would be: > > 1) Shift 50 Hz down to 0 Hz > 2) Decimate - do this is steps if necessary > 3) Final Filter to get the proper band edges you desire > 4) Interpolate back to original sampling frequency > 5) shift 0Hz back to 50 Hz > 6) Subtract the resulting signal from the original. > > Of course you must take care to handle the group delays properly, and > you want to design the filters so the overall group delay is an integer > number of samples - so you can delay the original signal by an integer > number. > > On 09/22/2010 08:14 PM, Romain Bossart wrote: > > > Hello experts, > > > I need to implement a multirate bandstop fir filter on the PC, but not > > in Matlab, for realtime processing. > > > I already have a bandpass filter based on the classical design [1] and > > [2]. As stated in this article or by Rabiner/Crochiere, the group delay > > of a cosine modulated bandpass filter varies with the modulation > > frequency. As such, I can't directly use the bandstop design given in > > [1] and [2] because I need to compensate for the bandpass group delay > > and I don't have a formula for it. > > > Could someone point me a reference for that formula, or to another > > multirate bandstop design? > > > Sorry if I was not clear enough, my first post here. > > > [1]www.mds.com/tech/filter/multirate_article.pdf > > [2] Crochiere, Rabiner. Multirate digital signal processing, 1983it appeared clear enough, but i guess wasn't paying attention. okay, if the bandpass filter you're sweeping is a simple biquad IIR: b0 + b1*z^-1 + b2*z^-2 H(z) = ------------------------ (Eq 1) a0 + a1*z^-1 + a2*z^-2 where BPF: H(s) = (s/Q) / (s^2 + s/Q + 1) (constant 0 dB peak gain) b0 = alpha b1 = 0 b2 = -alpha a0 = 1 + alpha a1 = -2*cos(w0) a2 = 1 - alpha where w0 = 2*pi*f0/Fs alpha = sin(w0)/(2*Q) i suppose that one can blast out what the group delay is and evaluate it at the resonant frequency w0. now what is it that you want to do with it? is it that you want a fractional delay filter that you can compensate for the changes in group delay when w0 is swepted? or would an all-pass filter to accomplish the same thing, but only at the resonant frequency, do? r b-j

Reply by ●October 8, 20102010-10-08

grumble grumble... :-| i took out the spurious word wrapping that google groups does (i wish you could turn it off: On Oct 8, 9:14�pm, robert bristow-johnson <r...@audioimagination.com> wrote: ...> > > � � � � � � b0 + b1*z^-1 + b2*z^-2 > � � H(z) = ------------------------ > � � � � � � a0 + a1*z^-1 + a2*z^-2 > > where > > BPF: � � � �H(s) = (s/Q) / (s^2 + s/Q + 1) > > � � � � � � b0 = � alpha > � � � � � � b1 = � 0 > � � � � � � b2 = �-alpha > � � � � � � a0 = � 1 + alpha > � � � � � � a1 = �-2*cos(w0) > � � � � � � a2 = � 1 - alpha > > where > > � � w0 = 2*pi*f0/Fs > > � � alpha = sin(w0)/(2*Q) >

Reply by ●October 9, 20102010-10-09

On 10/09/2010 03:14 AM, robert bristow-johnson wrote:> On Oct 7, 2:05 pm, Romain Bossart > <romain.bossart.nos...@free.fr.remove> wrote: >> Hi, >> >> In this 2005' threadhttp://www.dsprelated.com/showmessage/33089/3.php(summed >> up below), D. Kirkland began to give the solution I am looking for. Could >> someone tell me how to adjust the filter length so that the overall group delay >> is an integer number of samples? May be the solution is obvious (I know group >> delay is constant for FIR filters), but I have hard time finding it for >> modulated multirate FIR filters. >> >> Please ask for details if I am not clear/precise enough. >> >> Thank you in advance, >> Cheers >> >> Romain >> >> -- original thread >> >> A solution is to use a Multirate design. Essentially you would form a >> band pass version of the signal you are tryiing to filter out, and >> subtract it from the original signal. The steps would be: >> >> 1) Shift 50 Hz down to 0 Hz >> 2) Decimate - do this is steps if necessary >> 3) Final Filter to get the proper band edges you desire >> 4) Interpolate back to original sampling frequency >> 5) shift 0Hz back to 50 Hz >> 6) Subtract the resulting signal from the original. >> >> Of course you must take care to handle the group delays properly, and >> you want to design the filters so the overall group delay is an integer >> number of samples - so you can delay the original signal by an integer >> number. >> >> On 09/22/2010 08:14 PM, Romain Bossart wrote: >> >>> Hello experts, >> >>> I need to implement a multirate bandstop fir filter on the PC, but not >>> in Matlab, for realtime processing. >> >>> I already have a bandpass filter based on the classical design [1] and >>> [2]. As stated in this article or by Rabiner/Crochiere, the group delay >>> of a cosine modulated bandpass filter varies with the modulation >>> frequency. As such, I can't directly use the bandstop design given in >>> [1] and [2] because I need to compensate for the bandpass group delay >>> and I don't have a formula for it. >> >>> Could someone point me a reference for that formula, or to another >>> multirate bandstop design? >> >>> Sorry if I was not clear enough, my first post here. >> >>> [1]www.mds.com/tech/filter/multirate_article.pdf >>> [2] Crochiere, Rabiner. Multirate digital signal processing, 1983 > > it appeared clear enough, but i guess wasn't paying attention. > > okay, if the bandpass filter you're sweeping is a simple biquad IIR: > > > b0 + b1*z^-1 + b2*z^-2 > H(z) = ------------------------ > (Eq 1) > a0 + a1*z^-1 + a2*z^-2 > > > where > > BPF: H(s) = (s/Q) / (s^2 + s/Q + 1) (constant 0 dB peak > gain) > > b0 = alpha > b1 = 0 > b2 = -alpha > a0 = 1 + alpha > a1 = -2*cos(w0) > a2 = 1 - alpha > > where > > w0 = 2*pi*f0/Fs > > alpha = sin(w0)/(2*Q) > > i suppose that one can blast out what the group delay is and evaluate > it at the resonant frequency w0. now what is it that you want to do > with it? is it that you want a fractional delay filter that you can > compensate for the changes in group delay when w0 is swepted? or > would an all-pass filter to accomplish the same thing, but only at the > resonant frequency, do? > > r b-j > >Hi, Thank you all for your answers. Summary: the samplerate is above 2.8MHz, and I have to remove some frequency bands between 350Hz and 9000Hz. Detail: this is test data, that has to be processed in the time domain with a proprietary software. Unfortunately, this test data has been altered with various noise bands. I have to remove them so that the time signal fits the proprietary software requirements. So I am in a prototyping phase, just before the proprietary software, looking for the frequency bands I have to remove. The only thing I pretty confident about is that they are located between 350Hz and 9000Hz. My experiments with an iir notch filter or an elliptic bandstop filter show me that my requirements here are too high, and I probably need an multirate fir bandstop filter. From the quick tutorial referenced above (mds.com) I implemented a multirate cosine modulated bandpass filter, works great. My problem is that to have its bandstop companion, I have to know the delay of the modulated LP filter branch, which I don't. I was told section 6.2 in Crochiere Rabiner [1] tells all the truth of the subject, but I don't have the book. If someone could send me a scan of pp 267-270, it would be great. I've tried to dig into Vaidanathan's tutorial on the subject, but it is way too mathematical for me right now. Thanks again for your support. Romain

Reply by ●October 9, 20102010-10-09

On 10/09/2010 12:33 PM, Romain Bossart wrote:> On 10/09/2010 03:14 AM, robert bristow-johnson wrote: >> On Oct 7, 2:05 pm, Romain Bossart >> <romain.bossart.nos...@free.fr.remove> wrote: >>> Hi, >>> >>> In this 2005' >>> threadhttp://www.dsprelated.com/showmessage/33089/3.php(summed >>> up below), D. Kirkland began to give the solution I am looking for. >>> Could >>> someone tell me how to adjust the filter length so that the overall >>> group delay >>> is an integer number of samples? May be the solution is obvious (I >>> know group >>> delay is constant for FIR filters), but I have hard time finding it for >>> modulated multirate FIR filters. >>> >>> Please ask for details if I am not clear/precise enough. >>> >>> Thank you in advance, >>> Cheers >>> >>> Romain >>> >>> -- original thread >>> >>> A solution is to use a Multirate design. Essentially you would form a >>> band pass version of the signal you are tryiing to filter out, and >>> subtract it from the original signal. The steps would be: >>> >>> 1) Shift 50 Hz down to 0 Hz >>> 2) Decimate - do this is steps if necessary >>> 3) Final Filter to get the proper band edges you desire >>> 4) Interpolate back to original sampling frequency >>> 5) shift 0Hz back to 50 Hz >>> 6) Subtract the resulting signal from the original. >>> >>> Of course you must take care to handle the group delays properly, and >>> you want to design the filters so the overall group delay is an integer >>> number of samples - so you can delay the original signal by an integer >>> number. >>> >>> On 09/22/2010 08:14 PM, Romain Bossart wrote: >>> >>>> Hello experts, >>> >>>> I need to implement a multirate bandstop fir filter on the PC, but not >>>> in Matlab, for realtime processing. >>> >>>> I already have a bandpass filter based on the classical design [1] and >>>> [2]. As stated in this article or by Rabiner/Crochiere, the group delay >>>> of a cosine modulated bandpass filter varies with the modulation >>>> frequency. As such, I can't directly use the bandstop design given in >>>> [1] and [2] because I need to compensate for the bandpass group delay >>>> and I don't have a formula for it. >>> >>>> Could someone point me a reference for that formula, or to another >>>> multirate bandstop design? >>> >>>> Sorry if I was not clear enough, my first post here. >>> >>>> [1]www.mds.com/tech/filter/multirate_article.pdf >>>> [2] Crochiere, Rabiner. Multirate digital signal processing, 1983 >> >> it appeared clear enough, but i guess wasn't paying attention. >> >> okay, if the bandpass filter you're sweeping is a simple biquad IIR: >> >> >> b0 + b1*z^-1 + b2*z^-2 >> H(z) = ------------------------ >> (Eq 1) >> a0 + a1*z^-1 + a2*z^-2 >> >> >> where >> >> BPF: H(s) = (s/Q) / (s^2 + s/Q + 1) (constant 0 dB peak >> gain) >> >> b0 = alpha >> b1 = 0 >> b2 = -alpha >> a0 = 1 + alpha >> a1 = -2*cos(w0) >> a2 = 1 - alpha >> >> where >> >> w0 = 2*pi*f0/Fs >> >> alpha = sin(w0)/(2*Q) >> >> i suppose that one can blast out what the group delay is and evaluate >> it at the resonant frequency w0. now what is it that you want to do >> with it? is it that you want a fractional delay filter that you can >> compensate for the changes in group delay when w0 is swepted? or >> would an all-pass filter to accomplish the same thing, but only at the >> resonant frequency, do? >> >> r b-j >> >> > > > > Hi, > > Thank you all for your answers. > > Summary: the samplerate is above 2.8MHz, and I have to remove some > frequency bands between 350Hz and 9000Hz. > > Detail: this is test data, that has to be processed in the time domain > with a proprietary software. Unfortunately, this test data has been > altered with various noise bands. I have to remove them so that the time > signal fits the proprietary software requirements. So I am in a > prototyping phase, just before the proprietary software, looking for the > frequency bands I have to remove. The only thing I pretty confident > about is that they are located between 350Hz and 9000Hz. My experiments > with an iir notch filter or an elliptic bandstop filter show me that my > requirements here are too high, and I probably need an multirate fir > bandstop filter. > > From the quick tutorial referenced above (mds.com) I implemented a > multirate cosine modulated bandpass filter, works great. My problem is > that to have its bandstop companion, I have to know the delay of the > modulated LP filter branch, which I don't. I was told section 6.2 in > Crochiere Rabiner [1] tells all the truth of the subject, but I don't > have the book. If someone could send me a scan of pp 267-270, it would > be great. I've tried to dig into Vaidanathan's tutorial on the subject, > but it is way too mathematical for me right now. > > Thanks again for your support. > > RomainNote: Vaidayanathan's IEEE tutorial on the subject mainly aims at filter banks, which I'm not used to, and I don't think I need here.

Reply by ●October 9, 20102010-10-09

On Oct 9, 6:33�am, Romain Bossart <romain.bossart.nos...@free.fr.remove> wrote:> Thank you all for your answers.i'm still asking questions.> Summary: the samplerate is above 2.8MHz, and I have to remove some frequency > bands between 350Hz and 9000Hz.this is an exceedingly low frequency band (and low bandwidth) considering the sample rate you are using. you will need either (or both) an extremely long FIR filter and/or very long word widths for your coefficients (to get sufficient precision).> Detail: this is test data, that has to be processed in the time domain with a > proprietary software. Unfortunately, this test data has been altered with > various noise bands.these bands lie between 350 Hz and 9 kHz, right? can you just remove everything between 0.350 and 9.0 kHz?> I have to remove them so that the time signal fits the > proprietary software requirements. So I am in a prototyping phase, just before > the proprietary software, looking for the frequency bands I have to remove. The > only thing I pretty confident about is that they are located between 350Hz and > 9000Hz. My experiments with an iir notch filter or an elliptic bandstop filter > show me that my requirements here are too high, and I probably need an multirate > fir bandstop filter.what does a multirate FIR bandstop filter get you? does it make your notch filter any sharper in cutoff? or broader in covering the entire bandstop region? are you down-sampling to cover that low frequency band better? now, in your reformulation, you said nothing about time-varying specifications (as was in the original posting). if what you're doing is focusing a bandstop filter on a particular section of frequency, then the issue is still one of filtering. essentially the linear, time-invariant (LTI) system. if this data is not to be filtered in real time, i think you can use a very long FIR filter to do whatever you think you have to do. now, if your problem is that you want (whether you down-sample or not) to use a time-varying linear filter to bandpass filter the noise, and you have to compensate for the time-varying group delay as a consequence (sounds like you're intending to subtract this noise from the original after you up sample the filtered noise), then that's a different issue. i sorta understand why you might want to approach it that way (9 kHz is very small compared to 2.8 MHz), but i still think that a simple and long FIR is the way to do it. how do you plan to control your time-varying notch or bandpass filter? how do you determine what resonant frequency to set it to? r b-j