Raku Land

Math::Libgsl::DigitalFiltering

cpan:FRITH

Actions Status Build Status

Impulse filter

NAME

Math::Libgsl::DigitalFiltering - An interface to libgsl, the Gnu Scientific Library - Digital Filtering

SYNOPSIS

use Math::Libgsl::Vector;
use Math::Libgsl::DigitalFiltering;

my constant $N = 1000;
my constant $K = 21;
my Math::Libgsl::Vector $x .= new: :size($N);
$x.scanf('data.dat');
my Math::Libgsl::DigitalFiltering::Gaussian $gauss .= new: :size($K);
my $y = $gauss.filter(2.5, $x);

DESCRIPTION

Math::Libgsl::DigitalFiltering is an interface to the Digital Filtering functions of libgsl, the Gnu Scientific Library.

This module exports four classes:

each encapsulates the methods and the buffers needed to create and use the filter on the data stored in a Math::Libgsl::Vector object.

Math::Libgsl::DigitalFiltering::Gaussian

This class encapsulate a Gaussian filter.

multi method new(Int $size!)

multi method new(Int :$size!)

The constructor accepts one simple or named argument: the kernel size.

filter(Num() $alpha!, Math::Libgsl::Vector $x!, Int :$order = 0, Int :$endtype = GSL_MOVSTAT_END_PADZERO, Bool :$inplace? --> Math::Libgsl::Vector)

This method applies a Gaussian filter parameterized by $alpha to the input vector $x. The optional named argument :$order specifies the derivative order, with 0 corresponding to a Gaussian, 1 corresponding to a first derivative Gaussian, and so on. The optional named argument :$endtype specifies how the signal end points are handled. The symbolic names for this argument are listed in the Math::Libgsl::Constants module as follows:

The boolean named argument :$inplace directs the method to apply the filter in-place. This method returns the filter output as a Math::Libgsl::Vector object.

kernel(Num() $alpha!, Int $size, Int :$order = 0, Int :$normalize = 0 --> Math::Libgsl::Vector)

This method constructs a Gaussian kernel parameterized by $alpha, of size $size. The optional named argument :$order specifies the derivative order. The optional named argument :$normalize specifies if the kernel is to be normalized to sum to one on output. This method returns the filter output as a Math::Libgsl::Vector object.

Math::Libgsl::DigitalFiltering::Median

This class encapsulate a Median filter.

multi method new(Int $size!)

multi method new(Int :$size!)

The constructor accepts one simple or named argument: the kernel size.

filter(Math::Libgsl::Vector $x!, Int :$endtype = GSL_MOVSTAT_END_PADZERO, Bool :$inplace? --> Math::Libgsl::Vector)

This method applies a Median filter to the input vector $x. The optional named argument :$endtype specifies how the signal end points are handled. The optional boolean named argument :$inplace directs the method to apply the filter in-place. This method returns the filter output as a Math::Libgsl::Vector object.

Math::Libgsl::DigitalFiltering::RMedian

This class encapsulate a recursive Median filter.

multi method new(Int $size!)

multi method new(Int :$size!)

The constructor accepts one simple or named argument: the kernel size.

filter(Math::Libgsl::Vector $x!, Int :$endtype = GSL_MOVSTAT_END_PADZERO, Bool :$inplace? --> Math::Libgsl::Vector)

This method applies a Median filter to the input vector $x. The optional named argument :$endtype specifies how the signal end points are handled. The optional boolean named argument :$inplace directs the method to apply the filter in-place. This method returns the filter output as a Math::Libgsl::Vector object.

Math::Libgsl::DigitalFiltering::Impulse

This class encapsulate an Impulse detection filter.

multi method new(Int $size!)

multi method new(Int :$size!)

The constructor accepts one simple or named argument: the kernel size.

filter(Math::Libgsl::Vector $x!, Num() $tuning, Int :$endtype = GSL_MOVSTAT_END_PADZERO, Int :$scaletype = GSL_FILTER_SCALE_MAD, Bool :$inplace? --> List)

This method applies an Impulse filter to the input vector $x, using the tuning parameter $tuning. The optional named argument :$endtype specifies how the signal end points are handled. The optional named argument :$scaletype specifies how the scale estimate Sₙ of the window is calculated. The symbolic names for this argument are listed in the Math::Libgsl::Constants module as follows:

The optional boolean named argument :$inplace directs the method to apply the filter in-place. This method returns a List of values:

C Library Documentation

For more details on libgsl see https://www.gnu.org/software/gsl/. The excellent C Library manual is available here https://www.gnu.org/software/gsl/doc/html/index.html, or here https://www.gnu.org/software/gsl/doc/latex/gsl-ref.pdf in PDF format.

Prerequisites

This module requires the libgsl library to be installed. Please follow the instructions below based on your platform:

Debian Linux and Ubuntu 20.04

sudo apt install libgsl23 libgsl-dev libgslcblas0

That command will install libgslcblas0 as well, since it's used by the GSL.

Ubuntu 18.04

libgsl23 and libgslcblas0 have a missing symbol on Ubuntu 18.04. I solved the issue installing the Debian Buster version of those three libraries:

Installation

To install it using zef (a module management tool):

$ zef install Math::Libgsl::DigitalFiltering

AUTHOR

Fernando Santagata nando.santagata@gmail.com

COPYRIGHT AND LICENSE

Copyright 2020 Fernando Santagata

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.