clc
clear all;
close all;
%% 系统参数
B = 4e6; % 带宽
T = 256e-6; % 符号持续时间
miu = B/T; % 调频率
D = B*T; % 时宽带宽积
fs = 4e6; % 采样频率
over_fs = fs*2; % 过采样的采样频率
chirp_len = floor(T*fs); % 离散化信号长度(符号采样点数)
over_len = floor(T*over_fs); % 过采样的符号采样点数
%% 基带信号产生
p = rand(1,chirp_len)*2*pi; % 均匀相位序列
k0 = 0;
k1 = 1;
a = raylrnd(1/sqrt(2),[1,chirp_len]); % 瑞利幅度序列
t = 0:1/fs:T-1/fs; % 时间轴
over_t=0:1/over_fs:T-1/over_fs; % 过采样的时间轴
chirp = exp(j*pi*miu*over_t.^2); % 正调频率chirp信号
%% 信息调制
bit = 4; % 每个符号携带的比特数
M = 2^bit; % CCSK调制阶数
Num_x = 20; % 总的信息比特数
delta_len = floor(over_len/M) % CCSK调制的分段长度
CN0db = 40:0.5:46;
%EbN0db = 7; % Eb/N0
%SNR = EbN0db-10*log10(chirp_len)+10*log10(bit);
SNR = CN0db-10*log10(over_fs);
loop_times = 10000;
fal_cnt = 0;
CNW_refer = a.*exp(j*pi*miu*t.^2).*exp(j*k0*p); % 升类噪声chirp信号
over_refer = ifft([fft(CNW_refer),zeros(1,chirp_len)]); % 过采样的升类噪声chirp信号
for ii = 1:Num_x
trans_carrier(:,ii) = imag(over_refer); % 参考信号
end
trans = reshape(trans_carrier,1,[]); % 并串转换,生成发射信号
trans_I = [zeros(1,700),trans,zeros(1,400)];
%% 成型滤波
L = 8; % 内插倍数
tr_inter_I = reshape([trans_I;zeros(L-1,length(trans_I))],1,[]); % 内插0之后的信号
[yf,tf] = rcosine(1,L,'fir/sqrt'); % 成型滤波器系数
[tr_filter_I,to] = rcosflt(tr_inter_I,1,L,'filter/Fs',yf); % 成型滤波
tr_shape_I = tr_filter_I(L*3+1:length(tr_filter_I)-L*3)';
%% 加入频偏(上变频)
fc = 20e6;
fd = [0 100e3 400e3 800e3]; % 多普勒频偏值
tt = 0:1/(L*over_fs):(length(tr_shape_I)-1)/(L*over_fs); % 时间轴2
%% 加噪声
for ll = 1:length(SNR)
for mm = 1:length(fd)
doppler = exp(j*2*pi*(fd(mm)+fc)*tt);
tr_doppler = tr_shape_I.*cos(2*pi*(fd(mm)+fc)*tt);
dec_cnt = 0;
for jj = 1:loop_times
tr_noised = awgn(tr_doppler,SNR(ll),'measured');
%% 下变频
tr_I = tr_noised.*cos(2*pi*fc*tt);
tr_Q = tr_noised.*sin(2*pi*fc*tt);
%% 匹配滤波
[rx_match_I,to] = rcosflt(tr_I,1,L,'filter/Fs',yf); % 匹配滤波
rx_cept_I = rx_match_I(L*3+1:length(rx_match_I)-L*3)';
rx_comp_I = rx_cept_I(1:L:length(rx_cept_I));
[rx_match_Q,to] = rcosflt(tr_Q,1,L,'filter/Fs',yf); % 匹配滤波
rx_cept_Q = rx_match_Q(L*3+1:length(rx_match_Q)-L*3)';
rx_comp_Q = rx_cept_Q(1:L:length(rx_cept_Q));
%% 信号检测
peak_find0_I = xcorr(rx_comp_I,real(chirp)); % 捕获匹配滤波输出
peak_find1_I = xcorr(rx_comp_I,imag(chirp)); % 捕获匹配滤波输出
peak_find0_Q = xcorr(rx_comp_Q,imag(chirp)); % 捕获匹配滤波输出
peak_find1_Q = xcorr(rx_comp_Q,real(chirp)); % 捕获匹配滤波输出
peak_find0_full = (peak_find0_I-peak_find0_Q).^2+(peak_find1_I+peak_find1_Q).^2;
peak_find0 = peak_find0_full(length(rx_comp_I)-over_len+1:end);
Pfa = 1e-4;
N0 = sum(peak_find0(over_len+1:2*over_len))/over_len/2;
%thre = erfcinv(2*Pfa)*N0+N0; % 检测门限
thre = N0*(-2*log(Pfa));
syn_sequ0 = find(peak_find0>thre); % 搜索高于门限的峰
delta_len1 = 700-round(fd(mm)/B*over_len);
sum_initial = 1;
sum_thre = 1;
sum1 = sum_initial;
for kk = 1:Num_x
if peak_find0(kk*over_len+delta_len1)>thre
sum1 = sum1+1;
else
sum1 = sum1-1;
end
if sum1>sum_thre
dec_cnt = dec_cnt+1;
break
else
if sum1<1
dec_cnt = dec_cnt;
%sum1 = sum_initial;
break
end
end
end
end
d_num(mm,ll) = dec_cnt
end
end
pd = d_num/loop_times
plot(CN0db,pd(1,:),'-o');hold on
plot(CN0db,pd(2,:),'->');
plot(CN0db,pd(3,:),'-s');
plot(CN0db,pd(4,:),'-p');
grid on
xlabel('C/N0(db)');
ylabel('Pd');
legend('fd=0','fd=100kHz','fd=400kHz','fd=800kHz');