For details read Perl NOC. After June 25

John Lapeyre >
PDL-DSP-Iir >
PDL::DSP::Iir

PDL::DSP::Iir -- Infinite impulse response and recursive filters

This module provides recursive filters. Currently, only moving average filters are implemented. The moving average is actually a FIR, but it is implemented recursively as are IIR filters, so it is included here.

use PDL::LiteF; use PDL::DSP::Iir( 'moving_average' ); # apply three passes of a moving average with window size 2*5+1 = 11. $filtered_data = moving_average($data,5,3); # apply one pass of a moving average with window size 2*3+1 = 7. $filtered_data = moving_average($data,3); # call as method with window size 2 * $hw + 1 $y = $x->moving_average($hw);

The function `moving_average`

calls one of the lower level functions `mov_avg`

or `multi_pass_mov_avg`

, but they can be used directly as well.

moving_average($data, $half_width [, $n_passes ]);

Other terms for this kind of filter are: smoothing, sliding average, box smoothing, boxcar smoothing, boxcar filter, etc.

This function applies a moving average of ` $data `

with window of size `w = 2*$half_width+1`

. That is, the output value of point `i`

is the (uniformly weighted) average of the input points from `i - half_width`

through `i + half_width`

. The filter is repeated `$n_passes`

times if `$n_passes`

is supplied. This effectively applies a filter with a response that decreases with the distance from the point `i`

. The recursive algorithm is used, which can be much faster than the equivalent direct convolution with a rectangular window. The boundary at `data[0]`

is treated by using a window of size 1 at `data[0]`

, then of size 3 at `data[1]`

, and so on until the size reaches `w`

. The boundary at `datap[n-1]`

is treated in the same way. In this way, the response around each point is symmetric.

The accumulator for all fixed point types is of type `int`

, and for both floating point types is `double`

.

Signature: (x(n); double [o]y(n); int half_width)

Moving average with a single pass.

mov_avg ignores the bad-value flag of the input piddles. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

Signature: (x(n); double [o]y(n); double [t]ytemp(n); int half_width; int n_passes)

This is the same as `mov_avg`

, except that smoothing is repeated n_passes times. Note that storage `ytemp`

is created.

multi_pass_mov_avg ignores the bad-value flag of the input piddles. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

syntax highlighting: