# [ncl-talk] question regarding Butterworth filter

Daniel Barandiaran dbarandiaran at gmail.com
Tue Jun 16 12:38:19 MDT 2015

```Ok, I've done some more investigation and testing and here is what I found.

First off, like filtering methods in general, the Butterworth filter was
designed with electronic applications in mind, such as audio processing,
and so the processed end of the series being processed with this filter
attenuates to zero. In audio this is no big deal, but when looking at
something like a climate time series this can be a problem.

I talked with one of the professors in my department who knows quite a bit
about numerical methods, and he suggested padding the end of the series
with 1.5*(order of filter/fca) zeros.  I am attaching a figure with the
resulting filtered time series, with and without padding.

I tested this result with a variety of bandpass settings both narrow and
wide, low pass and high pass, and with length of the time series, and the
result is consistent. Without the zero padding, the signal attenuates to
zero, but with the padding the filtered data follows the raw data.

here is the relevant code for what I did:

fca   = 1./48.
fcb   = 1./1200.
order = 6

opt   = True
opt at m = order

;-----------------------

","r")
time  = fin->time
TIME  = cd_calendar(time,0)
tind  = ind(TIME(:,0).ge.minyr .and. TIME(:,0).le.maxyr)
ntind = dimsizes(tind)
t2m   = dim_avg_n(fin->air(tind,{minlat:maxlat},{minlon:maxlon}),(/1,2/))
do j  = 0,11
t2m(j::12) = dim_rmvmean_n(t2m(j::12),0)
end do

dum   = 0
dum(0:ntind-1)  = t2m
dumf  = bw_bandpass_filter(dum,fca,fcb,opt,0)

On Mon, Jun 15, 2015 at 5:43 PM, Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:

> Danny,
>
> The documentation for this filter says that it is optimized for narrow
> bandwidths.  The description goes on to mention certain shortcuts in its
> calculations.  Your settings describe a low pass filter with a very wide
> pass band, far to one end of the signals in your time series.  This is not
> what is meant by "narrow bandwidth".
>
> This is just speculation, but I think your settings may be breaking key
> assumptions within this filter's code implementation.  You may have chosen
> a filter function that is badly matched to your particular problem.
> Perhaps, look at some of the other available NCL functions.  HTH.
>
> --Dave
>
>
> On Mon, Jun 15, 2015 at 11:51 AM, Daniel Barandiaran <
> dbarandiaran at gmail.com> wrote:
>
>> Hi everyone,
>>
>> I was trying out the bw_bandpass_filter function and found some
>> unexpected results. The gist of the problem is that the end of the time
>> series being filtered approaches a smoothed zero, even if the time series
>> is doing something else entirely (see attached figure, consider bold blue
>> line and shaded blue area). I imagine this is due to the internal workings
>> of the filter itself, but regardless of that, does anyone have any ideas on
>> "fixing" this?
>>
>> Some details: I have fca set to 1/60., or 5 years, and fcb set
>> arbitrarily large, i.e. 1/100000., so the filter essentially behaves as low
>> pass. I am also making sure to not give the function any missing values.
>>
>> --
>> Danny Barandiaran
>> Ph.D. Candidate
>> Department of Plants, Soils, and Climate
>> Utah State University
>>
>

--
Danny Barandiaran
Ph.D. Candidate
Department of Plants, Soils, and Climate
Utah State University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150616/59e77e63/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Butterworth_test.png
Type: image/png
Size: 97159 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150616/59e77e63/attachment.png
```