QPSK基础与多径信道Matlab仿真
OFDM基础与多径信道Matlab仿真
多径信道:信号通过多条路径抵达接收端,由散射等引起,是时延。
时变信道:信道状态随时间变化与发送序列对应,分为慢衰落信道和快衰落信道,由运动引起,是时变。
close all;clc;
%% 参数设置
SNR=1:20; %信噪比变化范围
snr=10.^(SNR/10); %将信噪比转化成直角坐标
M=64;
N=100;
pathnum=3;
l_cp=pathnum+1;
w=zeros(2*M,N);
ww=zeros(2*M,N);
%% 初始序列生成qpsk调制
for ii=1:length(SNR)
a=randi([0 1],1,2*M*N);
a2= reshape(a,log2(4),[])';
a10= bi2de(a2);
xt=pskmod(a10,4,pi/4);
x=reshape(xt,M,N); %M×N
x1=zeros(M+l_cp,1);
x2=zeros(M,1);
for jj=1:N
h=channel_generation(pathnum,M) %信道设置
x2=x(:,jj);
x1=[x2(M-l_cp+1:M);x2]; %+cp x1=[M+1_cp×1]
%% 时变多径信道
yqq=zeros(M,1);
yqql=zeros(M,1);
cw3=1;
for cw1=1:M
cw2=cw3;
for cw4=pathnum:-1:1
yqq(cw1)=x1(cw2+2)*h(cw4,cw1);
yqql(cw1)=yqql(cw1)+yqq(cw1);
cw2=cw2+1;
end
cw3=cw3+1;
end %经过时变信道+去cp
%% 均衡矩阵
H=zeros(M,M);
for iv=1:M
H1=zeros(1,M);
H1(1)=h(1,iv);
jv=2;
for kv=M:-1:M-pathnum+2
H1(kv)=h(jv,iv);
jv=jv+1;
end
H(iv,:)=circshift(H1,iv-1); %每次求出一行(均按第一行形式)在循环移位
end
%% awgn
[m,n]=size(yqql);
N0=1/2/snr(ii);
N0_dB=10*log10(N0);
ni=wgn(m,n,N0_dB);
ys=yqql+ni;
%% 检测解调
% %迫0均衡
x_dect=pinv(H)*ys; %均衡 Y=H·X→X=invH×Y inv(A)*B=B/A;inv(B)*A=B\A
xxx=reshape(x_dect,[],1); %并串变换
yj=pskdemod(xxx,4,pi/4);
De_data1 = reshape(yj,[],1);
De_data2 = de2bi(De_data1,2);
w(:,jj)= reshape(De_data2',[],1);
% MMSE均衡
[nn,mm]=size(H*H');
W=H'*pinv(H*H'+1/SNR(ii)*eye(nn,mm));
wx_dect=W*ys;
wwx=reshape(wx_dect,[],1); %并串变换
wyj=pskdemod(wwx,4,pi/4);
wDe_data1 = reshape(wyj,[],1);
wDe_data2 = de2bi(wDe_data1,2);
ww(:,jj)= reshape(wDe_data2',[],1);
end
q=reshape(w,1,2*M*N);
[number1,BER_ZF(ii)] = symerr(a,q); %计算错误比特数和误码率
wq=reshape(ww,1,2*M*N);
[number1,BER_MMSE(ii)] = symerr(a,wq); %计算错误比特数和误码率
end
BER_ZF
BER_MMSE
%% 绘制图形
figure;
semilogy(SNR,BER_ZF,'-r*');hold on;
semilogy(SNR,BER_MMSE,'-g*');hold on;
% text(10,0.01,'MMSE');
axis([-1,20,10^-4,1]);
title('误码性能分析');
xlabel('信噪比SNR(dB)');ylabel('误码率BER');
close all;clc;
%% 参数设置
SNR=1:20; %信噪比变化范围
snr=10.^(SNR/10); %将信噪比转化成直角坐标
M=64;%Nfft
N=100; %符号数
pathnum=2 ;
l_cp=pathnum+1; %保护间隔长度
BER_S=zeros(1,length(SNR)); %误码率
BER_Ss=zeros(1,length(SNR)); %误码率
%H=[];y6=[];y_dect=[];
%w=zeros(2*M,N);
ws=zeros(2*M,N);
%% 初始序列生成qpsk调制
for ii=1:length(SNR)
a=randi([0 1],1,2*M*N);
a2= reshape(a,log2(4),[])';
a10= bi2de(a2);
xt=pskmod(a10,4,pi/4);
x=reshape(xt,M,N); %M×N
x1=zeros(M+l_cp,1);
x2=zeros(M,1);
for jj=1:N
h=channel_generation(pathnum,M) %信道设置
% hh=(randn(pathnum,1)+1i*randn(pathnum,1))*sqrt(1/2/pathnum);
% for tcv=1:M
% h(:,tcv)=hh;
% end %时不变信道信道设置-测试Y和H的生成
x2=x(:,jj);
x2i=ifft(x2)*sqrt(M);%ifft
x1=[x2i(M-l_cp+1:M);x2i]; %+cp x1=[M+1×1]
%% 时变多径信道
yqq=zeros(M,1);
yqql=zeros(M,1);
cw3=1;
for cw1=1:M
cw2=cw3;
for cw4=pathnum:-1:1
yqq(cw1)=x1(cw2+2)*h(cw4,cw1);
yqql(cw1)=yqql(cw1)+yqq(cw1);
cw2=cw2+1;
end
cw3=cw3+1;
end %经过时变信道+去cp
%% 均衡矩阵
H=zeros(M,M);
for iv=1:M
H1=zeros(1,M);
H1(1)=h(1,iv);
jv=2;
for kv=M:-1:M-pathnum+2
H1(kv)=h(jv,iv);
jv=jv+1;
end
H(iv,:)=circshift(H1,iv-1); %每次求出一行(均按第一行形式)在循环移位
end
%% awgn
[m,n]=size(yqql);
N0=1/2/snr(ii);
N0_dB=10*log10(N0);
ni=wgn(m,n,N0_dB);
ys=yqql+ni;
%% 检测解调
%% 均衡1(相位)
% HH=fft(h,M) ;
% y6= fft(ys)/sqrt(M);
% y_dect=y6.*conj(HH); %信道估计+均衡
% y7=reshape(y_dect,[],1); %并串变换
% yj=pskdemod(y7,4,pi/4); %qpsk解调
% De_data1 = reshape(yj,[],1);
% De_data2 = de2bi(De_data1,2);
% w(:,jj)= reshape(De_data2',[],1); %转换同输入a形式,便于误码率计算
%% 均衡2 Y=Hd*H*Hid*X+Hd*N
[sss,sssss]=size(H);
% fft(H(:,1));
dftmtx(sss);
Hs=dftmtx(sss)*H*dftmtx(sss)'
y6s= fft(ys)/sqrt(M);
y_dects=pinv(Hs)*y6s; % 均衡*HS^-1
y7s=reshape(y_dects,[],1);
yjs=pskdemod(y7s,4,pi/4);
De_data1s = reshape(yjs,[],1);
De_data2s = de2bi(De_data1s,2);
ws(:,jj)= reshape(De_data2s',[],1);
end
qs=reshape(ws,1,2*M*N);
[number1,BER_Ss(ii)] = symerr(a,qs); %计算错误比特数和误码率
end
BER_Ss
%% 绘制图形
figure
semilogy(SNR,BER_Ss,'-g*');hold on;
%text(10,0.01,'MMSE');
axis([-1,20,10^-4,1]);
title('误码性能分析');
xlabel('信噪比SNR(dB)');ylabel('误码率BER');
channel_generation为时变信道产生函数。最终当信道变化慢时信道矩阵Hs理应仍为对角矩阵,但本程序结果并不明显,并且误码率变化好像也有悖理论分析,仍需学习纠正完善。
两种仿真非常类似,只是OFDM多了其应有的部分,H与Y输出的方式是相同的。
相关博文
- QPSK基础与多径信道Matlab仿真
- OFDM基础与多径信道Matlab仿真