DSPRelated.com
Forums

frequency respons of halfband filter?

Started by alex65111 April 15, 2009
On Wed, 15 Apr 2009 16:31:24 -0500, "alex65111" <alex65111@list.ru>
wrote:

>Let the halfband filter is defined > >H=[0.033402 0 -0.015082 0 0.018968 0 -0.024143 0 0.031336 0 -0.042322 0 >0.061361 0 -0.10468 0 0.31784 0.5 0.31784 0 -0.10468 0 0.061361 0 -0.042322 >0 0.031336 0 -0.024143 0 0.018968 0 -0.015082 0 0.033402]; > >According to property of the halfband filter it has suppression on 1/4 >sampling frequency 6dB. > >Fx=fft(H,1024); >plot(20*log10(abs(Fx))) > >Let's calculate the frequency response > >s1=[zeros(1,128) 1 zeros(1,128)]; >s_f=filter(H,1,s1); >s_f=s_f(1:2:end); >figure, plot(20*log10(abs(fft(s_f)))) > >On figure it is clearly visible, that on half of new sampling of frequency >instead of 3dB suppression actually it is more than 15dB suppression. > > >Why at calculation of the frequency response instead of expected 3dB >actually it appears much more? > >If to generate a signal on frequency of 1/4 sampling frequencies, to pass >it through the halfband filter and then to decimate > >t=0:1023; >s=sin(2*pi*0.24999*t)+0.1*randn(1,length(t)); > >s_f1=filter(H,1,s); >s_f1=s_f1(1:2:end); >figure, plot(20*log10(abs(fft(s_f1)))) > >that will be visible, that suppression of this frequency will be not such >what should be according to the frequency response. >Why?
Alex, On 4/18/09 you sent your question to my personal E-mail. You caught me when I had some spare time and was in a good mood. I answered your E-mail on 4/19/ 09 with a detailed explanation why you're seeing what you're seeing, and why that "s_f1=s_f1(1:2:end);" command is wildly inappropriate. I even sent you some MATLAB code. I ended my E-mail with a request that you reply to my E-mail. I have not heard back from you. [-Rick-]
alex65111 wrote:

> > The calculated characteristic should show what suppression on > frequency > 0.5 (after decimation)?
First, let's define what you mean by 0.5. Usually this means fs/2 where the delay between coefficients is 1/fs. A half-band filter response looks like this: 1.0 from zero and approaching fs/4 depending on the transition width. 0.5 exactly at fs/4 0 from near fs/4 to 3fs/4 depending on the transition width. 0.5 exactly at 3fs/4 1.0 from just above 3fs/4 to fs depending on the transition width. Now, a half-band filter always has an odd number of coefficients. If there are an odd number of coefficients then there is no sample at fs/2. All this means is that if you take the fft of the coefficients, there's no value aligned at fs/2. But, if you pad the coefficients before taking the fft then you'll see an interpolated version of the frequency response and get an idea of what would happen if you pass a continuous sinusoid through the filter at any frequency below fs/2. And, you will notice that the magnitude of the samples straddling fs/2 are equal in magnitude. I believe it's correct that the real parts will be equal and the imaginary parts will be equal but opposite in sign for those two samples. Thus, the imaginary part goes through zero at fs/2. OK - enough of physics. Now for the specific question about the magnitude at fs/2: Since it's in the stopband it will be somewhere between the maximum stopband ripple and zero. If it's a minimax filter then generally a peak of the stopband occurs at fs/2 - so it's the peak stopband ripple value I do believe. Fred
On Apr 21, 1:57&#4294967295;pm, "Fred Marshall" <fmarshallx@remove_the_x.acm.org>
wrote:
> alex65111 wrote: > > > The calculated characteristic should show what suppression on > > frequency > > 0.5 (after decimation)? > > First, let's define what you mean by 0.5. &#4294967295;Usually this means fs/2 where the > delay between coefficients is 1/fs. > > A half-band filter response looks like this: > > 1.0 from zero and approaching fs/4 depending on the transition width. > 0.5 exactly at fs/4 > 0 from near fs/4 to 3fs/4 depending on the transition width. > 0.5 exactly at 3fs/4 > 1.0 from just above 3fs/4 to fs depending on the transition width. > > Now, a half-band filter always has an odd number of coefficients. &#4294967295;If there > are an odd number of coefficients then there is no sample at fs/2. &#4294967295;All this > means is that if you take the fft of the coefficients, there's no value > aligned at fs/2. > > But, if you pad the coefficients before taking the fft then you'll see an > interpolated version of the frequency response and get an idea of what would > happen if you pass a continuous sinusoid through the filter at any frequency > below fs/2. > > And, you will notice that the magnitude of the samples straddling fs/2 are > equal in magnitude. &#4294967295;I believe it's correct that the real parts will be > equal and the imaginary parts will be equal but opposite in sign for those > two samples. Thus, the imaginary part goes through zero at fs/2. > > OK - enough of physics. &#4294967295;Now for the specific question about the magnitude > at fs/2: > Since it's in the stopband it will be somewhere between the maximum stopband > ripple and zero. &#4294967295;If it's a minimax filter then generally a peak of the > stopband occurs at fs/2 - so it's the peak stopband ripple value I do > believe. > > Fred
If you shift the halfband filter to remove the delay and look at the frequency response (real and signed, linear scale) you find that the response is symmetric about the point at fs/4. So the ripple at fs/2 will be the same magnitude but opposite sign of the ripple at DC. Dirk
bellda2005@cox.net wrote:
> If you shift the halfband filter to remove the delay and look at the > frequency response (real and signed, linear scale) you find that the > response is symmetric about the point at fs/4. So the ripple at fs/2 > will be the same magnitude but opposite sign of the ripple at DC. > > Dirk
I agree but don't quite get the point.... And, this is only correct if you don't constrain the gain at DC to be exactly 1.0 - which can be done. If you shift the halfband filter unit sample response to be centered at zero delay it doesn't change the frequency magnitude response - except the function becomes purely real. The magnitude response in any case is symmetrical around zero and fs/2. I have seen cases where the purely real response flips sign at fs/2 relative to zero but don't recall the details. Probably an x4 case because of what I just said above. Fred
On Apr 22, 11:05&#4294967295;am, "Fred Marshall" <fmarshallx@remove_the_x.acm.org>
wrote:
> bellda2...@cox.net wrote: > > If you shift the halfband filter to remove the delay and look at the > > frequency response (real and signed, linear scale) you find that the > > response is symmetric about the point at fs/4. &#4294967295;So the ripple at fs/2 > > will be the same magnitude but opposite sign of the ripple at DC. > > > Dirk > > I agree but don't quite get the point.... > And, this is only correct if you don't constrain the gain at DC to be > exactly 1.0 - which can be done.
Fred, The ripples around the center of the ripples will still be the same for real and signed frequency response on a linear scale. The symmetry displayed this way around the point at fs/4 is not dependent on the filter scaling or what you set the center tap to. However, if you scale the filter and set the center tap to something other than half the distance between the two ripples' centers (like other than 0.5 for ripple center of gains 1 and 0), then the MAGNITUDE response will not be symmetric about the fs/4 point, because you will have more ripple in the stopband than is necessary (i.e. could be reduced at no cost, so why wouldn't you?). If the design was an equiripple design, setting the center tap in this way would make alternating stopband peaks have different magnitudes, the larger stopband peaks larger than they need to be. Just curious, why do want to constrain the gain at DC to be exactly 1.0? Dirk
> > If you shift the halfband filter unit sample response to be centered at zero > delay it doesn't change the frequency magnitude response - except the > function becomes purely real. &#4294967295;The magnitude response in any case is > symmetrical around zero and fs/2. > > I have seen cases where the purely real response flips sign at fs/2 relative > to zero but don't recall the details. &#4294967295;Probably an x4 case because of what I > just said above. > > Fred
On Apr 22, 3:20 pm, bellda2...@cox.net wrote:
> ... > > Just curious, why do want to constrain the gain at DC to be exactly > 1.0? > > Dirk > ...
In anti-aliasing filters that are going to be used in multiple passes of filter/desample it is desirable to use a reduced or zero ripple at DC design so that error doesn't accumulate with each application of the filter. That's why I've done it. Dale B. Dalrymple
On Apr 22, 10:53&#4294967295;pm, dbd <d...@ieee.org> wrote:
> On Apr 22, 3:20 pm, bellda2...@cox.net wrote: > > > ... > > > Just curious, why do want to constrain the gain at DC to be exactly > > 1.0? > > > Dirk > > ... > > In anti-aliasing filters that are going to be used in multiple passes > of filter/desample it is desirable to use a reduced or zero ripple at > DC design so that error doesn't accumulate with each application of > the filter. That's why I've done it. > > Dale B. Dalrymple
Hi Dale, I have used halfband filters for longer than I care to say; almost every 'permanent'/contract/consulting position I have ever had has had applications for them for rate changing or multi-rate applications. Making DC gain EXACTLY 1.0 is not a problem I have ever encountered in my designs, I am usually worried about the entire passband ripple and the corresponding stopband ripple. If you use the middle coefficient as 0.5 or 1.0 as is commonly mentioned in texts (it used to be important to save the multiply) you don't get exactly 1.0 at DC. For interpolation with a series of halfband filters if you want a gain of ~1.0 from each interpolating filter, the filters won't have a nominal passband gain of 1.0 (of course you could use a passband gain of ~1.0 and adjust the scaling elsewhere to get the desired end result). I was actually interested in Fred's response, since he brought it up; I thought he might have a different reason. Thanks for your input. Dirk
bellda2005@cox.net wrote:
> On Apr 22, 10:53 pm, dbd <d...@ieee.org> wrote: >> On Apr 22, 3:20 pm, bellda2...@cox.net wrote: >> >>> ... >> >>> Just curious, why do want to constrain the gain at DC to be exactly >>> 1.0?
....................................
> > I was actually interested in Fred's response, since he brought it up; > I thought he might have a different reason. > > Thanks for your input. > > Dirk
Oh, I didn't mean to suggest there was (or wasn't) a good reason for doing it, just that it could be done. If you do a minimax design and constrain the DC value to be 1.0 while the mid-point between the ripple peaks is also 1.0 then you use up one degree of freedom and the ripple magnitude is larger than it needs to be otherwise. In a typical halfband filter this also forces the response at fs/2 to be zero. One of my "things" is equality-constrained minimax design so I find things like this interesting. And, I had done exactly this for a while in my halfband design program. In general, the DC value (well all the band edges) will be a ripple peak. And, you can force that value to be 1.0 by scaling. Here's a trick I've used in minimax design to get all-positive stopband ripple leading up to Hermann-Schussler equiripple minimum phase FIR designs: Start with the stopband desired gain at zero. At the next iteration of the Remez algorithm, increase the desired stopband gain to be the same as the equalized error (which is not yet the peak ripple). The equalized error grows at each iteration so you continue to do this until you reach convergence. (The error peaks decrease with each iteration at the same time). When it's converged, the stopband value will be equal to the ripple peak magnitude and the negative going peaks will be zero-valued. [I've done this successfully and worked on a convergence proof but didn't quite finish it. It seems a useful extension to the Remez algorithm and could stand having that proof. Good grad student exercise I should think.] You could do the same in the passband but it's not quite as cool: Start with the passband desired value at 1.0. Then, in the next iteration, make the passband desired value equal to 1.0 minus (or plus) the equalized error. If the DC value is going to be at a positive peak then it will end up at 1.0. If the DC value is going to be at a negative peak then it will end up at 1.0 minus 2x the peak ripple. You could always run it twice: one with 1.0 minus... and one with 1.0 plus... Of course, all this does is scale the result but there's no loss of degrees of freedom. You might just as well divide all the coefficients by (1.0 + peak) after the filter is designed to get the DC value to be 1.0 AND not lose degrees of freedom. But then, the ripple is all one-sided and deviates 2x if a passband of 1.0 is what you wanted. You may well be better off losing one degree of freedom and having slightly larger peaks but not 2x peaks!! Fred
On Apr 23, 11:44&#4294967295;pm, "Fred Marshall" <fmarshallx@remove_the_x.acm.org>
wrote:
> bellda2...@cox.net wrote: > > On Apr 22, 10:53 pm, dbd <d...@ieee.org> wrote: > >> On Apr 22, 3:20 pm, bellda2...@cox.net wrote: > > >>> ... > > >>> Just curious, why do want to constrain the gain at DC to be exactly > >>> 1.0? > > .................................... > > > > > I was actually interested in Fred's response, since he brought it up; > > I thought he might have a different reason. > > > Thanks for your input. > > > Dirk > > Oh, I didn't mean to suggest there was (or wasn't) a good reason for doing > it, just that it could be done. &#4294967295;If you do a minimax design and constrain > the DC value to be 1.0 while the mid-point between the ripple peaks is also > 1.0 then you use up one degree of freedom and the ripple magnitude is larger > than it needs to be otherwise. > > In a typical halfband filter this also forces the response at fs/2 to be > zero. > > One of my "things" is equality-constrained minimax design so I find things > like this interesting. &#4294967295;And, I had done exactly this for a while in my > halfband design program. > > In general, the DC value (well all the band edges) will be a ripple peak. > And, you can force that value to be 1.0 by scaling. &#4294967295;Here's a trick I've > used in minimax design to get all-positive stopband ripple leading up to > Hermann-Schussler equiripple minimum phase FIR designs: > > Start with the stopband desired gain at zero. > At the next iteration of the Remez algorithm, increase the desired stopband > gain to be the same as the equalized error (which is not yet the peak > ripple). &#4294967295;The equalized error grows at each iteration so you continue to do > this until you reach convergence. &#4294967295;(The error peaks decrease with each > iteration at the same time). &#4294967295;When it's converged, the stopband value will > be equal to the ripple peak magnitude and the negative going peaks will be > zero-valued. > > [I've done this successfully and worked on a convergence proof but didn't > quite finish it. &#4294967295;It seems a useful extension to the Remez algorithm and > could stand having that proof. &#4294967295;Good grad student exercise I should think.] > > You could do the same in the passband but it's not quite as cool: > Start with the passband desired value at 1.0. > Then, in the next iteration, make the passband desired value equal to 1.0 > minus (or plus) the equalized error. > If the DC value is going to be at a positive peak then it will end up at > 1.0. > If the DC value is going to be at a negative peak then it will end up at 1.0 > minus 2x the peak ripple. > You could always run it twice: one with 1.0 minus... and one with 1.0 > plus... > Of course, all this does is scale the result but there's no loss of degrees > of freedom. &#4294967295;You might just as well divide all the coefficients by (1.0 + > peak) after the filter is designed to get the DC value to be 1.0 AND not > lose degrees of freedom. > But then, the ripple is all one-sided and deviates 2x if a passband of 1.0 > is what you wanted. &#4294967295;You may well be better off losing one degree of freedom > and having slightly larger peaks but not 2x peaks!! > > Fred
Interesting, Fred. Could you post the coefficients of an example filter? Thanks, Dirk
bellda2005@cox.net wrote:
> > Interesting, Fred. Could you post the coefficients of an example > filter? > > Thanks, > > Dirk
Dirk, Actually, it really does depend on which type so if you're a bit more specific then I could see if I still have the code that will generate it. The Hermann-Schussler work was done quite long ago. Do you mean a half-band with f(0)=1.0 ??? or something else? Fred