clear all;
clc;
carrier_count=2047;%总的子载波数
bits_per_symbol=2;%用4进制调制
symbols_per_carrier=1;
I=6;
pilot_index=[1:I:2047];%导频坐标
N=2047;%总载波数
[M_M M]=size(pilot_index);%导频子载波数
N_number=carrier_count*symbols_per_carrier*bits_per_symbol;%总二进制数
fd=0.01;%假设多普勒频移为0
ts=1;%采样周期
CP=100;%保护时间
C=5;%符号数
circle=1;%循环次数取平均
SNR_number=7;%SNR数量
err_rate=ones(C,SNR_number);
err_rate_ls=ones(C,SNR_number);
ERR_RATE=ones(circle,SNR_number);
ERR_RATE_ls=ones(circle,SNR_number);
averr=ones(1,SNR_number);
averr_ls=ones(1,SNR_number);
mse=ones(circle,SNR_number);
arrmse=ones(1,SNR_number);
mse_ls=ones(circle,SNR_number);
arrmse_ls=ones(1,SNR_number);
h=zeros(N,1);
for time=1:circle;
h_sv=[];
h_sv_ls=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%生成信道
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
K=6;%稀疏度为6
delay=[1 10 30 60 90 99];%各径延迟
% h(delay,1)=1+1*1i;
a=[1 -0.9 -4.9 -8.0 -7.8 -23.8]; %多径的幅度
RLchannel=rayleighchan(ts,fd,delay,a);
RLchannel.StorePathGains=1;
test = ones(C,1);%测试向量
filter(RLchannel,test);
h_RL=RLchannel.PathGains;%提取瑞利信道
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%生成信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ii=[1 C 2 3 4];%循环次数
%X_bit=randint(N_number,1);%产生随机2进制信号
X_msg=randint(N,1,4);
%%%%%%%%%%%%%%%QPSK调制%%%%%%%%%%%%%%%%%%%%
X=pskmod(X_msg,4);
% X_qpsk=(X_bit.*2-1)/sqrt(2);
% Xreal=X_qpsk(1:2:N_number);
% Ximage=X_qpsk(2:2:N_number);
% X=Xreal+j.*Ximage;%待发射信号
x0=ifft(X);%待传输信号
for i=1:carrier_count;
x(i+CP,1)=x0(i,1);
end
for i=1:CP;
x(i,1)=x0(i+carrier_count-CP,1);
end %加CP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%信道
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for hh=1:K;
h(1+delay(hh))= h_RL(ii,hh);%信道的冲击响应
end
H=fft(h);
y_r=filter(h,1,x);%收到的信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for SNR_index=1:SNR_number;%信噪比7个点
y = awgn(y_r,(SNR_index-1)*5,'measured');%加噪声;
%y=y_r;
%%%%%%%%%%%%
% symbol_power=[norm(CP+carrier_count)]^2/(length(CP+carrier_count));%信号的符号功率
% %bit_power=var(Tx_data);
% noise_power=10*log10((bit_power/(10^(snr_db/10))));%噪声功率
% noise=wgn(CP+carrier_count,1,noise_power,'complex');%产生GAUSS白噪声信号
%%%%%%%%%%%%
y0=y(CP+1:CP+carrier_count,1);%去CP
Y=fft(y0);
if ii==1||ii==C
%Y2=X.*H;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
% y2=ifft(Y2);
%norm(Y-Y2)/norm(Y)
X_pilot=X(pilot_index,1);
Y_pilot=Y(pilot_index,1);
H_R=Y_pilot./X_pilot;
% H2=H(pilot_index);
% ttttt=norm(H2-H_R)/norm(H2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%CS信道估计%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fai=fft(eye(2047));
phi=Fai(pilot_index,:);
%check=max(abs(H_R-phi*h))
v=H_R;
m=K;
%[h_esti lamda]=omp1(phi,2048,v,m);
h_esti=OMP_ofdm(v,phi,K);
mse(time,SNR_index)=sum(abs(h-h_esti).^2);
H_esti=fft(h_esti);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%LS信道估计%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
H_esti_ls=zeros(N,1);
H_esti_ls(1)=H_R(1);
lsm=1;
for lsn=2:N;
if lsn<pilot_index(lsm)||lsn==pilot_index(lsm)
H_esti_ls(lsn)=H_R(lsm-1)+(lsn-pilot_index(lsm-1))/I*(H_R(lsm)-H_R(lsm-1));
elseif lsm==M
H_esti_ls(lsn)=H_R(lsm);
else
lsm=1+lsm;
H_esti_ls(lsn)=H_R(lsm-1)+(lsn-pilot_index(lsm-1))/I*(H_R(lsm)-H_R(lsm-1));
end
end
h_esti_ls=ifft(H_esti_ls) ;
mse_ls(time,SNR_index)=sum(abs(h-h_esti_ls).^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X_esti=Y./H_esti;%%估计的导频加信号的值
X_esti_ls=Y./H_esti_ls;
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %QPSK解调
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% X_msg_esti=pskdemod(X_esti,4);
% [err_number,err_rate(ii,SNR_index)]=symerr(X_msg,X_msg_esti);
h_sv=[h_sv h_esti];
h_sv_ls=[h_sv_ls h_esti_ls];
else
h_esti=h_sv(:,SNR_index)+(h_sv(:,SNR_index+SNR_number)-h_sv(:,SNR_index))*(ii-1)/(C-1);%线性插值
H_esti=fft(h_esti);
X_esti=Y./H_esti;%%估计的导频加信号的值
h_esti_ls=h_sv_ls(:,SNR_index)+(h_sv_ls(:,SNR_index+SNR_number)-h_sv_ls(:,SNR_index))*(ii-1)/(C-1);%线性插值
H_esti_ls=fft(h_esti_ls);
X_esti_ls=Y./H_esti_ls;%%估计的导频加信号的值
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%QPSK解调
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X_msg_esti=pskdemod(X_esti,4);
X_msg_esti_ls=pskdemod(X_esti_ls,4);
[err_number,err_rate(ii,SNR_index)]=symerr(X_msg,X_msg_esti);
[err_number_ls,err_rate_ls(ii,SNR_index)]=symerr(X_msg,X_msg_esti_ls);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for kk=1:SNR_number;
ERR_RATE(time,kk)=mean(err_rate(:,kk));
ERR_RATE_ls(time,kk)=mean(err_rate_ls(:,kk));
end
end
for kk=1:SNR_number;
averr(kk)=mean(ERR_RATE(:,kk));
averr_ls(kk)=mean(ERR_RATE_ls(:,kk));
avmse(kk)=mean(mse(:,kk));
avmse_ls(kk)=mean(mse_ls(:,kk));
end
t=0:5:5*(SNR_number-1);
figure(1);
semilogy(t,averr,'-.r');
hold on;
xlabel('SNR(单位:dB)');
ylabel('SER');
grid on;
figure(3);
semilogy(t,averr_ls,'-.g');
hold on;
xlabel('SNR(单位:dB)');
ylabel('SER');
grid on;
%legend('CS Channel Estimation SER Internal=6','LS Channel Estimation SER Internal=6');
figure(2);
semilogy(t,avmse,'-or');
hold on;
xlabel('SNR(单位:dB)');
ylabel('MSE');
grid on;
figure(4);
semilogy(t,avmse_ls,'-og');
hold on;
xlabel('SNR(单位:dB)');
ylabel('MSE');
grid on;
%legend('CS Estimation MSE Internal=6','LS Estimation MSE Internal=6');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
clear all;
clc;
carrier_count=2047;%总的子载波数
bits_per_symbol=2;%用4进制调制
symbols_per_carrier=1;
I=12;
pilot_index=[1:I:2047];%导频坐标
N=2047;%总载波数
[M_M M]=size(pilot_index);%导频子载波数
N_number=carrier_count*symbols_per_carrier*bits_per_symbol;%总二进制数
fd=0.01;%假设多普勒频移为0
ts=1;%采样周期
CP=100;%保护时间
C=5;%符号数
circle=1000;%循环次数取平均
SNR_number=7;%SNR数量
err_rate=ones(C,SNR_number);
err_rate_ls=ones(C,SNR_number);
ERR_RATE=ones(circle,SNR_number);
ERR_RATE_ls=ones(circle,SNR_number);
averr=ones(1,SNR_number);
averr_ls=ones(1,SNR_number);
mse=ones(circle,SNR_number);
arrmse=ones(1,SNR_number);
mse_ls=ones(circle,SNR_number);
arrmse_ls=ones(1,SNR_number);
h=zeros(N,1);
for time=1:circle;
h_sv=[];
h_sv_ls=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%生成信道
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
K=6;%稀疏度为6
delay=[1 10 30 60 90 99];%各径延迟
% h(delay,1)=1+1*1i;
a=[1 -0.9 -4.9 -8.0 -7.8 -23.8]; %多径的幅度
RLchannel=rayleighchan(ts,fd,delay,a);
RLchannel.StorePathGains=1;
test = ones(C,1);%测试向量
filter(RLchannel,test);
h_RL=RLchannel.PathGains;%提取瑞利信道
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%生成信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ii=[1 C 2 3 4];%循环次数
%X_bit=randint(N_number,1);%产生随机2进制信号
X_msg=randint(N,1,4);
%%%%%%%%%%%%%%%QPSK调制%%%%%%%%%%%%%%%%%%%%
X=pskmod(X_msg,4);
% X_qpsk=(X_bit.*2-1)/sqrt(2);
% Xreal=X_qpsk(1:2:N_number);
% Ximage=X_qpsk(2:2:N_number);
% X=Xreal+j.*Ximage;%待发射信号
x0=ifft(X);%待传输信号
for i=1:carrier_count;
x(i+CP,1)=x0(i,1);
end
for i=1:CP;
x(i,1)=x0(i+carrier_count-CP,1);
end %加CP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%信道
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for hh=1:K;
h(1+delay(hh))= h_RL(ii,hh);%信道的冲击响应
end
H=fft(h);
y_r=filter(h,1,x);%收到的信号
%%%%
评论17