Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase conventions for spherical harmonics #81

Open
mberz opened this issue Dec 20, 2024 · 0 comments
Open

Phase conventions for spherical harmonics #81

mberz opened this issue Dec 20, 2024 · 0 comments

Comments

@mberz
Copy link
Member

mberz commented Dec 20, 2024

After checking for consistency, the current implementation of spharpy supports the following phase conventions for real and complex valued spherical harmonics:

Complex-valued including the Condon-Shortley phase

same as in B. Rafaely, Fundamentals of Spherical Array Processing, 2015

import spharpy
import numpy as np

n_max = 3
sampling = spharpy.samplings.equal_area(0, n_points=700)
Y_nm = spharpy.spherical.spherical_harmonic_basis(n_max, sampling)

image

Real-valued without Condon-Shortley phase

which is the same as the implementation in F. Zotter and M. Frank, Ambisonics, 2019, 10.1007/978-3-030-17207-7

import spharpy
import numpy as np

n_max = 3
sampling = spharpy.samplings.equal_area(0, n_points=700)
Y_nm = spharpy.spherical.spherical_harmonic_basis_real(n_max, sampling)

image

Currently not implemented

Real-valued including the Condon-Shortley Phase

import spharpy
import numpy as np
from scipy.special import sph_harm

def sph_harm_real(m, n, theta, phi):
    """With Condon-Shortley phase convention"""
    # careful here, scipy uses phi as the elevation angle and
    # theta as the azimuth angle
    Y_nm_cplx = sph_harm(np.abs(m), n, theta, phi)

    if m >= 0:
        Y_nm = np.real(Y_nm_cplx)
        if m != 0:
            Y_nm *= np.sqrt(2)
    else:
        Y_nm = np.imag(Y_nm_cplx)

    return Y_nm

n_max = 3
sampling = spharpy.samplings.equal_area(0, n_points=700)
Y_nm = np.zeros((sampling.cshape[0], (n_max+1)**2), dtype=complex)
for acn in np.arange((n_max+1)**2):
    n, m = spharpy.spherical.acn2nm(acn)
    Y_nm[:, acn] = sph_harm_real(m, n, sampling.azimuth, sampling.colatitude)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant