clear
clc
% fadingModel = 0 is no fading
% fadingModel = 1 is uniform profile
% fadingModel = 11 is uniform profile with constant gain ( for testing)
% fadingModel = 2 is Exponential profile
% fadingModel = 22 is Exponential profile with constant gain ( for testing)
fadingModel=2;
maxDelaySpreadInSamples=15;
SNRperCarrierdB = 10;
startSNRperSubcarrierdB=0.0;
stepSNRperSubcarrierdB=4.0;
stopSNRperSubcarrierdB=30.0;
snrArray=[startSNRperSubcarrierdB:stepSNRperSubcarrierdB:stopSNRperSubcarrierdB];
fftSize=128;
numGuardLeft=11;
numGuardRight=10;
cyclicPrefixRatio=0.125;
numUsedSubcariers=fftSize-numGuardLeft-numGuardRight-1;
numOFDMsymbols=2;
% for the time being there are no pilots
numDataSubcariers = numUsedSubcariers;
modulationIndex=2;
maxSimulationFrames=10000;
lowestNeededFER=1.0E-4;
sufficientChannelFrameError=200;
sufficientCodedFrameError=200;
%********************************
% Covolutional Coding parameters
%********************************
codeRate=0.5;
K=7;
Generator1=171;
Generator2=133;
Generator3=165;
t = poly2trellis(K, [Generator1 Generator2]); % Define trellis.
numTailBits=K-1;
%********************************
% uncoded Eb/No
uncodedEb_NodBarray=snrArray - 10.0*log10(modulationIndex) ;
% Coded Eb/No in dB
codedEb_NodBarray=uncodedEb_NodBarray - 10.0*log10(codeRate) ;
%***************************************
% Prepare what will be written on the figure
%=============================
if fadingModel==0
TXTchannelModel='AWGN'
elseif fadingModel==1
TXTchannelModel='Fading 1'
elseif fadingModel==2
TXTchannelModel='Fading 2'
else
TXTchannelModel='Fading ?'
end
%=============================
%=============================
if modulationIndex==1
TXTmodType='BPSK'
elseif modulationIndex==2
TXTmodType='QPSK'
elseif modulationIndex==4
TXTmodType='16QAM'
elseif modulationIndex==6
TXTmodType='64QAM'
else
TXTmodType='mod?';
end
%=============================
% any permutation number now
permutation=1;
if permutation==1
TXTpermutation=[num2str(fftSize) ' PUSC']% PARTIAL USAGE OF SUBCHANNELS
elseif permutation==2
TXTpermutation=[num2str(fftSize) ' FUSC']% FULE USAGE OF SUBCHANNELS
end
% number of source bits must be integer
numSourceBits=numDataSubcariers*modulationIndex*codeRate*numOFDMsymbols - numTailBits ;
%=======================================================
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loop over enough number of slots for simaultion
numberChannelBitErrors=zeros(1,length(snrArray));
numberCodedBitErrors=zeros(1,length(snrArray));
numberOfChannelFrameErrors=zeros(1,length(snrArray));
numberOfCodedFrameErrors=zeros(1,length(snrArray));
numSimulatedBits=zeros(1,length(snrArray));
numSimulatedSourceBits=zeros(1,length(snrArray));
numSimulatedFrames=zeros(1,length(snrArray));
snrDone=zeros(1,length(snrArray));
for frameNumber = 1 : maxSimulationFrames
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if mod(frameNumber,1000) ==0 , disp(['The count of frame that processed : ' num2str(frameNumber)]), end ;
if sum(snrDone)==length(snrDone) , break, end ; % all SNR are done
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Let us start with the data
% random Bits of desired user
sourceBits=round(rand(1, numSourceBits)) ;
msg = [sourceBits , zeros(1, numTailBits)]; % Random data
% Convolutional Encoder
codedBits = convenc(msg,t); % Encode the data
numChannelBits=length(codedBits);
% Random Interleaver for now till we make the standard
%=====================================================
interleaverState=randi([0,998],1);
interleavedCodedBits = interleaverDeinterleaver(codedBits, 0, interleaverState);
% Modulation
txSymbols= mapping( interleavedCodedBits, modulationIndex );
% make the symbols in matrix format. Each column=1 OFDM symbol
ofdmInput=reshape(txSymbols,numUsedSubcariers , numOFDMsymbols);
% Perform OFDM
txSamples= ofdmTx(ofdmInput, numGuardLeft, numGuardRight, fftSize, cyclicPrefixRatio );
% Apply fading
[fadedSamples, gainImpulseResponse]=ApplyFading(txSamples, fadingModel,...
maxDelaySpreadInSamples);
% generate unit variance complex Gaussian noise
noiseSamples=1/sqrt(2)*(randn(size(fadedSamples))+j*randn(size(fadedSamples))) ;
%===============================================
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is snr per subraiier in dB
for snrdBcounter = 1 : length(snrArray)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%=================================================================
%=================================================================
% Stop running snr values if not getting enough errors
% After "10/lowestNeededFER" frames, FER is below "lowestNeededFER/10"
% Then stop this SNR value
minFramesToRun=1000;
FERtest=1;
if frameNumber > 10
FERtest=numberOfCodedFrameErrors(snrdBcounter) / ...
numSimulatedFrames(snrdBcounter);
end
% condition1 means enough simualtion and can't get needed FER
condition1=frameNumber > max(minFramesToRun, 100/lowestNeededFER) & ...
FERtest < lowestNeededFER ;
% condition2 means that this SNR will never get the needed FER
condition2=frameNumber > max(minFramesToRun, 10/lowestNeededFER) & ...
FERtest < lowestNeededFER/10 ;
if condition1==1 | condition2==1
if snrDone(snrdBcounter) == 0
snrDone(snrdBcounter)=1;
'EB/No completed is:'
snrPerSubcarrierdB=snrArray(snrdBcounter)
channelBitErrorRate= numberChannelBitErrors(snrdBcounter) / ...
numSimulatedBits(snrdBcounter)
codedBitErrorRate= numberCodedBitErrors(snrdBcounter) / ...
numSimulatedSourceBits(snrdBcounter)
FER=FERtest
end
continue % Skip this SNR value
end
%=================================================================
%=================================================================
% Stop running Eb/No values after getting enough errors
if numberOfChannelFrameErrors(snrdBcounter) > sufficientChannelFrameError & ...
numberOfCodedFrameErrors(snrdBcounter) > sufficientCodedFrameError
if snrDone(snrdBcounter) == 0
snrDone(snrdBcounter)=1;
'EB/No completed is:'
snrPerSubcarrierdB=snrArray(snrdBcounter)
channelBitErrorRate= numberChannelBitErrors(snrdBcounter) / ...
numSimulatedBits(snrdBcounter)
%BER_BPSK=0.5*erfc(sqrt(snrArrayRatio(snrdBcounter))) % for testing
codedBitErrorRate= numberCodedBitErrors(snrdBcounter) / ...
numSimulatedSourceBits(snrdBcounter)
FER=FERtest
end
continue % Skip this snr value
end
%=================================================================
%=================================================================
snrPerSubcarrierdB=snrArray(snrdBcounter); % Eb/No of channel bits
numSimulatedBits(snrdBcounter)=numSimulatedBits(snrdBcounter)+ ...
numChannelBits;
numSimulatedSourceBits(snrdBcounter)=numSimulatedSourceBits(snrdBcounter)+ ...
numSourceBits;
numSimulatedFrames(snrdBcounter)=numSimulatedFrames(snrdBcounter)+ 1;
% SNR per carrier in dB. Each carrier carries one modulation symbol
snrPerCarrierRatio=10.0^(snrPerSubcarrierdB/10);
ofdm.zip_ofdm_ofdm matlab code_zip
版权申诉
23 浏览量
2022-09-20
23:30:38
上传
评论
收藏 7KB ZIP 举报
Kinonoyomeo
- 粉丝: 77
- 资源: 1万+
最新资源
- Screenshot_2024_0531_203438.png
- 旋转相册,上传图片替换即可使用
- 基于单通道脑电信号的自动睡眠分期研究python源码+使用说明+模型+数据(高分项目)
- 使用STM32实现对多个步进电机的位置自由控制,可使用编码器、函数等控制步进电机
- 基于宏晶STC单片机开发ISP程序Demo-使用Y-Modem协议软件源码+文档说明资料.zip
- 基于Vue+Echarts开发的风力发电机中传感器的数据展示监控
- 新普_软包电池_三是调试工程05301.zip
- 基于python遥感毕业设计TOA深度学习反演PM2.5源码+文档说明(高分项目)
- 基于stc8A系列单片机和ov7670模块制作的人脸识别系统
- 基于python的系统设计与实现博客系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈