1 ## Copyright (C) 2012 Nir Krakauer <nkrakauer@ccny.cuny.edu>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn{Function File} {@var{lambda} =} circulant_eig (@var{v})
18 ## @deftypefnx{Function File} {[@var{vs}, @var{lambda}] =} circulant_eig (@var{v})
20 ## Fast, compact calculation of eigenvalues and eigenvectors of a circulant matrix@*
21 ## Given an @var{n}*1 vector @var{v}, return the eigenvalues @var{lambda} and optionally eigenvectors @var{vs} of the @var{n}*@var{n} circulant matrix @var{C} that has @var{v} as its first column
23 ## Theoretically same as @code{eig(make_circulant_matrix(v))}, but many fewer computations; does not form @var{C} explicitly
25 ## Reference: Robert M. Gray, Toeplitz and Circulant Matrices: A Review, Now Publishers, http://ee.stanford.edu/~gray/toeplitz.pdf, Chapter 3
27 ## @seealso{circulant_make_matrix, circulant_matrix_vector_product, circulant_inv}
30 function [a, b] = circulant_eig (v)
32 ## FIXME when warning for broadcastin is turned off by default, this
33 ## unwind_protect block could be removed
35 ## we are using broadcasting on the code below so we turn off the
36 ## warnings but will restore to previous state at the end
37 bc_warn = warning ("query", "Octave:broadcast");
39 warning ("off", "Octave:broadcast");
45 lambda = sum(v .* exp(-2*pi*i*s'*s/n))';
52 #find the eigenvectors (which in fact do not depend on v)
53 a = exp(-2*i*pi*s'*s/n) / sqrt(n);
55 unwind_protect_cleanup
56 ## restore broadcats warning status
57 warning (bc_warn.state, "Octave:broadcast");
62 %!shared v,C,vs,lambda
64 %! C = circulant_make_matrix(v);
65 %! [vs lambda] = circulant_eig(v);
66 %!assert (vs*lambda, C*vs, 100*eps);