File Exchange

image thumbnail


version (7.05 KB) by Brett Shoelson
Performs a Lomb-Scargle periodogram analysis on unevenly spaced data.


Updated 17 Jul 2020

View Version History

View License

LOMBSCARGLE(INPUTDATA, DUPE_ELIM) performs a Lomb-Scargle periodogram (spectral) analysis on an n x 2 matrix of data (inputdata = x(i),y(i)) that are not necessarily evenly spaced. (For evenly spaced data, more traditional Fourier-based spectral methods may be more appropriate.)

DUPE_ELIM (= 0 or 1) is an optional argument that will prompt the program (if dupe_elim == 1) to eliminate duplicated samples from the analysis. The default value is 0.

This program will plot and spectrally analyze the input data, and then plot the power spectrum of the data.

The program is also capable of overlaying a signal of known frequency and amplitude; this may be helpful for spectral calibration. The resulting spectrum plot will also include significance levels. Finally, the program will reconstruct a plot of frequencies determined to be "significant" (at alpha = 0.05); for this reconstruction, frequencies within 5% of the calibration signal (if used) will be discarded. Significant frequencies and powers are written to the MATLAB command window.

(This program is based on a Lomb-Scargle implementation in Press, Teukolsky, et al. Numerical Recipes, "Spectral Analysis of Unevenly Sampled Data." Use of this program requires an understanding of the Press/Teukolsky implementation, inculding the usage of hifac and ofac variables. The user is referred to that source for a thorough discussion of the algorithms. In addition, the references cited in Press/Teukolsky are quite helpful--particularly Scargle 1982, and Horne and Baliunas, 1986.)

Note that there is an over-reliance in this code on global variables, and that no attempts have been made to vectorize for loops or to optimize the implementation. Perhaps in the next version....

The attached file INPUTTOLOMB.M includes code for easily generating test data with known frequencies and amplitudes. This file is helpful for users trying to understand the output generated by lombscargle.

Cite As

Brett Shoelson (2020). lombscargle.m (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (19)

Carlos Mayorga

Hi everybody. Quick question: Is there any restriction to define hifac or fhi? I am trying to use the code but I get the following message:
Error using drawnow
Undefined function 'gethifac' for input arguments of type 'char'.

Error using lombscargle>gethifac (line 465)
Error while evaluating UIControl Callback.

Error using matlab.ui.control.UIControl/get
Invalid or deleted object.

Error in lombscargle>gethifac (line 464)
while ~length(get(h_edit,'userdata'))

Error in lombscargle>period (line 267)
hifac2 = gethifac;
And I am using a fhi smaller than Nyquist frequency....

Thank you in advance for your help.


Brett Shoelson

Hi all,
Unfortunately, I am unable to support this piece of code. I wrote it VERY long ago, haven't touched it in a long time. The best I can do is (re-)steer you to the reference cited above. As for the calibration, that's my own implementation, and I don't know exactly how mathematically "rigorous" the idea is. The amplitude of peaks in the spectrum is only relevant relative to the amplitudes of other peaks. My thought was to add to the data a stationary signal of a know amplitude and frequency. The resulting "reference peak" would help to scale, or "calibrate," the spectrum of the data.


Excellent program! But how to realise an analyse of a phase shifted data input?


Hi could not get the use of calibration frequency and calibration amplitude? plz help.


Great piece of code!


it seems that the significant level strongly depends on the time resolution of the input. How to resolve this problem?

Pooria Sattari

Hey Guys:

I have problems with the inputdata prcedure. How should I input my n*2 matrix?


Hasan Demirhan

i have 538 data points and i need analyse these data. But when i entering hifac=1548 programme did't work, so i need fast computation for this value.

kondala rao rupa

sella lestari

i still learning about this topic.
thanks for help me to understand and use this file.

Shyam Sundar

samir khan

Ken Liao

Works exactly like it supposed to. It would be nice to output the raw spectrum data to a matrix.

Martin Trauth

Udo Schwarz

Russ Fischer

Well done. The significance levels on the spectral plot are especially useful.

Benjamin Lopez

Benjamin Rosenbluth

cj p

two functions with the same name ("period") so won't run...

MATLAB Release Compatibility
Created with R12.1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Lomb normalized periodogram

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!