close all
clc
fprintf('OFDM信道估计仿真\n\n')
num_sc = 1200%-----------载波数目 2048简化为正蠢岩1200
num_symbol = 14 %--------------OFDM符号个数
data_symbol = [0,1,2,4,5,6,7,8,9,11,12,13]
pilot_symbol = [3,10]
cp_len = [160,144,144,144,144,144,144,160,144,144,144,144,144,144]
modulation_mode = 16%---------调制方式
q = 20
time_offset = 1 %us
time_offset = ceil(time_offset * 30.72) %20M bandwidth
SNR = 0:2:20%-------------信噪比取值
num_loop = 15%-----------------循环次数
num_ant = 2
num_bit_err=zeros(length(SNR),num_loop)
num_bit_err_dft=zeros(length(SNR),num_loop)
num_bit_err_ls=zeros(length(SNR),num_loop)
MSE=zeros(length(SNR),num_loop)
MSE1=zeros(length(SNR),num_loop)
MSE2=zeros(length(SNR),num_loop)
%%%%%%%%%%%%%%%%%%%%%%%Rx信号产生%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---------------产生发送的随机序列举御————————————————————-
BitsLen = num_sc * length(data_symbol)
BitsTx = randint(1,BitsLen)
%---------------符号调制---------------------------------------—————
Modulated_Sequence=qammod(BitsTx,modulation_mode)
%---------------产生导档散频序列---------------------------------------———
prime_num = primes(num_sc)
prime_num = max(prime_num)
m = 0 : num_sc-1
xq = exp(-j*(pi*q*m.*(m+1)/prime_num))
pilot_symbols = xq( mod(m, prime_num) +1 )
pilot_symbols = pilot_symbols.'
%----------------导频插入-------------------------------------——————
piloted_ofdm_syms = zeros(num_sc, num_symbol)
piloted_ofdm_syms(:, data_symbol + 1) = reshape(Modulated_Sequence, num_sc, length(data_symbol))
piloted_ofdm_syms(:, pilot_symbol + 1) = repmat(pilot_symbols, 1, length(pilot_symbol))
%----------------IFFT变换—————————————————————————
time_signal = sqrt(num_sc) * ifft(piloted_ofdm_syms)
%----------------加循环前缀------------------------------------—————
Tx_data_trans = []
for k = 1 : num_symbol
add_cyclic_signal = [time_signal(num_sc - cp_len(k)+1 : num_sc, k)time_signal(:, k)].'
Tx_data_trans = [Tx_data_trans,add_cyclic_signal]
end
%%%%%%%%%%%%%%%%%%%%%%%主程序循环%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for c1 = 1:length(SNR)
fprintf('\n\n\n仿真信噪比为%f\n\n',SNR(c1))
for num1 = 1:num_loop
%----------------信道处理--------------------------------------
%ADD awgn
Tx_signal_power = sum(abs(Tx_data_trans(:)).^2) / length(Tx_data_trans(:))
noise_var = Tx_signal_power/(10^(SNR(c1)/10))
Rx_data(1, :) = awgn(Tx_data_trans, SNR(c1), 'measured')
Rx_data(2, :) = awgn(Tx_data_trans, SNR(c1), 'measured')
%ADD TO 正时偏
Rx_data(1, :) = [zeros(1,time_offset),Rx_data(1, 1:length(Tx_data_trans)-time_offset),]
Rx_data(2, :) = [zeros(1,time_offset),Rx_data(2, 1:length(Tx_data_trans)-time_offset),]
% %ADD TO 负时偏
% Rx_data(1, :) = [Rx_data(1, time_offset+1:length(Tx_data_trans)),zeros(1,time_offset)]
% Rx_data(2, :) = [Rx_data(2, time_offset+1:length(Tx_data_trans)),zeros(1,time_offset)]
%----------------信号接收、去循环前缀、FFT变换-----------------
%Ant0
total_len=0
for k=1 : num_symbol
Rx_signal_matrix(:, k) = Rx_data(1, total_len+cp_len(k)+1 : total_len+cp_len(k)+num_sc).'
total_len = total_len+cp_len(k)+num_sc
end
Rx_carriers_ant0 = fft(Rx_signal_matrix)/sqrt(num_sc)
%Ant1
total_len=0
for k=1 : num_symbol
Rx_signal_matrix(:, k) = Rx_data(2, total_len+cp_len(k)+1 : total_len+cp_len(k)+num_sc).'
total_len = total_len+cp_len(k)+num_sc
end
Rx_carriers_ant1 = fft(Rx_signal_matrix)/sqrt(num_sc)
%----------------导频和数据提取--------------------------------
Rx_pilot_ant0 = Rx_carriers_ant0(:, pilot_symbol+1)
Rx_data_ant0 = Rx_carriers_ant0(:, data_symbol+1)
Rx_pilot_ant1 = Rx_carriers_ant1(:, pilot_symbol+1)
Rx_data_ant1 = Rx_carriers_ant1(:, data_symbol+1)
%----------------导频位置LS信道估计------------------------———
pilot_patt = repmat(pilot_symbols, 1, length(pilot_symbol))
pilot_esti_ant0 = Rx_pilot_ant0.*conj(pilot_patt)
pilot_esti_ant1 = Rx_pilot_ant1.*conj(pilot_patt)
%----------------LS估计的信道系数平铺———————————————
LS_channel_coeff_ant0 = [repmat(pilot_esti_ant0(:, 1), 1, length(data_symbol)/2), ...
repmat(pilot_esti_ant0(:, 2), 1, length(data_symbol)/2)]
LS_channel_coeff_ant1 = [repmat(pilot_esti_ant1(:, 1), 1, length(data_symbol)/2), ...
repmat(pilot_esti_ant1(:, 2), 1, length(data_symbol)/2)]
%----------------导频位置DFT信道估计----------------------------
Tx_pilot_estimate_ifft_ant0 = ifft(pilot_esti_ant0)
Tx_pilot_estimate_ifft_ant1 = ifft(pilot_esti_ant1)
stem(1:1200, Tx_pilot_estimate_ifft_ant0(:,1))
grid on
h_len = cp_len(2)
Tx_pilot_estimate_ifft_ant0(h_len+1 : num_sc-h_len, :) = 0
Tx_pilot_estimate_dft_ant0 = fft(Tx_pilot_estimate_ifft_ant0)
Tx_pilot_estimate_ifft_ant1(h_len+1 : num_sc-h_len, :) = 0
Tx_pilot_estimate_dft_ant1 = fft(Tx_pilot_estimate_ifft_ant1)
%----------------DFT估计的信道系数平铺———————————————
DFT_channel_coeff_ant0 = [repmat(Tx_pilot_estimate_dft_ant0(:, 1), 1, length(data_symbol)/2),...
repmat(Tx_pilot_estimate_dft_ant0(:, 2), 1, length(data_symbol)/2)]
DFT_channel_coeff_ant1 = [repmat(Tx_pilot_estimate_dft_ant1(:, 1), 1, length(data_symbol)/2),...
repmat(Tx_pilot_estimate_dft_ant1(:, 2), 1, length(data_symbol)/2)]
%----------------ZF OR MRC EQ----------------------
Tx_data_estimate_dft = (Rx_data_ant0.*conj(DFT_channel_coeff_ant0) + Rx_data_ant1.*conj(DFT_channel_coeff_ant1))...
./((abs(DFT_channel_coeff_ant0).^2) + (abs(DFT_channel_coeff_ant0).^2))
Tx_data_estimate_ls = (Rx_data_ant0.*conj(LS_channel_coeff_ant0) + Rx_data_ant1.*conj(LS_channel_coeff_ant1))...
./((abs(LS_channel_coeff_ant0).^2) + (abs(LS_channel_coeff_ant1).^2))
%----------------DFT符号解调------------------------------------
demod_in_dft=Tx_data_estimate_dft(:).'
demod_out_dft=qamdemod(demod_in_dft,modulation_mode)
%----------------LS符号解调------------------------------------
demod_in_ls=Tx_data_estimate_ls(:).'
demod_out_ls=qamdemod(demod_in_ls,modulation_mode)
%----------------误码率的计算-----------------------------------
for i=1:length(BitsTx)
if demod_out_dft(i)~=BitsTx(i)
num_bit_err_dft(c1,num1)=num_bit_err_dft(c1,num1)+1
end
if demod_out_ls(i)~=BitsTx(i)
num_bit_err_ls(c1,num1)=num_bit_err_ls(c1,num1)+1
end
end
end
end
BER_dft=mean(num_bit_err_dft.')/length(BitsTx)
BER_ls=mean(num_bit_err_ls.')/length(BitsTx)
%%%%%%%%%%%%%%%%%%%a%%%%%%%%主程序循环换结束%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure
semilogy(SNR,BER_dft,'-mp',SNR,BER_ls,'-k+')
xlabel('SNR')
ylabel('BER')
legend('DFT信道估计','LS信道估计')
title('OFDM系统的LS和DFT信道估计')
grid on
你好 希望可以帮到你%本程序用于OFDM基本原理仿真
%数据调制采用QPSK
clear allclc
%*****************参数设置部分**********************
SNR=10 %信噪比取值,dB为单位
fl=128 %设置FFT长度
Ns=6 %设置一个帧结构中OFDM信号的个数
para=128%设置并行传输的子载波个数
gl=32 %设置保护时隙的长度
%***************发送端部分*************************
Signal=rand(1,para*Ns*2)>0.5 %产生0,1随机数列,符号个数为para*2*Ns
%for i=1:para
%for j=1:Ns*2
% SigPara(i,j)=Signal(i*j)错误的,作野雹者是傻X
%串并转换,将随机产生的二进制矩阵变换为行数为para,列谨贺数为2*Ns的矩阵
%end
%end
SigPara=reshape(Signal,para,2*Ns)
%***********进行QPSK数据调制,将数据分为两个通道**************
for j=1:Ns
ich(:,j)=SigPara(:,2*j-1)
qch(:,j)=SigPara(:,2*j)
end
kmod=1./sqrt(2)
ich1=ich.*kmod
qch1=qch.*kmod
x=ich1+qch1.*sqrt(-1) %产生复信号
y=ifft(x) %通过傅里叶反变换,将频域数据转换为时域数据
ich2=real(y)%I信道取变换后的实部
qch2=imag(y) %I信道取变换后的虚部
%*******************插入保护间祥脊派隔*******************
ich3=[ich2(fl-gl+1:fl,:)ich2]
qch3=[qch2(fl-gl+1:fl,:)qch2]
%******************并串转换*********************
ich4=reshape(ich3,1,(fl+gl)*Ns)
qch4=reshape(qch3,1,(fl+gl)*Ns)
%*****************形成复数发射数据***************
TrData=ich4+qch4.*sqrt(-1)
ReData=awgn(TrData,SNR,'measured')
%接收端 移去保护时隙
idata=real(ReData)
qdata=imag(ReData)
idata1=reshape(idata,fl+gl,Ns)
qdata1=reshape(qdata,fl+gl,Ns)
idata2=idata1(gl+1:gl+fl,:)
qdata2=qdata1(gl+1:gl+fl,:)
%********FFT*****************
Rex=idata2+qdata2*sqrt(-1)
ry=fft(Rex)
ReIchan=real(ry)
ReQchan=imag(ry)
ReIchan=ReIchan/kmod
ReQchan=ReQchan/kmod
%*******QPSK逆映射*********
for j=1:Ns
RePara(:,2*j-1)=ReIchan(:,j)
RePara(:,2*j)=ReQchan(:,j)
end
ReSig=reshape(RePara,1,para*Ns*2)
%符号抽样判决
ReSig=ReSig>0.5
figure
subplot(2,1,1)
stem(ReSig(1:1000))
legend('输出数据')
grid
subplot(2,1,2)
stem(Signal(1:1000))
legend('输入数据')
grid
%end of script file
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)