help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Circular convolution


From: John Smith
Subject: Re: Circular convolution
Date: Sun, 31 Oct 1999 09:33:46 +0000 (GMT)

Is this a circular convolution routine?

function a = circ_convolve( b, c )
  
  nb = length(b) ;
  nc = length(c) ;

  ##
  ## Ensure the two vectors are the same length
  ##
  if (nb < nc)
    b = [ b zeros(1,nc-nb) ] ;
  endif

  if (nc < nb)
    c = [ c zeros(1,nb-nc) ] ;
  endif

  a = ifft(fft(b) .* fft(c)) ;

  ##
  ## Get rid of any tiny imaginary bits that should be zero
  ##
  if (all(b == real(b)) && all(c == real(c)))
    a = real(a) ;
  endif

endfunction

with simple example

octave:21> circ_convolve( [ 1 2 3 4 ], [ 0 0 0 0 1 0 0 ] )
ans =

 Columns 1 through 5:

    4.0000e+00   -2.2839e-15    2.7914e-15    4.4409e-16    1.0000e+00

 Columns 6 and 7:

    2.0000e+00    3.0000e+00

octave:22> 



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]