Phase and Frequency detection • Detection of sinusoidal signal characteristics • Phase • Frequency • Usually involves some type of feedback. • Typically use a local oscillator (DDS) for a comparison.
The Analogy PLL
The digital World • Frequency detection
The digital World • Frequency detection • Key components • Local oscillator • Period detection
Frequency • Frequency detection • Key components • Local oscillator • Period detection • Edge detection
Frequency • Frequency detection • Key components • Local oscillator • Period detection • Edge detection • Frequency compensation
Frequency • Frequency detection • Key components (frequency detection) • Local oscillator • Period detection • Edge detection • Frequency compensation • +/- delta • Look at code and simulation. • counter.v, dds.v, edge_detect.v, period_detect.v, freq_detect.v
The digital World • Phase detection • We want a fixed phase relationship between the local osc and input. • In the digital world we can control the phase of the local osc. • Not the case with an analog VCO. • Need to measure the phase difference.
Phase difference • Phase difference detection. • Similar to period detection. • Requires another oscillator and a counter.
Phase lock • Phase difference compensation. • Integrate phase difference to determine phase correction. • Accumulated phase difference vs frequency? • Code and simulations • delta_phase_detect.v, phase_lock_osc.v
Phase ~ frequency • When the frequency of the l.o. did not match the frequency of the input signal: • The phase correction showed a slope. • This slope is proportional to the frequency offset. • k (d/dt) (phase correction) = freq offset • We should be able to measure this slope to compensate for the frequency offset.
Manual Calculation Δt =39.475-22.035 =17.44 us Δn =1744 clock cycles Δϕ =-4864 — 32640 =27776 (16bp4) = 1736 The frequency offset is estimated as Δϕ / Δn =1736/1744 Δf =.9954~1
In Hardware • Δϕ / Δn =1736/1744 • Requires division? • We can choose the interval in which to perform the estimation. • Use a power of 2 (e.g. 4,16,32 ...). • Just need to make sure the phase_corr does not wrap.
Frequency Correction • The frequency correction is an accumulation of the freq difference. • If f_lo is 100 and the delta is 2, we need to hold 2. f_lo = 100 + 2. • As soon as f_lo = 100 + 2, delta = 0. • Updated code and simulation • slope_detect.v
Phase Detection • Given an input signal • x in (t) = cos(2 π f in t + ϕ ) • How do we determine the angle • θ = 2π f in t + ϕ • With just the amplitude? • What would you do in matlab?
Matlab • In MATLAB you might do the following • y(t) = y r (t) + y i (t) = hilbert(x) • in which • y r (t) = x(t) • Now that we have real and imag • θ = atan2( y i ,y r )
Matlab
Two Key Operations • Hilbert Transform • atan2
Hilbert Transform • real sinusoid to complex sinusoid. • Think about the desired filter response.
Hilbert Transform • real sinusoid to complex sinusoid. • Think about the desired filter response. • Remember our half pass filter.
Hilbert Transform • Can be implemented with a complex half pass filter that extends from 0 to fs/2. • Similar to our previous half pass filter that extended from – fs/4 to fs/4. • Multiplier Free implementation*. *M. Kumm and M. S. Sanjari , “Digital Hilbert Transformers for FPGAbased Phase- Locked Loops,” in Field Programmable Logic and Applications, 2008. FPL 2008. International Conference on, 2008, pp. 251 – 256.
Hilbert Transform Implementation • Block design and simulation • (non graded HW) • Simulation
atan2 function
atan2 function • In a sense we have already done this in the fpga. • We want to find the rotational angle that takes us from (x,y) to y=0. • Assume x is positive. • If x isn’t negate both x and y and add pi to the result. • Now iterate: • If y is positive add theta and rotate x,y clockwise (-theta, remember we are going backwards compared to cos and sin). • If y is negative sub theta and rotate x,y counter-clockwise. • The final value of theta_approx will be the atan2 (assuming the pi is included if neg x). • The final value of (x) will be magnitude sqrt(x 2 +y 2 )/.60725 • post multiply by .60725 to get actual mag. • Simulation
Phase detection • Block Diagram
Simulation
Recommend
More recommend