DSPRelated.com
Forums

about deciding the order of the fir filter,,

Started by rashmi venugopal January 13, 2011
main intention is to
1) cancel the side lobes
2) to measure the THD
 now i need to develop a fir filter, now i have to decide the order of the
filter which can efficiently cancel the side lobes,

now how to decide the order of the filter


>main intention is to >1) cancel the side lobes >2) to measure the THD > now i need to develop a fir filter, now i have to decide the order of
the
>filter which can efficiently cancel the side lobes, > >now how to decide the order of the filter
The question is not very clear. What sidelobes are you trying to cancel?? Typically a filter is designed with specs like ap, as, fp, fs and Fs (passband ripple, stop band attn, pass band freq, stop band freq and sampling freq). Regards Bharat
On Jan 13, 2:44�pm, "rashmi venugopal"
<rashu32003@n_o_s_p_a_m.gmail.com> wrote:
> main intention is to > 1) cancel the side lobes > 2) to measure the THD > &#4294967295;now i need to develop a fir filter, now i have to decide the order of the > filter which can efficiently cancel the side lobes, > > now how to decide the order of the filter
If sidelobes is your main concern, you might want to have a look at what window functions to use. Or use something like the Parks-McClellan algorithm when designing your filter. Rune
On 01/13/2011 05:44 AM, rashmi venugopal wrote:
> main intention is to > 1) cancel the side lobes > 2) to measure the THD > now i need to develop a fir filter, now i have to decide the order of the > filter which can efficiently cancel the side lobes, > > now how to decide the order of the filter
My, that tree has very interesting bark! Perhaps you should pull the camera back a little bit, and tell us about the forest. Specifically, I gather that you're designing a system to measure THD, and you want a filter to go into it -- yes? So there's three areas that you can look into: One, perhaps you can have all sorts of huge sidelobes to your filter as long as you don't have any sidelobes that fall where you expect your harmonic distortion to be; two, perhaps a FIR filter isn't what you really want, and three, perhaps a traditional "filter", in the sense of a linear shift-invariant system hanging onto your signal, isn't the best method to achieve what you're trying to achieve? If you're doing the measurement with a traditional sine wave stimulus, then filtering out the fundamental and looking for the residual energy, I'd be awfully tempted to either make a digital equivalent of a lock-on amplifier and subtract the fundamental out, or I'd consider a good narrow notch filter. If speed were important I'd consider either a notch filter that would let me change widths to speed up settling or I'd go ahead and make a Kalman filter for the task (which should be easy as Kalman filters go, since everything is so well defined and the filter would only be 2nd order). -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
On Jan 13, 10:21&#4294967295;am, Rune Allnor <all...@tele.ntnu.no> wrote:
> On Jan 13, 2:44&#4294967295;pm, "rashmi venugopal" > > <rashu32003@n_o_s_p_a_m.gmail.com> wrote: > > main intention is to > > 1) cancel the side lobes > > 2) to measure the THD > > &#4294967295;now i need to develop a fir filter, now i have to decide the order of the > > filter which can efficiently cancel the side lobes, > > > now how to decide the order of the filter > > If sidelobes is your main concern, you might want to > have a look at what window functions to use. > > Or use something like the Parks-McClellan algorithm > when designing your filter.
this is what i have for the number of FIR taps for the P-McC: (watch out for word wrapping) if exist('SR') ~= 1, SR = 96; % sampling rate end; if exist('PB') ~= 1, PB = 20; % top of passband region (where filter should be flat and 0 dB) end; if exist('PBR') ~= 1, PBR = 0.01; % max passband ripple in dB which is twice the max error in passband end; if exist('SB') ~= 1, SB = 22; % bottom of stopband region (where filter should be flat and -inf dB) end; if exist('SBG') ~= 1, SBG = -140; % max stop band gain in dB end; % Number of required FIR taps, from a formula in Oppenhiem & Schafer p. 480 % the more complicated and accurate MATLAB function remlpord() could be used instead. % for nicety, we always round up to the nearest odd number of FIR taps. % when N is odd, the delay (N-1)/2 is always an integer number of samples N = 2*round( (-0.342416*log10(10^(0.025*PBR)-1) - 0.0171208*SBG - 0.4451408)/((SB-PB)/SR) ) + 1 there's some formula with an alpha or a beta in it for guessing at N when using a Kaiser window. someone else can look that up. it looks like, given two fixed ripples in the stop and pass bands, the length of the FIR is inversely proportional to the width of the transition band which sounds about right. honestly, i dunno where the numbers come from anymore. r b-j
On Jan 13, 5:09&#4294967295;pm, robert bristow-johnson <r...@audioimagination.com>
wrote:

for P-Mc:

> N = 2*round( (-0.342416*log10(10^(0.025*PBR)-1) - 0.0171208*SBG - > 0.4451408)/((SB-PB)/SR) ) + 1 > > there's some formula with an alpha or a beta in it for guessing at N > when using a Kaiser window.
i found this for the same design for the windowed sinc LPF: h = (((PB + SB)/SR)*sinc(t)) .* kaiser(N, 0.1102*(-SBG-8.7))'; for whatever reason, the FIR number N is the same as with the P-McC. i think the second argument in the kaiser() function is the so-called "beta" parameter. r b-j
On Jan 13, 5:39&#4294967295;pm, robert bristow-johnson <r...@audioimagination.com>
wrote:
> On Jan 13, 5:09&#4294967295;pm, robert bristow-johnson <r...@audioimagination.com> > wrote: > > for P-Mc: > > > N = 2*round( (-0.342416*log10(10^(0.025*PBR)-1) - 0.0171208*SBG - > > 0.4451408)/((SB-PB)/SR) ) + 1 > > > there's some formula with an alpha or a beta in it for guessing at N > > when using a Kaiser window. > > i found this for the same design for the windowed sinc LPF: >
whoops, forgot something. t = linspace(-((PB+SB)/SR)*(N-1)/2, ((PB+SB)/SR)*(N-1)/2, N);
> h = (((PB+SB)/SR)*sinc(t)) .* kaiser(N, 0.1102*(-SBG-8.7))'; > > for whatever reason, the FIR number N is the same as with the P-McC. > i think the second argument in the kaiser() function is the so-called > "beta" parameter. > > r b-j
I probably get it wrong by a factor of 2 now and then but here's how I 
think about it:

Let's design a filter using the windowing method.
Let's start with a rectangular window.
This means that we convolve the Desired Frequency Response with a sinc 
that corresponds to the rectangular window length.
I note that the rectangular window isn't *great* as a window in the 
windowing method BUT the rectangular window has the narrowest main lobe 
in the corresponding FT - the sinc above.

So, when we convolve with *that* particular sinc, brick wall transitions 
end up about as wide as the main lobe of the sinc.
The width of the main lobe is a direct function of the length of the 
filter and about 2X the distance between zeros in the sinc as the main 
lobe takes two of those intervals.  The intervals are 1/NT where NT is 
the length of the filter.  So the transition regions can't be less than 
2/NT.

So if you take the narrowest transition region of width W in Hz, 
multiply it by 2 and compute the inverse, you should get the length of 
the filter in seconds.  Then, divide by the filter sample interval to get N.

It's true that this says nothing about sidelobe levels but it's also 
true that the narrowest transition band is the strongest driver in 
determining length.  And, in fact, windowing does little to change the 
narrowest transition band width.  Small changes in the main lobe of the 
sinc-like function (transform of the window) make mighty changes in the 
sidelobe character.

Length in seconds ~ 2/BW  where BW is the narrowest transition band 
width in Hz.
Length in samples N ~ (2/BW)/T where T is the sample interval in seconds.
Length in seconds: NT ~ 2/BW

But, usually I just use 1/BW and thus, BW=1/NT for a quick answer.  The 
difference is in how one chooses to define or measure BW.
After all, design is so quick and easy one can simply iterate and find 
out what N has to be!

Fred
On Jan 13, 10:41&#4294967295;pm, Fred Marshall <fmarshall_xremove_the...@xacm.org>
wrote:
> I probably get it wrong by a factor of 2 now and then but here's how I > think about it: > > Let's design a filter using the windowing method. > Let's start with a rectangular window. > This means that we convolve the Desired Frequency Response with a sinc > that corresponds to the rectangular window length. > I note that the rectangular window isn't *great* as a window in the > windowing method BUT the rectangular window has the narrowest main lobe > in the corresponding FT - the sinc above. > > So, when we convolve with *that* particular sinc, brick wall transitions > end up about as wide as the main lobe of the sinc. > The width of the main lobe is a direct function of the length of the > filter and about 2X the distance between zeros in the sinc as the main > lobe takes two of those intervals. &#4294967295;The intervals are 1/NT where NT is > the length of the filter. &#4294967295;So the transition regions can't be less than > 2/NT.
yes, this explains why the number of FIR taps must be inversely proportional to the width of the transition band of the LPF. those other terms in that equation having to do with the magnitude of ripples in the passband and stopband, that is harder for me to figger out why. and the funny constants that go with them is not clear to me. without the rounding: (N-1)/2 = (-0.342416*log10(10^(PBR/40)-1) - 0.0171208*SBG - 0.4451408)/ ((SB-PB)/SR) PBR and SBG are in dB. if i convert them to the more natural Nepers, it's (N-1)/2 = (-0.14870938*ln(e^(PBR/2)-1) - 0.14870938*SBG - 0.4451408)/ ((SB-PB)/SR) ((SB-PB)/SR) is the normalized transition band width. now that it's in "natural units", where do the numbers 0.14870938 and 0.4451408 come from? it must be from a heuristic or from some optimized fit. it looks like there's about a factor of 3 relating the two. even if we scale it by 2*pi (so that the transition band is measure in the natural units of the DTFT) we get numbers like 0.93436859 and 2.796902134. so i really don't know where the special constants come from. the only thing that makes natural sense is that the normalized ((SB-PB)/SR) is in the denominator. r b-j
On Jan 13, 10:09&#4294967295;pm, robert bristow-johnson
<r...@audioimagination.com> wrote:
> On Jan 13, 10:21&#4294967295;am, Rune Allnor <all...@tele.ntnu.no> wrote: > > > > > On Jan 13, 2:44&#4294967295;pm, "rashmi venugopal" > > > <rashu32003@n_o_s_p_a_m.gmail.com> wrote: > > > main intention is to > > > 1) cancel the side lobes > > > 2) to measure the THD > > > &#4294967295;now i need to develop a fir filter, now i have to decide the order of the > > > filter which can efficiently cancel the side lobes, > > > > now how to decide the order of the filter > > > If sidelobes is your main concern, you might want to > > have a look at what window functions to use. > > > Or use something like the Parks-McClellan algorithm > > when designing your filter. > > this is what i have for the number of FIR taps for the P-McC: > > (watch out for word wrapping) > > if exist('SR') ~= 1, > &#4294967295; &#4294967295; &#4294967295; &#4294967295; SR = 96; &#4294967295; &#4294967295; &#4294967295; &#4294967295;% sampling rate > end; > > if exist('PB') ~= 1, > &#4294967295; &#4294967295; &#4294967295; &#4294967295; PB = 20; &#4294967295; &#4294967295; &#4294967295; &#4294967295;% top of passband region (where filter should be flat and 0 > dB) > end; > > if exist('PBR') ~= 1, > &#4294967295; &#4294967295; &#4294967295; &#4294967295; PBR = 0.01; &#4294967295; &#4294967295; % max passband ripple in dB which is twice the max error > in passband > end; > > if exist('SB') ~= 1, > &#4294967295; &#4294967295; &#4294967295; &#4294967295; SB = 22; &#4294967295; &#4294967295; &#4294967295; &#4294967295;% bottom of stopband region (where filter should be flat and > -inf dB) > end; > > if exist('SBG') ~= 1, > &#4294967295; &#4294967295; &#4294967295; &#4294967295; SBG = -140; &#4294967295; &#4294967295; % max stop band gain in dB > end; > > % Number of required FIR taps, from a formula in Oppenhiem & Schafer > p. 480 > % &#4294967295; the more complicated and accurate MATLAB function remlpord() could > be used instead. > % for nicety, we always round up to the nearest odd number of FIR > taps. > % &#4294967295; when N is odd, the delay (N-1)/2 is always an integer number of > samples > > N = 2*round( (-0.342416*log10(10^(0.025*PBR)-1) - 0.0171208*SBG - > 0.4451408)/((SB-PB)/SR) ) + 1 > > there's some formula with an alpha or a beta in it for guessing at N > when using a Kaiser window. &#4294967295;someone else can look that up. &#4294967295;it looks > like, given two fixed ripples in the stop and pass bands, the length > of the FIR is inversely proportional to the width of the transition > band which sounds about right. &#4294967295;honestly, i dunno where the numbers > come from anymore. > > r b-j
Kaiser's empirical formula for estimating the order of a filter: DeltaF =(FilterSpec.StopBand - FilterSpec.PassBand) / FilterSpec.FilterRate; NoOfFilterCoefficients = 2 * (int) (FilterSpec.Attenuation - 8) / (29 * DeltaF) + 1; Chris --- Chris Bore BORES Signal Processing www.bores.com