Similarity between two Signals: cycle by cycle I need to find the similarity between two signals, i.e., measured signal and the reference signal(e.g. a simple sinusoidal signal). What I mean by similarity is, if there is any decentralized glitch or any change in freq for one particular cycle, the similarity measure should give 'False' or a value in 0 - 1 scale for that cycle. Phase difference also should be considered. Could this be done using correlation? Or is it possible to use wavelets? Or any other method?

Many Thanks...
so i'll throw the cross-correlation and/or matched-filter thing at you.  a little bit similar to Karthik but maybe a little more rigor.

so you have a reference signal, $y(t)$, and a measured signal $x(t)$.  suppose they have something in common and some differences and may one of the differences is a misalignment in time.  but if you investigate what these two signals have in common (or what they don't) for a variety of different offsets in time, that dissimilarity due to time misalignment can be made non-salient (or maybe you want to know the time offset).

so first consider measuring the dissimilarity (at a variety of different offsets or "lags") as:

$$ Q_{xy}(\tau) \triangleq \int\limits_{-\infty}^{+\infty} \left( x(t) - y(t+\tau) \right)^2 dt $$

so you're looking at how much $x(t)$ and $y(t+\tau)$ are different, for different lags, $\tau$, squaring that difference or "error" so that it's always positive (this is analytically easier than if you use the absolute value), adding up the total squared-difference over all of time and you have an overall measure in how dissimilar $x(t)$ and $y(t+\tau)$ are.  then picking the lag $\tau$ so that $Q_{xy}(\tau) \ge 0$ is minimum might be considered to be a measure on how dissimilar $x(t)$ and $y(t+\tau)$ are.

the smaller this measure (which is always non-negative), the more similar $x(t)$ and $y(t+\tau)$ are.  this is the Average Squared Difference Function (ASDF) and has a similar motivation in its definition as does the more well-known and historical AMDF function.

now the cool thing you get that you don't if it's AMDF is

$$ \begin{align}
Q_{xy}(\tau) &amp; = \int\limits_{-\infty}^{+\infty} \left( x(t) - y(t+\tau) \right)^2 \ dt  \\
&amp; = \int\limits_{-\infty}^{+\infty} x^2(t) + y^2(t+\tau) - 2x(t)y(t+\tau) \ dt \\
&amp; = \ \int\limits_{-\infty}^{+\infty} x^2(t) dt \ + \ \int\limits_{-\infty}^{+\infty}y^2(t+\tau) dt \ - \ 2\int\limits_{-\infty}^{+\infty}x(t)y(t+\tau) dt \\
&amp; = \ \int\limits_{-\infty}^{+\infty} x^2(t) dt \ + \ \int\limits_{-\infty}^{+\infty}y^2(t) dt \ - \ 2\int\limits_{-\infty}^{+\infty}x(t)y(t+\tau) dt \\
&amp; = \ E_x \ + \ E_y \ - \ 2\int\limits_{-\infty}^{+\infty}x(t)y(t+\tau) dt \\
\end{align} $$

$E_x$ and $E_y$ are the energies of $x(t)$ and $y(t)$ and not functions of $\tau$.  so $Q_{xy}(\tau)$ will be minimum with a $\tau$ that makes the integral on the right maximum.  we'll give that integral a name:

$$ R_{xy}(\tau) \triangleq \int\limits_{-\infty}^{+\infty}x(t)y(t+\tau) dt $$

and we see that 

$$  Q_{xy}(\tau) = E_x + E_y - 2  R_{xy}(\tau) $$

so so $Q_{xy}(\tau)$ is minimum when $R_{xy}(\tau)$ is maximum.  in fact, with a scaling constant of $2$ tossed in there $Q_{xy}(\tau)$ and $R_{xy}(\tau)$ are upside-down mirror images of each other.

we call $R_{xy}(\tau)$, the cross-correlation function of $x(t)$ and $y(t)$ and is the inner product (if we're pretending we're living in a Hilbert space) of $x(t)$ and $y(t+\tau)$.  if we're dealing with complex $x(t)$ and $y(t)$ (we're not, i hope) then $y(t)$ should be complex-conjugated.  where $R_{xy}(\tau)$ is maximum is the time offset that $x(t)$ and $y(t)$ are most similar to each other.  

the above can be rearranged:

$$ R_{xy}(\tau) = \frac{1}{2} \left( E_x + E_y - Q_{xy}(\tau) \right) $$

or 

$$ \frac{R_{xy}(\tau)}{\frac{1}{2}(E_x + E_y)} =  1 - \frac{Q_{xy}(\tau)}{E_x + E_y} $$

so the cross-correlation is getting normalized by the average energy of $x(t)$ and $y(t)$.  we're always subtracting a non-negative number from 1 so that normalized cross-correlation is never larger than 1

and pick the $\tau_0 \ne 0$ where $R_{xy}(\tau_0)&gt;R_{xy}(\tau)$ for all other $\tau$ and calculate that normalized cross-correlation and you have a measure of similarity with

$$ -1 \le \frac{R_{xy}(\tau_0)}{\frac{1}{2}(E_x + E_y)} \le 1 $$

if it's -1, they are identical but with opposite polarity.  if it's 1, they're totally similar (at that offset of $\tau_0$).