Advanced maths

Real spherical harmonic expansion calculator from weighted samples

Fit a real spherical-harmonic expansion to weighted directional samples and reconstruct their values.

Your numbers

Separate rows with new lines and columns with commas.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Fit a real spherical-harmonic expansion to weighted directional samples and reconstruct their values. The basis convention,angular coordinates and full-rank requirement are explicit.

THE FORMULAmin_c Σ_i w_i(Σ_(l,m)c_lm Y_lm(θ_i,φ_i)−y_i)²;real orthonormal Y_lm with Condon–Shortley phase.

A worked example

The five prefilled directional observations all have value1. A degree-one fit has coefficient c00=√(4π)≈3.544907702 and all degree-one coefficients zero,with zero residual up to roundoff.

Good to know

Degree0–4,at least(L+1)²and at most200 rows. Polar θ0–180degrees,azimuth within±360degrees,positive finite weights. Full-rank weighted QR required. Real orthonormal basis includes Condon–Shortley phase. No regularization,missing-data inference or angular quadrature guarantee from arbitrary samples.

Two angles describe a direction rather than a location

The first coordinate is the polar angle from the positive z-axis,and the second is the azimuth around that axis. Both are entered in degrees. A radius is absent because spherical harmonics describe angular variation on a sphere.

Polar angle is not geographic latitude:latitude zero lies at the equator,while polar angle zero is the north pole. Confusing those conventions changes the design matrix even if the input rows still look like plausible angular pairs.

A constant directional field needs only its normalized constant modeConstant observations:y=1Y00=1/√(4π)c00=√(4π)All nonconstant coefficients vanish
Scroll across to see the full diagram.
The five prefilled directional observations all have value1. A degree-one fit has coefficient c00=√(4π)≈3.544907702 and all degree-one coefficients zero,with zero residual up to roundoff.

Compare this with the Nonuniform Fourier transform calculator from irregular sample times. A temporal nonuniform Fourier transform does not use spherical angular basis functions.

Degree sets the number of fitted coefficients

Including all real harmonics through degree L introduces(L+1)² coefficients. The calculator therefore requires at least that many samples,and it also checks whether their actual directional arrangement gives a numerically full-rank weighted design.

Sample count alone does not guarantee identification. Many repeated or poorly distributed directions can leave some modes indistinguishable. The solver rejects an unresolved rank deficiency rather than filling unconstrained coefficients with an invented regularized answer.

The real basis includes a stated phase convention

Associated Legendre functions include the Condon–Shortley sign. Positive and negative orders use cosine and sine angular factors under the displayed real orthonormal convention. Another real-harmonic library may order or sign these components differently.

Such presentation differences do not necessarily imply a different reconstructed field. Compare both the mode labels and the basis definition before comparing raw coefficient arrays. The page reports degree and order beside every fitted coefficient to preserve that information.

Weighted least squares is not automatic sphere integration

The weights multiply squared sample residuals in a least-squares objective. They can express deliberate fitting priorities,but arbitrary positive weights do not turn an irregular set of directions into an exact spherical quadrature rule.

The implementation scales design rows and responses by square roots of weights and uses QR least squares. No normal-equation inverse is silently regularized,and the stated residual belongs to this discrete weighted objective rather than an integral over all directions.

The constant-field default checks normalization

Every default observation equals one at its entered direction. The normalized constant harmonic is1 divided by the square root of4π,so its coefficient must be the square root of4π to reconstruct that field.

All nonconstant degree-one coefficients should vanish to roundoff in the full-rank example. This verifies the constant normalization and separates a true constant mode from an accidental fit produced by a rank-deficient arrangement or a different basis scaling.

A small residual does not prove global reconstruction quality

The weighted residual measures agreement only at the supplied sample directions. A richer expansion can fit those samples closely while behaving differently between them,especially if observations cluster or leave a large unsampled region.

There is no uncertainty band,penalty or held-out validation hidden in the output. Choose degree with the data and application in mind,and inspect directional coverage rather than treating a small training residual as a complete accuracy certificate.

Retain coefficient conventions when exporting the fit

Store degree,order,phase convention and angular units together with the coefficients. Without them,a downstream implementation can reconstruct a rotated,sign-flipped or incorrectly normalized field while using the same numerical values.

This page handles a scalar real field and a low-degree expansion. Vector spherical harmonics,complex-valued observations,spin-weighted functions and automatic geographic coordinate conversion require different representations and are not inferred from the presence of directional samples.

A few questions, answered

Is theta latitude?

No. It is the polar angle from the positive z-axis.

What do the weights mean?

They weight squared fitting residuals,not automatically spherical quadrature area.

Why reject enough rows?

The directional design can remain rank deficient despite a sufficient row count.

Is a zero sample residual a global error bound?

No. It describes the entered sample locations only.

Find your calculator

Start typing to explore the library.