%实现OFDM传输的仿真程序
para=128; %并行子信道的个数
fftlen:128; %FFT的长度
paradata=reshape(seldata,para,nd
*m1);
%QPSK调制
[ich,qch]=qpskmod(paradata,para,nd,m1);
kmod=1/sqrt(2);
ichl=ich.*kmod;
qchl=qch.*kmod;
%In叩(离散傅里叶反变换)
X=ichl+qchl.*i:
y=ifft(x);
ich2=real(y);
qch2=imag(y);
%插入保护间隔
[ich3,qch3]=giins(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%衰减计算
spow=suln(ich3.2+qch3.“2)/nd./para;
attn=0.郑敬5*spow*sr/br*10.“(.ebn0/10);扒档
attn=sqrt(attn);
%高斯自信道
[ich4,qeh4]=eomb(ich3,qch3,attn);
%接收部分
%去除保护间隔
[ieh5,,qeh5]=girem(ich4,qch4,fftlen2,gilen,
nd);
%FFr(离散傅里叶变换)
IX=ich5+qch5.*i:
ry=fit(Ⅸ);
ich6=real(ry);
qch6=imag(ry);
%春丛乱QPSK解调
ieh7=ich6./kmod;
qch7=qch6./kmod;
[derrtxtata]=qpskdemod(ich7,qch7,para,nd,m1);
%并串变换
demodatal=reshape(demodata,I,para*nd*rnl);
%比特误码率(BER)
bit—errors=find(seldata~=demodatal);
bit—error—count 2 size(bit—e/TOES,2);
total—bits=size(demodatal,2);
bit—error—rate=bit—error—count/total—bits;
fprintf(7%f\n’,bit—eITor—rate)
%end offile
程序运行结果,输出误码率为:
>>0.037109
clear allclose 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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)