⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 costas2.m

📁 costas的matlab代码
💻 M
字号:
close all;
clear all;
%**** Initialize the Varibales ******
fs = 12e6; %sampling rate
ts = 1/fs; %time delay
num = 2.5e6;
SNR = -15;
real_fc = 3563000; % real signal frequency
data = sin(2*pi*real_fc*(0:num-1)*ts+pi/4)+sqrt(10^(SNR/10))*randn(1,num); % input signal
fc = 3562800; % local signal

n = fs/1000; % accumulate time (1ms)
nn = [0:n-1];
nf = floor(length(data)/n);% divide input into nf 1ms block signal
wfc = 2*pi*fc; % loacal signal
phi_prv = 0;
temp = 0;
frame = 0;
pull_in_frames = 0;
carrier_phase = 0;
phase = 0;

% ***** Compute the PLL coefficients for the PLL_IN phase ******
[c1,c2] = calculatePLLCoef(0.707,30); %

for frame=1:nf 
% ***** Generate local sine and consine replica *****************
expcol = exp(j*(wfc*ts*nn+phase));
sine = imag(expcol);
cosine = real(expcol);

% ***** Take 1ms of data from the input data **********************
x = data((1:n)+((frame-1)*n));

% **** Convent the signal down to baseband ***********************
x_sine = x.*sine;
x_cosine = x.*cosine;

% ***** Correlate the baseband signal with the three local replica **
Q = sum(x_sine);
I = sum(x_cosine);

% **** Code and Phase discriminators *************************
phase_discri(frame) = atan(Q/I);

pull_in_frames = pull_in_frames+1;
%if pull_in_frames == 30
% [c1,c2] = calculatePLLCoef(0.707,15);
%end

% ******* Phase lock loop (PLL) ************
dfrq = c1*phase_discri(frame)+temp; % remember output of filter is frequency
temp = temp+c2*phase_discri(frame);
wfc = wfc-dfrq*2*pi; % change local frequency(must be -)
dfrq_frame(frame) = wfc; % save the changes of local frequency (also can save dfrq_frame(frame)=dfrq)
phase = wfc*ts*n+phase; % make the phase of each block continue (note: n=5000)
end
plot(dfrq_frame/(2*pi));
hold on
plot(fc,'r');
legend('PLL tracking','Real Carrier frequency');
grid
mean_freq=mean(dfrq_frame)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -