Alright, this code uses a slicer to calculate error:
clear
clc
load RRC.mat
rf_signal = cos(2*pi*(1:5000)*0.1);
N = length(rf_signal);
phi_inc = zeros(1, N);
bb = zeros(1, N);
bb_f = zeros(1, N);
I_f = zeros(1, N);
Q_f = zeros(1, N);
I_r = zeros(1, N);
Q_r = zeros(1, N);
error = zeros(1, N);
error_f = zeros(1, N);
%loop filter coefficients
alpha = 0.1;
b = alpha;
a = ;
fs = 1.0E8;
fc = 0.1;
for i = 1:N
% Downconverting to Baseband
bb(i) = rf_signal(i).*exp(j*2*pi*fc*i);
% Filtering
bb_f = filter(RRC, bb(1:i));
I_f(i) = real(bb_f(i));
Q_f(i) = imag(bb_f(i));
% Slicing
if I_f(i) > 0
I_r(i) = 1;
else
I_r(i) = -1;
end
if Q_f(i) > 0
Q_r(i) = 1;
else
Q_r(i) = -1;
end
% Error
error(i) = I_f(i) .* Q_r(i) - Q_f(i) .* I_r(i);
% Loop Filter
error_f = filter(b, a, error(1:i));
phi_inc(i+1) = phi_inc(i) - error_f(i);
end
figure
subplot 221
plot(real(bb))
title('I Channel')
subplot 222
plot(imag(bb))
title('Q Channel')
subplot 223
plot(I_f)
title('I Channel Filter')
subplot 224
plot(Q_f)
title('Q Channel Filter')
figure; plot(phi_inc); title('Phase');
figure; plot(error_f); title('Error');
I didn't feed the phase back to NCO just to observe the error and phase signals. They look acceptable and have some life. Plus, if I add instead of subtract error I get an opposite signals. However, I tried to control NCO through phase and frequency and none got me a good result. But I feel that error signal without feedback is correct.
I attached the RRC coeff so that you can try this code if you like.