close all;
clc;
clear all;
tic;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%系统函数调用与自编函数调用控制,字符A为系统函数调用;字符B为自编函数调用
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rcos_filter_c='A';
error_bit_expr='A';
qammod_sel='A';
awgn_sel='A';
qamdemod_sel='A';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%仿真序列长度控制
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N=10000; %产生一帧内的0/1序列总比特数
frame=200; %传输的总帧数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%发端成型滤波器设计
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M=16; %16QAM调制
fd=1; %符号采样频率
fs=8; %滤波器采样频率
rolloff=0.8; %滚降系数因子
delay=3; %滤波器半边带数
if strcmp(rcos_filter_c,'A')
[b,den]=rcosine(fd,fs,'sqrt',rolloff,delay); %设计滤波器系数(系统函数调用)
else
b=sqrtcos_filter(rolloff,delay,fs); %设计滤波器系数(自编函数调用)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%载波参数设计
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N_insert=16;
fc=10; %载波频率为信号符号频率10倍
ts=1/(fc*(N_insert-1));
t=0:ts:((2*N+2*delay*fs)*20-1)*ts; %一个符号周期内的载波时间控制
cos_c=cos(2*pi*fc.*t); %载波正弦公式
sin_c=sin(2*pi*fc.*t); %载波正弦公式
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%滤波之前与滤波之后信号信噪比
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SNR_out=[0 1 2 3 4 5 6 7 8 9 10 11 12]; %滤波之后的Eb/N0比特信噪比
SNR_in=SNR_out+10*log10(log2(M))-10*log10(fs); %滤波之前的Es/N0符号信噪比
snr_in=10.^(SNR_in/10); %滤波之前的Es/N0的线性值
snr_out=10.^(SNR_out/10); %滤波之后的Eb/N0的线性值
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%理论误码率公式
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(error_bit_expr,'A')
ber1=berawgn(SNR_out,'qam',M); %理论误码率公式(系统函数调用)
else
P4=2*(1-1/sqrt(M))*qfunc(sqrt(3*snr_out*log2(M)/(M-1))); %单边PAM调制的误符号率
ser1=1-(1-P4).^2; %QAM看作两个PAM调制时的误符号率
ber1=1/log2(M)*ser1; %理论误码率公式-将误符号率除以每符号比特数
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:length(SNR_in)
error_bit_num=0;
for l=1:frame
x=randint(1,N); %产生一帧内的N个0/1比特序列
y=bittosymbol(x,log2(M)); %串并转化,4个二进制序列编程一个十进制数
symbol_in=y; %保存串并转换的十进制数据,便于后面误码率计算
y=BintoGray(y); %二进制转换成格雷码
if strcmp(qammod_sel,'A')
y=qammod(y,M); %16QAM调制(系统函数调用)
else
y=dectocomp(y); %16QAM调制(自编函数调用)
end
y_real=real(y); %取出调制信号实部
y_imag=imag(y); %取出调制信号虚部
y_real=upsample(y_real,fs); %对实部进行fs倍上采样
y_imag=upsample(y_imag,fs); %对虚部进行fs倍上采样
y_real_pulse=conv(b,y_real); %实部信号成型
y_imag_pulse=conv(b,y_imag); %虚部信号成型
y_real_interp=interp(y_real_pulse,fc*N_insert/fs); %成型信号实部加载波
y_imag_interp=interp(y_imag_pulse,fc*N_insert/fs); %成型信号虚部加载波
y_real_carry=y_real_interp.*cos_c;
y_imag_carry=y_imag_interp.*sin_c;
if strcmp(awgn_sel,'A')
s_noise_real=awgn(y_real_pulse,SNR_in(1,k),'measured');
s_noise_imag=awgn(y_imag_pulse,SNR_in(1,k),'measured');
else
s_pow_avg=(y_real_pulse*y_real_pulse'+y_imag_pulse*y_imag_pulse')/length(y_imag_pulse); %计算每个符号的平均功率
sigma=sqrt(s_pow_avg/(2*snr_in(1,k))); %计算每个传输序列的噪声幅度值
s_noise_real=y_real_pulse+sigma*randn(1,length(y_real_pulse)); %实部序列加高斯噪声
s_noise_imag=y_imag_pulse+sigma*randn(1,length(y_imag_pulse)); %虚部序列加高斯噪声
end
s_filter_real_pulse=conv(s_noise_real,b); %实部信号滤波
s_filter_imag_pulse=conv(s_noise_imag,b); %虚部信号滤波
s=zeros(1,N); %新建接受端复数序列数组
s_real_r=downsample(s_filter_real_pulse,fs); %滤波之后实部信号下采样
s_imag_r=downsample(s_filter_imag_pulse,fs); %滤波之后虚部信号下采样
s_r_real=s_real_r((2*delay+1):(end-2*delay)); %去掉由于卷积产生的延时
s_r_imag=s_imag_r((2*delay+1):(end-2*delay)); %去掉由于卷积产生的延时
s=s_r_real+i*s_r_imag; %实部与虚部组成复数信号
if strcmp(qamdemod_sel,'A')
r=qamdemod(s,M); %接收信号解调成符号序列
else
r=demod(s); %将有噪声的星座点映射到标准星座点
r=comptodec(r); %将星座点映射成对应的十进制实数
end
r=Graytobin(r); %格雷编码逆映射
[errorBit(1,k),BER(1,k)]=biterr(symbol_in,r,log2(M)); %计算误码比特数和误码率
error_bit_num=errorBit(1,k)+error_bit_num; %多帧误码比特数的累加
if error_bit_num>100 || l==frame %判断帧循环条件,以加速程序运行速度
BER(1,k)=error_bit_num/(N*l); %多帧误码率计算结果
break;
end
if k==13 && l==1
figure(1);
scatterplot(y);
figure(2);
subplot(211);
plot(y_real(1:400));
subplot(212);
plot(y_imag(1:400));
figure(3);
subplot(211);
plot(y_real_pulse(1:400));
subplot(212);
plot(y_imag_pulse(1:400));d
figure(4);
plot(y_real_carry(400:1400));
hold on
plot(y_real_interp(400:1400),'--r');
figure(5);
subplot(211);
plot(s_filter_real_pulse(1:500));
subplot(212);
plot(s_filter_imag_pulse(1:500));
scatterplot(s);
figure(6);
w=-5:0.1:5;
subplot(211);
hist(s_r_real,w);
subplot(212);
hist(s_r_imag,w);
else
end
end
end
figure(7);
semilogy(SNR_out,BER,'-r*',SNR_out,ber1,'--bo'); %红色的是实际误码率,蓝色是理论误码率曲线
title('16QAM在AWGN信道下的性能');
xlabel('SNR/dB');
ylabel('BER');
legend('实际BER','理论BER');
toc;
- 1
- 2
前往页