⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dpll.m

📁 DPLL SIMULATION in MATLAB
💻 M
字号:
% A second order DPLL design
% Block diagram
%             +---+  e    +-----------+      y
%    x ------>| + |------>|   H1(z)   |---------+  
%             +---+       +-----------+         |
%               ^                               |
%               |   z     +-----------+         |
%               |---------|  H2(z)    |<--------+
%                         +-----------+
% 
clear all

% number of bits in the quantizer
b = 15;
q = 1/2^b;
phase = 0;
amplitude = 5;

% DPLL parameters, from closed-loop transfer function
g1 = 0.0147;
g2 = 0.0001;

% gain of the phase detector
Gpd = 1;
% VCO gain
Gvco = 1;
G1 = g1/(Gpd*Gvco);
G2 = g2/(Gpd*Gvco);
G = G1 + G2;

% input (reference) signal
t = 0:0.0001: 1;
f = 10;
%x = ones(1, 1000);     % step response only
if mod(t,100) == 0
	%phase = phase + rand()*360 ;
	phase = phase + 100 ;
	if phase > 360
		phase = (phase-360);
	end
end

%x = sin (amplitude * exp(j * (2*pi*f*t + phase) ) );
x = amplitude * sin (2*pi*f*t + phase )
%x = AWGN(temp_sine,50);    %AWGN(X,SNR) adds white Gaussian noise to X. The SNR is in dB. 
%x = chirp(t,0,1,150);


figure
plot(x);

% quantize x into b bits (Can take the following 3 lines out to compare
% with and without quantizer)
signs = sign(x);
signs(~signs) = ones(size(signs(~signs)));
x = q .* floor(abs(x./q) + 0.5) .* signs;

y(1) = (G1 + G2) * x(1);
z(1) = y(1);

% quantize y and z into b bits (Can take the following 6 lines out to
% compare with and with quantizer)
sign_y = sign(y(1));
sign_y(~sign_y) = ones(size(sign_y(~sign_y)));
y(1) = q .* floor(abs(y(1)./q) + 0.5) .* sign_y;

sign_z = sign(z(1));
sign_z(~sign_z) = ones(size(sign_z(~sign_z)));
z(1) = q .* floor(abs(z(1)./q) + 0.5) .* sign_z;

e(1) = x(1) - z(1);

for i = 2 : length(x)
    % phase detector
    e(i) = x(i) - z(i-1);
    
    % loop filter H1(z), an IIR filter
    y(i) = G * e(i) - G1 * e(i-1) + y(i-1);
    
    % Can take the following 3 lines out to compare
    % with and without quantizer
    sign_y = sign(y(i));
    sign_y(~sign_y) = ones(size(sign_y(~sign_y)));
    y(i) = q .* floor(abs(y(i)./q) + 0.5) .* sign_y;
    
    % VCO filter, an IIR accumulator
    z(i) = z(i-1) + Gvco * y(i);
    
    % Can take the following 3 lines out to compare
    % with and without quantizer
    sign_z = sign(z(i));
    sign_z(~sign_z) = ones(size(sign_z(~sign_z)));
    z(i) = q .* floor(abs(z(i)./q) + 0.5) .* sign_z;
end



figure
plot(e);

figure
plot(y);

% equivalent close-loop transfer function, the ideal case
Z = tf('z',1);
H = (0.0148*Z - 0.0147)/(Z^2 -1.9852*Z +0.9853);
step = ones(1,1000);
step_response = lsim(H, step, 1:length(step));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -