⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main1.asv

📁 基于MATLAB平台的ofdm的无线信道算法
💻 ASV
字号:
%噪声加在时域上,四种比较:理想信道、导频、插值,EM
clc;
clear;
echo off;
T = 0.01;               % set the simulation time
Td =1e-6 ;              % set the bit signal rate , etc 10M hz
Ts = Td ;               % set the sample rate
SNRdB=0:5:40;           % the loop of the SNRindB     当SNRdB>50时,所画曲线开始向上走?是不是与sigma有关?
Td2Ts = Td/Ts;
baseType = 2;           % set the baseband mapping Type , 1: BPSK ; 2 : QPSK ; 3 : 16QAM
subcaNUM =32 ;          % the number of the OFDM subcarrier
fftdm    = subcaNUM ;   % the number of the FFT points
cp_l     = 1/4;         % the relative length of the cp 
simulNUM = T/Ts ;       % calculate the simulation points
Dist=60;                %导频的间距     
Dist_em=Dist/Dist*1;
Cyc_time=10;             %计算BER循环次数
Eav = 1;                % QPSK符号的平均能量 = 1+1
bitSource = bitSource_Gen(simulNUM);                  %产生一系列的01序列
dSource = baseMapping(bitSource,baseType);            %按照不同的方式进行调制
% ==================the S2P function
P_dSource = P2S( dSource,subcaNUM);                   %调制方法
P_dSource_tr = P_dSource;                             % ====the 1TX1Rx;
% ==================add training symbol here
[P_dSource_pilot,pilotNUM] = addpilot_em(P_dSource_tr,Dist);
size_P_dSource_pilot=size(P_dSource_pilot);           %   ending  其实是要算P_dSource_pilot的大小     32*159
ofdm_dSource = ifft(P_dSource_pilot,fftdm);           % ifft comuputation   32*159(157+2列导频信息)
Td_ofdm = Ts* Td2Ts * subcaNUM;
cp_length = round(fftdm * cp_l);                      %cp_l保护间隔是加在频域上的    8
tempo_Signal_cp = [ofdm_dSource( fftdm - cp_length+1 : fftdm ,:);ofdm_dSource];  % add cp   后8列
tmp = size(tempo_Signal_cp);                          %  40 159
ofdm_tempo = reshape(tempo_Signal_cp,1,tmp(1)*tmp(2)) + eps;%1e-5;    % 1e-5 is to avoid NaN%重新变成串行的哦
clear tmp;
 % ==============generate the Rayleigh Multipath fading channel
sim('Mph_Rayleigh_channel1',Ts*(length(ofdm_tempo)-1)); % ==========the channel is defined in the simulink model "Mph_Rayleigh_channel"
%第二个参数是指时间轴上的长度
Rayleigh_channel = rec_Signal0 ./ofdm_tempo';           %rec_Signal0为信道的接收信号,ofdm_tempo为信道的发送信号   简单计算channel
% ===============end of the Rayleigh Multipath fading channel
%================计算BER循环
sum_BER=zeros(Cyc_time,length(SNRdB));
for m=1:Cyc_time
    for k = 1:length(SNRdB)   
        snr_indB =SNRdB(k);   
        snr = 10^(snr_indB/10);                           %SNR换成10的幂次
        N0 = Eav/snr;                                     %功率谱密度
        if snr_indB<11
            sigma0=sqrt(N0/2);                            %sigma0指的是方差      方差的取值有要求吗?
        elseif snr_indB<21 sigma0 = 2*sqrt (N0/2);        %加入双边带功率谱
        elseif snr_indB<31 sigma0=5*sqrt(N0/2);
        elseif snr_indB<50 sigma0=10*sqrt(N0/2);
        else sigma0=1000*sqrt(N0/2);
        end
        %=====================remove cp
        rec_P_tempo = reshape(rec_Signal0,size(tempo_Signal_cp));  %tempo_Signal_cp是加完cp后的发射信号,rec_P_tempo是把信号恢复到前面向量同样的维数然后去cp
        rec_tempo_Signal = rec_P_tempo(cp_length +1 : fftdm+cp_length ,:); % rec_tempo_Signal为去完cp脉冲的信号
        %====================fft computationrec_freq_Signal_ideal = fft(rec_tempo_Signal,fftdm); 
%====================calculae  ideal channel  function
H_ideal=rec_freq_Signal_ideal./P_dSource_pilot;              %理想信道函数  
% =====================noise is added to channel here 
rec_freq_Signal=add_noise(rec_freq_Signal_ideal,snr_indB,Eav);  %频域  加噪声
% ==================The start of the channel estimation section
[channel_we_esti,kh]= channel_esti_em730a(rec_freq_Signal,Dist,pilotNUM,sigma0);   %要改载波数的话,要改这个函数  
rec_freq_Signal_nopilot = channel_esti_after_em(channel_we_esti,rec_freq_Signal,Dist,pilotNUM,1);
ERR=abs(channel_we_esti-H_ideal);
%MSE(k)=sum(sum(ERR))'/(size_P_dSource_pilot(2)*size_P_dSource_pilot(1));
rec_freq_Signal_soft = reshape(rec_freq_Signal_nopilot,1,length(rec_freq_Signal_nopilot(1,:)) * length(rec_freq_Signal_nopilot(:,1)) );  %并串转换
rec_bitSource = ofdmSlice(rec_freq_Signal_soft,baseType);    %解调
BER(k) = bitErrorCalc(bitSource,rec_bitSource);
end % =============the end of the SNRindB loop
sum_BER(m,:)=BER;
clear BER;
clear k;
end
sum_ber=sum(sum_BER);
mean_BER=sum_ber./Cyc_time;
semilogy( SNRdB,mean_BER,'r--o'); xlabel('SNR(dB)'),ylabel('BER');hold on 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -