close all
clear all
%% ====================仿真基本参数====================
f_delta = 15e3; %子载波间隔15KHz
pilot_interval = 5; %插入导频间隔
M = 2; %每星座符号比特数,对应QPSK调制
ce_method = 1; %信道估计方法,1和2分别对应LS和MMSE
symbol_len = 1000; %OFDM符号数
p=1;
%% ====================仿真可配置参数====================
awgn_en = 0; %信道类型,为1表示AWGN信道,为0表示 ETU信道
fd = 300; %最大多普勒扩展
sta_num = 10; %仿真次数统计
num_carriers = input('请输入子载波数:'); %子载波数
cp_length = input('请输入循环前缀长度:'); %循环前缀长度
%% ====================仿真过程=======================
% 产生0-1随机序列 =>(交织)=> 符号映射 => 串并转换 => 插入导频
% => IFFT变换 => 加循环前缀CP => 并串转换 => (信道编码) => 多径信道% => 加AWGN => (信道译码)=> 串并转换 =>去循环前缀CP => 去导频 =>
% FFT变换 / 信道估计与频域均衡 => 并串转换 => 解映射 =>(解交织)
% => 计算误码率 => 绘制误码率曲线
% ==================================================
%% ================产生随机序列=======================
sr0=sourcebits(symbol_len*num_carriers*M);%随即序列长度为子载波数目×ofdm符号数×M
%% 卷积编码
[sr,tre1,tblen,p]=conv(sr0);
%% ================交织=======================
sr = interlace(sr,M);
%% ================符号映射=======================
ak=qpsk_modulation(sr);
%% ================串并转换=======================
parallel_ak = reshape(ak,num_carriers,symbol_len/p);
%% ================插入导频=======================
pilot_bit = ones(num_carriers*2,1);%生成导频序列
[insert_pilot_out,count,pilot_seq] = ...
insert_pilot_f(parallel_ak,pilot_bit,pilot_interval,num_carriers);
%% ================IFFT变换=======================
OFDMmoddata_out = ifft (insert_pilot_out,num_carriers)*sqrt(num_carriers);%离散傅立叶变换点数为子载波数
%% ================加循环前缀CP=======================
CP_output=Inset_CP(OFDMmoddata_out,cp_length);
%% ================并串转换=======================
[m,n] = size(CP_output);%并行数据的长度为加cp后的数据矩阵的元素总数m*n
OFDMmoddata_out_serial = reshape(CP_output,m*n,1);
%% ================多径信道=======================
%信道参数为36.101协议指定
SNR = 0:2:34; % 用于检测的信噪比值
for snr_index = 1:length(SNR)
fs = num_carriers * f_delta;
ts = 1/fs;
tau = [0,50,120,200,230,500,1600,2300,5000]/(10^9);
pdb = [-1.0 ,-1.0 ,-1.0 ,0, 0, 0, -3.0, -5.0, -7.0];
chan = rayleighchan(ts,fd,tau,pdb);
chan.ResetBeforeFiltering = 0;
Channel_data = OFDMmoddata_out_serial;
%经过多径信道
if (awgn_en == 1)
Add_Multipath_data = Channel_data;
else
if (fd ~= 0)
Add_Multipath_data = filter(chan,Channel_data);
end
end
Add_noise_data = awgn(Add_Multipath_data,SNR(snr_index),'measured');
%% ================串并转换,去循环前缀CP=======================
Delete_CP_out = Delete_CP(Add_noise_data,cp_length,num_carriers,p);
%% ================去导频,取出导频矩阵=======================
[DeletePolit_out,H_ifft] = Get_pilot(Delete_CP_out,pilot_interval,num_carriers,p);
%% ====================直接解调,无信道补偿=======================
fft_out = fft (DeletePolit_out)/sqrt(num_carriers);
%并串转换
serial_ak_1 = reshape(fft_out,num_carriers*symbol_len/p,1);
%解映射
demod_sr_1 = qpsk_demodulation(serial_ak_1);
%解交织
demod_sr_1 = delete_interlace(demod_sr_1,M);
% %viterbi译码
demod_sr_1 = viterbi(demod_sr_1,tblen,tre1);
%% ==================信道估计与频域均衡=======================
estimation_output = ls_estimation(DeletePolit_out,H_ifft,pilot_seq,num_carriers,p);
%并串转换
serial_ak_2 = reshape(estimation_output,num_carriers*symbol_len/p,1);
%解映射
demod_sr_2 = qpsk_demodulation(serial_ak_2);
%解交织
demod_sr_2 = delete_interlace(demod_sr_2,M);
%viterbi译码
demod_sr_2 = viterbi(demod_sr_2,tblen,tre1);
%% ===================计算误码率=======================
errorbit_num_1(snr_index) = length(find(demod_sr_1~= sr0));%统计直接解调错误比特数
BER_1(snr_index) = errorbit_num_1(snr_index) / (symbol_len*num_carriers*M);
errorbit_num_2(snr_index) = length(find(demod_sr_2 ~= sr0));%统计信道估计与频域均衡错误比特数
BER_2(snr_index) = errorbit_num_2(snr_index) / (symbol_len*num_carriers*M);
end
%% ================绘制 SNR-BER 曲线================
semilogy(SNR,BER_1,'b*-.');
hold on;
semilogy(SNR,BER_2,'m+-');
xlabel('SNR (dB)');
ylabel('BER');
grid on;
legend('直接解调','信道估计与频域均衡')
axis([SNR(1) SNR(end) 0.01 1])
- 1
- 2
- 3
- 4
- 5
前往页