NCO and Phase Detector Modeling in MatLab: Part I

advertisement
NCO and Phase Detector Modeling in MatLab: Part I
NCO
A digital voltage controlled oscillator (VCO) or numerically controlled oscillator
(NCO) generates a waveform of frequency, fo, based on an input control voltage, M, and
the length of an accumulator, K. The sinusoid is generated up with the use of a lookup
table that has an amplitude value for every phase value. The number of points in the
lookup table is proportional to the length of the accumulator:
L 2 K
(1)
And the spacing between the phases can be determined by:
 
2
2K
(2)
There are two methods that I thought of employing to emulate multiple
frequencies. The first method was to use the relationship:
  2ft
(3)
Then by combining (2) and (3), it is obvious that the time interval can be set to acquire
the required frequency:
t 
1
2K f
(4)
However, the problem arises in defining the time interval for higher frequencies.
The precision of the amplitude tends to decrease as the time interval increases.
The other method that was employed was the analogy to elementary physics. If an
individual wishes to attain a high velocity, he can either travel a certain distance for a
short period of time, or travel a long distance over a decent period of time. The frequency
of the waveform can be modified by taking predetermined steps in the lookup table up to
2pi radians. The step is determined by M¸ and is called the frequency selecting word. An
increase in M yields an increase in the resulting frequency. The highest frequency that
can be attained is one half the sampling frequency, reading two entries in the table. The
value of the frequency is dependent upon M by the following relation:
f M
fs
2K
(4)
The domain of f is 1 < M < 2K-1
The
highest
frequency
waveform
for
a
16-bit
shown:
Figure 1 NCO output of maximum frequency of 16-bit accumulator length
accumulator
is
The limitations of the MatLab simulation are the 16-bit accumulator length. An
accumulator length of 32 bits would have resulted in more entries, and was not feasible in
MatLab. Another problem that was faced was expanding the matrix of the desired entries
so to allow a proper visualization of the change in frequency. A hard coded algorithm
was generated for the f/2 frequency, but a generalized algorithm is needed for the
expansion. Looking forward to the DSP-FPGA integrated architecture implementation,
the lookup table was not designed as a straight phase-to-amplitude table. Rather the first
four terms were used in the Taylor polynomial to calculate sin(x):
sin x  x 
x3 x5 x7


3! 5! 7!
(5)
which generated an error of 0.0821 at a maximum x of 2pi radians. This will be
implemented in a FPGA. A few tweaks are needed with the implementation of a lookup
table. Primarily, the design of a more efficient lookup table, which uses the properties of
the sine function to have phase values up to pi/2 radians. In other words, to generate a
complete sinusoid cycle, only distinct values up to pi/2 radians are needed. From pi/2 to
pi, the table is read backwards. From pi to 3pi/2, the values are read off forwards but
multiplied by -1. From 3pi/2 to 2pi, the values are read backwards but multiplied by -1.
Phase Detector
There are two types of phase detectors, the ideal and sinusoidal phase detector. The ideal
phase detector simply takes the error of the two input phases as a function of time and
generates the difference:
 (t )  1 (t )   2 (t )
(6)
A graph of the error for x = 2cos(2pi7t + 7t) and y = 2cos(2pi7t + 8t) where 7t, 8t are the
respective phase changes.
Figure 2 Ideal phase detector
After the ideal phase detector portion of the loop, the signal will be averaged out by a
loop filter which will then go back to the NCO. However, the ideal phase detector has not
been implemented practically because of the necessity to implement the acos and asin
functions. However, for this design, just as for the NCO, it will be attempted to use a
Taylor polynomial with decent error in the FPGA.
The sinusoidal phase detector simply implements utilizes the relationship:
sin Asin B 
cos(A  B)  cos(A  B)
2
(7)
to generate the cosine of the error instead of the error itself. However, in the output itself
there are multiple frequencies present such as the sum of the frequencies, as
shown:
Figure 3 The sinusoidal phase detector output.
It is apparent from Figure 3 that there are many frequencies present, including the
individual input frequencies, the sum of the frequencies, and the difference of the
frequencies. To isolate the difference frequency, the waveform must first be passed
through a low-pass filter and then the resulting sinusoid must then be passed through the
loop filter to generate a constant voltage.
Download