%%主程序
clc
clear
close all
% 定义参数
fd=250*10^6; %码元速率250M
fs=2500*10^6; %滤波器采样率
fc=2500*10^6; %载波频率2.5G
f=10000*10^6; %对载波采样
data_len=10000; %数据长度
sym_len=data_len/4; %码元序列长度
init_pos=zeros(1,sym_len);%均衡前的各数据位置
error_k = 0;
error = 0;
M_QAM=16;%QAM数
SNR=1:12;%白噪声信噪比
k0=1; k1=1; k2=1; k3=1; k4=1; k5=1; k6=1; k7=1; k8=1; k9=1; k10=1; k11=1; k12=1; k13=1; k14=1; k15=1;
% ------------------------------------------------------------
bit_tx=randint(1,data_len);%产生随机序列
echo off; %关闭所有命令文件的显示方式
rec_qam16=QamMod(bit_tx,M_QAM); %方形16QAM调制
base_rec=base_shape(fd,fs,f,rec_qam16); %基带成型滤波
for i=1:length(SNR) %信噪比从1dB到12dB计算误码率
SNR_=i
%方形映射16QAM
rf_rec_qam16=CarrierMod(fc,f,base_rec); %载波调制
rf_rec_qam16_n=awgn(rf_rec_qam16,SNR(i),'measured'); %加噪声(信道)
[rec_qam16_rx, base_rec_rx]=CarrierDemod(fd,fs,fc,f,rf_rec_qam16_n); %载波解调
bit_rec_rx=QamDemod(rec_qam16_rx,M_QAM); %MQAM解调
qam16_data_rec(i,:)=rec_qam16_rx; %(i,:):矩阵中第i行的所有数值
end
% 基带波形
N=200;
n=1:N;
t=1:N*10;
%发送端波形
figure;
stem(n,bit_tx(n));
title('发送序列');
figure('Name','发送端基带信号');
subplot(211);
plot(t,real(base_rec(t))); title('映射-Q路');
subplot(212);
plot(t,imag(base_rec(t))); title('映射-I路');
%接收端波形
figure;
stem(n,bit_rec_rx(n));
title('接收序列');
figure('Name','接收端基带信号');
subplot(211);
plot(t,real(base_rec_rx(t)));
title('映射-Q路');
subplot(212);
plot(t,imag(base_rec_rx(t)));
title('映射-I路');
% 接收端星座图
figure('Name',[num2str(M_QAM),'QAM接收端星座图']);
i=6;
for j=1:length(qam16_data_rec(i,:))
if (real(qam16_data_rec(i,j)) > 2) && (imag(qam16_data_rec(i,j)) > 2)
%0
flagx0(k0) = real(qam16_data_rec(i,j));
flagy0(k0) = imag(qam16_data_rec(i,j));
k0 = k0+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.r'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 2) && (imag(qam16_data_rec(i,j)) > 2) && (0 < real(qam16_data_rec(i,j)))
%1
flagx1(k1) = real(qam16_data_rec(i,j));
flagy1(k1) = imag(qam16_data_rec(i,j));
k1 = k1+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.b'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 0) && (imag(qam16_data_rec(i,j)) > 2) && (-2 < real(qam16_data_rec(i,j)))
%3
flagx3(k3) = real(qam16_data_rec(i,j));
flagy3(k3) = imag(qam16_data_rec(i,j));
k3 = k3+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.g'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < -2) && (imag(qam16_data_rec(i,j)) > 2) && (-4 < real(qam16_data_rec(i,j)))
%2
flagx2(k2) = real(qam16_data_rec(i,j));
flagy2(k2) = imag(qam16_data_rec(i,j));
k2 = k2+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.y'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < -2) && (imag(qam16_data_rec(i,j)) < 2) && (-4 < real(qam16_data_rec(i,j))) && (0 < imag(qam16_data_rec(i,j)))
%6
flagx6(k6) = real(qam16_data_rec(i,j));
flagy6(k6) = imag(qam16_data_rec(i,j));
k6 = k6+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.r'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 0) && (imag(qam16_data_rec(i,j)) < 2) && (-2 < real(qam16_data_rec(i,j))) && (0 < imag(qam16_data_rec(i,j)))
%7
flagx7(k7) = real(qam16_data_rec(i,j));
flagy7(k7) = imag(qam16_data_rec(i,j));
k7 = k7+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.b'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 2) && (imag(qam16_data_rec(i,j)) < 2) && (0 < real(qam16_data_rec(i,j))) && (0 < imag(qam16_data_rec(i,j)))
%5
flagx5(k5) = real(qam16_data_rec(i,j));
flagy5(k5) = imag(qam16_data_rec(i,j));
k5 = k5+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.g'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 4) && (imag(qam16_data_rec(i,j)) < 2) && (2 < real(qam16_data_rec(i,j))) && (0 < imag(qam16_data_rec(i,j)))
%4
flagx4(k4) = real(qam16_data_rec(i,j));
flagy4(k4) = imag(qam16_data_rec(i,j));
k4 = k4+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.y'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 4) && (imag(qam16_data_rec(i,j)) < 0) && (2 < real(qam16_data_rec(i,j))) && (-2 < imag(qam16_data_rec(i,j)))
%12
flagx12(k12) = real(qam16_data_rec(i,j));
flagy12(k12) = imag(qam16_data_rec(i,j));
k12 = k12+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.r'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 2) && (imag(qam16_data_rec(i,j)) < 0) && (0 < real(qam16_data_rec(i,j))) && (-2 < imag(qam16_data_rec(i,j)))
%13
flagx13(k13) = real(qam16_data_rec(i,j));
flagy13(k13) = imag(qam16_data_rec(i,j));
k13 = k13+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.b'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 0) && (imag(qam16_data_rec(i,j)) < 0) && (-2 < real(qam16_data_rec(i,j))) && (-2 < imag(qam16_data_rec(i,j)))
%15
flagx15(k15) = real(qam16_data_rec(i,j));
flagy15(k15) = imag(qam16_data_rec(i,j));
k15 = k15+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.g'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < -2) && (imag(qam16_data_rec(i,j)) < 0) && (-4 < real(qam16_data_rec(i,j))) && (-2 < imag(qam16_data_rec(i,j)))
%14
flagx14(k14) = real(qam16_data_rec(i,j));
flagy14(k14) = imag(qam16_data_rec(i,j));
k14 = k14+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.y'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < -2) && (imag(qam16_data_rec(i,j)) < -2) && (-4 < real(qam16_data_rec(i,j))) && (-4 < imag(qam16_data_rec(i,j)))
%10
flagx10(k10) = real(qam16_data_rec(i,j));
flagy10(k10) = imag(qam16_data_rec(i,j));
k10 = k10+1;
plot(real(qam16_data_rec(i,j)),imag(qam16_data_rec(i,j)),'.r'); %实部横坐标,虚部纵坐标,第i行代表信噪比为i的数据
end
hold on;
if (real(qam16_data_rec(i,j)) < 0) && (imag(qam16_data_rec(i,j)) < -2) && (-2 < real(qam16_data_rec(i,j))) && (-4 < imag(qam16_data_rec(i,j)))
%11