# Properly applying BandstopFilter

In the documentation about BandstopFilter it says that the cutoff-frequencies w1 and w2 in BandstopFilter[data,{w1,w2}] should be values between 0 and Pi. I am certain that this is helpful information for someone more knowledgeable than me, but I cannot figure out how to apply it to my specific problem.

I have time-series data acquired at fixed sampling rate (1 kHz) of a certain duration (let's say 20.000 data points). The data is contaminated with 50Hz line noise. How do I properly set up w1and w2, as a function of the sampling rate and the length of the data, to properly reduce the 50Hz contamination?

Incidentally, it would be nice to have an appropriate example in the documentation.

-

You'd need to convert your analog frequencies to digital. Using the relation $\frac{F_s}{2 \pi} = \frac{f_1}{\omega_1}$ where $F_s$ is the sampling frequency in Hz, $f_1$ is one of your cutoff frequencies in Hz, and solve for $\omega_1$ which comes out to be

$$\omega_1=2\pi \frac{f_1}{F_s}$$

So, in your case, lets use $f_1=49$ hz and $f_2=51$ hz for example (you can try different band, larger or narrower, then

{w1, w2} = 2 Pi #/1000 & /@ {49, 51}


So now you can do

 BandstopFilter[data,{w1,w2}]


See if this works. I never tried this function myself.

Edit

For completeness, one can also use

{w1,w2} = 2 Pi {49,51};
BandstopFilter[data,{w1,w2},SampleRate->1000]


But, as already noted in my comment below, for my particular data, this had basically no noticeable effect on the data. Increasing the window size helped for me:

windowsize=1000; (* or at least something larger than 500 *)

{w1,w2} = 2 Pi {49,51};
BandstopFilter[data,{w1,w2},windowsize,SampleRate->1000]


or

{w1,w2} = 2/1000 Pi {49,51};
BandstopFilter[data,{w1,w2},windowsize]

-
Thank you @Nasser, after some playing around this worked. It turns out that the automatically chosen window width was too small to have an effect. What I ended up using was BandstopFilter[data,{w1,w2},1000], with the values for w1 and w2 as suggested by you. – Thomas Feb 10 '14 at 12:08