Wrlccywrlfh
- 2
- 2
- Homework Statement
- Find the relationship that gives Ki as a function of all the parameters to obtain the correct impulse response
at a phase step regardless of the rate and the number of samples per symbol
- Relevant Equations
- H(s) = (Kd(Kp*s + Ki)) / (s^2 + Kd(Kp*s + Ki))
Kp = 2*Xi*wn / K
Ki = (wn)^2 / K
Hello everyone, it's not really for my homework (because I'm not at school anymore) but I'm new and I don't know how to start a new forum. I've never done automatic before and I need help.
I have a 2nd ordre PLL on MATLAB, with an NCO and a PI corrector; the PLL works via the Mid/End algorithm (that's part is ok). I need to find the link between the theoretical formulas and their values in the code to find the value of the gain Ki, and possibly that of Kp if it's not correct. Unfortunately, I can't find the formulas so that my gains are always adapted when I change the rate or the number of samples per symbol, while I'm sure that it exists. Xi and wn are fixed. I thing the problem is K (Kd * Knco), which must not be correct, but I know that sum(g) is.
Here's the code :
I hope I'm clear. Please, be nice with me, English is not my native language and I don't know a lot about PLL
I have a 2nd ordre PLL on MATLAB, with an NCO and a PI corrector; the PLL works via the Mid/End algorithm (that's part is ok). I need to find the link between the theoretical formulas and their values in the code to find the value of the gain Ki, and possibly that of Kp if it's not correct. Unfortunately, I can't find the formulas so that my gains are always adapted when I change the rate or the number of samples per symbol, while I'm sure that it exists. Xi and wn are fixed. I thing the problem is K (Kd * Knco), which must not be correct, but I know that sum(g) is.
Here's the code :
Matlab:
% Modulation
rng(0);
rate = 1e6;
fe = 80e6;
N_SR = fe / rate;
nb_bits = 1000;
Tb = 1/rate;
Ts = 1/fe;
% =========== No need help part ===========
bitstream = 2 * randi([0 1], 1, nb_bits) - 1;
nrz = kron(bitstream, ones(1, N_SR));
h = 0.7; L = 1; v = 0:(L*N_SR - 1);
g = (1 / (2 * L * N_SR)) * (1 - cos(2 * pi * v / (L * N_SR)));
s_filtered = conv(nrz, g);
phi = 2 * pi * h * cumsum(s_filtered) / N_SR;
S_ideal = exp(1i * phi);
phi_ideal = unwrap(angle(S_ideal));
S = exp(1i * phi_ideal);
% Phase offset
phi_offset = pi;
S = S * exp(1i * phi_offset);
% Demodulation
fc = 1e6;
omegac = fc / (fe/2);
order = 90;
f_reject = 1.2e6 / (fe/2);
f = [0 omegac f_reject 1];
a = [1 1 0 0];
w = [1 100];
b = firpm(order, f, a, w);
S_real_filtered = filter(b, 1, real(S));
S_imag_filtered = filter(b, 1, imag(S));
S_filtered = S_real_filtered + 1i * S_imag_filtered;
phi_rec = unwrap(atan2(imag(S_filtered), real(S_filtered)));
freq_inst = diff(phi_rec);
freq_inst(end+1) = freq_inst(end);
freq_inst = freq_inst / (h*pi);
% Filter (LP)
filtre_PB = fir1(10, 0.1);
freq_filtered = conv(freq_inst, filtre_PB, 'same');
% ============= Need help part =============
Xi = sqrt(2)/2; % Fixed
wn = rate*1e-3; % Fixed
Kd = sum(g);
K0 = Ts/Kd; % Not used
Knco = Kd/K0; % Not used
Kp = (2*Xi*wn) / (Kd);
Ki = (wn)^2 / (Kd*fe);
incr0 = 1/(N_SR);
incr = incr0; % Initial release of the VCO
alpha = 0; % alpha to detect when there is a new symbol
Aq_mid = 0;
Aq_end = 0;
alpha_prec = 0;
top_symb = 0;
S_end = 0;
S_mid = 0;
S_end_prec = 0;
S_mid_prec = 0;
k = 1;
err_ph = 0;
sum_err_ph = 0;
err_phi_rad = 0;
incr_hist = 0;
nco_sync = zeros(1, length(phi_rec)-1);
bitsync = zeros(1, length(phi_rec)-1);
decalage = zeros(1, length(phi_rec)-1);
for n = 1:length(phi_rec)-1
alpha = alpha + incr;
top_symb = 0;
% Update Mid/End
if alpha >= 0.5 && alpha_prec <0.5
S_mid_prec = S_mid;
S_mid = Aq_mid;
Aq_mid = s_filtered(n);
else
Aq_mid = Aq_mid + s_filtered(n);
end
if alpha >= 1.0
alpha = mod(alpha,1.0);
S_end_prec = S_end;
S_end = Aq_end;
Aq_end = s_filtered(n);
top_symb = 1;
k = k+1;
else
Aq_end = Aq_end + s_filtered(n);
end
if top_symb == 1
nco_sync(n) = 1;
if (S_end_prec >0 && S_end <=0 )
err_ph(k) = S_mid/N_SR;
elseif (S_end_prec <= 0 && S_end > 0 )
err_ph(k) = -S_mid/N_SR;
else
err_ph(k) = err_ph(k-1);
end
sum_err_ph = sum_err_ph + err_ph(k);
incr = incr0 - Kp*err_ph(k) - Ki*sum_err_ph;
end
alpha_prec = alpha;
end
% Bode
% Transfer function (open)
p = tf('s');
G = tf([Kd*Kp Kd*Ki], [1 Kd*Kp Kd*Ki]);
figure;
subplot(2,1,1);
bode(G, {0, 1e7}); % Plage de fréquences de 1 kHz à 10 MHz
title('Bode diagram - open loop');
grid on;
subplot(2,1,2);
bode(H, {0, 1e7});
title('Bode diagram - closed loop');
grid on;
% Error phase plot
figure;
plot((0:length(err_ph)-1)*Tb/1e-6,err_ph);
% title('Différence bitsync - nco');
title('PLL phase error');
xlabel('Time (us)');
ylabel('Phase error');
grid on;