Here I will present the notes I made while developing the phase lock algorithm used to detect trace amounts of DNA orbiting an electrical focal point.
It took me some time to wrap my mind intimately enough around the phase lock concept to be able to code it simply into an application. I am going to lay down my thoughts here for my future self to reference.
Phase Locking allows me to hone in on a signal from a noisy source by eliminating all other components of the noisy source except for a known frequency at a known phase. I know the frequency and phase because I either generate the signal or whoever is generating it passes on this information to me. I found that what helped the most was the following mathematical presentation.
Let:
(1) 
be an Encoded Signal.
is composed of the carrier wave and the Signal of Interest I want to transmit across the medium. In this case the amplitude of
varies and is proportional to the Signal of Interest.
Let:
(2) 
be the Background Noise that accompanies the Encoded Signal. In this case the sum indicates that the profile of the Background Noise spans many frequencies at different amplitudes and phase offsets.
The signal that I receive and that I am going to apply the Phase Lock procedure on contains both the Encoded Signal and the Background Noise:
(3) 
Here is how I imagine the signal of interest, carrier wave and channel noise are combined to result in what gets received by the sensing module:
At this point I am going to delve into a bit of signal processing. My end goal is to extract the amplitude
from the noisy
. For this I will use my knowledge that the Encoded Signal
is broadcast at a frequency
with a phase offset
. The procedure is the following:
1) Multiply
by a reference signal
. In this case
has has the same frequency and phase as
.
2) Convolve the result by a constant function (this can also be interpreted as integrating the result).
To understand what the two steps above do I am going to present their effects both in time and frequency domain.
Remember: CONVOLUTION in time domain is MULTIPLICATION in frequency domain. And the other way around.

The outcome of the first step (the
in the time domain) in the frequency domain is to shift the frequency
of my Encoded Signal to DC (0 Hz).
The second step (the convolution of the result of step 1 with a DC function in the time domain) results in all frequencies except DC being multiplied by 0 – practically leaving only the power component of the Encoded Signal.
If you manage to understand the sequence of steps above the math below will make much more sense.
Now that I have a good intuition on what I am planning on doing I’ll go through the math in time domain to make sure I get all the fine details right.
So first up is the multiplication – which is also known as “beating”
with a reference signal
.
Let:
(4) 
Then:
(5) ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} S_T \times S_{ref} &= [A_{enc} \times sin(\omega_{enc} \times t + \theta_{enc})] \times sin(\omega_{ref} \times t + \theta_{ref}) +\\ &\phantom{=}\, +[\sum_{k=1}^n A_k \times sin(\omega_k \times t + \theta_k)] \times sin(\omega_{enc} \times t + \theta_{ref}) \end{split} \end{equation*}](http://e1z.ca/code/clog/wp-content/ql-cache/quicklatex.com-dbb321dcbea2e2f3551d77a7e9daf015_l3.png)
Remembering from whatever is left of my trigonometry memories that:
(6) 
The top term of (5) simplifies to:
(7) ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} \frac{A_{enc}}{2} \times [cos(\omega_{enc} \times t + \theta_{enc} - \omega_{ref} \times t - \theta_{ref}) - \\ - cos(\omega_{enc} \times t + \theta_{enc} + \omega_{enc} \times t + \theta_{ref})] \end{split} \end{equation*}](http://e1z.ca/code/clog/wp-content/ql-cache/quicklatex.com-1fd6bac42310d26d4d9ced5b76af009f_l3.png)
Now remember from the way I chose
that
and that
so the first
becomes
which is a DC (non-oscilating) term. So the top term ends up being:
(8) ![Rendered by QuickLaTeX.com \begin{equation*} \frac{A_{enc}}{2} \times [1 - cos(2 \times ( \omega_{enc} \times t + \times \theta_{enc}))] \end{equation*}](http://e1z.ca/code/clog/wp-content/ql-cache/quicklatex.com-e0e9c1c481b418ce25e9e0a009f5f17a_l3.png)
The bottom term of (5) becomes:
(9) ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} \sum_{k=1}^n \frac{A_k}{2} \times [cos(\omega_k \times t + \theta_k - \omega_{ref} \times t - \theta_{ref}) - \\ - cos(\omega_k \times t + \theta_k + \omega_{ref} \times t + \theta_{ref})] \end{split} \end{equation*}](http://e1z.ca/code/clog/wp-content/ql-cache/quicklatex.com-ced407e9873040cbdbdb7ec7673c07fb_l3.png)
In this case however we can’t cancel out
with
unless
is equal to
and
. This happens for Background Noise frequencies
that are “close” to the Encoded Signal
frequency and at about the same phase offset
.
Putting everything together equation (5) can then be simplified to:
(10) ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} S_T \times S_{ref} &= \frac{A_{enc}}{2} \times [1 -\\ &\phantom{=}\, - \frac{A_{enc}}{2} \times cos(2 \times (\omega_{enc} \times t + \theta_{enc})) + \\ &\phantom{=}\, + \frac{A_k}{2} \times \sum_{k=1}^n cos[(\omega_k - \omega_{ref}) \times t + \theta_k - \theta_{ref}] - \\ &\phantom{=}\, - \sum_{k=1}^n cos[(\omega_k + \omega_{ref}) \times t + \theta_k + \theta_{ref}] \end{split} \end{equation*}](http://e1z.ca/code/clog/wp-content/ql-cache/quicklatex.com-cd7d8bafcf81618bdef95bd3151110a5_l3.png)
Upon a slightly more careful inspection I observe that the result of beating
with
is a DC term and a series of oscillatory terms at different frequencies.
NOTE: Actually there’s two DC terms. The 2nd DC term is hidden in the
term. This happens as mentioned before when
is about the same frequency as
and when
is equal to
.
So if I were to filter the result of
with a DC filter I would remove all the oscillating terms. To filter using a DC term I convolve the multiplication by a constant term which leaves me with:
(11) ![Rendered by QuickLaTeX.com \begin{equation*} [ S_T \times S_{ref} ] * 1 = \frac{A_{enc}}{2} \times 1 + \frac{A_{k0}}{2} \times 1 \end{equation*}](http://e1z.ca/code/clog/wp-content/ql-cache/quicklatex.com-80f76cd90374cee901434ada11972ead_l3.png)
where the
term is used to indicate the frequency
for which
and
. That is the component of the Background Noise that has a frequency and phase equal (or very close to) the Encoded Signal’s frequency and phase.
If we assume the Background Noise at the
frequency and offset is small. Then:
(12) ![Rendered by QuickLaTeX.com \begin{equation*} [S_T \times S_{ref} ] * 1 = \frac{A_{enc}}{2} \end{equation*}](http://e1z.ca/code/clog/wp-content/ql-cache/quicklatex.com-2df1980956d6f722d25c6cdd1a46816c_l3.png)
Which means that:
(13) ![Rendered by QuickLaTeX.com \begin{equation*} A_{enc} = \frac {[S_T \times S_{ref}] *1}{2} \end{equation*}](http://e1z.ca/code/clog/wp-content/ql-cache/quicklatex.com-7f5b8920351e20caaa8dbbd9897aa3a5_l3.png)
which brings us to the goal of finding
.
Thanks to the people at tex.stackexchange for teaching me how to use Latex properly.
The biggest thanks go to The Scientist and Engineer’s Guide to Digital Signal Processing by Steven W. Smith, Ph.D for teaching me the intro knowledge on convolution.