A method of classifying generic orbits in arbitrary 2D and 3D potentials is presented. It is based on the concept of spectral dynamics introduced by Binney & Spergel that uses the Fourier transform of the time series of each coordinate. The method is tested using a number of potentials previously studied in the literature and is shown to distinguish correctly between regular and irregular orbits, to identify the various families of regular orbits (boxes, loops, tubes, boxlets, etc.), and to recognize the second-rank resonances that bifurcate from them. The method returns the position of the potential centre and, for 2D potentials, the orientation of the principal axes as well, should this be unknown. A further advantage of the method is that it has been encoded in a FORTRAN program that does not require user intervention, except for `fine tuning' of search parameters that define the numerical limits of the code. The automatic character makes the program suitable for classifying large numbers of orbits.