# FIR notch filters using the Windowing method

Started by April 13, 2005
```
jim wrote:
>
> Bob Cain wrote:
>
>>jim wrote:
>>
>>
>>>You were doing well up to now. Your filter is not differentiation
>>>regardless of a popular belief that it is. A simple yes to the question
>>>would have been a better answer.
>>
>>Care to elaborate?
>
>
> Not really but here goes. The correct answer to the question is it
> linear was yes. It's an FIR filter why wouldn't it be linear. Whether
> differentiation is linear or not is irrelevant.

Gee, thanks. That helped a whole lot.  IOW, never mind.

Bob
--

"Things should be described as simply as possible, but no
simpler."

A. Einstein
```
```
jim wrote:

>>
>> Jerry Avins wrote:
>>
>> I've long (a little longer than I've been hanging around here) taken
>> it for granted that in order to affect a frequency significantly, a
>> filter's significant impulse response needs to last in the order of
>> that frequencies reciprocal.
>>

Just to clarify. I think I know what Jerry is getting at in the above
maxim (something like - potential of a filter to discriminate between
frequencies). But the counter example given makes it clear this is not
the way to state it. The counter example is the shortest meaningful
filter possible yet the longer the wavelength fed to this filter the
greater it will be affected.

-jim

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
```
```jim wrote:
>
> jim wrote:
>
>
>>>Jerry Avins wrote:
>>>
>>>I've long (a little longer than I've been hanging around here) taken
>>>it for granted that in order to affect a frequency significantly, a
>>>filter's significant impulse response needs to last in the order of
>>>that frequencies reciprocal.
>>>
>
>
> Just to clarify. I think I know what Jerry is getting at in the above
> maxim (something like - potential of a filter to discriminate between
> frequencies). But the counter example given makes it clear this is not
> the way to state it. The counter example is the shortest meaningful
> filter possible yet the longer the wavelength fed to this filter the
> greater it will be affected.
>
> -jim

Your filter is indeed proof that my rule of thumb suffers from extreme
brachydactylia. In other words, it is way too short. While it is a
perfect counterexample to the short statement, ii is on the edge, not at
the heart, of what I had in mind. Its maximum slope is 6 dB/decade; the
gain of frequencies an octave apart differ by at most 2:1. Moreover, no
particular low frequency is singled out and its significant frequency,
the corner frequency below which the response drops, is near enough to
Fs to be "in the order of" the sampling rate itself. That's in keeping
with the spirit of my rule, even though it was stated too briefly.

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;
```
```
Jerry Avins wrote:

> Your filter is indeed proof that my rule of thumb suffers from extreme
> brachydactylia. In other words, it is way too short. While it is a
> perfect counterexample to the short statement, ii is on the edge, not at
> the heart, of what I had in mind.

Understood, Jerry.  That's why I put a smiley at the end.
Any "interesting" filter will likely obey your simple rule.

Bob
--

"Things should be described as simply as possible, but no
simpler."

A. Einstein
```
```On Wed, 13 Apr 2005 11:33:43 -0700, "Fred Marshall"
<fmarshallx@remove_the_x.acm.org> wrote:

>
>"Greer" <Greer.GRAY@oxinst.co.uk> wrote in message
>news:q5WdnZYwX6dsysDfRVn-sw@giganews.com...
>> Hi,
>>
>> I am trying to obtain a FIR notch filter which is very narrow. For
>> example, a 50 Hz notch filter to remove mains noise from a 1250Hz signal
>> say.
>>
> Many thanks,
> Greer

(snipped)

Hello Greer,

I just went through an analysis of narrowband notch FIR
filters and discovered that we can build a
computationally-efficient 3-tap narrowband FIR notch filter.

The FIR filter's coefficients are [1, b, 1].
The value for "b" is equal to:

b = -2cos(4*pi*Fnotch/Fs)

where Fnotch is the center freq of the filter's notch
in Hz, and Fs is the sample rate in Hz.

Good Luck,
[-Rick-]
You friendly neighborhood DSP junkie.

```
```Rick Lyons wrote:

...

>   I just went through an analysis of narrowband notch FIR
> filters and discovered that we can build a
> computationally-efficient 3-tap narrowband FIR notch filter.
>
> The FIR filter's coefficients are [1, b, 1].
> The value for "b" is equal to:
>
>    b = -2cos(4*pi*Fnotch/Fs)
>
> where Fnotch is the center freq of the filter's notch
> in Hz, and Fs is the sample rate in Hz.

WOW! Zowie! This I have to plot!

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;
```
```On Sat, 16 Apr 2005 23:21:38 -0400, Jerry Avins <jya@ieee.org> wrote:

>Rick Lyons wrote:
>
>   ...
>
>>   I just went through an analysis of narrowband notch FIR
>> filters and discovered that we can build a
>> computationally-efficient 3-tap narrowband FIR notch filter.
>>
>> The FIR filter's coefficients are [1, b, 1].
>> The value for "b" is equal to:
>>
>>    b = -2cos(4*pi*Fnotch/Fs)
>>
>> where Fnotch is the center freq of the filter's notch
>> in Hz, and Fs is the sample rate in Hz.
>
>WOW! Zowie! This I have to plot!
>

Ah ha.  This is good.  I'd be tickled if your
independent analysis gives the same results as mine.
That way I'd be more confident that
the above expression for "B" is correct.

See Ya' Jer,
[-Rick-]

```
```
Rick Lyons wrote:

> >
> >>   I just went through an analysis of narrowband notch FIR
> >> filters and discovered that we can build a
> >> computationally-efficient 3-tap narrowband FIR notch filter.
> >>
> >> The FIR filter's coefficients are [1, b, 1].
> >> The value for "b" is equal to:
> >>
> >>    b = -2cos(4*pi*Fnotch/Fs)
> >>
> >> where Fnotch is the center freq of the filter's notch
> >> in Hz, and Fs is the sample rate in Hz.
> >
> >WOW! Zowie! This I have to plot!
> >
>
> Ah ha.  This is good.  I'd be tickled if your
> independent analysis gives the same results as mine.
> That way I'd be more confident that
> the above expression for "B" is correct.

shouldn't it be:

b = -2cos(2*pi*Fnotch/Fs)

f    DC   fs/4   fs/2
b    -2     0      2

-jim

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
```
```On Sat, 16 Apr 2005 23:21:38 -0400, Jerry Avins <jya@ieee.org> wrote:

>Rick Lyons wrote:
>
>   ...
>
>>   I just went through an analysis of narrowband notch FIR
>> filters and discovered that we can build a
>> computationally-efficient 3-tap narrowband FIR notch filter.
>>
>> The FIR filter's coefficients are [1, b, 1].
>> The value for "b" is equal to:
>>
>>    b = -2cos(4*pi*Fnotch/Fs)
>>
>> where Fnotch is the center freq of the filter's notch
>> in Hz, and Fs is the sample rate in Hz.
>
>WOW! Zowie! This I have to plot!
>

OOoops!

Hey Jerry, I just realized: I gave you the wrong
form of the equation for coeff "b".
My incorrect form came from an AM demod
circuit I'm trying to understand.

In any case, the correct formula for "b" is:

b = -2cos(2*pi*Fnotch/Fs)

My original "4*pi* should be "2*pi".
Sheece!  Sorry 'bout that.

[-Rick-]

```
```On Sun, 17 Apr 2005 11:47:45 -0500, jim <"N0sp"@m.sjedging@mwt.net>
wrote:

>
>
>Rick Lyons wrote:
>
>> >
>> >>   I just went through an analysis of narrowband notch FIR
>> >> filters and discovered that we can build a
>> >> computationally-efficient 3-tap narrowband FIR notch filter.
>> >>
>> >> The FIR filter's coefficients are [1, b, 1].
>> >> The value for "b" is equal to:
>> >>
>> >>    b = -2cos(4*pi*Fnotch/Fs)
>> >>
>> >> where Fnotch is the center freq of the filter's notch
>> >> in Hz, and Fs is the sample rate in Hz.
>> >
>> >WOW! Zowie! This I have to plot!
>> >
>>
>> Ah ha.  This is good.  I'd be tickled if your
>> independent analysis gives the same results as mine.
>> That way I'd be more confident that
>> the above expression for "B" is correct.
>
>shouldn't it be:
>
> b = -2cos(2*pi*Fnotch/Fs)
>
>f    DC   fs/4   fs/2
>b    -2     0      2
>
>-jim

Hi Jim,

yep. you are correct.  You caught my error before
I did.  Good catch Jim!

Ya know what's interesting.  I tried to
derive the equation for the "b" coefficient
for an FM demod problem on which I was working.
I went through a z-transform derivation (brute-force
& clumsy) and ended up with an equation to compute the
"b" coefficient.  But my equation involved square roots
and tangent-squared stuff.  Messy, but it was correct.

Then a few days ago I ran into a equation on the
Internet (in the context of an AM demodulation discussion)
that also computed the "b" coefficient, but this
equation was the very simple cosine expression that
I originally posted.  I thought to myself, "Now how
did that guy come up with with such a clean simple expression
for the "b" coefficient.  Then it hit me.  We can
use the discrete-time Fourier transform (DTFT)
to arrive at the simpler "cosine" expression
for "b".  So in terms of the "Fnotch" frequency
I had an equation for coeff "b".  OK, neat.

Then this afternoon, I'm not joking, this afternoon
I'm diggin' through a DSP book for info on another
subject and I ran into the author's discussion of
"Here's a simple 3-tap FIR notch filter, and here's
how to compute the center "b"  filter coefficient"!!!

It seems that every time I discover something that
I think is mildly clever and "not so well-known", later
I see that it's already been described in some
clever guy's DSP book!!

See Ya',
[-Rick-]

```