-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphase_locked_loop.m
More file actions
40 lines (30 loc) · 882 Bytes
/
Copy pathphase_locked_loop.m
File metadata and controls
40 lines (30 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function y = phase_locked_loop(Ztotal, Kp, Ki, Kd)
% QEA FINAL RUSSIAN WEATHER SATELLITE!
% Zi = input1; %will get this value from the USRP
% Zq = input2; %will get this value from the USRP
%
% Zq = 1i*Zq;
% Ztotal = Zi + Zq; %this is a complex number Zi + iZq
y = zeros(size(Ztotal));
phi = 0;
oldPhi = 0;
sumPhi = 0;
errors = zeros(size(Ztotal));
for k = 1:length(Ztotal)
y(k) = Ztotal(k)*exp(-1i*phi);
realPart = real(y(k));
imagPart = imag(y(k));
signReal = sign(realPart);
signImag = sign(imagPart);
realPart = signImag*realPart;
imagPart = signReal*imagPart;
phi = -1*(realPart - imagPart)/2;
sumPhi = sumPhi + phi;
phi = Kp*phi + Ki*(sumPhi) + Kd*(phi - oldPhi);
oldPhi = phi;
errors(k) = phi;
end
% bits = Ztotal.*exp(1i*phi);
% firstBits = sign(real(bits));
% secondBits = sign(imag(bits));
end