OFDM.m:OFDMSimulator(outerfunction)clearall;A=[11/exp(1)1/exp(2)];%powerdelayprofileN=64;%numberofsymbolsinasingleOFDMsymbolGI=16;%guardintervalMt=1;%numberofTxantennasMr=1;%numberofRxantennassig2=1e-3;%noisevarianceM=8;%maxconstellationbitnumberMgap=10.^(1:(1.7/10):2.7);%gapBtot=100*Mt;%total#bitsperOFDMsymbolTransmitIter=50;%#iterationsofsymboltransmissionsforeachchannelinstanceChannelIter=100;%#iterationsofindependentidenticallydistributedchannelinstancesGapIter=length(Mgap);loadENC2.matloadENC4.matloadENC16.matloadENC64.matloadENC256.matTotEbNo=[];Errors=[];EbNo=[];forlGap=1:GapIterlGapgap=Mgap(lGap);totalErrors=0;forlChan=1:ChannelIter%createchannel[Hh_f]=create_channel(Mt,Mr,A,N+GI);%decomposeeachsubchannelinthefrequencydomain[USV]=svd_decompose_channel(Mt,Mr,h_f,N);%bitloading[bits_alloc,energy_alloc]=BitLoad(S,Btot,Mt*N,gap,sig2,M);%energy_alloc=energy_alloc/(mean(energy_alloc));%energy_alloc=ones(1,128);forlTrans=1:TransmitIter%bitstotransmitx=(randn(1,Btot)0);%modulatex_mod=modulate(x,bits_alloc,energy_alloc,s2,s4,s16,s64,s256);%precodemodulatedsignalx_pre=precode(Mt,x_mod,V,N);%ifft,withcyclicprefixforeachantennaofdm_symbol=[];fori=1:Mtofdm_symbol=[ofdm_symbol;ifft_cp_tx_blk(x_pre(i:Mt:Mt*(N-1)+i),N,GI)];endofdm_symbol2=reshape(ofdm_symbol,Mt*(N+GI),1);%channely=transpose(channel(sig2,Mt,Mr,ofdm_symbol2,H,N+GI));%fftrec_symbol=[];fori=1:Mtrec_symbol=[rec_symbol;fft_cp_rx_blk(y(i:Mt:Mt*(N+GI-1)+i),N,GI)];endrec_symbol2=reshape(rec_symbol,1,Mt*N);%shapereceivedsignalshaped_vals=shape(rec_symbol2,Mr,U,N);%demodulatey_demod=demodulate(shaped_vals,bits_alloc,energy_alloc,S,s2,s4,s16,s64,s256,c2,c4,c16,c64,c256);%comparisontotalErrors=totalErrors+sum(xor(y_demod,x));endEbNo=[EbNosum(energy_alloc)/Btot/sig2];endErrors=[ErrorstotalErrors/Btot/ChannelIter/TransmitIter]TotEbNo=[TotEbNomean(EbNo)]EbNo=[];endsemilogx(TotEbNo,Errors);xlabel('Eb/No');ylabel('BER');title('SISOlink,adaptiverateandpower')saveSISO_adaptive2.matErrorsEbNocreate_channel.m:GeneratesaRayleighfadingfrequency-selectivechannel,parametrizedbytheantennaconfiguration,theOFDMconfiguration,andthepower-delayprofile.function[H,H_f]=create_channel(Mt,Mr,A,N);%function[H,H_f]=create_channel(Mt,Mr,A,N);%%A-vectorcontainingthepower-delayprofile(realvalues)%Mt-numberofTxantennas%Mr-numberofRxantennas%N-numberofvectorsymbolstobesentinasingleOFDMsymbolTx%ie:NMIMOtransmissionsinoneOFDMsymbol%ThisisforRayleighfrequency-selectivefading,whichassumescomplex%Gaussianmatrixelementswithin-phaseandquadraturecomponentsindependent.%Assumeiidmatrixchannelelements,andfurther,independentchanneltaps%definethechanneltapsH_int=1/sqrt(2)*(randn(Mr*length(A),Mt)+j*randn(Mr*length(A),Mt));H_int2=[];fori=1:length(A)H_int2=[H_int2;sqrt(A(i))*H_int((i-1)*Mr+1:i*Mr,:)];end%h_f=fft(H_int2',64);%%H=H_int2';H_int2=[H_int2;zeros((N-length(A))*Mr,Mt)];H_f=zeros(Mr,Mt*(N-16));fori=1:Mtforj=1:Mrh_f=fft(H_int2(j:Mr:(N-16-1)*Mr+j,i));fork=1:(N-16)H_f(j,i+(k-1)*Mt)=h_f(k);endendendH=[H_int2];fori=1:N-1H=[H,[zeros(Mr*i,Mt);H_int2(1:(N-i)*Mr,:)]];endsvd_decompose_channel.m:Sincefullchannelknowledgeisassumed,transmissionisacrossparallelsingularvaluemodes.Thisfunctiondecomposesthechannelintothesemodes.function[U,S,V]=svd_decompose_channel(Mt,Mr,h_f,N);%[USV]=svd_decompose_channel(Mt,Mr,h_f,N);%%FunctiondecomposesthechannelateachsubcarrierintoitsSVDcomponents%%Mt-#Txantennas%Mr-#Rxantennas%h_f-MIMOimpulseresponse-Mrrows,Mt*Lcolumns,whereListhenumberof%channeltaps%N-#subcarriersU=[];S=[];V=[];fori=1:N[UtmpStmpVtmp]=svd(h_f(:,(i-1)*Mt+1:i*Mt));U=[UUtmp];V=[VVtmp];S=[SStmp];endS=sum(S,1);BitLoad.m:Applythebit-loadingalgorithmtoachievethedesiredbitandenergyallocationforthecurrentchannelinstance.function[bits_alloc,energy_alloc]=BitLoad(subchan_gains,total_bits,num_subc,gap,noise,M)%BitLoadingAlgorithm%---------------------%%Inputs:%subchan_gains:SubCarrierGains%total_bits:TotalNumberofbits%num_subc:NumberofSubcarriers%gap:Gapofthesystem%noise:NoisePower%M:MaxConstellationSize%Outputs:%bits_alloc:Bitsallocationforeachsubchannel%power_alloc:TotalPowerallocation%---------------------------------------------------------------%ComputeSNR'sforeachchannelSNR=ComputeSNR(subchan_gains,noise,gap);%Thisfunctionjustinitializesthesystemwithaparticularbit%allocationandenergyallocationusingChow'sAlgorithm.Thisis%furtherefficientizeusingCampello'sAlgorithm[bits_alloc,energy_alloc]=chow_algo(SNR,num_subc,M);%FormtheEnergyIncrementTablebasedonthepresentchannel%gainsforallthesubchannelsinordertobeusedbyCampello%Algorithmenergytable=EnergyTableInit(SNR,M);%EfficientizethealgorithmusingtheCampello'salgorithm[bits_alloc,energy_alloc]=campello_algo(bits_alloc,energy_alloc,energytable,total_bits,num_subc,M);ComputeSNR.m:Giventhesubcarriergains,thissimplefunctiongeneratestheSNRvaluesofeachchannel(eachsingularvalueoneachtoneisaseparatechannel).functionSNR=ComputeSNR(subcar_gains,noise,gap)SNR=abs((subcar_gains.^2)./(noise*gap));chow_algo.m:ApplyChow'salgorithmtogenerateaparticularbitandenergyallocation.%Chow'sAlgorith