- NAME
- VERSION
- SYNOPSIS
- SUBROUTINES/METHODS
- new(WAVELET,VAR)
- new(WAVELET)
- new()
- dwt(SIGNAL,LEVEL,LO-PASS,HI-PASS)
- dwt(SIGNAL,LEVEL)
- dwt(SIGNAL)
- idwt(COEFFICIENTS,LEVEL,LO-PASS,HI-PASS)
- idwt(COEFFICIENTS,LEVEL)
- idwt(COEFFICIENTS)
- cshift(ARRAY,SHIFT)
- afb(SIGNAL,LO-PASS,HI-PASS)
- sfb(LO-PART,HI-PART,LO-PASS,HI-PASS)
- upfirdn(A,B,UP,DN)
- set_filters(LO_D,HI_D,LO_R,HI_R)
- get_filters()

- SEE ALSO
- AUTHOR
- BUGS
- ACKNOWLEDGEMENTS
- LICENSE AND COPYRIGHT

# NAME

Math::DWT - Pure Perl 1-D Discrete Wavelet Transform.

# VERSION

Version 0.022

# SYNOPSIS

This module computes the forward and inverse Discrete Wavelet Transform using arbitrary wavelets defined in modules (many are included in the distribution).

```
use Math::DWT;
my $dwt = Math::DWT->new('Daubechies',1); # Haar
my @x = qw/8 6 7 5 3 0 9 0/; # zero-pad input to make it 2^n long
# perform a single transform with default loaded filters
my $coeffs = $dwt->dwt(\@x);
# $coeffs points to LEVEL+1 array refs
# Check perfect reconstruction:
my @X = $dwt->idwt($coeffs);
my $maxerr=0;
for(my $i=0;$i<scalar(@X);$i++) {
my $err=abs($x[$i] - $X[$i]);
$maxerr = $err if ($err > $maxerr);
}
print $maxerr . "\n"; # 5.27844434827784e-12 (close enough to 0)
```

# SUBROUTINES/METHODS

## new(WAVELET,VAR)

## new(WAVELET)

## new()

Create a new DWT object with the wavelet WAVELET and variable VAR. The wavelet is loaded from the module Math::DWT::Wavelet::WAVELET, so there will be an error if this module is not installed. If VAR is omitted, then VAR is set to whatever the default is as defined in the module (usually the lowest option). If WAVELET is left blank, then an empty object is returned with no filters defined. See the set_filters method to set custom filters (TODO).

## dwt(SIGNAL,LEVEL,LO-PASS,HI-PASS)

## dwt(SIGNAL,LEVEL)

## dwt(SIGNAL)

This performs the forward Discrete Wavelet Transform on SIGNAL using LO-PASS and HI-PASS as filters. The process is repeated LEVEL times. If LO-PASS and HI-PASS are omitted, then it uses defaults set in loaded wavelet. If LEVEL is omitted, then it sets LEVEL=1. SIGNAL is an array ref. The length of SIGNAL must be a power of 2, e.g. 256, 512, 1024, etc.

dwt returns an arrayref (or array, if called in array context) of arrayrefs, one for each set of detail coefficients, and an extra one for the last set of scaling coefficients. So for a 256-sample long input signal, processed to 4 levels, the return value of dwt would be an array/arrayref with 5 arrayrefs with sizes 128, 64, 32, 16, and 16, in that order.

```
@x=@x[0..255];
my $coeffs = $dwt->dwt(\@x,4);
foreach my $i (@$coeffs) { print scalar(@$i) . " "; }
# prints
# 128 64 32 16 16
```

## idwt(COEFFICIENTS,LEVEL,LO-PASS,HI-PASS)

## idwt(COEFFICIENTS,LEVEL)

## idwt(COEFFICIENTS)

Inverse Discrete Wavelet Transform. Same defaults setup as for dwt. COEFFICIENTS must be an array ref of the structure returned by dwt. Returns an array or arrayref (depending on the value of wantarray()) with the original signal, or at least the signal inversely processed LEVEL times.

## cshift(ARRAY,SHIFT)

Utility method that shifts the elements of ARRAY by SHIFT amount in a circular fashion (i.e. elements positioned past the end of the array are placed back at the beginning). Accepts negative values for SHIFT.

## afb(SIGNAL,LO-PASS,HI-PASS)

This is a utility method you shouldn't need to use. Stands for Analysis Filter Bank. This method convolves SIGNAL with LO-PASS and separately with HI-PASS, then downsamples each by 2, and returns arrayrefs of the results of the proper length (half the input length).

## sfb(LO-PART,HI-PART,LO-PASS,HI-PASS)

This is an internal utility method for reconstructing a signal from a set of wavelet coefficients and scaling coefficients and a pair of lo-pass and hi-pass reconstruction filters. It stands for Synthesis Filter Bank and it returns a single array or arrayref that is the result of upsampling the input by 2, then convolving each set of coefficients with its respective filter, and, finally, adding up corresponding lo-pass/hi-pass values.

## upfirdn(A,B,UP,DN)

This is an internal utility method modeled after MATLAB's upfirdn command. First, it upsamples signal A by the value of UP (use 1 to disable), then convolves A and B, then downsamples the result by a factor of DN (again, use 1 to disable). The result is an array or arrayref with length defined by: (((length(A)-1)*UP+length(B))/DN)

## set_filters(LO_D,HI_D,LO_R,HI_R)

Set the filters manually. Each of LO_D, HI_D, LO_R, and HI_R is an arrayref to the set of coefficients for the respective filter set. Returns undef.

## get_filters()

Get the set of filters. Returns an array or an arrayref containing LO_D, HI_D, LO_R, HI_R in that order.

# SEE ALSO

Math::DWT::UDWT(3pm), Math::DWT::Wavelet::Haar(3pm), Math::DWT::Wavelet::Coiflet(3pm), Math::DWT::Wavelet::Symlet(3pm), Math::DWT::Wavelet::Biorthogonal(3pm), Math::DWT::Wavelet::ReverseBiorthogonal(3pm), Math::DWT::Wavelet::Daubechies(3pm), Math::DWT::Wavelet::DiscreteMeyer(3pm), perl(1)

# AUTHOR

Mike Kroh, `<kroh at cpan.org>`

# BUGS

Please report any bugs or feature requests to `bug-math-dwt at rt.cpan.org`

, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-DWT. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

# ACKNOWLEDGEMENTS

Special thanks to Ivan Selesnick for his software (on which these modules are based) available here http://eeweb.poly.edu/iselesni/software/index.html.

Some wavelet filter coefficients scraped from this site: http://wavelets.pybytes.com/.

# LICENSE AND COPYRIGHT

Copyright 2016 Mike Kroh.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.