%\input /pros/doc/scidoc/skeleton.tex
\def\version{\it Version 1.0 --- 5/14/86}
\def\chapter{\it Timing Analysis: Folding and Period Searches}
%\chapterhead{Science Specifications for the PROS}
%\chapterhead{Timing Analysis: Folding and Period Searches}
\chapterhead{IV.~Folding and Period Searches}

\@{Overview}

\noindent
{\it Science Contact}:  R. Kelley (GSFC)


\@{Folding data}

One of the most frequently applied operations in the analysis of data
containing, or suspected of containing, periodic signals is epoch folding.  The
idea is to fold or superpose a time series on itself with respect to some
period.  Computationally, this can be accomplished using the following
algorithm:

\vskip 12pt

\halign{\indent#&\hfil#\hfil\quad&#\hfil\quad \cr
&&DO 10 I = 1,NPTS \cr
\noalign{\vskip 6pt}
&&PHASE = (T(I) - TE)/PFOLD \cr
\noalign{\vskip 6pt}
&&PHI = MOD(PHASE,1.0) \cr
\noalign{\vskip 6pt}
&&IF (PHI .LT. 0.0) PHI = PHI +1.0 \cr
\noalign{\vskip 6pt}
&&IBIN = PHI*NBINS + 1.0 \cr
\noalign{\vskip 6pt}
&&C(IBIN) = C(IBIN) + X(I) \cr
\noalign{\vskip 6pt}
&&E(IBIN) = E(IBIN) + 1.0 \cr
\noalign{\vskip 6pt}
&&S2 = S2 + S(I)$\ast\ast$2 \cr
\noalign{\vskip 6pt}
&10&CONTINUE \cr
\noalign{\vskip 6pt}
&&DO 20 I = 1,NBINS \cr
\noalign{\vskip 6pt}
&&IF (E(I) .GT. 0.0) C(I) = C(I)/E(I) \cr
\noalign{\vskip 6pt}
&&IF (E(I) .GT. 0.0) S(I) = SQRT(S2)/E(I) \cr
\noalign{\vskip 6pt}
&20&CONTINUE \cr }

where the quantities are defined as follows:

\vskip 12pt

\halign{\indent\qquad\qquad#&#\hfil&#&#\hfil \cr
&T(I)&&time of the i$^{th}$ bin \cr
\noalign{\vskip 6pt}
&X(I)&&the number of counts in the i$^{th}$ bin \cr
\noalign{\vskip 6pt}
&S(I)&&uncertainty in X(I) \cr
\noalign{\vskip 6pt}
&TE&&chosen reference epoch \cr
\noalign{\vskip 6pt}
&PFOLD&&fold period \cr
\noalign{\vskip 6pt}
&NPTS&&number of data points \cr
\noalign{\vskip 6pt}
&NBINS&&number of phase bins \cr
\noalign{\vskip 6pt}
&C(J)&=&counts array \cr
\noalign{\vskip 6pt}
&E(J)&=&exposure array \cr }
\vskip 12pt

At this point the folded lightcurve, $C(I)$, along with the errors, $S(I)$, should
be displayed as a histogram.  In practice it is useful to plot the array
$C(I)$ \underbar{twice}, as if two consecutive cycles of the pulsation had been plotted.
The time $T(I)$ should be referred to an inertial reference frame, so it will be
necessary to make barycentric corrections on the photon arrival times.
(Barycentric corrections are not performed as part of the production processing.)

\@{Period search using epoch folding}


To search for a coherent modulation, a chi-squared statistic is computed for
each trial fold period:

$$\chi^2 = \sum [C(I) - \mu]^2 / S(I)^2 \qquad\qquad I = 1 \ldots {\rm NBINS}$$

where $\mu$ is the mean value of $C(I)$.  If there is no modulation present, $\chi^2$
should of course be approximately equal to NBINS.  If, however, there is a
modulation present, $\chi^2$ will be maximized for PFOLD equal to the actual
pulse period.  Thus, the procedure is simply to plot $\chi^2$ versus PFOLD for a
range of periods, and look for a statistically significant peak in accordance
with the $\chi^2$ distribution for NBINS-1 degrees of freedom.  The value of $\chi^2$
corresponding to a given confidence level is given by the solution of the
expression

$$[1 - {\rm prob} (>\chi^2)]^{N_p} = c$$

where prob($>\chi^2$) is the probability of exceeding the value of $\chi^2$ for
NBINS-1 degrees of freedom, $N_p$ is the number of periods searched, and $c$ is
the confidence level (e.g., 0.95 for 95\% confidence).  The values of PFOLD
should be incremented in steps of less than $\Delta P = P^2/T$, where $P$ is the mean
of the period range to be searched, and $T$ is the length of the time series.
This value of $\Delta P$ corresponds to the difference between adjacent Fourier
frequencies , $\Delta f = 1/T$, where $\Delta P/P = \Delta f/f$.  In practice, a value of
$\Delta P = {1\over 4} P^2/T$ is a good choice so that the period domain is somewhat
over-sampled.

\@{The Rayleigh test}

The Rayleigh test has been applied to astrophysical data by Gibson
{\it et al.}
(1982) and has been discussed recently by Leahy, Elsner, and Weisskopf
(1983).  Whereas the epoch folding test is applied to binned data, the
Rayleigh test is applied to individual photon arrival times.  The procedure
is to compute the vector $\underline{r}_i = (\cos\theta_i, \sin\theta_i$) for each photon
where $\theta_i = (t_i - t_o)/P_{trial}$, modulo 1.0.  Then the vector

$$\underline{R} = \sum \underline{r}_i (i = 1 \ldots N)\ {\rm is\
formed,\ and\ the\ quantity}\ S = N^{-1}\mid\underline{R}\mid^2$$

is computed, where $N$ is the total number of photon arrival times.  It can be
shown that the $S$ statistic is distributed as $\chi^2$ with 2 degrees of freedom, and
therefore has an exponential distribution.  The probability of exceeding $S$ is
simply e$^{-S}$.  As with the folding test, the value of $S$ corresponding to a
given confidence level is given by

$$[1 - e^{-S}]^{N_p} = c.$$

According to Leahy, Elsner and Weisskopf, the Rayleigh test is more sensitive
than epoch folding for pulse shapes that are sinusoidal or have large duty
cycles.  However, epoch folding is much better for detecting narrow pulse
shapes.  This is because the function $S$ is closely related to the power density
spectrum, and for complex pulse shapes, there is power in the higher harmonics
that does not contribute to $S$ at the fundamental period.  For example, a pulse
shape that has a $\sin 2\omega t$ component will make contributions to 
$\underline{R}$ that are
180$^{\circ}$ apart when folded with respect to the fundamental period, $P$, and
will thus tend to cancel out.  In this case, the function $S$ should have a
maximum at a period of $P/2$.  A comparison of the relative sensitivities of the
epoch folding and Rayleigh tests for more complex pulse shapes has not yet
been carried out, but it is clear that care must be exercised when applying
the Rayleigh test to period searches.

\@{Required output}


\**{Plots of folded lightcurves, including error bars.}

\**{Plots of $\chi^2$ versus $P$ with specified confidence levels indicated.}

\**{Plots of $S$ versus $P$ with specified confidence levels indicated.}

\@{References}

\refindent
Gibson, A.I., et al. 1982, {\it Nature}, {\bf 296}, 833.

\refindent
Leahy, D.A., Elsner, R.F., and Weisskopf, M.C. 1983, {\it Ap. J.},
{\bf 272}, 256.


\vfill\eject
