fastmath.transform

Transforms.

See transformer and TransformProto for details.

Wavelet

Based on JWave library.

Be aware that some of the wavelet types doesn’t work properly. :battle-23, :cdf-53, :cdf-97.

Cos/Sin/Hadamard

Orthogonal or standard fast sine/cosine/hadamard 1d transforms.

Fourier

DFT.

compress

(compress trans xs mag)(compress xs mag)

Compress transformed signal xs with given magnitude mag.

Examples

Compress 1d - explicite usage

(let [t (transformer :fast :symlet-5)]
  (seq (reverse-1d t (compress (forward-1d t [1 2 3 4]) 0.3))))
;;=> (1.4193190842687744
;;=>  1.5520720330586624
;;=>  3.0147763185070553
;;=>  4.013832564167568)

Compress 1d - implicit usage

(let [t (transformer :fast :symlet-5)] (seq (compress t [1 2 3 4] 0.3)))
;;=> (1.4193190842687744
;;=>  1.5520720330586624
;;=>  3.0147763185070553
;;=>  4.013832564167568)

Compress 2d - explicit usage

(let [t (transformer :fast :symlet-5)]
  (m/double-double-array->seq
   (reverse-2d t (compress (forward-2d t [[1 2] [3 4]]) 0.5))))
;;=> ((1.4999999999976417 1.5000000000047216)
;;=>  (3.499999999992923 3.5000000000094422))

Compress 2d - implicit usage

(let [t (transformer :fast :symlet-5)]
  (m/double-double-array->seq (compress t [[1 2] [3 4]] 0.5)))
;;=> ((1.4999999999976417 1.5000000000047216)
;;=>  (3.499999999992923 3.5000000000094422))

denoise

(denoise xs soft?)(denoise trans xs soft?)(denoise xs)

Adaptive denoising of time series (1d).

Use on transformed sequences or call with transformer object.

SMILE implementation of WaveletShrinkage denoise function.

Examples

Denoise signal - implicit usage

(let [t (transformer :packet :haar)]
  (v/approx (seq (denoise t [1 2 3 4 5 6.5 7.5 8] true))))
;;=> (1.76 2.0 3.0 3.24 6.01 6.25 7.25 7.49)

Denoise signal - explicit usage

(let [t (transformer :packet :haar)]
  (v/approx
   (vec (reverse-1d t
                    (denoise (forward-1d t [1 2 3 4 5 6.5 7.5 8])
                             true)))))
;;=> [1.76 2.0 3.0 3.24 6.01 6.25 7.25 7.49]

forward-1d

(forward-1d t xs)

Forward transform of sequence or array.

Examples

Usage

(seq (forward-1d (transformer :packet :haar-orthogonal) [-1 8 7 6]))
;;=> (20.0 -6.0 -8.0 -10.0)
(seq (forward-1d (transformer :fast :haar-orthogonal) [-1 8 7 6]))
;;=> (20.0 -6.0 -9.0 1.0)
(seq (forward-1d (transformer :decomposed-fast :haar-orthogonal)
                 [10 -1 8 7 6]))
;;=> (24.0 -6.0 11.0 1.0 6.0)
(seq (forward-1d (transformer :orthogonal :sine) [0 -1 8 7]))
;;=> (0.0 8.65685424949238 -5.65685424949238 -2.6568542494923815)
(seq (forward-1d (transformer :standard :hadamard) [-1 8 7 6]))
;;=> (20.0 -8.0 -6.0 -10.0)
(seq (forward-1d (transformer :standard :dft) [-1 8 7 6]))
;;=> (3.0 7.0 -3.9999999999999996 0.9999999999999996)

forward-2d

(forward-2d t xss)

Forward transform of sequence or array.

Examples

Usage

(m/double-double-array->seq
 (forward-2d (transformer :packet :daubechies-6) [[-1 8] [7 6]]))
;;=> ((9.999999999999998 -3.9999999999999987)
;;=>  (-3.000000000000001 -4.999999999999999))
(m/double-double-array->seq
 (forward-2d (transformer :fast :daubechies-6) [[-1 8] [7 6]]))
;;=> ((9.999999999999998 -3.9999999999999987)
;;=>  (-3.000000000000001 -4.999999999999999))

reverse-1d

(reverse-1d t xs)

Forward transform of sequence or array.

Examples

Usage

(let [t (transformer :packet :haar-orthogonal)]
  (seq (reverse-1d t (forward-1d t [-1 8 7 6]))))
;;=> (-1.0 8.0 7.0 6.0)
(let [t (transformer :fast :haar-orthogonal)]
  (seq (reverse-1d t (forward-1d t [-1 8 7 6]))))
;;=> (-1.0 8.0 7.0 6.0)
(let [t (transformer :decomposed-fast :haar-orthogonal)]
  (seq (reverse-1d t (forward-1d t [10 -1 8 7 6]))))
;;=> (10.0 -1.0 8.0 7.0 6.0)
(let [t (transformer :orthogonal :sine)]
  (seq (reverse-1d t (forward-1d t [0 8 7 6]))))
;;=> (0.0 8.0 7.000000000000002 6.0)
(let [t (transformer :standard :hadamard)]
  (seq (reverse-1d t (forward-1d t [-1 8 7 6]))))
;;=> (-1.0 8.0 7.0 6.0)
(let [t (transformer :standard :dft)]
  (seq (reverse-1d t (forward-1d t [-1 8 7 6]))))
;;=> (-0.9999999999999996 8.0 7.0 6.0)

reverse-2d

(reverse-2d t xss)

Forward transform of sequence or array.

Examples

Usage

(let [t (transformer :packet :daubechies-20)]
  (m/double-double-array->seq
   (reverse-2d t (forward-2d t [[-1 8] [7 6]]))))
;;=> ((-0.9999999999999988 7.9999999999999964)
;;=>  (6.999999999999999 5.999999999999997))
(let [t (transformer :fast :daubechies-20)]
  (m/double-double-array->seq
   (reverse-2d t (forward-2d t [[-1 8] [7 6]]))))
;;=> ((-0.9999999999999988 7.9999999999999964)
;;=>  (6.999999999999999 5.999999999999997))

transformer

multimethod

Create transform object for given wavelet.

Wavelets

  • :fast for 1d or 2d Fast Wavelet Transform. Size of data should be power of 2.
  • :packet for 1d or 2d Wavelet Packet Transform. Size of data should be power of 2.
  • :decomposed-fast for 1d Fast Wavelet Transform. Data can have any size (Ancient Egyptian Decomposition is used).
  • :decomposed-packet for 1d Wavelet Packet Transform. Data can have any size (Ancient Egyptian Decomposition is used).

Second argument is wavelet name as key. See wavelets-list for all supported names.

Sine/Cosine/Hadamard

  • :standard for 1d :sine, :cosine, :hadamard.
  • :orthogonal for 1d :sine, :cosine.

Note that :sine and :cosine require first element to be equal 0. Size of data should be power of 2.

Fourier

  • :standard :dft - 1d Discrete Fourier Transform - returns double-array where even elements are real part, odd elements are imaginary part.

Examples

Usage

(transformer :packet :discrete-mayer)
;;=> jwave.transforms.WaveletPacketTransform@2f2da33a

wavelets-list

List of all possible wavelets.

Examples

List of wavelets

(sort wavelets-list)
;;=> (:battle-23
;;=>  :biorthogonal-11 :biorthogonal-13
;;=>  :biorthogonal-15 :biorthogonal-22
;;=>  :biorthogonal-24 :biorthogonal-26
;;=>  :biorthogonal-28 :biorthogonal-31
;;=>  :biorthogonal-33 :biorthogonal-35
;;=>  :biorthogonal-37 :biorthogonal-39
;;=>  :biorthogonal-44 :biorthogonal-55
;;=>  :biorthogonal-68 :cdf-53
;;=>  :cdf-97 :coiflet-1
;;=>  :coiflet-2 :coiflet-3
;;=>  :coiflet-4 :coiflet-5
;;=>  :daubechies-10 :daubechies-11
;;=>  :daubechies-12 :daubechies-13
;;=>  :daubechies-14 :daubechies-15
;;=>  :daubechies-16 :daubechies-17
;;=>  :daubechies-18 :daubechies-19
;;=>  :daubechies-2 :daubechies-20
;;=>  :daubechies-3 :daubechies-4
;;=>  :daubechies-5 :daubechies-6
;;=>  :daubechies-7 :daubechies-8
;;=>  :daubechies-9 :discrete-mayer
;;=>  :haar :haar-orthogonal
;;=>  :legendre-1 :legendre-2
;;=>  :legendre-3 :symlet-10
;;=>  :symlet-11 :symlet-12
;;=>  :symlet-13 :symlet-14
;;=>  :symlet-15 :symlet-16
;;=>  :symlet-17 :symlet-18
;;=>  :symlet-19 :symlet-2
;;=>  :symlet-20 :symlet-3
;;=>  :symlet-4 :symlet-5
;;=>  :symlet-6 :symlet-7
;;=>  :symlet-8 :symlet-9)