clear all;
clc;
IFFT_bin_length=64;%FFT变换的点数
symbols_per_carrier=2048;%每路载波上的符号数
bits_per_symbol=2;
GI=8;%保护间隔的大小
N_snr=60;
snr=2;
N_number=IFFT_bin_length*symbols_per_carrier*bits_per_symbol;
%-----------------------------------
%QPSK调制
X=zeros(1,N_number);
X=randint(1,N_number);
s=(X.*2-1)/sqrt(2);
sreal=s(1:2:N_number);
simage=s(2:2:N_number);
X1=sreal+j.*simage;
%------------------------------------
%串并转换
X2=reshape(X1,IFFT_bin_length,symbols_per_carrier);
%------------------------------------
%IFFT
X3=ifft(X2);
%------------------------------------
%加保护间隔
for k=1:symbols_per_carrier;
for i=1:IFFT_bin_length;
X4(i+GI,k)=X3(i,k);
end
for i=1:GI;
X4(i,k)=X3(i+IFFT_bin_length-GI,k);
end
end
%------------------------------------
%并串转换
X5=reshape(X4,1,symbols_per_carrier*(IFFT_bin_length+GI));
%------------------------------------
%多径干扰
% r=8;
% a=[0.09 0.1 0.09 0.082 0.11 0.091 0.1 0.12]; %多径的幅度
% d=[4 5 7 8 9 10 11 12];
% channel1=[zeros(1,d(1)),a(1)*X5(1:length(X5)-d(1))];
% channel2=[zeros(1,d(2)),a(2)*X5(1:length(X5)-d(2))];
% channel3=[zeros(1,d(3)),a(3)*X5(1:length(X5)-d(3))];
% channel4=[zeros(1,d(4)),a(4)*X5(1:length(X5)-d(4))];
% channel5=[zeros(1,d(5)),a(5)*X5(1:length(X5)-d(5))];
% channel6=[zeros(1,d(6)),a(6)*X5(1:length(X5)-d(6))];
% channel7=[zeros(1,d(7)),a(7)*X5(1:length(X5)-d(7))];
% channel8=[zeros(1,d(8)),a(8)*X5(1:length(X5)-d(8))];
% X6=X5+channel1+channel2+channel3+channel4+channel5+channel6+channel7+channel8;
X6=X5;
%------------------------------------
%加高斯白噪声
Error_ber=[]; %误比特率
for snr_db=0:snr:N_snr
code_power=0;
code_power=[norm(X5)]^2/(length(X5));%信号的符号功率
bit_power=code_power/bits_per_symbol;%比特功率
noise_power=10*log10((bit_power/(10^(snr_db/10))));%噪声功率
noise=wgn(1,length(X5),noise_power,'complex');%产生GAUSS白噪声信号
Tx_data=X6+noise;
%-----------------------------------
Y5=Tx_data;
%-----------------------------------
%串并变换
Y4=reshape(Y5,IFFT_bin_length+GI,symbols_per_carrier);
%------------------------------------
%去保护间隔
for k=1:symbols_per_carrier;
for i=1:IFFT_bin_length;
Y3(i,k)=Y4(i+GI,k);
end
end
Y2=fft(Y3);
%----------------------------------
%并串转换
Y1=reshape(Y2,1,IFFT_bin_length*symbols_per_carrier);
%----------------------------------
%QPSK解调
y_real=sign(real(Y1));
y_image=sign(imag(Y1));
y_re=y_real./sqrt(2);
y_im=y_image./sqrt(2);
Rx=[y_re;y_im];
Y=reshape(Rx,1,N_number);
%------------------------------------
%
dif_bit=s-Y;
ber_snr=0;
for k=1:N_number;
if dif_bit(k)~=0;
ber_snr=ber_snr+1;
end
end;
Error_ber=[Error_ber,ber_snr];
end
%------------------------------------
%计算误码率
BER=zeros(1,length(0:snr:N_snr));
BER=Error_ber./N_number;
BER1=[];
for snr_db=0:snr:N_snr;
BER1=[BER1,(erfc(snr_db/sqrt(2)))/2];
end
%------------------------------------
i=0:snr:N_snr;
semilogy(i,BER,'-*red','linewidth',2);
hold on;
axis([min(i) max(i) 0.00000001 1])
%semilogy(i,BER1,'-ob');
grid on;
%title('QPSK调制解调');