Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Matlab code for a simple Phase lock loop(PLL)

Status
Not open for further replies.

yksdsu

Newbie level 5
Newbie level 5
Joined
Sep 2, 2006
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,331
phase locked loop matlab

hai buddies,
I am providing a simple phase lock loop implementation in matlab.. Try this, I have simulated a long back... I will try provide you the theory of phase lock loop in the time being..
 

Your code is close but had a few errors. Here is the working code.
close all;
clear all;
reg1 =0;
reg2 =0;
reg3 = 0;

eta =sqrt(2)/2;
theta =2*pi*1/100;
Kp = [(4*eta*theta)/(1+2*eta*theta+theta^2)];
Ki = [(4*theta^2)/(1+2*eta*theta+theta^2)];
d_phi_1 = 1/20;
n_data = 100;

for nn =1:n_data
phi1= reg1 +d_phi_1;
phi1_reg(nn) = phi1;

s1 =exp(j*2*pi*reg1);
s2 =exp(j*2*pi*reg2);

s1_reg(nn) =s1;
s2_reg(nn) =s2;

t =s1*conj(s2);
phi_error =atan(imag(t)/real(t))/(2*pi);
phi_error_reg(nn) = phi_error;
sum1 =Kp*phi_error + phi_error*Ki+reg3;

reg1_reg(nn) =reg1;
reg2_reg(nn) = reg2;
reg1 =phi1;

reg2=reg2+sum1;
reg3 =reg3+phi_error*Ki;
phi2_reg(nn) =reg2;
end

figure(1)
plot(phi1_reg);
hold on
plot(phi2_reg,'r');
hold off;
grid on;
title('phase plot');
xlabel('Samples');
ylabel('Phase');


figure(2)

plot(phi_error_reg);
title('phase Error of phase detector');
grid on;
xlabel('samples(n)');
ylabel('Phase error(degrees)');


figure(3)
plot(real(s1_reg));
hold on;
plot(real(s2_reg),'r');
hold off;
grid on;
title('Input signal & Output signal of VCO');
xlabel('Samples');
ylabel('Amplitude');
axis([0 n_data -1.1 1.1]);
 
Re: phase locked loop matlab

Hi, I tried to model PLL in SIMULINK, Since there is no component available for phase detector in SIMULINK I couldn't build the model. I have found that a Mixer can be used instead of a phase detector. Yet I couldn't get an output. Appreciate it very much if you can help me on this. Thanks!
 

Your code is close but had a few errors. Here is the working code.
close all;
clear all;
reg1 =0;
reg2 =0;
reg3 = 0;

eta =sqrt(2)/2;
theta =2*pi*1/100;
Kp = [(4*eta*theta)/(1+2*eta*theta+theta^2)];
Ki = [(4*theta^2)/(1+2*eta*theta+theta^2)];
d_phi_1 = 1/20;
n_data = 100;

for nn =1:n_data
phi1= reg1 +d_phi_1;
phi1_reg(nn) = phi1;

s1 =exp(j*2*pi*reg1);
s2 =exp(j*2*pi*reg2);

s1_reg(nn) =s1;
s2_reg(nn) =s2;

t =s1*conj(s2);
phi_error =atan(imag(t)/real(t))/(2*pi);
phi_error_reg(nn) = phi_error;
sum1 =Kp*phi_error + phi_error*Ki+reg3;

reg1_reg(nn) =reg1;
reg2_reg(nn) = reg2;
reg1 =phi1;

reg2=reg2+sum1;
reg3 =reg3+phi_error*Ki;
phi2_reg(nn) =reg2;
end

figure(1)
plot(phi1_reg);
hold on
plot(phi2_reg,'r');
hold off;
grid on;
title('phase plot');
xlabel('Samples');
ylabel('Phase');


figure(2)

plot(phi_error_reg);
title('phase Error of phase detector');
grid on;
xlabel('samples(n)');
ylabel('Phase error(degrees)');


figure(3)
plot(real(s1_reg));
hold on;
plot(real(s2_reg),'r');
hold off;
grid on;
title('Input signal & Output signal of VCO');
xlabel('Samples');
ylabel('Amplitude');
axis([0 n_data -1.1 1.1]);


Hello, I read your code but I don't understand about Kp and Ki. Could you tell me more about that. And you use d_phi_1 = 1/20, therefore phi1 will linear (not suitable with real).Thank you so much!
 

Kp and Ki are two parameters about second-order filter.
you can find the ralation between KP Ki and aquisition bandwidth in gardner's book
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top