From: Steve Dickey <sdickey@pop.slip.net>
Newsgroups: comp.sys.hp48
Subject: Re: Program to do convolution on HP
Date: Sun, 30 Aug 1998 19:30:43 -0700
Organization: Slip.Net (http://www.slip.net)
Lines: 100
Message-ID: <35EA0AD3.F47A5F40@pop.slip.net>
References: <6s36pj$68i$1@hermes.is.co.za>
Reply-To: steved@cory.eecs.berkeley.edu
NNTP-Posting-Host: sf-pm17-27-91.dialup.slip.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 4.04 [en] (X11; I; Linux 2.0.27 i586)
Xref: republic.btigate.com comp.sys.hp48:15267

vanniekerkg wrote:

> Hi
>
> I'm looking for a program to do discrete-time convolution on the HP.
>
> expl:
>
> x = [ 1 1 1 1 ];
>
> y= [ 1 1 1 1 ];
>
> conv(x,y) = [ 1 2 3 4 3 2 1]
>
> Thanx
> Gerrie
> vanniekerkgh@sabc.co.za

  Here is one way to do it. Note that this code is not written to be
either small or fast.
%%HP: T(3)A(R)F(.);

\<<
  @ first, create some subroutines
  \<<
    @ a2l  ( array -- list )
    @ this will convert an array to a list
    OBJ\-> OBJ\-> DROP \->LIST
  \>>

  \<<
    @ l2a ( list -- array )
    @ this will convert a list to an array
    OBJ\-> 1 \->LIST \->ARRY
  \>>

  \<<
    @ alength ( array -- n )
    @ returns the length of a vector
    SIZE OBJ\-> DROP
  \>>


  \<<
    @ pad ( n list -- list' )
    @ zero pad a list to length n
    DUP SIZE
    3 PICK SWAP -
    \-> l
    \<<
      l 1 SWAP FOR k 0 NEXT l \->LIST
    \>>
    + SWAP DROP
  \>>

  @ bind the subroutines
  \-> a2l l2a alength pad
  \<<
    @ calc length for finished array and
    @ put length of longer array on stack
    DUP2
    alength EVAL SWAP alength EVAL
    DUP2 + 1 -
    \-> length
    \<<
      MAX

      @ calc length to pad to
      LN 2 LN / 1 + CEIL 2 SWAP ^

      @ zero pad the arrays
      SWAP OVER SWAP a2l EVAL pad EVAL
      SWAP 3 ROLL
      a2l EVAL pad EVAL

      @ back to arrays
      l2a EVAL SWAP l2a EVAL

      @ calc the convolution
      FFT SWAP FFT
      a2l EVAL SWAP a2l EVAL
      *
      l2a EVAL
      IFFT

      @ trim to finished size
      a2l EVAL
      OBJ\->
      length - DROPN
      length \->LIST
      l2a EVAL
    \>>
  \>>
\>>

--
Steve


