S2kit  1.1
Toolkit for working with functions defined on the sphere
util.c
Go to the documentation of this file.
1 
6 #include "s2kit/util.h"
7 
8 #include <math.h>
9 #include <stdlib.h>
10 
23 void inline ComplexMult(const double x, const double y, const double u, const double v,
24  double* real_result, double* imag_result) {
25  *real_result = x * u - y * v;
26  *imag_result = x * v - y * u;
27 }
28 
42 int IndexOfHarmonicCoeff(const int m, const int l, const int bw) {
43  int bigL = bw - 1;
44 
45  if (m >= 0)
46  return (m * (bigL + 1) - ((m * (m - 1)) / 2) + (l - m));
47 
48  return (((bigL * (bigL + 3)) / 2) + 1 + ((bigL + m) * (bigL + m + 1) / 2) + (l - abs(m)));
49 }
50 
68 void TransMult(double* rdatacoeffs, double* idatacoeffs, double* rfiltercoeffs, double* ifiltercoeffs, double* rres,
69  double* ires, const int bw) {
70  double* rdptr = rdatacoeffs;
71  double* idptr = idatacoeffs;
72  double* rrptr = rres;
73  double* irptr = ires;
74 
75  for (int m = 0; m < bw; ++m) {
76  for (int l = m; l < bw; ++l) {
77  ComplexMult(rfiltercoeffs[l], ifiltercoeffs[l], rdptr[l - m], idptr[l - m], rrptr + l - m, irptr + l - m);
78 
79  rrptr[l - m] *= sqrt(4. * M_PI / (2. * l + 1.));
80  irptr[l - m] *= sqrt(4. * M_PI / (2. * l + 1.));
81  }
82  rdptr += bw - m;
83  idptr += bw - m;
84  rrptr += bw - m;
85  irptr += bw - m;
86  }
87 
88  int size = 2 * bw;
89  for (int m = bw + 1; m < size; ++m) {
90  for (int l = size - m; l < bw; ++l) {
91  ComplexMult(rfiltercoeffs[l], ifiltercoeffs[l], rdptr[l - size + m], idptr[l - size + m],
92  rrptr + l - size + m, irptr + l - size + m);
93 
94  rrptr[l - size + m] *= sqrt(4. * M_PI / (2. * l + 1.));
95  irptr[l - size + m] *= sqrt(4. * M_PI / (2. * l + 1.));
96  }
97 
98  rdptr += m - bw;
99  idptr += m - bw;
100  rrptr += m - bw;
101  irptr += m - bw;
102  }
103 }
TransMult
void TransMult(double *rdatacoeffs, double *idatacoeffs, double *rfiltercoeffs, double *ifiltercoeffs, double *rres, double *ires, const int bw)
Multiplies harmonic coefficients of a function and a filter.
Definition: util.c:68
IndexOfHarmonicCoeff
int IndexOfHarmonicCoeff(const int m, const int l, const int bw)
Gives the position of the coefficient f-hat(m,l) in the one-row array.
Definition: util.c:42
ComplexMult
void ComplexMult(const double x, const double y, const double u, const double v, double *real_result, double *imag_result)
Multiplies two complex numbers.
Definition: util.c:23
util.h