Professional Documents
Culture Documents
MASTER'S THESIS
Hans Eklund
HANS EKLUND
Department of Computer Science and Electrical Engineering
Lulea University of Technology
hanekl-9@student.luth.se
September 2004 to March 2005
Abstract
This report covers a master thesis in signal processing. It deals with solving a
problem in a special type of audio encoder used in the Swedish speech newspaper
system. However, design methods and algorithms developed or investigated are
rather general. A large part of the report covers the fundamental theory of
phase locked loops and can be regarded as a beginners introduction to the field.
Along the way, the theory aims at a software implementation, and therefore
tries to deal with such specific matters. Also the issues with implementing a
time critical system in digital hardware is outlined and a custom method for
achieving phase-lock is presented. A successful implementation was made on a
digital signal processor based hardware platform.
Contents
1 Introduction
1.1 Overview . . . . .
1.2 The audio encoder
1.3 Objectives . . . . .
1.4 Outline . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
1
1
2
4
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
view
. . .
. . .
. . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
6
7
8
9
10
11
12
16
19
19
21
22
22
24
3 Results
3.1 Matlab . . . . . . . . . . . . . . . . .
3.2 Real-time hardware implementation
3.2.1 Hardware specification . . . .
3.2.2 Developing environment . . .
3.2.3 Measurements . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
29
29
30
30
30
32
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4 Conclusion
35
A Program code
36
iii
iv
List of Figures
1.1
1.2
1.3
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10
2.11
2.12
2.13
3.1
3.2
2
2
3
.
.
5
6
.
.
8
9
. 14
. 14
. 18
. 18
. 20
. 21
. 23
. 26
. 28
3.3
3.4
vi
Acknowledgement
Thanks goes to the Rubico AB founders Anders and Per for having
me as their Master Thesis student and for their support in every
aspect. Thanks to James Leblanc for valuable insights and patience
in this long drama. Also, hats off for Robert Selberg for acting
as the thesis opponent. Thanks to the percolator for keeping the
coffee warm and aromatic. Finally, thanks to all the staff, current
and past, at Rubico for being around for support and laughter.
Hans Eklund, September 2006.
vii
viii
Chapter 1
Introduction
Engineering is all about development. This master thesis uses new technology
to improve an old system. In this case the new technology are digital signal
processors - DSP. The system in need of improvement is the Swedish speech
newspaper distribution system.
1.1
Overview
The speech newspaper system has been available since mid nineteen eighties
and makes newspapers available to the visually impaired. Newspaper staff read
and record the written articles, advertisements, radio and TV tableaus etc. The
speech newspapers are distributed by mail on a tape, or via an ordinary FM
network, taking advantage of unused channel capacity during night.
The technique used in several parts of the current system were developed
during that time. One part sits in between the recording studio and the FM
link. That part scrambles the speech in a certain way to ensure only subscribers
of the speech newspaper can listen to it. Currently, the scrambling is performed
by analog electronics that has to be tuned once a year. It has now been proposed
that the old audio encoder may be replaced by a more flexible digital system.
Using a digital method to scramble the audio is attractive in several aspects.
First and foremost, the aspect of quality. Using the old analog equipment
requires regular service and tuning of parameters. With a digital platform the
way the audio gets encoded does not change with time. Second, the new coder
platform is flexible and will be easy to upgrade for future demands.
1.2
are common in analog communications theory, see [1] for details. The effect
is that the frequency contents will be reversed if not decoded correctly, high
pitch sound will become low and vice versa, as seen in Fig. 1.3. Before sending
the modulated audio to the external FM network, a disturbing 1 KHz tone is
added to further decrease the hearability. At the heart of the scrambling alVSB Modulation
40 Hz - 7 kHz
bandpass
Audio
input
MPX
input
9.5 kHz
tone
PLL
Encoded
output
Lowpass
filter
1 kHz
tone
gorithm is the VSB modulation that shifts the spectrum, as described earlier.
The audio has to be modulated upon a signal at half the frequency of a 19 KHz
tone available in the so called MPX signal. The MPX signal is the baseband
information signal in the FM system with spectral contents roughly as seen in
Fig. 1.2. How do we generate a signal, locked in phase, at exactly half the
frequency? And what method is suitable for a software implementation?
Audio (Mono)
Pilot
carrier
L+R
0
DSB-SC
15
L-R (upper
sideband)
L- R (lower
sideband)
19 23
RDS
38
53
57
f in kHz
1.3
Objectives
The coding method in the system is obsolete in many ways. The coding is
performed in a way that is really sub par when it comes to security, but for
the application it works. If the system would be replaced by an entirely digital
one, the coding method would be of another kind. However since the coder has
to be backward compatible with old receivers, the new coder has to be able to
1.3 Objectives
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
1
4
x 10
Magnitude [dB]
1.5
0.5
0.5
1.5
2
4
x 10
Spectrum of signal after VSB filter.
40
20
0
20
2
1.5
0.5
0
0.5
Frequency[Hz]
1.5
2
4
x 10
implement the analog scrambling described above. Most of the blocks in the
coder are more or less trivial to implement, such as filters and the modulation.
As hinted above, the block that needs extra attention is the synchronization
block used to synthesize the 9.5 kHz signal before the VSB modulation scheme.
The company that wanted this thesis to be made initially had experience,
equipment and software already available for a specific platform. So the solution
had to be tailored for that particular target. Therefore, the main objective of
the thesis was to investigate the possibility of implementing the synchronization
block in a DSP for a real time application.
The specifications on what to be accomplished where quite clear though.
The audio input was to be modulated onto a carrier at exactly half the frequency
of the 19 kHz MPX-signal and at a specific phase shift. Early on a possible
solution to the problem was seen. It was concluded that a phase locked loop
might do the job, if properly designed. However, the field of phase-locked loops
is deep and somewhat intricate. A thorough study on the subject was made to
lay the foundation to the design.
1.4
Outline
The report is structured into two main blocks. An introduction and design
guide to phase locked loops with en emphasis on software implementation comes
first. The chapter after is shorter and provide a presentation of a working
implementation of the theory. Last of all the results are discussed and further
work are suggested.
Chapter 2
z1 = e
z2 = ej(w2t)
q1
q2
Re{zn}
Figure 2.1: Complex representation of two signals. The arrows move around since their
phase (angle) is a function of time. The speed of the rotation is the frequency
of the sinusoids.
Z t
n (t)dt.
The phase is the property of interest for the PLL designer. As an example,
assume the first vector is rotating at constant angular frequency 1 (t) = c . To
make the new, generated signal follow the input signal, the new one has to adjust
its phase to minimize the distance to the reference, that is the phase error,
denoted as e . Adjusting its phase is done by either increasing or decreasing its
angular frequency. When both vectors are moving about at the same rate we
say they are locked to each other. In the locked state the phase error between
the two systems are zero or constant, depending on the system design. If the
reference signal deviates from its current angular frequency and a phase error
develops, a control system acts upon the second system to make the phase error
smaller. The control system locks the phase of the output to the input, hence
the name - Phase locked loop.
Phase locked loops are used mainly in two fields of application. When
analog signals are modulating a high-frequency carrier the PLL is needed to
demodulate the received signal back to the baseband. Classical modulation
schemes include amplitude modulation (AM), frequency modulation (FM) and
phase modulation (PM). An important application was found in 1950, the color
subcarrier in television systems was recovered with the use of a PLL.
The other important application is in the field of frequency synthesis, that is
creating a signal with correct and stable frequency. The synthesis application
is commonly found in the sending part of communication systems where the
carrier is created for bandpass signaling. By synthesis we mean that a signal
from an oscillator is fed to the PLL and the output is a signal with another
frequency.
In this thesis, the application is frequency synthesis and the PLL described
below is designed for that purpose. It does not differ much from the PLL used in
receivers, the main difference is a parameter used to set a multiplication/division
ratio of the input frequency.
2.1
Lets have a closer look at the first class of PLLs - Linear PLLs (LPLL). There
are other types of PLLs, digital PLLs (DPLL) and All-digital PLLs (ADPLL).
All of which can be implemented as the last class - the Software PLL (SPLL)
- a phase locked loop that is running on a processor controlled by a suitable
program. Linear PLLs consists mainly of four components as seen in Fig. 2.2.
First the phase of the generated signal and the phase of the reference input
uin(t)
ufb(t)
Phase
detector
Loop
filter
Frequency
divider
VCO
uout(t)
2.2
Phase signals
As pointed out by Best [2], phase signals are a source of much trouble when
understanding phase locked loops. For the PLL designer a signal such as
A1 sin(1 t + 1 (t))
(2.1)
carries its information, not in the amplitude A1 , not in its frequency 1 , but
in the phase 1 (t). To clarify what happens in phase when the frequency is
changed in a certain way, a few examples might help. Assume that the frequency
is constant, 0 for t < 0 and then abruptly changes frequency by at t = 0.
That is, makes a frequency step as seen in Fig. 2.3a. After t = 0 the reference
frequency can be written as
u1 (t) = A1 sin((0 + )t) = A1 sin(0 t + 1 )
(2.2)
(2.3)
We clearly see that the phase signal 1 is a ramp with slope . That reminds
us of an important relationship to always bare in mind, the angular frequency
of a signal is the first derivative of its phase with respect to time,
1 =
d1
.
dt
rad/s
Amplitude
1
1
0
Frequency of signal
1
1
0.02
0.2
0.01
0.1
0
1
rad
0
Phase of signal
0
1
50
200
50
1
0
time
200
1
0
Frequency of signal
0
Phase of signal
0
time
Figure 2.3: A few signals applied to a PLL. Observe the relationship between frequency and
phase signals. (a) Frequency step. (b) Frequency ramp.
2.3
A linear model
Considering input and the output of the PLL are phase signals, we can do the
system analysis using the transfer function H(s). Hence, we consider the system
linear with respect to phase relationships. We also assume that the LPLL is
locked and remains so in the near future. The Laplace transforms of the input
and output phase functions, in (t) and out (t) respectively, defines the transfer
function
H(s) =
out (s)
.
in (s)
(2.4)
The function H(s) is now a phase transfer function, and the model is only valid
for small changes in phase of the reference, if the phase error becomes too big
too fast, the LPLL will unlock and a non-linear process takes place. Although
that process is described by a cumbersome non-linear differential equation it
can be understood on an intuitive level.
To express H(s) we must know the transfer functions of the three building
blocks of the LPLL, as seen in Fig. 2.2. As stated earlier, a PLL is nothing but
a control system for phase signals, therefore we can rely on basic control theory
when explaining the linear model. A control system with a regulator in series
with a process has a well known transfer function when the process output is
fed back and subtracted from the system input as in Fig. 2.4.
Regulator
uin(t) +
e(t)
Process
Gr(s)
Gp(s)
uout(t)
ufb(t)
Gg(s)
Feedback system
Figure 2.4: A simple control system with a regulator, process and feedback.
Let the regulator have the transfer function Gr (s) and the process in need
of regulation have the transfer function Gp (s). The system transfer function is
then described by
Gr (s)Gp (s)
H(s) =
.
(2.5)
1 + Gr (s)Gp (s)Gg (s)
Such a relationship is derived by any basic text on control theory, such as [3]. In
the PLL case the regulator is the loop filter and the process in need of regulation
is the VCO.
2.3.1
Phase detector
Reviewing Fig. 2.2, and as earlier stated the input to the LPLL is usually a
sine wave,
uin (t) = Uin sin(in t + in ).
The signal generated by the VCO, fed back through the divider is another
sinusoid,
uf b (t) = Uf b sin(f b t + f b ).
The phase difference between the two signals are obtained by multiplying the
two signals and then filtering the result. That is the sole operation of the phase
detector. The behavior has to be modeled in a linear fashion. Assuming the
PLL is close to locked or locked in frequency, we have = in = f b and the
operation becomes
ud (t) = Uin sin(t + in )Uf b sin(t + f b )
(2.6)
Uin Uf b
(cos(in f b ) cos(2t + in + f b )).
2
(2.7)
10
The first term is the wanted dc component. The higher order component
cos(2t + in + f b ) will be canceled by the subsequent filter, hence they can be
neglected in the linear model. The output can then be simplified to
ud (t) = Kd cos(e )
(2.8)
Uin Uf b
(sin(in f b ) + sin(2t + in + f b )).
2
(2.9)
Again neglecting the higher order component, the simplified input/ouput relationship becomes
(2.10)
ud (t) = Kd sin(e ).
And for small errors in phase, the assumption
ud (t) Kd e
(2.11)
2.3.2
(2.12)
The parameter Ko is called VCO gain, and is specific to the selected VCO. It
has to be considered when designing PLLs in hardware when the VCO is not
designed from scratch, but chosen suitably. K0 has the dimension rad s1 V 1 .
11
When designing the PLL in software it can be arbitrarily chosen since the filter
design will accommodate for it. More on determining constants in section 2.3.5.
However, what we need is the transfer function of the VCO. As seen in Eq. 2.12
the angular frequency of the VCO is
out (t) = c + Ko uf (t)
But we do not want to express the VCO frequency, we want the phase transfer
function. Therefore, by definition, the phase out (t) is given by integration of
the frequency variation K0 uf (t).
Z
out =
K0 uf dt = K0
uf dt
The laplace transform for integration over time is 1/s. The laplace transform
for the output phase out is then
K0
Uf (s)
s
The transfer function of the VCO is then simply
out (s) =
out (s)
K0
=
Uf (s)
s
(2.13)
(2.14)
2.3.3
Divide by N circuit
The classical linear PLL used for frequency synthesis is suppose to generate a
periodic signal of frequency
N
in (t).
(2.15)
M
Where N and M are integers. Analog linear PLL implements the integer division in frequency by counting and triggering on every N pulses, and there by
generating a square wave at N times lower frequency. That is not a problem
since the fundamental component of the square wave is the one that locks to the
reference input, remembering that the loop filter cancels the higher components
in the square wave as well. A divider before the PLL input makes the signal
have M times lower frequency in the same way. Selecting the divide ratios N
and M suitably, any division ratio can be obtained.
In this thesis another method is used since the PLL is implemented in
software. With that method the M-divider can be discarded since N can be a
fractional number. When locked, f b = in , therefore
out (t) =
(2.16)
The relationship described by Eq. 2.16 has to be modeled for the phase signals
in the linear model. The relationship is simple, but the derivation is done for
the sake of completeness. From
Z
(t) =
(t) dt,
12
(2.17)
Acting upon the phase signal in the feedback is simply a gain factor Kn .
2.3.4
So far we have assumed that a filter exists in the LPLL to cancel higher order
components so the wanted dc term, the phase error, can be used to control the
VCO. However the loop filter has another function. Viewing the LPLL as a
control system for phase signals, the loop filter is the regulator. Bertil Thomas
[4] mentions that in control theory the regulator mainly has two tasks. One is
to compensate for disturbances that affects the system. The other is to take
necessary actions when the desired value is changed. In the PLL case, the
desired value is the current phase of the input signal. When determining how
well a regulator can cope with the two tasks several properties can be studied.
Properties such as static accuracy, speed and stability.
As this paper deals with the design of an audio coder and its clear specifications, the discussion will be taken to solve that problem and not the general
one since it is beyond the scope of this thesis.
Closed loop performance demands
The choice of the loop filter is critical to the system performance. Beginning
with the specifications of the coder a few hard demands has to be met. The
coder has to modulate the audio input onto a carrier operating at exactly half
the frequency of the FM pilot tone. The divide by N-circuit described above
make that behavior possible.
Static accuracy Since we can only tolerate a small phase difference or drift
between the pilot tone input and the half frequency output we have defined the
demand of static accuracy: zero remaining error when the input is changed.
It has to be asymptotically zero independently how the input is changed. The
regulator has to cope with whatever action is done at the input.
Speed Another important property of a control system is the speed. When
the desired value is changed in some manner, it takes some time for the output
of the system to change and finally settle at the new value. Several measures
of speed exists and one common is the rise time. The rise time is defined
as the time it takes for the output to go from 10% to 90% of its final value.
Remembering that we are dealing with a linearized model of an actual system,
other non-linear properties of the LPLL defines the settling speed when the
system unlocks and has to work towards a locking state. More on such effects
13
below. Also speed and stability are contradictory demands, higher speed implies
smaller stability margins and vice versa. I let the speed demand be defined as:
as fast as possible when stability demands are met. Defining the speed of the
system comes down to make the closed loop system have a suitable damping
factor.
Stability This is probably the most important, and therefore the most complex part of the entire paper. As hinted above the actual behavior of the LPLL
is described by a non linear differential equation. The complete system stability and how the filter affects it in all situations is not theoretically derived or
predicted by this thesis due to its high complexity. Instead testing and simulations of the system is made to ensure that the system is stable even when in its
non-linear mode of operation. The linear part of the stability problem however,
can be analyzed using the properties of linear systems using the model derived
in this chapter. Stability issues is discussed further below, once the filter type
is selected.
Selecting a filter
The selection of the correct loop filter implies the selection of the type and
order of the filter so the closed loop system type and order can accommodate
the above demands. Type refers to the number of poles in the transfer function,
the order is the same as the highest degree of the characteristic equation. Best
[2] mentions three basic filter types common in PLL applications, seen in Fig.
2.5. Clearly they are all low pass filters with different cutoff frequencies. The
first is called passive lag filter. Its transfer function F(s) is given by
F1 (s) =
1 + s1
1 + s(1 + 2 )
(2.18)
The second type has a similar transfer function, but has an additional gain term
Ka , given by
F2 (s) = Ka
1 + s2
1 + s1
(2.19)
14
Magnitude (dB)
10
20
30
3
10
10
10
10
Frequency (rad/sec)
10
10
Magnitude (dB)
20
10
10
3
10
10
10
10
Frequency (rad/sec)
10
10
40
Magnitude (dB)
30
20
10
0
10
3
10
10
10
10
Frequency (rad/sec)
10
10
Figure 2.5: Bode diagram of the filter types mentioned. (top) Passive lag filter. (mid) Active
lag filter with Ka = 10. (bottom) PI-filter, observe the high gain near DC.
Phase detecor
Qin(s) +
Qe(s)
Loop filter
Kd
Ud(s)
F(s)
VCO
Uf(s)
Qfb(s)
Kn
Feedback gain
Figure 2.6: Linear model of the PLL.
_K
s
Qout(s)
15
e (s)
1
=
.
in (s)
1 + Kd F (s) Ks0 Kn
(2.21)
Knowing the error transfer function, we can find the error function e (t) for any
given input in (t) since
(2.22)
e (s) = in (s)E(s),
by inverse transformation of e (s). But since we want to find the error as time
goes to infinity, the final error, we can take a shortcut by using the final value
theorem of laplace transforms:
Assume that g is causal and that G = L{g} is rational. If all poles to sG(s)
has negative real part, then
lim g(t) = lim sG(s)
t+
s+0
It gives us the opportunity to find the error as time goes to infinity without
having to transform e (s) back to the time domain.
Tracking frequency means that the frequency of the feedback signal uf b (t)
has to be adjusted correctly by the VCO if a new frequency suddenly appears
in the reference uin (t). That is, the system senses a frequency step. Now recall
that a frequency step, as in Fig. 2.3, really is a phase ramp for our linear system.
Therefore we know what our system has to deal with to follow specifications.
The laplace transform of the a phase ramp input is
Cv
,
s2
as given by any laplace transform table, or derived by any text on linear systems
such as [5]. Cv is the frequency difference in radians per second at the phase
detector. If a the phase ramp is applied to our error transfer function as in Eq.
2.22, we have the Laplace transform of the error as
Ri (s) =
e (s) = in (s)E(s) =
Cv
1
Cv
= 2
K
2
0
s 1 + Kd F (s) s Kn
s + Kd K0 F (s)Kn s
(2.23)
t+
s+0
s+0
s2
Cv
+ Kd K0 F (s)Kn s
(2.24)
t+
(2.25)
Any filter transfer function F (s) can now be inserted in Eq. 2.25 to obtain the
final error when the system is subject to a phase ramp. A generalized filter
transfer function can be expressed as
F (s) =
N (s)
.
D(s)sn
(2.26)
16
Where N (s) and D(s) are the nominator and denominator polynomials respectively. in the laplace domain, sn are poles at s = 0. Inserting Eq. 2.26 into Eq.
2.25 gives us
e () = lim
Cv
s+0
N (s)
s + Kd K0 D(s)s
n Kn
Cv D(s)sn
s+0 sn+1 D(s) + Kd K0 Kd N (s)
= lim
(2.27)
Inspection of Eq. 2.27 tells us that if n 1 the limit will approach zero as time
goes to infinity. We can therefore state that if we want our LPLL to track the
reference phase with zero phase error, a filter pole in s = 0 is needed.
For example,the first filter suggested by Best [2]. Inserting Eq. 2.18 into
2.25 gives us
lim e (t) = lim
t+
s+0
Cv
s+
1+s1
Kd K0 1+s(
Kn
1 +2 )
Cv
,
Kd K0 Kn
(2.28)
1+s1
by observing that 1+s(
1 as s 0. That filter does not reduce the
1 +2 )
error to zero, however it may very well do if the loop gain(Kd K0 Kn ) is kept
high enough. The second filter, F2 has a similar transfer function and yields a
similar final error, reduced by the amplification factor Ka . The third suggested
filter, the PI filter of Eq. 2.20 has a pole in s = 0 and should be a candidate
capable of reducing final error to zero. The error is calculated as
t+
s+0
Cv
=0
2
s + Kd K0 1+s
s1 Kn
(2.29)
2
by observing that the filter part 1+s
as s 0. The pole in s = 0
s1
provides the filter with, at least theoretically, infinite gain at DC and therefore
the system reduces any remaining phase error to zero eventually.
Concluding the filter discussion, as motivated above the filter type for this
particular LPLL application will be of the PI type,
F (s) =
1 + s2
s1
What remains in the filter design is selecting the constants 1 and 2 appropriately. This will be done in the next section.
At this point, we have covered the four main blocks of the linear model
of the LPLL. By closing the loop and seeing it as a feedback control system,
the final analysis can be made. The filter and amplification constants can be
selected to give the system its desired overall characteristics.
2.3.5
Summarizing the blocks covered above, as depicted in Fig. 2.6, the phase
transfer function is
H(s) =
2 K0
Kd 1+s
Kd F (s) Ks0
out (s)
s1
s
=
=
2 K0
in (s)
1 + Kn Kd F (s) Ks0
1 + Kn Kd 1+s
s1
s
(2.30)
17
by remembering the general transfer function for control theory as in Eq. 2.5.
When analyzing the closed loop it is convenient to put the transfer function on
a special form, the so called normalized form, by making the dominator be
D = s2 + 2n s + n2
where n is the natural frequency and is the damping factor. Simplifying Eq.
2.30 further,
H(s) =
Kd K0 (1 + 2 s)
=
1 s + Kd Kn K0 (1 + 2 s)
s2 +
2 s)
Kd K0 (1+
1
Kd Kn K0 2
s
1
Kd Kn K0
1
(2.31)
n =
K0 Kd Kn
1
n 2
2
(2.32)
H(s) =
1
2
Kn (2n s + n )
s2 + 2n s + n2
(2.33)
Also, the phase error transfer function, Eq. 2.21 can be rewritten in terms of
the defined damping factor and natural frequency as
E(s) = 1 H(s) =
1
s2
2
Kn s + 2n s + n2
(2.34)
From this point, using Eq. 2.33 it is easy to investigate the transient response
of the PLL as we would on any control system. The parameters n - the natural
frequency, and - the damping factors, are key design parameters. Once they
are determined, the filter parameters 1 and 2 can be obtained and the PLL
design is complete. A system with a high damping factor is said to be over
damped and the response may become sluggish. If the damping factor is too
low, as in an under damped system, the system may become oscillatory. Setting
= 12 is usually a good tradeoff between speed and stability. We see how the
damping factor affects the step response of the error function in Fig. 2.7.
18
0.8
0.6
=2.00
=0.71
0.4
=0.30
0.2
=0.05
0
0.05
0.1
0.15
0.2
Time[sec.]
Figure 2.7: Step response of the LPLL error function for various damping factors when
system is set to follow at half the frequency of the input.
|E(j)|(dB)
10
0
=2.00
10
=0.71
20
=0.30
30
40
1
10
=0.05
0
10
10
10
Figure 2.8: Amplitude response of the LPLL for various damping factors, , plotted against
normalized frequency /n
generated by the phase detector is nothing but noise for this application. The
19
tone will affect the VCO and make it tremble around its desired frequency.
Therefore we may want to narrow down the bandwidth of the system to make
the damping high at that double frequency. This is where the noise criterion
comes into the picture.
A low loop bandwidth will reject high frequency noise fed into, or created in
the system. But how low can it be set? For this particular PLL implementation
the input signal is most likely to be stable and it does not contain any baseband
information that needs to be preserved. If we were to design an FM receiver we
would have to consider the bandwidth of the baseband signal when determining
the natural frequency.
Determining a correct natural frequency n implies determining some important non linear properties of the LPLL. A brief overview of non linear LPLL
behavior will be covered in the next section and if it has any implications on
how the filter parameters will be calculated.
2.4
A linear phase-locked loop actually has important non linear properties as well
as linear ones. When the reference frequency and the VCO has different frequencies we say that the LPLL is in its unlocked mode and the linear model
derived above is not valid. We will not derive the non linear equation since it
is quite intricate.
As Best [2] states, it is not of major concern to know exactly what the LPLL
does when it is in the unlocked state. He mentions three important questions
though.
Under what conditions will the LPLL get locked?
How much time does the lock-in process need?
Under what conditions will the LPLL lose lock?
The answers to those questions are not given by theoretical derivation of mathematical relations, instead experiments was conducted to ensure that the LPLL
performed well enough for the task. However the question of a suitable natural
frequency of the system still remains to be answered.
2.4.1
Unlocked behavior
The LPLL has four important stability regions. The regions are defined as
certain deviations in frequency from the quiescent frequency of the VCO and
how fast the reference frequency changes, as seen in Fig. 2.9. The following
definitions are taken from [2], with additional comments:
20
DwH
Hold range
DwP
Pull-in range
DwPO
Pull-out range
DwL
Lock range
w0
w
Figure 2.9: The various ranges of interest for a linear PLL.
1. The hold range H . This is the range where the PLL can statically
maintain phase tracking. That is, if the reference frequency deviates this
far from the designed quiescent frequency the LPLL will unlock and the
phase error will go to infinity. This is independently of the speed the
frequency was changed.
2. The pull-in range P . This is the range within which an LPLL will
always become locked if unlocked. This range can be infinite if the correct
filter is used. The pull-in process is slow and will be explained below.
3. The pull-out range P O This is the dynamic limit for stable operation
of a PLL. If tracking is lost within this range, an LPLL normally will lock
again. This process is slow if it is a pull-in process. This defines how large
a frequency step the LPLL can handle without unlocking.
4. The lock range L . This is the frequency range within which a PLL
locks within a single-beat note between reference frequency and output
frequency. It is independent of the speed the phase was changed, just as
long as it does not exceed this range.
The definitions are not specific to his book, but are standard terms among PLL
designers. However they do not apply to the other types of PLLs mentioned,
the digital PLL and the all-digital PLL.
As a vivid example of the non-linear behavior, an actual pull-in process
simulated in Matlab is shown in Fig. 2.10. The LPLL is initially locked in
phase (/2 rad out of phase as explained above). At t = 1 a large frequency step
(larger than the pull-out range) is applied and the LPLL loses phase tracking,
but since the reference is within the pull-in range, the LPLL will try to pull the
VCO closer to the reference.
21
60
Phase[rad]
50
40
30
20
10
0.9
1.1
1.2
1.3
Time[s]
1.4
1.5
1.6
Figure 2.10: The pull-in process for a LPLL implemented in software. it finally settled at
21 = 65.97 radians out of phase.
After the pull-in process, the linear locking phase takes place and it settles
at N out of phase, which is a true phase lock. In the unlocked state,
the phase detector modulates the VCO in a nonharmonic way. That implies
that the output of the VCO is nonharmonic. The frequency of the VCO is
then sometimes closer to the reference, and sometimes further from it. That
is, we have a time dependent frequency difference. But the frequency of the
VCO varies in such way that is more often closer to than further from the
reference. Therefore, in each cycle, the average frequency is slightly shifted
towards the reference. This asymmetry of the VCO causes it to change the
average frequency even faster towards the reference. The VCO is pulling itself
in.
2.4.2
Depending on the choice of filter, the PLL will stay unlocked or slowly work
towards its locked state. It can be shown that a LPLL designed with filter
having a pole in s = 0 always becomes locked eventually. We can state that it
has infinite pull-in range. If speed is never an issue, the afore mentioned natural
frequency parameter n can be set very low to make the system minimize the
phase jitter noise. However if speed is crucial a trade off has to be found between
noise and speed. For the application under consideration the bandwidth will be
set low, making it slow and low noise. For quite stable 19 kHz input, a natural
frequency of around 20-50 hz proved to produce a pure input and still provide
a fast enough lock-in process.
22
2.5
2.5.1
After covering the theory of linear PLLs, a discrete model can now be made,
suitable for implementation on a digital signal processor. The fundamental rule
to follow when digitizing a signal or system is the Nyquist criterion. It states:
the sampling frequency has to be at least twice the highest frequency of the
signal if we want to avoid aliasing.
When moving from a continuous to a discrete model a discrete model of a
continuous system, we take one step closer to a working software implementation. However, it is not the final step. The target hardware platform has to
be taken into consideration. The hardware specific issues will be covered in the
next section, right after dealing with the discretized models.
Discrete phase detector
The phase detector is the part where aliasing effects may occur if we are not
careful. Since the phase detector is a multiplier, the output when subject to
two sinusoids is, as defined above,
Uin Uf b
(cos(in f b ) cos(2t + in + f b )).
(2.35)
2
By observing the second term, cos(2t + in + f b ), the sampling frequency
has to be extended. The phase detector doubles the bandwidth requirements.
Therefore, the sampling frequency has to be four times the highest frequency
in the system to avoid aliasing. Depending on the frequency characteristics
of the input we may or may not have to extend the criterion. If it is pure
sinusoid and the resulting aliased frequency content does not affect the following
systems negatively it might suffice with twice the sampling frequency after all.
Problems arise when the aliased contents comes close to DC. It will then affect
the Software Controlled Oscillator (SCO) since the signal passes the discrete
low pass filter.
ud (t) =
2 z1
T z+1
(2.36)
23
1
T
1+
b0 =
21
tan(T /22 )
1
T
1
b1 =
21
tan(T /22 )
After transforming Eq. 2.37 back to the discrete time domain, the following
difference equation is the result,
a0 uf [n] = b0 ud [n] + b1 ud [n 1] + a1 uf [n 1].
(2.38)
The filtered output uf [n] is then used to control the total phase in the SCO. The
expression total phase will be explained below. The analog PI filter described
above and its digital version can be seen in Fig. 2.11.
Amplitude resp.
Magnitude [dB]
100
Analog
Digital
50
0
50
5
10
10
Frequency [Hz]
Phase resp.
10
Phase [deg]
50
0
50
100
5
10
10
Frequency [Hz]
10
Figure 2.11: Analog PI filter and its digital counterpart created using the bilinear transform.
24
2.5.2
Up to this point, neither the LPLL design discussion nor the SPLL extension has
taken any of the hardware related problems into account. When implementing
algorithms for a specific hardware, another layer of problems have to be solved.
In the following subsections the most important problems are outlined and if
possible, dealt with.
Fixed point number representations
Only a finite number can be represented on any hardware platform and this
has to be considered at all time. Floating point hardware have many upsides.
Large numbers or small numbers with high precision can be represented. In
addition algorithms tend to be easier to implement in contrary to a fixed point
environment. However floating point hardware tend to be more costly. The
target for this particular implementation is a less expensive fixed point DSP
platform. Therefore the algorithm has to take that into consideration.
In the SCO case, if we add more phase to that highest value, the variable
overflows and the largest negative number will be the result. One solution to
this is to wrap the phase by subtracting 2 from the total phase when it exceeds
2, because
sin(2 n) = sin((k22 ) n).
Where k is an integer number of revolutions around the unit circle. Another
solution is to take advantage of the overflow effect and use that for wrapping.
By representing the highest positive number by and the most negative number
25
26
Sampled domain
uin(t)
SPLL
uin[n]
ADC
delay
Phase
detector
ufb[n]
SCO(f2[n])
uout[n]
Frequency
multiplier
SCO(f2[n]+Sfm)
Frequency
multiplier
DAC
delay
ADC
delay
Loop
filter
Phase
detector
Slow MA
filter
fm
Parameter
decision
Figure 2.12: An SPLL with secondary oscillator controlled by a phase adjusting subsystem. The dashed line is the adjustments made at specific times decided by the
parameter decision block, and not at system sampling instances.
needed to the total phase defined by Eq. 2.39. With this method of an external
phase adjustment, any phase differences introduced, inside or outside the SPLL
is compensated for. The phase of the final output is therefore an adjusted
DAC
delay
uout(t)
27
(2.40)
But since 2 , the accumulator for the SPLL, can not be touched, we keep a
separate accumulator 3 . It will really be 2 + m since both are set to zero
at start. In plain text, this means that 3 follow 2 in frequency but adds a
small correcting phase shift. The adjusted phase is then fed to a sine generator
that generates the final output.
The parameter decision block is implemented as a threshold device, making
the phase corrections be
m = KL ug [m], ug > |L|
and
m = 0, ug [m] <= |L|
where ug [m] being the filtered output of the secondary phase detector. L being
a predefined threshold. If the phase difference is driven below the threshold,
the filter before the parameter decision block is made slower to suppress jitter
and increase accuracy. A very slow moving average filter worked well for this
implementation. If the error was still not small enough the same routine was
performed again until the phase error was reduced below a certain desired
minimal phase error. Also, if the phase error increased above the threshold
the slow filter was released. The parametric low pass filter was necessary to
maintain speed while the error was large, and to maintain accuracy when the
error became smaller.
Switched filter technique
Another useful application of the secondary phase detector is that the synthesized signal at 1/N times the input frequency can be made more pure. When
locked in frequency and in phase as detected by the external phase detector,
the loop filter in the SPLL can be made slower(more narrow band) once locked
in order to reduce the jitter introduced by the phase detector. If the SPLL
unlocks, the filter is set to its original state and the SPLL begins its pull-in
process to acquire frequency lock again. The results of this operation can be
seen in Fig. 2.13.
28
0.5
1.5
2.5
3.5
4.5
4
x 10
Spectrum of output whithout additional loop filter
0
20
40
60
80
0
0.5
1.5
2.5
3.5
4.5
4
x 10
Spectrum of output with additional filter in place
0
20
40
60
80
0
0.5
1.5
2
2.5
3
Frequency[Hz]
3.5
4.5
4
x 10
Figure 2.13: Improvement in signal quality due to a slower loop filter switched in when
system is locked in frequency.
Chapter 3
Results
This report has up to this point covered the theory of linear phase locked loops
and an additional discussion on how to implement them in software. A working SPLL was designed using the methods presented in the previous chapter.
To gain understanding in how the SPLL operates, tests and experiments were
conducted using Matlab mostly. However, as the SPLL design began to look
promising, the developing process where continued on the target hardware simulation platform.
3.1
Matlab
The Matlab implementation began with allocations of signals and result data
vectors. Main design parameters such as SCO center frequency and filter natural frequency were set. Before simulation the analog filter design were discretized using Matlabs bilinear command. Also the filter constants were
rounded off to emulate the 16-bit fixed point environment on the target hardware. The piece of commented MATLAB program code below show how it was
implemented. It shows the sample-by-sample loop where the SPLL is running.
for(n=2:indEnd-1)
% Phase detector, uin - noisy input sinusoid
ud(n)=uin(n)*ufb(n);
% IIR Filter, fac depends on the accuracy used in the filter
% design, filter constants where rounded off to emulate fixed
% point problem pointed out.
%a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
uf(n)=(b0*ud(n)+b1*(ud(n-1))-a1*uf(n-1))/fac;
% Estimate phase
phi2(n+1)=phi2(n)+w0*Ts+uf(n);
% Non wrapped phase for measurements
phi3(n+1)=phi3(n)+w0*Ts+uf(n);
30
Results
% Wrap phase
if(phi2(n+1)>pi)
phi2(n+1)=(phi2(n+1)-2*pi);
end
% SCO
uout(n+1)=sin(phi2(n+1));
% Feedback
ufb(n+1)=Uf*sin(Kn*phi2(n+1));
end
The signals in the program code can be seen in Fig. 3.1. The center frequency of
the SCO was set to 4 kHz in the example and the input kept a stable frequency
during the first second. After one second the input were stepped up to 4.1 kHz
and the SPLL where allowed to settle. A DC offset can be seen in the signal
uf [n] due to the offset from the center frequency of the SCO.
3.2
3.2.1
When the matlab model proved to be accurate and working, the SPLL was
implemented on a real-time hardware platform, the Analog Devices ADSPBF533 EZ-KIT LITE REV 1.5, based upon the Blackfin 533 DSP.
The EZ-KIT LITE has a high quality audio codec built in, the AD1836 is
also made by Analog Devices. It supports four ADCs and 6 DACs at a maximum sampling frequency of 96 kHz with a resolution of 24-bits. It utilizes high
oversampling and low pass filtering to avoid aliasing. However the same filtering
operation is specified to take up to 1 ms according to the data sheet. At this
point the codec delays, mentioned earlier were discovered. The delay made it
impossible for the SPLL to gain phase lock between the two analog signals(main
input to codec, and output at divided frequency) without an additional phase
correcting system.
3.2.2
Developing environment
The language used for programming the DSP was C exclusively. An excessive
part of the SPLL performance where evaluated on the target hardware using the
debugging tools in VisualDSP++ IDE(Integrated Developing Environment).
In addition, the PC communicated with the DSP via a piece of external
hardware called an In-Circuit Emulator or ICE. ICE hardware is used to debug
the software of an embedded system. The ICE hardware communicated in
turn with the DSP via the JTAG interface. When using the ICE hardware,
debugging went more smooth, stepping code was easy, and data transfer rates
were improved.
31
1
0
1
0
10
15
20
25
30
35
40
30
35
40
30
35
40
30
35
40
30
35
40
30
35
40
10
15
20
25
10
15
20
25
10
15
20
25
0.5
0
0.5
10
15
20
25
10
15
20
25
Figure 3.1: The signals of importance in a discrete linear PLL. It is locked to a noisy input
of 4.1 kHz.
32
3.2.3
Results
Measurements
Figure 3.2: Spectrogram of input and output to the SPLL implemented on a DSP.
33
34
Results
Figure 3.3: Oscilloscope dump of the SPLL input at 19 kHz and the in phase locked half
frequency output.
Figure 3.4: Oscilloscope dump of the FFT of the SPLL output. 10dBV per square.
Chapter 4
Conclusion
The theory of linear PLL were studied and the most relevant parts were outlined
in this report, as well as design methods for implementing one in software for
a real-time application. A working implementation were tested in both Matlab
and in real-time. The report deals with subjects such as control theory, analog
and digital filter design, C programming and writing of a technical report. The
solution to the codec delay problem were custom made, but proved to work well
for the particular application.
The thesis was very rewarding from both a theoretical and a practical point
of view. Knowledge from a broad range of courses studied during my engineering
education was used throughout the work. Nothing was obvious to start with,
and i find the solution to be creative rather than close to optimal.
As a valuable bonus to the thesis work; i was hired by the firm Rubico and
has by the time of writing worked there for over a year.
Appendix A
Program code
The complete source code used in the thesis is not included since it is owned
by the company that offered this thesis. However, questions regarding the
implementation in general is best answered by sending the author an e-mail.
Bibliography
[1] Leon W. Couch III. Digital and analog communication systems. Prentice
hall, sixth edition, 2001.
[2] Roland E. Best. Phase-Locked loops. McGraw-Hill, 1999.
[3] Lennart Ljung Torkel Glad. Reglerteknik, Grundlggande teori. Studentlitteratur, 2nd edition, 1989.
[4] Bertil Thomas. Modern Reglerteknik. Liber, 2nd edition, 1999.
[5] Sven Spanne. LINEARA SYSTEM. KFS AB, 3rd edition, 1995.
[6] Boaz Porat. A course in digital signal processing. Wiley, 1997.
[7] Iain Paterson-Stephens Andrew Bateman. The DSP Handbook. Prentice
hall, 2002.