Try out NAG Library functions

Explore NAG maths and stats routines with interactive demos
Function ID
One-dimensional discrete wavelet transform
discrete transform | wavelets | wavelets, one-dimensional
This example computes the one-dimensional discrete wavelet decomposition for 8 values using the Daubechies wavelet, WAVNAM='DB4', with zero end extension.
The example data reflects that shown in the "Example" section of the routine documentation. You can change this here to try alternative inputs. The formatting will need to be kept as it is here, otherwise the program is likely to fail to run correctly.

Please note that incompatible data will however cause the example output to display an error message. These error messages are fully explained in the Routine document
    Program c09cafe

!     C09CAF Example Program Text

!     Mark 26 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: c09aaf, c09caf, c09cbf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: ifail, n, nf, nwc, nwl, ny
      Character (12)                   :: mode, wavnam, wtrans
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: ca(:), cd(:), x(:), y(:)
      Integer                          :: icomm(100)
!     .. Executable Statements ..
      Write (nout,*) 'C09CAF Example Program Results'
!     Skip heading in data file
      Read (nin,*)
!     Read problem parameters.
      Read (nin,*) n
      Read (nin,*) wavnam, mode
      Allocate (x(n),y(n))

      Write (nout,99999) wavnam, mode
!     Read array
      Read (nin,*) x(1:n)
      Write (nout,*) 'Input Data      X :'
      Write (nout,99997) x(1:n)
!     Query wavelet filter dimensions
      wtrans = 'Single Level'

!     ifail: behaviour on error exit
!            =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      Call c09aaf(wavnam,wtrans,mode,n,nwl,nf,nwc,icomm,ifail)

      Allocate (ca(nwc),cd(nwc))

      ifail = 0
      Call c09caf(n,x,nwc,ca,cd,icomm,ifail)

      Write (nout,99998)
      Write (nout,99997) ca(1:nwc)
      Write (nout,99996)
      Write (nout,99997) cd(1:nwc)

      ny = n

      ifail = 0
      Call c09cbf(nwc,ca,cd,ny,y,icomm,ifail)

      Write (nout,99995)
      Write (nout,99997) y(1:ny)

99999 Format (1X,'DWT :: Wavelet: ',A,', End mode: ',A)
99998 Format (1X,'Approximation coefficients CA : ')
99997 Format (1X,8(F8.4,1X),:)
99996 Format (1X,'Detail coefficients        CD : ')
99995 Format (1X,'Reconstruction              Y : ')
    End Program c09cafe
The NAG Library
The world’s largest collection of robust, documented, tested and maintained numerical algorithms.
Learn more here or contact us for purchasing information