OFDMMATLAB仿真程序_第1页
OFDMMATLAB仿真程序_第2页
OFDMMATLAB仿真程序_第3页
OFDMMATLAB仿真程序_第4页
OFDMMATLAB仿真程序_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、OFDM.m : OFDM Simulator (outer function) clear all;A = 1 l/exp(l) 1/exp(2);% power delay profileN = 64;% number of symbols in a single OFDM symbolGI = 16;% guard intervalMt = 1;% number of Tx antennasMr = 1;% number of Rx antennassig2 = le-3;% noise varianceM = 8;% max consteRation bit numberMgap =

2、104(1:(1.7/10)27);% gapBtot = 100*Mt;% total# bits per OFDM symbolTransmitter = 50; % # ite rations of symbol transmissions for each channel instance Channellter = 100; % # iterations of independent identicaDy distributed channel instances Gaplter = length(Mgap);load ENC2.matload ENC4.matload ENC16.

3、matload ENC64.matload ENC256.matTotEbNo =;Errors =;EbNo = 0; for IGap = l:GapIterIGapgap = Mgap(lGap); totalEnors = 0;for IChan = 1:Channellter% create channelH h_f=create_channel(Mt, Mr, A, N+GI);% decompose each subchannel in the frequency domain U S V = svd_decompose_channel(Mt, Mr, h_f, N);% bit

4、loadingbits_alloc,energy_alloc = BitLoad(S,Btot,Mt*N,gap,s ig2,M); % e nergy_a lloc=e ne rgy_a lloc/(me an(ene rgy_a Hoc); %energy_alloc=ones(l,128);for lTrans = 1 :TransmitIter% bits to transmitx = (randn(l,Btot)0);% modulatex_mod = modulate(x,bits_alloc,energy_aHoc, s2,s4,s 16,s64,s256);% precode

5、modulated signal x_pre = precode(Mt, x_mod, V, N);% ifft, with cyclic pre fix for each antennaofdm_symbol =;for i=l:Mtofdm_symbol = ofUm_symbol; ifft_cp_tx_blk(x_pre(i:Mt:Mt*(N-l)+i),N,GI); endofdm_symbol2 = re shape (ofdm_s ymboLMt*(N+GI), 1);% channely = trans pose (channel(sig2, Mt, Mr, oftim_sym

6、bol2, H, N+GI);% fft rec_symbol =;for i=l:Mtrec_symbol = rec_symbol; fft_cp_rx_blk(y(i:Mt:Mt*(N+GI-l)4-i),N,G; endrec_symbol2 = re s ha p e (re c_s ymb o 1,1 ,Mt*N);% shape received signalshaped_vals = shape(rec_symbo!2, Mr, U, N);% demodulatey_demod = de modulate (shaped_va Is, bits_alloc, energy_a

7、lloc, S, s2,s4,s 16,s64,s256, c2,c4,cl6,c64,c256);% comparisontotalEnors = to ta Errors + sum(xor(y_demod,x); endEbNo = EbNo sum(energy_alloc)/Btot/sig2; endErrors = Errors tota Errors/Btot/Channe liter/Trans mitlter TotEbNo = TotEbNo mean(EbNo)EbNo =;end semilogx(TotEbNo, Errors);xlabel( Eb/No);yla

8、bel( BER);title(*SISO link, adaptive rate and power* ) function H,H_f=create_channel(Mt, Mr, A, N); % function H, H_f=cre a te_cha nne l(Mt, Mr, A, N);save SISO_adaptive2.mat Errors EbNocreate_channel.m : Generates parametrized by the antenna power-delay profile.a Rayleigh configuration,fadingire q

9、u e n c y- s e le c ti vethe OFDM configuration,channel, and the% A - vector containing the power-delay profile (real values)% Mt - number of Tx antennas% Mr - number of Rx antennas% N number of vector symbols to be sent in a single OFDM symbol Tx% ie: N MIMO transmissions in one OFDM symbol% This i

10、s for Rayleigh frequency-selective fading, which assumes complex% Gaussian matrix elements with in-phase and quadrature components independent.% Assume iid matrix channel elements, and further, independent channel taps% define the channel tapsH_int = 1 /s qrt(2)*(ra ndn(Mr*le ngth(A),Mt) + j*randn(M

11、r*length(A),Mt);H_int2=0;for i= l:length(A)H_int2 = H_int2;s qrt(A(i)*H_int(i-l )*Mr+1:i*Mr,:);endH_int2 = H_int2;zeros(N-length(A)*Mr,Mt);H_f = zeros(Mr,Mt*(N-16);for i = l:Mtfor j = 1:Mrh_f = ffi(H_int2(j:Mi*:(N-16-1 尸Mr+j,i); for k = 1:(N-16)H_f(j,i+(k-l)*Mt) = h_f(k);endendendH=H_int2J;for i = 1

12、:N-1H=HJzeros(Mr*i,Mt);H_int2(l:(N-i)*Mr,:);endsvd decomposc channcLm:Since lull channel knowledge isassumed, transmissiondecomposesthe channel intois across parallel singular value modes. This iunction these modesfunction U, S, V = svd_decompose_channel(Mt, Mr, h_f, N);% U S V = svd_decompose_chann

13、el(Mt, Mr, h_f, N);%S VD componentsL is the number% Function decomposes the channel at each subcarrierinto its% Mt - # Tx antennas% Mr - # Rx antennas% h_f - MIMO impulse response - Mr rows, Mt*L columns, where of% channel taps% N # subcarriersU = ;S = ;v=n;for i= 1:NUtmp Stmp Vtmp = s vd(h_f(:,(i-l

14、)*Mt+l :i*Mt);U=U Utmp;V=V Vtmp;S=S Stmp; endS = sum(S J);BitLoad.m : Apply the bit-loading algorithm to achieve the desired bit and energy allocation for the current channel instance.function bits_alloc,energy_alloc=BitLoad(subchan_gains,total_bits,num_subc,gap,noise,M)% Bit Loading Algorithm% Inpu

15、ts :% subchan_gains : SubCarrier Gains% total_bits : Total Number of bits% num_subc : Number of Subcarriers% gap: Gap of the sys tem% noise : Noise Power%M: Max Constellation Size% Outputs:% bits_alloc : Bits allocation for each subchannel% power_alloc : Total Power allocation% Compute SNRs for each

16、 channelSNR = Computes NR(subchan_ga ins,noise,gap);% This function just initializes the system with a particular bit% allocation and energy allocation using Chows Algorithm. This is% further efficientize using Campellos Algorithmbits_alloc, energy_alloc = chow_algo(SNR,num_subc,M);% Form the Energy

17、 Increment Table based on the present channel% gains for all the subchannels in order to be used by Campello% Algorithmenergytable = EnergyTableInit(SNR,M);% Effieientize the algorithm using the Campello s algorithmbits_a Hoc ,e ne rgy_a Hoc J =campello_algo(bits_alloc,energy_alloc,energytable,total

18、_bits,num_subc,M );ComDUtcSNR.m : Given the subcarrier gains, this simple lunction generates the SNR values of each channel (each singular value on each tone is a separate channel) function SNR = Computes NR(subcar_ga ins,noise,gap)SNR = abs(subcar_gains.A2)./(noise*gap);chow_algom : Apply Chows alg

19、orithm to generate a particular bit and energy allocation.% Chows Algorithm% This is based on the paper by Chow et al titled% A Practical Discrete Multitone Transceiver Loading Algorithm% for Data Transmission over Spectra lly Shaped Channels .IEEE Trans% on Communications. Vol. 43, No 2/3/4, pp. 77

20、3-775, Feb/Mar/Apr 1995function bits_alloc, energy_alloc = chow_a!go(SNR,num_subc,M)for i = 1:num_subc% Assuming each of the subchannels% of the bits for each subchannelte mpbits= log2(l + abs(SNR(i);roundte mpbits = round(te mpbits);if (roundtempbits 8) roundte mpbits = 8; endhas a flat foding, we

21、get initial% bits per two dimension. % round the bits% Limit them between 2 and 15estimateif (mod(roundtempbits,2)= 1 &roundtempbits = 1) roundtempbits = roundtempbits -1;endif roundte mpbits 0for the subchannelenergy_alloc(i) = (2Aroundtempbits-l)/SNR(i); elseenergy_alloc(i) = 0;end% Calculatethe E

22、nergyrequiredend% end of functionEncrgyTablelnif.m : Given the SNR values, form a table of energy increments for each channel.function energytable = EnergyTablelnit(SNR.M);% Inputs:% subcar_gains : Subcarrier Gains%M : max Constellation Size%Gap : Gap of the system% Noise : Noise Power% Outputs:% en

23、ergytable : Energytable% Based on the Subcarrier Gains, we calculate the energy% increment required by each subcarrier for transmitting% 1,2 ,4 ,6,8 bits.% Energy = 2A(i-l)/subcar_gains;%subcar_gains = (subcar_gains.A2)/(Gap*Noise);energytable = abs(l ./SNR)*(2.A(1:M+l-l);% Increase the energy value

24、 for constellation size of more than M to% a very high value so that it is not assignedenergytable(:,M+l) = Infone s (s ize (e ne rgyta ble (:,M+1);for i= 3:2:Menergytable(:,i) = (energytable(:,i) +e ne rgyta ble (:4+1 )/2;energytable(:,i+l) = energytable(: ,i);end%energytable = one s(l,size (energy

25、table J)1 energytable;campello_algom : Apply Campellos algorithm to converge to the optimal bit and energy allocation for the given channel conditions % campello_algo.m% This function is used by Campellos algorithm to allocate bits and energy for% each subchannel optimallyfunctionbits_aHoc, energy_a

26、llocj =campeIlo_algo(bits_alloc,energy_aHoc,energytable Jotal_bits,num_subc,M )bt = sum(bits_alloc);% We cant transmit more than M*(Number of subchannel) bitsif total_bits M*num_subctotal_bits = M*num_subc;endwhile (bt = total_bits)if (bt total_bits)max_val = 0;max_ind = ceil(rand(l)*num_subc);for i = 1:num_subcif bits_alloc(i) = 0te mp = e ne rgyta b le (i,bits_a lloc (i);elsetemp = 0;endif (temp max_va 1)max_val = te mp;max_ind = i;endendif (bits_alloc(max_ind) 0) bits_alloc(max_ind) = bits_alloc(max

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论