Code covered by the BSD License  

Highlights from
Spherical Harmonics

3.92308

3.9 | 14 ratings Rate this file 39 Downloads (last 30 days) File Size: 2.17 KB File ID: #8638
image thumbnail

Spherical Harmonics

by Daniel Ennis

 

04 Oct 2005 (Updated 05 Oct 2005)

This function generates the Spherical Harmonics basis functions of degree L and order M.

| Watch this File

File Information
Description

This function generates the Spherical Harmonics basis functions of degree L and order M.

SYNTAX: [Ymn,THETA,PHI,X,Y,Z]=spharm4(L,M,RES,PLOT_FLAG);

INPUTS:

L - Spherical harmonic degree, [1x1]
M - Spherical harmonic order, [1x1]
RES - Vector of # of points to use [#Theta x #Phi points],[1x2] or [2x1]
PLOT_FLAG - Binary flag to generates a figure of the spherical harmonic surfaces (DEFAULT=1)

OUTPUTS:
 
Ymn - Spherical harmonics coordinates, [RES(1) x RES(2)]
THETA - Circumferential coordinates, [RES(1) x RES(2)]
PHI - Latitudinal coordinates, [RES(1) x RES(2)]
X,Y,Z - Cartesian coordinates of magnitude, squared, spherical harmonic surface points, [RES(1) x RES(2)]

NOTE: It is very important to keep the various usages of THETA and PHI straight. For this function THETA is the Azimuthal/Longitude/Circumferential coordinate and is defined on the interval [0,2*pi], whereas PHI is the Altitude/Latitude/Elevation and is defined on the interval [0,pi]. Also note that the conversion to cartesian coordinates requires that PHI be offset by pi/2 so that the conversion is on the interval [-pi/2,pi/2].

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
05 Oct 2005 Michael Kleder

Nice.

10 Oct 2005 GOUTAM BISWAS  
15 Nov 2005 Oliver Müller

This is a very good starting point for me and my work - thanx ;-)

30 May 2006 Ritter Dieter  
09 Nov 2006 Ting HUANG

There's something wrong with the dimension of Ymn.
"[THETA,PHI]=meshgrid(THETA,PHI);"
should be "[THETA,PHI]=ndgrid(THETA,PHI);" (line 53)

26 Feb 2007 Tamar Kashti

Nice start point. Note that the function is mainly for ploting Ylm's, since the output is a matrix of different angles (theta,phi). The opposite convation of (theta,phi) is confusing.

04 Mar 2007 GOUTAM BISWAS  
19 Mar 2007 B L

Great, math is correct, but Matlab 7 doesn't know what setfig is:
??? Undefined command/function 'setfig'.

Error in ==> spharm4 at 92
  setfig(gcf,10,5,12);

Easy to tweak for my needs.

11 May 2007 Miguel Neto  
27 Jan 2008 Anamika Gupto  
09 Feb 2008 bapitha anbalagan

sir,
i am final year M.E. student. i want the matlab coding for harmonic elimination in PWM AC chopper using genetic algorithm.

30 Jun 2008 Seo Lee

Nice start point. Note that the function is mainly for ploting Ylm's, since the output is a matrix of different angles (theta,phi).

17 Sep 2008 Jon Casey  
21 Jul 2009 Jacek

Nice work .

One minor comment: the output argument Ymn has the elevation and azimuth dimensions flipped with respect to the input RES argument, due to the nature of meshgrid. Thus, the rows of the output Ymn refer to elevation, while the columns of the output Ymn refer to azimuth.

07 Dec 2009 Etai Rosenkrantz  
18 Apr 2010 Rush

just one question, let's say i want to find spherical harmonics with m=-1 and l=1, it gives me error statements. im sure it has to do with the modulus sign. if so, why do we put the modulus sign? thanx.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
differential equations Daniel Ennis 22 Oct 2008 08:01:49
spherical Daniel Ennis 22 Oct 2008 08:01:49
harmonic Daniel Ennis 22 Oct 2008 08:01:49
legendre Daniel Ennis 22 Oct 2008 08:01:49
polynomial Daniel Ennis 22 Oct 2008 08:01:49
differential equations Francesco Grubas 03 Mar 2009 16:58:28
harmonic Francesco Grubas 03 Mar 2009 16:58:28
legendre Francesco Grubas 03 Mar 2009 16:58:28
polynomial Francesco Grubas 03 Mar 2009 16:58:28
spherical Francesco Grubas 03 Mar 2009 16:58:28

Contact us at files@mathworks.com