From 92b9deaf8d7c2a96c3977e1204341d6b6feb1fc1 Mon Sep 17 00:00:00 2001 From: Franz Zotter Date: Wed, 14 Jan 2009 10:58:32 +0000 Subject: renamed [mtx_sh] to [mtx_spherical_harmonics]. svn path=/trunk/externals/iem/iemmatrix/; revision=10549 --- .../sharmonics_normalization.c | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/mtx_spherical_harmonics/sharmonics_normalization.c (limited to 'src/mtx_spherical_harmonics/sharmonics_normalization.c') diff --git a/src/mtx_spherical_harmonics/sharmonics_normalization.c b/src/mtx_spherical_harmonics/sharmonics_normalization.c new file mode 100644 index 0000000..ca97292 --- /dev/null +++ b/src/mtx_spherical_harmonics/sharmonics_normalization.c @@ -0,0 +1,60 @@ +/* + * Recursive computation of (arbitrary degree) normalization constants + * for spherical harmonics, according to Gumerov and Duraiswami, + * "The Fast Multipole Methods for the Helmholtz Equation in Three Dimensions", + * Elsevier, 2005. + * + * Implementation by Franz Zotter, Institute of Electronic Music and Acoustics + * (IEM), University of Music and Dramatic Arts (KUG), Graz, Austria + * http://iem.at/Members/zotter, 2007. + * + * This code is published under the Gnu General Public License, see + * "LICENSE.txt" + */ + +#include "mtx_spherical_harmonics/sharmonics_normalization.h" + +SHNorml *sharmonics_normalization_new (const size_t nmax) { + SHNorml *wn; + int n,n0,m; + const double oneoversqrt2 = 1.0/sqrt(2); + + // memory allocation + if ((wn=(SHNorml*)calloc(1,sizeof(SHNorml)))!=0) { + wn->nmax=nmax; + if ((wn->n=(double*)calloc((nmax+1)*(nmax+2)/2,sizeof(double)))==0) { + free(wn); + wn=0; + } + else { + // computing N_n^m for m=0, wrongly normalized + wn->n[0]=sqrt(1/(2*M_PI)); + for (n=1,n0=1; n<=nmax; n++) { + wn->n[n0]=wn->n[0] * sqrt(2*n+1); + n0+=n+1; + } + // computing N_n^m for 0n[n0+m]= - wn->n[n0+m-1] / sqrt((n+m)*(n-m+1)); + } + n0+=n+1; + } + // correcting normalization of N_n^0 + for (n=0,n0=0; n<=nmax; n++) { + wn->n[n0]*=oneoversqrt2; + n0+=n+1; + } + } + } + return wn; +} + +void sharmonics_normalization_free(SHNorml *wn) { + if (wn!=0) { + free(wn->n); + free(wn); + } +} + + -- cgit v1.2.1