科斯塔斯锁相环的 matlab 仿真程序:
clear all;close all;
fs = 12e6; %采样频率
ts = 1/fs;
num = 2.5e6; %数据长度
SNR = -15;
real_fc = 3563000; %实信号频率
data = sin(2*pi*real_fc*(0:num-1)*ts+pi/4)+sqrt(10^(SNR/10))*randn(1,num); %科斯塔斯
环的输入信号
fc = 3563010; %本地频率
n = fs/1000; %累积时间为 1ms
nn = [0:n-1];
nf = floor(length(data)/n);% 将输入数据分成 1ms 的多个数据块
wfc = 2*pi*fc; %本地信号
phi_prv = 0;
temp = 0;
frame = 0;
carrier_phase = 0;
phase = 0;
%环路滤波器的参数
c1 = 153.7130;
c2 = 6.1498;
for frame=1:nf
% 产生本地的 sin 和 cos 函数
expcol = exp(j*(wfc*ts*nn+phase));
sine = imag(expcol);
cosine = real(expcol);
x = data((1:n)+((frame-1)*n));
%将数据转换到基带
x_sine = x.*sine;
x_cosine = x.*cosine;
Q = sum(x_sine); %经过滤波器
I = sum(x_cosine);
phase_discri(frame) = atan(Q/I); %得到锁相环的输入
%锁相环
dfrq = c1*phase_discri(frame)+temp; %经过环路滤波器
temp = temp+c2*phase_discri(frame);
wfc = wfc-dfrq*2*pi; %改变本地频率