NAME
PDL::DSP::Fir - Finite impulse response filter kernels.
SYNOPSIS
use PDL;
use PDL::DSP::Fir qw( firwin );
# return a 10 sample lowpass filter kernel
# with a cutoff at 90% of the Nyquist frequency.
$kernel = firwin( N => 10, fc => 0.9 );
# Equivalent way of calling.
$kernel = firwin( { N => 10, fc => 0.9 } );
DESCRIPTION
This module provides routines to create one-dimensional finite impulse response (FIR) filter kernels. This distribution inlcudes a simple interface for filtering in PDL::DSP::Fir::Simple.
The routine "firwin" returns a filter kernel constructed from windowed sinc functions. Available filters are lowpass, highpass, bandpass, and bandreject. The window functions are in the module PDL::DSP::Windows.
Below, the word order refers to the number of elements in the filter kernel.
No functions are exported be default.
FUNCTIONS
firwin
Usage
$kern = firwin({OPTIONS});
$kern = firwin(OPTIONS);
Returns a filter kernel (a finite impulse response function) to be convolved with data.
The kernel is built from windowed sinc functions. With the option type => 'window'
no sinc is used, rather the kernel is just the window. The options may be passed as a list of key-value pairs, or as an anonymous hash.
OPTIONS
- N
-
order of filter. This is the number of elements in the returned kernel pdl.
- type
-
Filter type. One of
lowpass
,highpass
,bandpass
,bandstop
,window
. Aliases forbandstop
arebandreject
andnotch
. Default islowpass
. Forbandpass
andbandstop
the number of samples "N" must be odd. If type iswindow
, then the kernel returned is just the window function. - fc
-
Cutoff frequency for low- and highpass filters as a fraction of the Nyquist frequency. Must be a number between
0
and1
. No default value. - fclo, fchi
-
Lower and upper cutoff frequencies for bandpass and bandstop filters. No default values.
All other options to "firwin" are passed to the function "window" in PDL::DSP::Windows.
The following three functions are called by the firwin
, but may also be useful by themselves, for instance, to construct more complicated filters.
ir_sinc
$sinc = ir_sinc($f_cut, $N);
Return an $N
point sinc function representing a lowpass filter with cutoff frequency $f_cut
.
$f_cut
must be between 0 and 1, with 1 being Nyquist freq. The output pdl is the function sin( $f_cut * $x ) / $x
where $x is pdl of $N
uniformly spaced values ranging from - PI * ($N-1)/2
through PI * ($N-1)/2
. For what it's worth, a bit of efficiency is gained by computing the index at which $x
is zero, rather than searching for it.
spectral_inverse
$fir_inv = spectral_inverse($fir);
Return output kernel whose spectrum is the inverse of the spectrum of the input kernel.
The number of samples in the input kernel must be odd. Input $fir
and output $fir_inv
are real-space fir filter kernels. The spectrum of the output kernel is the additive inverse with respect to 1 of the spectrum of the input kernel.
spectral_reverse
$fir_rev = spectral_reverse($fir);
Return output kernel whose spectrum is the reverse of the spectrum of the input kernel.
That is, the spectrum is mirrored about the center frequency.
AUTHOR
John Lapeyre, <jlapeyre at cpan.org>
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2012 John Lapeyre.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.