OFDM技术仿真(MATLAB代码)
- 格式:doc
- 大小:1014.00 KB
- 文档页数:31
O F D M调制解调仿真------------------------------------------作者xxxx------------------------------------------日期xxxx实验四 OFDM调制解调仿真一、实验目的(1)了解OFDM调制解调的原理。
(2)学会用星座图分析系统性能。
二、实验内容(1)编写MATLAB程序,实现OFDM系统调制解调。
(2)绘制各步骤图形并分析系统特性。
三、实验代码1、主代码如下:clear all;close all;N=input('请输入码元数');SNR=input('请输入信噪比');xx=randint(1,4*N); %原序列figure(1),stem(xx,'.k'); %原序列图形title('原序列');B=0;for m=1:4:4*NA=xx(m)*8+xx(m+1)*4+xx(m+2)*2+xx(m+3);B=B+1;ee(B)=A;endfigure(2),stem(ee,'.b');title('化为0~15的码元');yy=star(ee,N);figure(3),plot(yy,'.r'); %映射后的星座图title('映射后的星座图');ff=ifft(yy,N); %傅里叶反变换N1=floor(N*1/4);N3=floor(N*3/4);N5=floor(N*5/4);figure(4),stem(ff,'.m');title('傅里叶反变换后');for j=1:N1 %加循环前缀ss(j)=ff(N3+j);endfor j=1:N %变成长度为N*5/4的序列 ss(N1+j)=ff(j);endfigure(5),stem(ss,'.k'); %画出图形title('加N/4循环前后缀');%ss=wgn(1,N5,0,10,'dBW','complex');ss=awgn(ss,SNR); %加入噪声figure(6),stem(ss,'.m'); %加入噪声后的图形title('加入噪声后');zz=fft(ss((N1+1):N5),N); %傅里叶变换figure(7),plot(zz,'.b'); %画图title('傅里叶变换后');rr=istar(zz,N); %星座图纠错figure(8),plot(rr,'.r'); %画图title('纠错后的星座图');dd=decode(rr,N); %解码figure(9),stem(dd,'.m'); %画图title('星座图纠错并解码后');%bb=d2b(dd,N);bb=d2bb(dd,N); %转化为0/1比特流figure(10),stem(bb,'.b');title('转化为0/1比特流后');2、调用的函数:(1)星座图映射%星座图映射function yy=star(xx,N)B=[-3-3*i,-3-i,-1-3*i,-1-i,-3+3*i,-3+i,-1+3*i,-1+i,3-3*i,3-i,1-3*i,1-i,3+3*i,3+i,1+3*i,1+i];for j=1:Nyy(j)=B(xx(j)+1);end(2)星座图逆映射%星座图逆映射function rr=istar(zz,N)for j=1:Nif(mod((floor(real(zz(j)))),2)==0)zz1(j)=ceil(real(zz(j)));else zz1(j)=floor(real(zz(j)));endif(mod((floor(imag(zz(j)))),2)==0)zz1(j)=zz1(j)+ceil(imag(zz(j)))*i;else zz1(j)=zz1(j)+floor(imag(zz(j)))*i;endrr(j)=zz1(j);end(3)十进制转二进制function bb=d2b(dd,N)%十进制转二进制for j=1:N*4bb(j)=;endfor j=1:4:N*4bb1=dec2bin(dd(floor(j/4)+1),4);for k=1:4bb(4*(j-1)+k)=bb1(k);endend(4)十进制转化为01比特流%十进制转化为01比特流function bb=d2bb(dd,N)for j=1:N*4bb(j)=1;endj=1;while(j<=N*4)N1=ceil(j/4)a4=mod(dd(N1),2);dd(N1)=floor(dd(N1)/2);a3=mod(dd(N1),2);dd(N1)=floor(dd(N1)/2);a2=mod(dd(N1),2);dd(N1)=floor(dd(N1)/2);a1=mod(dd(N1),2);bb(j)=a1;j=j+1;bb(j)=a2;j=j+1;bb(j)=a3;j=j+1;bb(j)=a4;j=j+1;end(5)星座图逆映射function yy=decode(rr,N)for j=1:Nswitch(rr(j))%星座图逆映射case -3-3*iyy(j)=0;case -3-iyy(j)=1;case -1-3*iyy(j)=2;case -1-iyy(j)=3;case -3+3*iyy(j)=4;case -3+iyy(j)=5;case -1+3*iyy(j)=6;case -1+iyy(j)=7;case 3-3*iyy(j)=8;case 3-iyy(j)=9;case 1-3*iyy(j)=10;case 1-iyy(j)=11;case 3+3*iyy(j)=12;case 3+iyy(j)=13;case 1+3*iyy(j)=14;case 1+iyy(j)=15;otherwise break;endend四、五、实验结果【精品文档】【精品文档】。
OFDM原理及matlab代码仿真我也不明⽩OFDM是个咋回事OFDM⼀,OFDM的原理OFDM(Orthogonal Frequency Division Multiplexing)即正交频分复⽤技术,实际上OFDM是MCM(Multi Carrier Modulation),多载波调制的⼀种。
通过频分复⽤实现⾼速串⾏数据的并⾏传输, 它具有较好的抗多径衰弱的能⼒,能够⽀持多⽤户接⼊。
OFDM的主要思想是将信道分成N个⼦信道。
每个⼦信道包含⼀个⼦载波,不同的⼦载波之间相互正交。
实现时,将⼀路⾼速串⾏输⼊的数据信号流转换成N路并⾏的低速⼦数据流,调制到每个⼦载波上进⾏传输。
(类似于CDMA?)那么什么是正交呢?上图给出了详细的定义:两个波形在⼀段时间内内积为零,则他们在这段时间内正交。
那平时我们都知道sin(x)和cos(x)正交,他们在⼀个周期内的乘积为0。
如图sin和cos相乘,最后他们的乘积在⼀个周期内积分为0,则sin和cos在这段时间内是正交的。
那么同理,sin(x)和sin(2x)呢?从图上可以看到,sin(x)和sin(2x)的乘积在⼀个周期内的积分也为零,所以sin(x)和sin(2x)在这段时间内也是正交的。
那现在我们知道sin和cos是正交的,sin(x)和sin(2x)也是正交的。
“OFDM的主要思想是将信道分成N个⼦信道。
每个⼦信道包含⼀个⼦载波,不同的⼦载波之间相互正交。
”,那么在实现时将不同频率的相互正交的信号进⾏调制,最后再加和发送(所以觉得和CMDA类似,不得不说通信这⾥正交才是核⼼啊)。
(上⾯的图是从上截的)实现时,我们先对不同的信道不同频率的信号进⾏调制,再将其加和,很明显这种清楚易懂的⽅法实现起来对硬件的要求⽐较⾼,所以我们能不能找到⼀条更容易实现的⽅法。
博客园这个都不能写公式的吗.....从上⾯可以看出,将信号表⽰为指数形式,OFDM就可以采⽤FFT进⾏调制,⽽现实中DSP芯⽚技术已经成熟,可以采⽤相较于加法器⽽⾔速度更快的数字芯⽚。
close all;carrier_count=200;%子载波数symbols_per_carrier=12;%每子载波含符号数bits_per_symbol=4;%每符号含比特数,16QAM调制IFFT_bin_length=512;%FFT点数PrefixRatio=1/4;%保护间隔与OFDM数据的比例1/6~1/4GI=PrefixRatio*IFFT_bin_length ;%每一个OFDM符号添加的循环前缀长度为1/4*IFFT_bin_length 即保护间隔长度为128beta=1/32;%窗函数滚降系数GIP=beta*(IFFT_bin_length+GI);%循环后缀的长度20SNR=15; %信噪比dB%==================================================%================信号产生=================================== baseband_out_length = carrier_count * symbols_per_carrier * bits_per_symbol;%所输入的比特数目carriers = (1:carrier_count) + (floor(IFFT_bin_length/4) - floor(carrier_count/2));%共轭对称子载波映射复数数据对应的IFFT点坐标conjugate_carriers = IFFT_bin_length - carriers + 2;%共轭对称子载波映射共轭复数对应的IFFT点坐标rand( 'state',0);baseband_out=round(rand(1,baseband_out_length));%输出待调制的二进制比特流%==============16QAM调制====================================complex_carrier_matrix=qam16(baseband_out);%列向量complex_carrier_matrix=reshape(complex_carrier_matrix',carrier_count,symbols_per_car rier)';%symbols_per_carrier*carrier_count 矩阵figure(1);plot(complex_carrier_matrix,'*r');%16QAM调制后星座图axis([-4, 4, -4, 4]);grid on%=================IFFT===========================IFFT_modulation=zeros(symbols_per_carrier,IFFT_bin_length);%添0组成IFFT_bin_length IFFT 运算IFFT_modulation(:,carriers ) = complex_carrier_matrix ;%未添加导频信号,子载波映射在此处IFFT_modulation(:,conjugate_carriers ) = conj(complex_carrier_matrix);%共轭复数映射%========================================================stem(0:IFFT_bin_length-1, abs(IFFT_modulation(2,1:IFFT_bin_length)),'b*-')%第一个OFDM符号的频谱grid onaxis ([0 IFFT_bin_length -0.5 4.5]);ylabel('Magnitude');xlabel('IFFT Bin');title('OFDM Carrier Frequency Magnitude');figure(3);plot(0:IFFT_bin_length-1, (180/pi)*angle(IFFT_modulation(2,1:IFFT_bin_length)), 'go') hold onstem(0:carriers-1, (180/pi)*angle(IFFT_modulation(2,1:carriers)),'b*-');%第一个OFDM符号的相位stem(0:conjugate_carriers-1,(180/pi)*angle(IFFT_modulation(2,1:conjugate_carriers)),'b*-');axis ([0 IFFT_bin_length -200 +200])grid onylabel('Phase (degrees)')xlabel('IFFT Bin')title('OFDM Carrier Phase')%================================================================= signal_after_IFFT=ifft(IFFT_modulation,IFFT_bin_length,2);%OFDM调制即IFFT变换time_wave_matrix =signal_after_IFFT;%时域波形矩阵,行为每载波所含符号数,列ITTF 点数,N个子载波映射在其内,每一行即为一个OFDM符号figure(4);subplot(3,1,1);plot(0:IFFT_bin_length-1,time_wave_matrix(2,:));%第一个符号的波形axis([0, 700, -0.2, 0.2]);grid on;ylabel('Amplitude');xlabel('Time');title('OFDM Time Signal, One Symbol Period');%===========================================================%=====================添加循环前缀与后缀====================================XX=zeros(symbols_per_carrier,IFFT_bin_length+GI+GIP);for k=1:symbols_per_carrier;for i=1:IFFT_bin_length;XX(k,i+GI)=signal_after_IFFT(k,i);endfor i=1:GI;XX(k,i)=signal_after_IFFT(k,i+IFFT_bin_length-GI);%添加循环前缀endfor j=1:GIP;XX(k,IFFT_bin_length+GI+j)=signal_after_IFFT(k,j);%添加循环后缀endendtime_wave_matrix_cp=XX;%添加了循环前缀与后缀的时域信号矩阵,此时一个OFDM符号长度为IFFT_bin_length+GI+GIP=660subplot(3,1,2);plot(0:length(time_wave_matrix_cp)-1,time_wave_matrix_cp(2,:));%第一个符号添加循环前缀后的波形axis([0, 700, -0.2, 0.2]);grid on;ylabel('Amplitude');xlabel('Time');title('OFDM Time Signal with CP, One Symbol Period');%==============OFDM符号加窗==========================================windowed_time_wave_matrix_cp=zeros(1,IFFT_bin_length+GI+GIP);for i = 1:symbols_per_carrierwindowed_time_wave_matrix_cp(i,:) =real(time_wave_matrix_cp(i,:)).*rcoswindow(beta,IFFT_bin_length+GI)';%加窗升余弦窗endsubplot(3,1,3);plot(0:IFFT_bin_length-1+GI+GIP,windowed_time_wave_matrix_cp(2,:));%第一个符号的波形axis([0, 700, -0.2, 0.2]);grid on;ylabel('Amplitude');xlabel('Time');title('OFDM Time Signal Apply a Window , One Symbol Period');%========================生成发送信号,并串变换==================================================windowed_Tx_data=zeros(1,symbols_per_carrier*(IFFT_bin_length+GI)+GIP); windowed_Tx_data(1:IFFT_bin_length+GI+GIP)=windowed_time_wave_matrix_cp(1,:); for i = 1:symbols_per_carrier-1 ;windowed_Tx_data((IFFT_bin_length+GI)*i+1:(IFFT_bin_length+GI)*(i+1)+GIP)=window ed_time_wave_matrix_cp(i+1,:);%并串转换,循环后缀与循环前缀相叠加end%=======================================================Tx_data_withoutwindow=reshape(time_wave_matrix_cp',(symbols_per_carrier)*(IFFT_bin_length+GI+GIP),1)';%没有加窗,只添加循环前缀与后缀的串行信号Tx_data=reshape(windowed_time_wave_matrix_cp',(symbols_per_carrier)*(IFFT_bin_length+GI +GIP),1)';%加窗后循环前缀与后缀不叠加的串行信号%================================================================= temp_time1 = (symbols_per_carrier)*(IFFT_bin_length+GI+GIP);%加窗后循环前缀与后缀不叠加发送总位数figure (5)subplot(2,1,1);plot(0:temp_time1-1,Tx_data );%循环前缀与后缀不叠加发送的信号波形grid onylabel('Amplitude (volts)')xlabel('Time (samples)')title('OFDM Time Signal')temp_time2 =symbols_per_carrier*(IFFT_bin_length+GI)+GIP;subplot(2,1,2);plot(0:temp_time2-1,windowed_Tx_data);%循环后缀与循环前缀相叠加发送信号波形grid onylabel('Amplitude (volts)')xlabel('Time (samples)')title('OFDM Time Signal')%=================未加窗发送信号频谱==================================symbols_per_average = ceil(symbols_per_carrier/5);%符号数的1/5,10行avg_temp_time = (IFFT_bin_length+GI+GIP)*symbols_per_average;%点数,10行数据,10个符号averages = floor(temp_time1/avg_temp_time);average_fft(1:avg_temp_time) = 0;%分成5段for a = 0:(averages-1)subset_ofdm = Tx_data_withoutwindow(((a*avg_temp_time)+1):((a+1)*avg_temp_time));%subset_ofdm_f = abs(fft(subset_ofdm));%将发送信号分段求频谱average_fft = average_fft + (subset_ofdm_f/averages);%总共的数据分为5段,分段进行FFT,平均相加endaverage_fft_log = 20*log10(average_fft);figure (6)subplot(2,1,1);plot((0:(avg_temp_time-1))/avg_temp_time, average_fft_log)%归一化0/avg_temp_time : (avg_temp_time-1)/avg_temp_timehold onplot(0:1/IFFT_bin_length:1, -35, 'rd')grid onaxis([0 0.5 -40 max(average_fft_log)])ylabel('Magnitude (dB)')xlabel('Normalized Frequency (0.5 = fs/2)')title('OFDM Signal Spectrum without windowing')%===============加窗的发送信号频谱================================= symbols_per_average = ceil(symbols_per_carrier/5);%符号数的1/5,10行avg_temp_time = (IFFT_bin_length+GI+GIP)*symbols_per_average;%点数,10行数据,10个符号averages = floor(temp_time1/avg_temp_time);average_fft(1:avg_temp_time) = 0;%分成5段for a = 0:(averages-1)subset_ofdm = Tx_data(((a*avg_temp_time)+1):((a+1)*avg_temp_time));%利用循环前缀后缀未叠加的串行加窗信号计算频谱subset_ofdm_f = abs(fft(subset_ofdm));%分段求频谱average_fft = average_fft + (subset_ofdm_f/averages);%总共的数据分为5段,分段进行FFT,平均相加endaverage_fft_log = 20*log10(average_fft);subplot(2,1,2)plot((0:(avg_temp_time-1))/avg_temp_time, average_fft_log)%归一化0/avg_temp_time : (avg_temp_time-1)/avg_temp_timehold onplot(0:1/IFFT_bin_length:1, -35, 'rd')grid onaxis([0 0.5 -40 max(average_fft_log)])ylabel('Magnitude (dB)')xlabel('Normalized Frequency (0.5 = fs/2)')title('Windowed OFDM Signal Spectrum')%====================添加噪声============================================Tx_signal_power = var(windowed_Tx_data);%发送信号功率linear_SNR=10^(SNR/10);%线性信噪比noise_sigma=Tx_signal_power/linear_SNR;noise_scale_factor = sqrt(noise_sigma);%标准差sigmanoise=randn(1,((symbols_per_carrier)*(IFFT_bin_length+GI))+GIP)*noise_scale_factor; %产生正态分布噪声序列%noise=wgn(1,length(windowed_Tx_data),noise_sigma,'complex');%产生复GAUSS白噪声信号Rx_data=windowed_Tx_data +noise;%接收到的信号加噪声%=====================接收信号串/并变换去除前缀与后缀==========================================Rx_data_matrix=zeros(symbols_per_carrier,IFFT_bin_length+GI+GIP);for i=1:symbols_per_carrier;Rx_data_matrix(i,:)=Rx_data(1,(i-1)*(IFFT_bin_length+GI)+1:i*(IFFT_bin_length+GI)+GI P);%串并变换endRx_data_complex_matrix=Rx_data_matrix(:,GI+1:IFFT_bin_length+GI);%去除循环前缀与循环后缀,得到有用信号矩阵%============================================================%==== ============================================================%==============================================================% OFDM解码16QAM解码%=================FFT变换=================================Y1=fft(Rx_data_complex_matrix,IFFT_bin_length,2);%OFDM解码即FFT变换Rx_carriers=Y1(:,carriers);%除去IFFT/FFT变换添加的0,选出映射的子载波Rx_phase =angle(Rx_carriers);%接收信号的相位Rx_mag = abs(Rx_carriers);%接收信号的幅度figure(7);polar(Rx_phase, Rx_mag,'bd');%极坐标坐标下画出接收信号的星座图%================================================================== ====[M, N]=pol2cart(Rx_phase, Rx_mag);Rx_complex_carrier_matrix = complex(M, N);figure(8);plot(Rx_complex_carrier_matrix,'*r');%XY坐标接收信号的星座图axis([-4, 4, -4, 4]);grid on%====================16qam解调==================================================Rx_serial_complex_symbols =reshape(Rx_complex_carrier_matrix',size(Rx_complex_carrier_matrix,1)*size(Rx_complex_carrier_matrix,2),1)' ;Rx_decoded_binary_symbols=demoduqam16(Rx_serial_complex_symbols);%============================================================ baseband_in = Rx_decoded_binary_symbols;figure(9);subplot(2,1,1);stem(baseband_out(1:100));subplot(2,1,2);stem(baseband_in(1:100));%================误码率计算=============================================bit_errors=find(baseband_in ~=baseband_out);bit_error_count = size(bit_errors, 2)ber=bit_error_count/baseband_out_length。
基于MATLAB的OFDM系统仿真及分析OFDM(正交频分复用)是一种广泛应用于无线通信系统中的多载波调制技术。
在OFDM系统中,信号被分为多个独立的子载波,并且每个子载波之间正交。
这种正交的特性使得OFDM系统具有抗频率选择性衰落和多径干扰的能力。
本文将基于MATLAB对OFDM系统进行仿真及分析。
首先,我们需要确定OFDM系统的参数。
假设我们使用256个子载波,其中包括8个导频符号用于信道估计,每个OFDM符号的时域长度为128个采样点。
接下来,我们需要生成调制信号。
假设我们使用16QAM调制方式,每个子载波可以传输4个比特。
在MATLAB中,我们可以使用randi函数生成随机的比特序列,然后将比特序列映射为16QAM符号。
生成的符号序列可以通过IFFT(Inverse Fast Fourier Transform)将其转换为时域信号。
OFDM系统的发射端包括窗函数、导频符号插入、IFFT和并行到串行转换等模块。
窗函数用于增加OFDM符号之间的过渡带,导频符号用于信道估计和符号同步。
通过将符号序列与导频图案插入到OFDM符号序列中,然后进行IFFT变换,再进行并行到串行转换即可得到OFDM信号的时域波形。
接下来,我们需要模拟OFDM信号在信道中传输和接收。
假设信道是Additive White Gaussian Noise(AWGN)信道。
在接收端,OFDM信号的时域波形通过串行到并行转换,然后进行FFT(Fast Fourier Transform)变换得到频域信号。
通过在频域上对导频符号和OFDM信号进行正交插值,可以进行信道估计和等化。
最后将频域信号进行解调,得到接收后的比特序列。
通过比较发送前和接收后的比特序列,我们可以计算比特误码率(BER)来评估OFDM系统的性能。
比特误码率是接收到错误比特的比特数与总传输比特数之比。
通过改变信噪比(SNR)值,我们可以评估OFDM系统在不同信道条件下的性能。
OFDM.m : OFDM Simulator (outer function)clear all ;A = [1 1/exp(1) 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 = 1e-3; % noise varianceM = 8; % max constellation bit numberMgap = 10.^(1:(1.7/10):2.7);% gapBtot = 100*Mt;% total # bits per OFDM symbolTransmitIter = 50;% # iterations of symbol transmissions for each channel instance ChannelIter = 100; % # iterations of independent identically distributed channel instances GapIter = length(Mgap);load ENC2.matload ENC4.matload ENC16.matload ENC64.matload ENC256.matTotEbNo = [];Errors =[];EbNo = [];for lGap = 1:GapIterlGapgap = Mgap(lGap);totalErrors = 0;for lChan = 1:ChannelIter% create channel[H 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);%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);for lTrans = 1:TransmitIter% bits to transmitx = (randn(1,Btot)>0);% modulatex_mod = modulate(x,bits_alloc,energy_alloc, s2,s4,s16,s64,s256);% precode modulated signalx_pre = precode(Mt, x_mod, V, N);% ifft, with cyclic prefix for each antennaofdm_symbol =[];for i=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 =[];for i=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);% shape received signalshaped_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 = [EbNo sum(energy_alloc)/Btot/sig2];endErrors = [Errors totalErrors/Btot/ChannelIter/TransmitIter]TotEbNo = [TotEbNo mean(EbNo)]EbNo = [];endsemilogx(TotEbNo, Errors);xlabel( 'Eb/No' );ylabel( 'BER' );title( 'SISO link, adaptive rate and power' )save SISO_adaptive2.mat Errors EbNocreate_channel.m : Generates a Rayleigh fading frequency-selective channel,parametrized by the antenna configuration, the OFDM configuration, and the power-delay profile.function[H, H_f]=create_channel(Mt, Mr, A, N);%function [H, H_f]=create_channel(Mt, Mr, A, N);%% 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 is for Rayleigh frequency-selective fading, which assumes complex%Gaussian matrix elements with in-phase and quadrature componentsindependent.% Assume iid matrix channel elements,and further,independent channel taps% define the channel tapsH_int = 1/sqrt(2)*(randn(Mr*length(A),Mt) + j*randn(Mr*length(A),Mt));H_int2=[];for i = 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));for i = 1:Mtfor j = 1:Mrh_f = fft(H_int2(j:Mr:(N-16-1)*Mr+j,i));for k = 1:(N-16)H_f(j,i+(k-1)*Mt) = h_f(k);endendendH=[H_int2];for i = 1:N-1H=[H,[zeros(Mr*i,Mt);H_int2(1:(N-i)*Mr,:)]];endsvd_decompose_channel.m: Since full channel knowledge is assumed, transmissionis across parallel singular value modes. This function decomposes the channel into these modes.function[U, S, V] = svd_decompose_channel(Mt, Mr, h_f, N);% [U S V] = svd_decompose_channel(Mt, Mr, h_f, N);%into its SVD components % Function decomposes the channel at each subcarrier%%Mt - # Tx antennas%Mr - # Rx antennaswhere L is the number % h_f- MIMO impulse response- Mr rows,Mt*L columns,of%channel taps%N - # subcarriersU = [];S = [];V = [];for i = 1:N[Utmp Stmp Vtmp] = svd(h_f(:,(i-1)*Mt+1:i*Mt));U=[U Utmp];V=[V Vtmp];S=[S Stmp];endS = sum(S,1);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% ---------------------%%Inputs :%subchan_gains : SubCarrier Gains% total_bits : Total Number of bits% num_subc : Number of Subcarriers% gap : Gap of the system% noise : Noise Power%M: Max Constellation Size%Outputs:%bits_alloc: Bits allocation for each subchannel%power_alloc: Total Power allocation%---------------------------------------------------------------%Compute SNR's for each channelSNR = ComputeSNR(subchan_gains,noise,gap);%This function just initializes the system with a particular bit%allocation and energy allocation using Chow's Algorithm. This is%further efficientize using Campello's Algorithm[bits_alloc, energy_alloc] = chow_algo(SNR,num_subc,M);%Form the Energy Increment Table based on the present channel%gains for all the subchannels in order to be used by Campello%Algorithmenergytable = EnergyTableInit(SNR,M);%Efficientize the algorithm using the Campello's algorithm[bits_alloc,energy_alloc] =campello_algo(bits_alloc,energy_alloc,energytable,total_bits,num_subc,M );ComputeSNR.m : Given the subcarrier gains, this simple function generates the SNRvalues of each channel (each singular value on each tone is a separate channel).function SNR = ComputeSNR(subcar_gains,noise,gap)SNR = abs((subcar_gains.^2)./(noise*gap));chow_algo.m : Apply Chow's algorithm to generate a particular bit and energy allocation.%Chow's Algorithm%----------------%This is based on the paper by Chow et al titled%%A Practical Discrete Multitone Transceiver Loading Algorithm%for Data Transmission over Spectrally Shaped Channels.IEEE Trans%on Communications. Vol. 43, No 2/3/4, pp. 773-775, Feb/Mar/Apr 1995function [bits_alloc, energy_alloc] = chow_algo(SNR,num_subc,M)for i = 1:num_subc% Assuming each of the subchannels has a flat fading, we get initial estimate % of the bits for each subchanneltempbits= log2(1 + abs(SNR(i))); roundtempbits= round(tempbits);% bits per two dimension. % round the bitsif (roundtempbits > 8)roundtempbits = 8;end% Limit them between 2 and 15if (mod(roundtempbits,2)== 1 & roundtempbits ~= 1)roundtempbits = roundtempbits -1;endif roundtempbits> 0for the subchannelenergy_alloc(i) = (2^roundtempbits-1)/SNR(i) ;elseenergy_alloc(i) = 0;end% Calculate the Energy requiredend% end of functionEnergyTableInit.m : Given the SNR values, form a table of energy increments for eachchannel.function energytable = EnergyTableInit(SNR,M);%Inputs:%subcar_gains : Subcarrier Gains%M : max Constellation Size%Gap : Gap of the system%Noise : Noise Power%Outputs:%energytable : Energytable%%Based on the Subcarrier Gains, we calculate the energy%increment required by each subcarrier for transmitting%1,2 ,4 ,6,8 bits.%Energy = 2^(i-1)/subcar_gains;%------------------------------------------------------%subcar_gains = (subcar_gains.^2)/(Gap*Noise);energytable = abs((1./SNR)'*(2.^([1:M+1]-1)));%Increase the energy value for constellation size of more than M to%a very high value so that it is not assigned.energytable(:,M+1) = Inf*ones(size(energytable(:,M+1)));for i = 3:2:Menergytable(:,i) = (energytable(:,i) +energytable(:,i+1))/2;energytable(:,i+1) = energytable(:,i);end%energytable = [ones(1,size(energytable,1))' energytable];campello_algo.m : Apply Campello's algorithm to converge to the optimal bit and energy allocation for the given channel conditions.%campello_algo.m%--------------% This function is usedfor% each subchannel optimally.by Campello's algorithm to allocate bits and energyfunction[bits_alloc, energy_alloc] =campello_algo(bits_alloc,energy_alloc,energytable,total_bits,num_subc,M )bt = sum(bits_alloc);% We can't transmit more than M*(Number of subchannel) bitsif total_bits > M*num_subctotal_bits = M*num_subc;endwhileif (bt ~= total_bits) (bt > total_bits)max_val = 0;max_ind = ceil(rand(1)*num_subc);for i = 1:num_subcif bits_alloc(i) ~= 0temp = energytable(i,bits_alloc(i)) ;elsetemp = 0;endif (temp > max_val)max_val = temp;max_ind = i;endendif (bits_alloc(max_ind) > 0)bits_alloc(max_ind) = bits_alloc(max_ind) -1;energy_alloc(max_ind) = energy_alloc(max_ind) - max_val;bt = bt-1;endelsemin_val = Inf;min_ind = ceil(rand(1)*num_subc);for i = 1:num_subcif bits_alloc(i) ~=0 & bits_alloc(i) <9temp = energytable(i,bits_alloc(i) + 1);elsetemp = Inf;endif (temp < min_val)min_val = temp;min_ind = i;endendif (bits_alloc(min_ind) < 8)bits_alloc(min_ind) = bits_alloc(min_ind) +1;if (min_val==inf)min_val = energytable(min_ind,bits_alloc(min_ind));endenergy_alloc(min_ind) = energy_alloc(min_ind) +min_val;bt = bt+1;endendendfor i = 1:length(bits_alloc)if (mod(bits_alloc(i),2) == 1 & bits_alloc(i) ~=1)[bits_alloc,energy_alloc] =ResolvetheLastBit(bits_alloc,energy_alloc,i,energytable,num_subc);endendResolvetheLastBit.m: An optimal bit-loading of the last bit requires a unique optimization.function[bits_alloc, energy_alloc] =ResolvetheLastBit(bits_alloc,energy_alloc,index,energytable,num_subc)max_val = 0;for i = 1:num_subcif (i ~= index & bits_alloc(i) == 1)if bits_alloc(i) ~= 0temp = energytable(i,bits_alloc(i)) ;endif (temp > max_val)max_val = temp;max_ind = i;endendendmin_val = Inf;for i = 1:num_subcif (i~= index & bits_alloc(i) == 1)if bits_alloc(i) ~=0temp = energytable(i,bits_alloc(i) + 1);endif (temp < min_val)min_val = temp;min_ind = i;endendendif (min_val < max_val)bits_alloc(min_ind) = bits_alloc(min_ind) + 1;bits_alloc(index) = bits_alloc(index) - 1;energy_alloc(index) = energy_alloc(index) - min_val; elsebits_alloc(max_ind) = bits_alloc(max_ind) - 1;bits_alloc(index) = bits_alloc(index) + 1;energy_alloc(index) = energy_alloc(index) + max_val; end。
: OFDM Simulator (outer function)clear all;A = [1 1/exp(1) 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 = 1e-3; % noise varianceM = 8; % max constellation bit numberMgap = 10.^(1:(1.7/10):2.7); % gapBtot = 100*Mt; % total # bits per OFDM symbolTransmitIter = 50; % # iterations of symbol transmissions for each channel instance ChannelIter = 100; % # iterations of independent identically distributed channel instances GapIter = length(Mgap);loadloadloadloadloadTotEbNo = [];Errors =[];EbNo = [];for lGap = 1:GapIterlGapgap = Mgap(lGap);totalErrors = 0;for lChan = 1:ChannelIter% create channel[H 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);% 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);for lTrans = 1:TransmitIter% bits to transmitx = (randn(1,Btot)>0);% modulatex_mod = modulate(x,bits_alloc,energy_alloc, s2,s4,s16,s64,s256);% precode modulated signalx_pre = precode(Mt, x_mod, V, N);% ifft, with cyclic prefix for each antennaofdm_symbol =[];for i=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 =[];for i=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);% shape received signalshaped_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 = [EbNo sum(energy_alloc)/Btot/sig2];endErrors = [Errors totalErrors/Btot/ChannelIter/TransmitIter]TotEbNo = [TotEbNo mean(EbNo)]EbNo = [];endsemilogx(TotEbNo, Errors);xlabel('Eb/No');ylabel('BER');title('SISO link, adaptive rate and power')save Errors EbNo: Generates a Rayleigh fading frequency-selective channel, parametrized by the antenna configuration, the OFDM configuration, and the power-delay profile.function [H, H_f]=create_channel(Mt, Mr, A, N);% function [H, H_f]=create_channel(Mt, Mr, A, N);%% 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 is 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/sqrt(2)*(randn(Mr*length(A),Mt) + j*randn(Mr*length(A),Mt));H_int2=[];for i = 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));for i = 1:Mtfor j = 1:Mrh_f = fft(H_int2(j:Mr:(N-16-1)*Mr+j,i));for k = 1:(N-16)H_f(j,i+(k-1)*Mt) = h_f(k);endendendH=[H_int2];for i = 1:N-1H=[H,[zeros(Mr*i,Mt);H_int2(1:(N-i)*Mr,:)]];end: Since full channel knowledge is assumed, transmission is across parallel singular value modes. This function decomposes the channel into these modes.function [U, S, V] = svd_decompose_channel(Mt, Mr, h_f, N);% [U S V] = svd_decompose_channel(Mt, Mr, h_f, N);%% Function decomposes the channel at each subcarrier into its SVD components %% Mt - # Tx antennas% Mr - # Rx antennas% h_f - MIMO impulse response - Mr rows, Mt*L columns, where L is the number of% channel taps% N - # subcarriersU = [];S = [];V = [];for i = 1:N[Utmp Stmp Vtmp] = svd(h_f(:,(i-1)*Mt+1:i*Mt));U=[U Utmp];V=[V Vtmp];S=[S Stmp];endS = sum(S,1);: 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% ---------------------%% Inputs :% subchan_gains : SubCarrier Gains% total_bits : Total Number of bits% num_subc : Number of Subcarriers% gap : Gap of the system% noise : Noise Power% M : Max Constellation Size% Outputs:% bits_alloc : Bits allocation for each subchannel% power_alloc : Total Power allocation% ---------------------------------------------------------------% Compute SNR's for each channelSNR = ComputeSNR(subchan_gains,noise,gap);% This function just initializes the system with a particular bit% allocation and energy allocation using Chow's Algorithm. This is% further efficientize using Campello's Algorithm[bits_alloc, energy_alloc] = chow_algo(SNR,num_subc,M);% Form the Energy Increment Table based on the present channel% gains for all the subchannels in order to be used by Campello% Algorithmenergytable = EnergyTableInit(SNR,M);% Efficientize the algorithm using the Campello's algorithm[bits_alloc,energy_alloc] =campello_algo(bits_alloc,energy_alloc,energytable,total_bits,num_subc,M );: Given the subcarrier gains, this simple function generates the SNR values of each channel (each singular value on each tone is a separate channel).function SNR = ComputeSNR(subcar_gains,noise,gap)SNR = abs((subcar_gains.^2)./(noise*gap));: Apply Chow's algorithm to generate a particular bit and energy allocation.% Chow's Algorithm% ----------------% This is based on the paper by Chow et al titled%% A Practical Discrete Multitone Transceiver Loading Algorithm% for Data Transmission over Spectrally Shaped Channels.IEEE Trans% on Communications. Vol. 43, No 2/3/4, pp. 773-775, Feb/Mar/Apr 1995 function [bits_alloc, energy_alloc] = chow_algo(SNR,num_subc,M)for i = 1:num_subc% Assuming each of the subchannels has a flat fading, we get initial estimate % of the bits for each subchanneltempbits = log2(1 + abs(SNR(i))); % bits per two dimension. roundtempbits = round(tempbits); % round the bitsif (roundtempbits > 8) % Limit them between 2 and 15 roundtempbits = 8;endif (mod(roundtempbits,2)== 1 & roundtempbits ~= 1)roundtempbits = roundtempbits -1;endif roundtempbits > 0 % Calculate the Energy required for the subchannelenergy_alloc(i) = (2^roundtempbits-1)/SNR(i) ;elseenergy_alloc(i) = 0;endbits_alloc(i) = roundtempbits; % Update the BitSubChan end% end of function: Given the SNR values, form a table of energy increments for each channel.function energytable = EnergyTableInit(SNR,M);% Inputs:% subcar_gains : Subcarrier Gains% M : max Constellation Size% Gap : Gap of the system% Noise : Noise Power% Outputs:% energytable : Energytable%% Based on the Subcarrier Gains, we calculate the energy% increment required by each subcarrier for transmitting% 1,2 ,4 ,6,8 bits.% Energy = 2^(i-1)/subcar_gains;% ------------------------------------------------------%subcar_gains = (subcar_gains.^2)/(Gap*Noise);energytable = abs((1./SNR)'*(2.^([1:M+1]-1)));% Increase the energy value for constellation size of more than M to% a very high value so that it is not assigned.energytable(:,M+1) = Inf*ones(size(energytable(:,M+1)));for i = 3:2:Menergytable(:,i) = (energytable(:,i) +energytable(:,i+1))/2;energytable(:,i+1) = energytable(:,i);end%energytable = [ones(1,size(energytable,1))' energytable];: Apply Campello's algorithm to converge to the optimal bit and energy allocation for the given channel conditions.% --------------% This function is used by Campello's algorithm to allocate bits and energy for% each subchannel optimally.function [bits_alloc, energy_alloc] =campello_algo(bits_alloc,energy_alloc,energytable,total_bits,num_subc,M)bt = sum(bits_alloc);% We can't 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(1)*num_subc);for i = 1:num_subcif bits_alloc(i) ~= 0temp = energytable(i,bits_alloc(i)) ;elsetemp = 0;endif (temp > max_val)max_val = temp;max_ind = i;endendif (bits_alloc(max_ind) > 0)bits_alloc(max_ind) = bits_alloc(max_ind) -1;energy_alloc(max_ind) = energy_alloc(max_ind) - max_val;bt = bt-1;endelsemin_val = Inf;min_ind = ceil(rand(1)*num_subc);for i = 1:num_subcif bits_alloc(i) ~=0 & bits_alloc(i) <9temp = energytable(i,bits_alloc(i) + 1);elsetemp = Inf;endif (temp < min_val)min_val = temp;min_ind = i;endendif (bits_alloc(min_ind) < 8)bits_alloc(min_ind) = bits_alloc(min_ind) +1;if (min_val==inf)min_val = energytable(min_ind,bits_alloc(min_ind));endenergy_alloc(min_ind) = energy_alloc(min_ind) +min_val;bt = bt+1;endendendfor i = 1:length(bits_alloc)if (mod(bits_alloc(i),2) == 1 & bits_alloc(i) ~=1)[bits_alloc,energy_alloc] =ResolvetheLastBit(bits_alloc,energy_alloc,i,energytable,num_subc);endend: An optimal bit-loading of the last bit requires a unique optimization.function [bits_alloc, energy_alloc] =ResolvetheLastBit(bits_alloc,energy_alloc,index,energytable,num_subc) max_val = 0;for i = 1:num_subcif (i ~= index & bits_alloc(i) == 1)if bits_alloc(i) ~= 0temp = energytable(i,bits_alloc(i)) ;endif (temp > max_val)max_val = temp;max_ind = i;endendendmin_val = Inf;for i = 1:num_subcif (i~= index & bits_alloc(i) == 1)if bits_alloc(i) ~=0temp = energytable(i,bits_alloc(i) + 1);endif (temp < min_val)min_val = temp;min_ind = i;endendendif (min_val < max_val)bits_alloc(min_ind) = bits_alloc(min_ind) + 1;bits_alloc(index) = bits_alloc(index) - 1;energy_alloc(index) = energy_alloc(index) - min_val; elsebits_alloc(max_ind) = bits_alloc(max_ind) - 1;bits_alloc(index) = bits_alloc(index) + 1;energy_alloc(index) = energy_alloc(index) + max_val; end。
一、题目OFDM系统的Matlab仿真二、仿真要求要求一:OFDM系统的数据传输①传输的数据随机产生;②调制方式采用16QAM;③必须加信道的衰落④必须加高斯白噪声⑤接收端要对信道进行均衡。
要求二:要求对BER的性能仿真设计仿真方案,得到在数据传输过程中不同信噪比的BER性能结论,要求得到的BER曲线较为平滑。
三、仿真方案详细设计(一)基于IFFT/FFT 实现的OFDM 系统方框图:(二)详细设计方案: 1确定参数需要确定的参数为:子信道,子载波数,FFT 长度,每次使用的OFDM 符号数,调制度水平,符号速率,比特率,保护间隔长度,信噪比,插入导频数,基本的仿真可以不插入导频,可以为0。
2产生数据使用个随机数产生器产生二进制数据,每次产生的数据个数为carrier_count * symbols_per_carrier * bits_per_symbol 。
3编码交织交织编码可以有效地抗突发干扰。
4子载波调制OFDM 采用BPSK 、QPSK 、16QAM 、64QAM4种调制方式。
按照星座图,将每个子信道上的数据,映射到星座图点的复数表示,转换为同相Ich 和正交分量Qch 。
其实这是一种查表的方法,以16QAM 星座为例,bits_per_symbol=4,则每个OFDM 符号的每个子信道上有4个二进制数{d1,d2,d3,d4},共有16种取值,对应星座图上16个点,每个点的实部记为Qch 。
为了所有的映射点有相同高的平均功率,输出要进行归一化,所以对应BPSK,PQSK,16QAM,64QAM ,分别乘以归一化系数系数1,21, 101, 421.输出的复数序列即为映射后的调制结果。
5串并转换。
将一路高速数据转换成多路低速数据 6 IFFT 。
对上一步得到的相同分量和正交分量按照(Ich+Qch*i )进行IFFT 运算。
并将得到的复数的实部作为新的Ich ,虚部作为新的Qch 。
mimoofdm无线通信技术与matlab代码1. 引言1.1 概述无线通信技术的发展迅猛,随着移动互联网时代的到来,人们对高速、稳定的无线通信需求日益增加。
MIMO-OFDM无线通信技术作为一种重要的解决方案,在提升系统容量和抗干扰性能方面具有显著优势。
本文旨在介绍MIMO-OFDM 无线通信技术原理,并借助MATLAB代码实现,通过仿真和性能评估分析展示其有效性和优越性。
1.2 文章结构本文分为五个部分:引言、MIMO-OFDM无线通信技术、MATLAB代码实现、实验结果与讨论以及结论与展望。
在引言部分,我们将简要介绍文章的背景和目标。
接下来,会详细讲解MIMO-OFDM无线通信技术的基本原理,并说明其在提高系统容量和抗干扰性能方面的作用。
然后,我们会详细描述如何使用MATLAB编写MIMO-OFDM系统模拟代码,并进行性能评估与分析。
随后,我们会展示仿真参数设置和结果展示,并对结果进行深入分析和性能讨论。
最后,在结论与展望部分,我们将总结本文的研究工作和贡献,并讨论目前的不足之处以及可能的改进方案。
1.3 目的本文的主要目的是深入介绍MIMO-OFDM无线通信技术及其原理,并通过MATLAB代码实现来验证其性能。
通过对实验结果进行分析和讨论,我们旨在揭示MIMO-OFDM技术在提高系统容量和抗干扰性能方面的优势。
同时,本文也希望为读者提供一个了解和学习MIMO-OFDM无线通信技术以及使用MATLAB进行系统模拟的参考。
以上就是“1. 引言”部分内容,概述了本文的背景、目标和结构。
在接下来的章节中,我们将逐一展开讲解MIMO-OFDM无线通信技术、MATLAB代码实现、实验结果与讨论以及结论与展望部分。
2. MIMO-OFDM无线通信技术:2.1 MIMO技术介绍:多输入多输出(MIMO)技术是一种通过在发射和接收端使用多个天线来增加系统容量和提高通信质量的无线通信技术。
MIMO技术利用空间上的多样性,通过在不同天线之间形成独立的传输通道,从而带来更好的抗干扰能力和信号接收品质。
: OFDM Simulator (outer function)clear all;A = [1 1/exp(1) 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 = 1e-3; % noise varianceM = 8; % max constellation bit numberMgap = 10.^(1:(1.7/10):2.7); % gapBtot = 100*Mt; % total # bits per OFDM symbolTransmitIter = 50; % # iterations of symbol transmissions for each channel instance ChannelIter = 100; % # iterations of independent identically distributed channel instances GapIter = length(Mgap);loadloadloadloadloadTotEbNo = [];Errors =[];EbNo = [];for lGap = 1:GapIterlGapgap = Mgap(lGap);totalErrors = 0;for lChan = 1:ChannelIter% create channel[H 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);% 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);for lTrans = 1:TransmitIter% bits to transmitx = (randn(1,Btot)>0);% modulatex_mod = modulate(x,bits_alloc,energy_alloc, s2,s4,s16,s64,s256);% precode modulated signalx_pre = precode(Mt, x_mod, V, N);% ifft, with cyclic prefix for each antennaofdm_symbol =[];for i=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 =[];for i=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);% shape received signalshaped_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 = [EbNo sum(energy_alloc)/Btot/sig2];endErrors = [Errors totalErrors/Btot/ChannelIter/TransmitIter]TotEbNo = [TotEbNo mean(EbNo)]EbNo = [];endsemilogx(TotEbNo, Errors);xlabel('Eb/No');ylabel('BER');title('SISO link, adaptive rate and power')save Errors EbNo: Generates a Rayleigh fading frequency-selective channel, parametrized by the antenna configuration, the OFDM configuration, and the power-delay profile.function [H, H_f]=create_channel(Mt, Mr, A, N);% function [H, H_f]=create_channel(Mt, Mr, A, N);%% 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 is 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/sqrt(2)*(randn(Mr*length(A),Mt) + j*randn(Mr*length(A),Mt));H_int2=[];for i = 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));for i = 1:Mtfor j = 1:Mrh_f = fft(H_int2(j:Mr:(N-16-1)*Mr+j,i));for k = 1:(N-16)H_f(j,i+(k-1)*Mt) = h_f(k);endendendH=[H_int2];for i = 1:N-1H=[H,[zeros(Mr*i,Mt);H_int2(1:(N-i)*Mr,:)]];end: Since full channel knowledge is assumed, transmission is across parallel singular value modes. This function decomposes the channel into these modes.function [U, S, V] = svd_decompose_channel(Mt, Mr, h_f, N);% [U S V] = svd_decompose_channel(Mt, Mr, h_f, N);%% Function decomposes the channel at each subcarrier into its SVD components %% Mt - # Tx antennas% Mr - # Rx antennas% h_f - MIMO impulse response - Mr rows, Mt*L columns, where L is the number of% channel taps% N - # subcarriersU = [];S = [];V = [];for i = 1:N[Utmp Stmp Vtmp] = svd(h_f(:,(i-1)*Mt+1:i*Mt));U=[U Utmp];V=[V Vtmp];S=[S Stmp];endS = sum(S,1);: 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% ---------------------%% Inputs :% subchan_gains : SubCarrier Gains% total_bits : Total Number of bits% num_subc : Number of Subcarriers% gap : Gap of the system% noise : Noise Power% M : Max Constellation Size% Outputs:% bits_alloc : Bits allocation for each subchannel% power_alloc : Total Power allocation% ---------------------------------------------------------------% Compute SNR's for each channelSNR = ComputeSNR(subchan_gains,noise,gap);% This function just initializes the system with a particular bit% allocation and energy allocation using Chow's Algorithm. This is% further efficientize using Campello's Algorithm[bits_alloc, energy_alloc] = chow_algo(SNR,num_subc,M);% Form the Energy Increment Table based on the present channel% gains for all the subchannels in order to be used by Campello% Algorithmenergytable = EnergyTableInit(SNR,M);% Efficientize the algorithm using the Campello's algorithm[bits_alloc,energy_alloc] =campello_algo(bits_alloc,energy_alloc,energytable,total_bits,num_subc,M );: Given the subcarrier gains, this simple function generates the SNR values of each channel (each singular value on each tone is a separate channel).function SNR = ComputeSNR(subcar_gains,noise,gap)SNR = abs((subcar_gains.^2)./(noise*gap));: Apply Chow's algorithm to generate a particular bit and energy allocation.% Chow's Algorithm% ----------------% This is based on the paper by Chow et al titled%% A Practical Discrete Multitone Transceiver Loading Algorithm% for Data Transmission over Spectrally Shaped Channels.IEEE Trans% on Communications. Vol. 43, No 2/3/4, pp. 773-775, Feb/Mar/Apr 1995 function [bits_alloc, energy_alloc] = chow_algo(SNR,num_subc,M)for i = 1:num_subc% Assuming each of the subchannels has a flat fading, we get initial estimate % of the bits for each subchanneltempbits = log2(1 + abs(SNR(i))); % bits per two dimension. roundtempbits = round(tempbits); % round the bitsif (roundtempbits > 8) % Limit them between 2 and 15 roundtempbits = 8;endif (mod(roundtempbits,2)== 1 & roundtempbits ~= 1)roundtempbits = roundtempbits -1;endif roundtempbits > 0 % Calculate the Energy required for the subchannelenergy_alloc(i) = (2^roundtempbits-1)/SNR(i) ;elseenergy_alloc(i) = 0;endbits_alloc(i) = roundtempbits; % Update the BitSubChan end% end of function: Given the SNR values, form a table of energy increments for each channel.function energytable = EnergyTableInit(SNR,M);% Inputs:% subcar_gains : Subcarrier Gains% M : max Constellation Size% Gap : Gap of the system% Noise : Noise Power% Outputs:% energytable : Energytable%% Based on the Subcarrier Gains, we calculate the energy% increment required by each subcarrier for transmitting% 1,2 ,4 ,6,8 bits.% Energy = 2^(i-1)/subcar_gains;% ------------------------------------------------------%subcar_gains = (subcar_gains.^2)/(Gap*Noise);energytable = abs((1./SNR)'*(2.^([1:M+1]-1)));% Increase the energy value for constellation size of more than M to% a very high value so that it is not assigned.energytable(:,M+1) = Inf*ones(size(energytable(:,M+1)));for i = 3:2:Menergytable(:,i) = (energytable(:,i) +energytable(:,i+1))/2;energytable(:,i+1) = energytable(:,i);end%energytable = [ones(1,size(energytable,1))' energytable];: Apply Campello's algorithm to converge to the optimal bit and energy allocation for the given channel conditions.% --------------% This function is used by Campello's algorithm to allocate bits and energy for% each subchannel optimally.function [bits_alloc, energy_alloc] =campello_algo(bits_alloc,energy_alloc,energytable,total_bits,num_subc,M)bt = sum(bits_alloc);% We can't 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(1)*num_subc);for i = 1:num_subcif bits_alloc(i) ~= 0temp = energytable(i,bits_alloc(i)) ;elsetemp = 0;endif (temp > max_val)max_val = temp;max_ind = i;endendif (bits_alloc(max_ind) > 0)bits_alloc(max_ind) = bits_alloc(max_ind) -1;energy_alloc(max_ind) = energy_alloc(max_ind) - max_val;bt = bt-1;endelsemin_val = Inf;min_ind = ceil(rand(1)*num_subc);for i = 1:num_subcif bits_alloc(i) ~=0 & bits_alloc(i) <9temp = energytable(i,bits_alloc(i) + 1);elsetemp = Inf;endif (temp < min_val)min_val = temp;min_ind = i;endendif (bits_alloc(min_ind) < 8)bits_alloc(min_ind) = bits_alloc(min_ind) +1;if (min_val==inf)min_val = energytable(min_ind,bits_alloc(min_ind));endenergy_alloc(min_ind) = energy_alloc(min_ind) +min_val;bt = bt+1;endendendfor i = 1:length(bits_alloc)if (mod(bits_alloc(i),2) == 1 & bits_alloc(i) ~=1)[bits_alloc,energy_alloc] =ResolvetheLastBit(bits_alloc,energy_alloc,i,energytable,num_subc);endend: An optimal bit-loading of the last bit requires a unique optimization.function [bits_alloc, energy_alloc] =ResolvetheLastBit(bits_alloc,energy_alloc,index,energytable,num_subc) max_val = 0;for i = 1:num_subcif (i ~= index & bits_alloc(i) == 1)if bits_alloc(i) ~= 0temp = energytable(i,bits_alloc(i)) ;endif (temp > max_val)max_val = temp;max_ind = i;endendendmin_val = Inf;for i = 1:num_subcif (i~= index & bits_alloc(i) == 1)if bits_alloc(i) ~=0temp = energytable(i,bits_alloc(i) + 1);endif (temp < min_val)min_val = temp;min_ind = i;endendendif (min_val < max_val)bits_alloc(min_ind) = bits_alloc(min_ind) + 1;bits_alloc(index) = bits_alloc(index) - 1;energy_alloc(index) = energy_alloc(index) - min_val; elsebits_alloc(max_ind) = bits_alloc(max_ind) - 1;bits_alloc(index) = bits_alloc(index) + 1;energy_alloc(index) = energy_alloc(index) + max_val; end。
第一章绪论1.1简述OFDM是一种特殊的多载波传输方案,它可以被看作是一种调制技术,也可以被当作一种复用技术。
多载波传输把数据流分解成若干子比特流,这样每个子数据流将具有低得多的比特速率,用这样的低比特率形成的低速率多状态符号再去调制相应的子载波,就构成多个低速率符号并行发送的传输系统。
正交频分复用是对多载波调制(MCM,Multi-Carrier Modulation)的一种改进。
它的特点是各子载波相互正交,所以扩频调制后的频谱可以相互重叠,不但减小了子载波间的干扰,还大大提高了频谱利用率。
符号间干扰是多径衰落信道宽带传输的主要问题,多载波调制技术包括正交频分复用(OFDM)是解决这一难题中最具前景的方法和技术。
利用OFDM技术和IFFT方式的数字实现更适宜于多径影响较为显著的环境,如高速WLAN 和数字视频广播DVB等。
OFDM作为一种高效传输技术备受关注,并已成为第4代移动通信的核心技术。
如果进行OFDM系统的研究,建立一个完整的OFDM系统是必要的。
本文在简要介绍了OFDM 基本原理后,基于MATLAB 构建了一个完整的OFDM动态仿真系统。
1.2 OFDM基本原理概述1.2.1 OFDM的产生和发展OFDM的思想早在20世纪60年代就已经提出,由于使用模拟滤波器实现起来的系统复杂度较高,所以一直没有发展起来。
在20世纪70年代,提出用离散傅里叶变换(DFT)实现多载波调制,为OFDM的实用化奠定了理论基础;从此以后,OFDM在移动通信中的应用得到了迅猛的发展。
OFDM系统收发机的典型框图如图1.1所示,发送端将被传输的数字信号转换成子载波幅度和相位的映射,并进行离散傅里叶变换(IDFT)将数据的频谱表达式变换到时域上。
IFFT变换与IDFT变换的作用相同,只是有更高的计算效率,所以适用于所有的应用系统。
其中,上半部分对应于发射机链路,下半部分对应于接收机链路。
由于FFT操作类似于IFFT,因此发射机和接收机可以使用同一硬件设备。
clear all。
close all。
fprintf( '\n OFDM仿真\n \n'> 。
% --------------------------------------------- %% 参数定义%% --------------------------------------------- %IFFT_bin_length = 1024。
carrier_count = 200。
bits_per_symbol = 2。
symbols_per_carrier = 50。
% 子载波数200% 位数/ 符号 2% 符号数/ 载波50% 训练符号数10% 循环前缀长度T/4<作者注明)All-zero CP % 调制方式QDPSK% 多径信道数 2、3、4<缺省)% 信道最大时延7 (单位数据符号>% 仿真条件收发之间严格同步 %SNR=input('SNR='>。
% 输入信噪比参数SNR=3:14。
%定义信噪比范围BER=zeros(1,length(SNR>>。
baseband_out_length = carrier_count * symbols_per_carrier * bits_per_symbol。
% 计算发送的二进制序列长度carriers = (1: carrier_count> + (floor(IFFT_bin_length/4> - floor(carrier_count/2>>。
% 坐标: (1 to 200> + 156 , 157 -- 356conjugate_carriers=IFFT_bin_length-carriers+2。
% 坐标:1024 - (157:356> + 2 = 1026 - (157:356> = (869:670> % 构造共轭时间-载波矩阵,以便应用所谓的RCC,Reduced Computational Complexity算法,即i fft之后结果为实数% Define the conjugate time-carrier matrix% 也可以用flipdim函数构造对称共轭矩阵% --------------------------------------------- %% 信号发射%% --------------------------------------------- %%out = rand(1,baseband_out_length>。
第一章绪论1.1简述OFDM是一种特殊的多载波传输方案,它可以被看作是一种调制技术,也可以被当作一种复用技术。
多载波传输把数据流分解成若干子比特流,这样每个子数据流将具有低得多的比特速率,用这样的低比特率形成的低速率多状态符号再去调制相应的子载波,就构成多个低速率符号并行发送的传输系统。
正交频分复用是对多载波调制(MCM,Multi-Carrier Modulation)的一种改进。
它的特点是各子载波相互正交,所以扩频调制后的频谱可以相互重叠,不但减小了子载波间的干扰,还大大提高了频谱利用率。
符号间干扰是多径衰落信道宽带传输的主要问题,多载波调制技术包括正交频分复用(OFDM)是解决这一难题中最具前景的方法和技术。
利用OFDM技术和IFFT方式的数字实现更适宜于多径影响较为显著的环境,如高速WLAN 和数字视频广播DVB等。
OFDM作为一种高效传输技术备受关注,并已成为第4代移动通信的核心技术。
如果进行OFDM系统的研究,建立一个完整的OFDM 系统是必要的。
本文在简要介绍了OFDM 基本原理后,基于MATLAB构建了一个完整的OFDM动态仿真系统。
1.2 OFDM基本原理概述1.2.1 OFDM的产生和发展OFDM的思想早在20世纪60年代就已经提出,由于使用模拟滤波器实现起来的系统复杂度较高,所以一直没有发展起来。
在20世纪70年代,提出用离散傅里叶变换(DFT)实现多载波调制,为OFDM的实用化奠定了理论基础;从此以后,OFDM在移动通信中的应用得到了迅猛的发展。
OFDM系统收发机的典型框图如图1.1所示,发送端将被传输的数字信号转换成子载波幅度和相位的映射,并进行离散傅里叶变换(IDFT)将数据的频谱表达式变换到时域上。
IFFT变换与IDFT变换的作用相同,只是有更高的计算效基于MATLAB实现OFDM的仿真率,所以适用于所有的应用系统。
其中,上半部分对应于发射机链路,下半部分对应于接收机链路。
OFDM.m : OFDM Simulator (outer function)clear all;A = [1 1/exp(1) 1/exp (2) ]; % power delay profileN = 64; % number of symbols in a single OFDM symbolGI = 16; % guard in tervalMt = 1; % n umber of Tx antennasMr = 1; % n umber of Rx antennassig2 = 1e-3; % no ise varia neeM = 8; % max eon stellati on bit n umberMgap = 10.A(1:(1.7/10):2.7); % gapBtot = 100*Mt; % total # bits per OFDM symbolTransmitIter = 50; % # iterations of symbol transmissions for each channel instanee Channeliter = 100; % # iterations of independent identically distributed channel instances Gapiter = len gth(Mgap);load ENC2.matload ENC4.matload ENC16.matload ENC64.matload ENC256.matTotEbNo =[];Errors =[];EbNo =[];for lGap = 1:GaplterlGapgap = Mgap(lGap);totalErrors = 0;for lCha n = 1:Cha nn ellter% create cha nnel[H h_f]=create_cha nn el(Mt, Mr, A, N+GI);% decompose each subcha nnel in the freque ncy doma in[U S V] = svd_decompose_cha nn el(Mt, Mr, h_f, N);% bitloadi ng[bits_alloc,e nergy_alloc] = BitLoad(S,Btot,Mt*N,gap,sig2,M);%en ergy_alloc=e nergy_alloc/(mea n(e nergy_alloc));%e nergy_alloc=o nes(1,128);for lTra ns = 1:Tra nsmitlter% bits to tra nsmitx = (ra ndn (1,Btot)>0);% modulatex_mod = modulate(x,bits_alloc,e nergy_alloc, S2,S4,S16,S64,S256);% precode modulated sig nal x_pre = precode(Mt, x_mod, V, N);% ifft, with cyclic prefix for each antennaofdm_symbol =[];for i=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);% cha nnely = transpose(channel(sig2, Mt, Mr, ofdm_symbol2, H, N+GI));% fftrec_symbol =[];for i=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);% shape received sig nalshaped_vals = shape(rec_symbol2, Mr, U, N);% demodulatey_demod = demodulate(shaped_vals, bits_alloc, en ergy_alloc, S, s2,s4,s16,s64,s256, c2,c4,c16,c64,c256);% comparis ontotalErrors = totalErrors + sum(xor(y_demod,x));endEbNo = [EbNo sum(e nergy_alloc)/Btot/sig2];endErrors = [Errors totalErrors/Btot/Cha nn elIter/Tra nsmitlter]TotEbNo = [TotEbNo mea n(EbNo)]EbNo =[];endsemilogx(TotEbNo, Errors);xlabel('Eb/No');ylabel('BER');title( 'SISO link, adaptive rate and power')save SISO_adaptive2.mat Errors EbNocreate cha nn el.m : Gen erates a Rayleigh fadi ng freque ncy-selective cha nn el, parametrized by the antenna con figurati on, the OFDM con figurati on, and the power-delay profile.fun cti on [H, H_f]=create_cha nn el(Mt, Mr, A, N);% function [H, H_f]=create_channel(Mt, Mr, A, N);% - -% A - vector containing the power-delay profile (real values)% Mt - n umber of Tx antennas% Mr - n umber of Rx antennas% N - n umber of vector symbols to be sent in a sin gle OFDM symbol Tx% ie: N MIMO tran smissio ns in one OFDM symbol% This is for Rayleigh freque ncy-selective fading, which assumes complex% Gaussia n matrix eleme nts with in-phase and quadrature comp onentsin depe ndent.% Assume iid matrix channel elements, and further, independent channel taps% defi ne the cha nnel tapsH」nt = 1/sqrt(2)*(ra ndn( Mr*le ngth(A),Mt) + j*ra ndn (Mr*le ngth(A),Mt));H_in t2=[];for i = 1:le ngth(A)H」nt2 = [H」n t2;sqrt(A(i))*H _in t((i-1)*M r+1:i*Mr,:)];end%h_f = fft(H_in t2',64);%%H = H」n t2';H」nt2 = [H」n t2;zeros((N-le ngth(A))*Mr,Mt)];H_f = zeros(Mr,Mt*(N-16));for i = 1:Mtfor j = 1:Mrh_f = fft(H _in t2(j:Mr:(N-16-1)*Mr+j,i));for k = 1:(N-16)H_f(j,i+(k-1)*Mt) = h_f(k);endendendH=[H」n t2];for i = 1:N-1H=[H,[zeros(Mr*i,Mt);H」n t2(1:(N-i)*Mr,:)]];endsvd_decompose_channel.m : Since full channel knowledge is assumed, transmissionis across parallel singular value modes. This function decomposes the channel into these modes.fun cti on [U, S, V] = svd_decompose_cha nn el(Mt, Mr, h_f, N);% [U S V] = svd_decompose_cha nn el(Mt, Mr, h_f, N);%% Function decomposes the channel at each subcarrier into its SVD components %% Mt - # Tx antennas% Mr - # Rx antennas% h_f - MIMO impulse response - Mr rows, Mt*L columns, where L is the numberof% cha nnel taps% N - # subcarriersU =[];S =[];V =[];for i = 1:N[Utmp Stmp Vtmp] = svd(h_f(:,(i-1)*Mt+1:i*Mt));U=[U Utmp]; -V=[V Vtmp];S=[S Stmp]; endS = sum(S,1);BitLoad.m : Apply the bit-loading algorithm to achieve the desired bit andallocati on for the curre nt cha nnel in sta nee. fun cti on [bits_alloc,e nergy_alloc]=BitLoad(subcha n_gain s,total_bits ,n um_subc,gap ,no ise,M) % Bit Loading Algorithm% ........................%% In puts :subchan_gains : SubCarrier Gains total_bits : Total Number of bits n um_subc : Number of Subcarriers gap : Gap of the system no ise : Noise PowerM : Max Con stellation Size % Outputs:% bits alloc : Bits allocation for each subchannel % power_alloc : Total Power allocati on% ................................................................... % Compute SNR's for each cha nnel SNR = ComputeSNR(subcha n_gains,no ise,gap);% This fun cti on just in itializes the system with a particular bit % allocation and energy allocation using Chow's Algorithm. This is % further efficientize using Campello's Algorithm[bits_alloc, en ergy_alloc] = chow_algo(SNR ,n um_subc,M);% Form the En ergy In creme nt Table based on the prese nt cha nnel % gains for all the subcha nn els in order to be used by Campello % Algorithmen ergytable = En ergyTablel ni t(SNR,M);% Efficientize the algorithm using the Campello's algorithm [bits_alloc,e nergy_alloc]=campello_algo(bits_alloc,e nergy_alloc,e nergytable,total_bits, num_subc,M ); _ _ _ - -ComputeSNR.m : Give n the subcarrier gains, this simple fun ctio n gen erates the SNR values of each cha nn el (each sin gular value on each tone is a separate cha nn el).fun cti on SNR = ComputeSNR(subcar_ga ins,no ise,gap)SNR = abs((subcar_ga in s.A 2)./( noise*gap));en ergy% % %% %chow_algo.m : Apply Chow's algorithm to gen erate a particular bit anden ergy% Chow's Algorithm% ..................% This is based on the paper by Chow et al titled%% A Practical Discrete Multit one Tran sceiver Loadi ng Algorithm% for Data Tran smissi on over Spectrally Shaped Chann els .I EEE Tra ns% on Communications. Vol. 43, No 2/3/4, pp. 773-775, Feb/Mar/Apr 1995fun cti on [bits_alloc, en ergy_alloc] = chow_algo(SNR, num_subc,M) for i = 1:n um_subc% Assuming each of the subchannels has a flat fading, we get initial estimate% of the bits for each subcha nneltempbits = log2(1 + abs(SNR(i))); % bits per two dime nsion.rou ndtempbits = roun d(tempbits); % round the bitsif (rou ndtempbits > 8)% Limit them betwee n 2 and 15 rou ndtempbits = 8;end if (mod(rou ndtempbits,2)== 1 & rou ndtempbits ~= 1) roundtempbits = roundtempbits -1;endif rou ndtempbits > 0for the subcha nnelenergy_alloc(i) = (2A roundtempbits-1)/SNR(i);elseen ergy_alloc(i) = 0;endbits_alloc(i) = roun dtempbits;end % end of fun cti on En ergyTable In it.m : Give n the SNR values, form a table of en ergy in creme nts for eachcha nn el.fun cti on en ergytable = En ergyTablel ni t(SNR,M);% In puts:subcar_ga ins : Subcarrier Gains% M : max Con stellati on Size % Gap : Gap of the system % Noise : Noise Power % Outputs: % en ergytable : En ergytable % Based on the Subcarrier Gai ns, we calculate the en ergy % in creme nt required by each subcarrier for tran smitt ing % 1,2 ,4 ,6,8 bits.% En ergy = 2A(i-1)/subcar_ga ins;% Calculate the En ergy required % Update the BitSubChan% ...............................................................%subcar_ga ins = (subcar_ga in s.A2)/(Gap*Noise);en ergytable = abs((1./SNR)'*(2.A([i:M+1]-1)));% In crease the en ergy value for con stellati on size of more tha n M to % a very high value so that it is not assig ned.en ergytable(:,M+1) = lnf*on es(size(e nergytable(:,M+1)));for i = 3:2:Men ergytable(:,i) = (en ergytable(:,i) +en ergytable(:,i+1))/2;en ergytable(:,i+1) = en ergytable(:,i);end%en ergytable = [on es(1,size(e nergytable,1))' en ergytable];campello algo.m : Apply Campello's algorithm to con verge to the optimal en ergy allocati on for the give n cha nnel con diti ons.% campello_algo.m% ................% This function is used by Campello's algorithm to allocate bits andfor% each subcha nnel optimally.fun cti on [bits_alloc, en ergy_alloc]=campello_algo(bits_alloc,e nergy_alloc,e nergytable,total_bits, num_subc,M) _ _ _ - -bt = sum(bits_alloc);% We can't tran smit more tha n M*(Number of subcha nn el) bitsif total_bits > M*n um_subctotal_bits = M*n um_subc;endwhile (bt ~= total_bits)if (bt > total_bits)max_val = 0;max_i nd = ceil(ra nd(1)* num_subc);for i = 1:n um_subcif bits_alloc(i) ~= 0temp = en ergytable(i,bits_alloc(i));elsetemp = 0;endif (temp > max_val)max_val = temp;max_i nd = i;end bit and en ergyendif (bits_alloc(max_i nd) > 0) bits_alloc(max_i nd) = bits_alloc(max_i nd) -1; en ergy_alloc(max_i nd) = en ergy_alloc(max_i nd) - max_val; bt = bt-1;endelsemin_val = Inf;min_ind = ceil(ra nd(1)* num_subc);for i = 1:n um_subcif bits_alloc(i) ~=0 & bits_alloc(i) <9temp = en ergytable(i,bits_alloc(i) + 1);elsetemp = Inf;endif (temp < min_val)min_val = temp;min_i nd = i;endendif (bits_alloc(min_i nd) < 8)bits_alloc(min_i nd) = bits_alloc(min_i nd) +1;if (min_val==i nf)min_val = en ergytable(min_i nd,bits_alloc(min_i nd));enden ergy_alloc(min_i nd) = en ergy_alloc(min_i nd) +min_val;bt = bt+1;endendendfor i = 1:le ngth(bits_alloc)if (mod(bits_alloc(i),2) == 1 & bits_alloc(i) ~=1)[bits_alloc,e nergy_alloc]=ResolvetheLastBit(bits_alloc,e nergy_alloc,i,e nergytable, num_subc);endendResolvetheLastBit.m : An optimal bit-loading of the last bit requires optimizati on.a unique fun cti on [bits_alloc, en ergy_alloc]=ResolvetheLastBit(bits_alloc,e nergy_alloc,i ndex,e nergytable, num_subc)max_val = 0;for i = 1:n um_subcif (i ~= index & bits_alloc(i) == 1)if bits_alloc(i) ~= 0 temp = energytable(i,bits_alloc(i)) ;endif (temp > max_val) max_val = temp;max_ind = i;end end end min_val = Inf;for i = 1:num_subcif (i~= index & bits_alloc(i) == 1) if bits_alloc(i) ~=0temp = energytable(i,bits_alloc(i) + 1); end if (temp < min_val)min_val = temp;min_ind = i;endendend if (min_val < max_val)bits_alloc(min_ind) = bits_alloc(min_ind) + 1; bits_alloc(index) = bits_alloc(index) - 1;energy_alloc(index) = energy_alloc(index) - min_val;elsebits_alloc(max_ind) = bits_alloc(max_ind) - 1;bits_alloc(index) = bits_alloc(index) + 1;energy_alloc(index) = energy_alloc(index) + max_val;end。
OFDM.m : OFDM Simulator (outer function)clear all;A = [1 1/exp(1) 1/exp (2) ]; % power delay profileN = 64; % number of symbols in a single OFDM symbolGI = 16; % guard in tervalMt = 1; % n umber of Tx antennasMr = 1; % n umber of Rx antennassig2 = 1e-3; % no ise varia neeM = 8; % max eon stellati on bit n umberMgap = 10.A(1:(1.7/10):2.7); % gapBtot = 100*Mt; % total # bits per OFDM symbolTransmitIter = 50; % # iterations of symbol transmissions for each channel instanee Channeliter = 100; % # iterations of independent identically distributed channel instances Gapiter = len gth(Mgap);load ENC2.matload ENC4.matload ENC16.matload ENC64.matload ENC256.matTotEbNo =[];Errors =[];EbNo =[];for lGap = 1:GaplterlGapgap = Mgap(lGap);totalErrors = 0;for lCha n = 1:Cha nn ellter% create cha nnel[H h_f]=create_cha nn el(Mt, Mr, A, N+GI);% decompose each subcha nnel in the freque ncy doma in[U S V] = svd_decompose_cha nn el(Mt, Mr, h_f, N);% bitloadi ng[bits_alloc,e nergy_alloc] = BitLoad(S,Btot,Mt*N,gap,sig2,M);%en ergy_alloc=e nergy_alloc/(mea n(e nergy_alloc));%e nergy_alloc=o nes(1,128);for lTra ns = 1:Tra nsmitlter% bits to tra nsmitx = (ra ndn (1,Btot)>0);% modulatex_mod = modulate(x,bits_alloc,e nergy_alloc, S2,S4,S16,S64,S256);% precode modulated sig nal x_pre = precode(Mt, x_mod, V, N);% ifft, with cyclic prefix for each antennaofdm_symbol =[];for i=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);% cha nnely = transpose(channel(sig2, Mt, Mr, ofdm_symbol2, H, N+GI));% fftrec_symbol =[];for i=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);% shape received sig nalshaped_vals = shape(rec_symbol2, Mr, U, N);% demodulatey_demod = demodulate(shaped_vals, bits_alloc, en ergy_alloc, S, s2,s4,s16,s64,s256, c2,c4,c16,c64,c256);% comparis ontotalErrors = totalErrors + sum(xor(y_demod,x));endEbNo = [EbNo sum(e nergy_alloc)/Btot/sig2];endErrors = [Errors totalErrors/Btot/Cha nn elIter/Tra nsmitlter]TotEbNo = [TotEbNo mea n(EbNo)]EbNo =[];endsemilogx(TotEbNo, Errors);xlabel('Eb/No');ylabel('BER');title( 'SISO link, adaptive rate and power')save SISO_adaptive2.mat Errors EbNocreate cha nn el.m : Gen erates a Rayleigh fadi ng freque ncy-selective cha nn el, parametrized by the antenna con figurati on, the OFDM con figurati on, and the power-delay profile.fun cti on [H, H_f]=create_cha nn el(Mt, Mr, A, N);% function [H, H_f]=create_channel(Mt, Mr, A, N);% - -% A - vector containing the power-delay profile (real values)% Mt - n umber of Tx antennas% Mr - n umber of Rx antennas% N - n umber of vector symbols to be sent in a sin gle OFDM symbol Tx% ie: N MIMO tran smissio ns in one OFDM symbol% This is for Rayleigh freque ncy-selective fading, which assumes complex% Gaussia n matrix eleme nts with in-phase and quadrature comp onentsin depe ndent.% Assume iid matrix channel elements, and further, independent channel taps% defi ne the cha nnel tapsH」nt = 1/sqrt(2)*(ra ndn( Mr*le ngth(A),Mt) + j*ra ndn (Mr*le ngth(A),Mt));H_in t2=[];for i = 1:le ngth(A)H」nt2 = [H」n t2;sqrt(A(i))*H _in t((i-1)*M r+1:i*Mr,:)];end%h_f = fft(H_in t2',64);%%H = H」n t2';H」nt2 = [H」n t2;zeros((N-le ngth(A))*Mr,Mt)];H_f = zeros(Mr,Mt*(N-16));for i = 1:Mtfor j = 1:Mrh_f = fft(H _in t2(j:Mr:(N-16-1)*Mr+j,i));for k = 1:(N-16)H_f(j,i+(k-1)*Mt) = h_f(k);endendendH=[H」n t2];for i = 1:N-1H=[H,[zeros(Mr*i,Mt);H」n t2(1:(N-i)*Mr,:)]];endsvd_decompose_channel.m : Since full channel knowledge is assumed, transmissionis across parallel singular value modes. This function decomposes the channel into these modes.fun cti on [U, S, V] = svd_decompose_cha nn el(Mt, Mr, h_f, N);% [U S V] = svd_decompose_cha nn el(Mt, Mr, h_f, N);%% Function decomposes the channel at each subcarrier into its SVD components %% Mt - # Tx antennas% Mr - # Rx antennas% h_f - MIMO impulse response - Mr rows, Mt*L columns, where L is the number of% cha nnel taps% N - # subcarriersU =[];S =[];V =[];for i = 1:N[Utmp Stmp Vtmp] = svd(h_f(:,(i-1)*Mt+1:i*Mt));U=[U Utmp]; -en ergy % % %%V=[V Vtmp];S=[S Stmp]; endS = sum(S,1);BitLoad.m : Apply the bit-loading algorithm to achieve the desired bit and allocati on for the curre nt cha nnel in sta nee.fun cti on [bits_alloc,e nergy_alloc]=BitLoad(subcha n_gain s,total_bits ,n um_subc,gap ,no ise,M) % Bit Loading Algorithm% ..................................% % In puts :subchan_gains : SubCarrier Gains total_bits : Total Number of bits n um_subc : Number of Subcarriers gap : Gap of the system no ise : Noise PowerM : Max Con stellation Size % Outputs: % bits alloc : Bits allocation for each subchannel % power_alloc : Total Power allocati on% ...................................................................................................... % Compute SNR's for each cha nnelSNR = ComputeSNR(subcha n_gains,no ise,gap);% This fun cti on just in itializes the system with a particular bit % allocation and energy allocation using Chow's Algorithm. This is % further efficientize using Campello's Algorithm[bits_alloc, en ergy_alloc] = chow_algo(SNR ,n um_subc,M);% Form the En ergy In creme nt Table based on the prese nt cha nnel % gains for all the subcha nn els in order to be used by Campello % Algorithmen ergytable = En ergyTablel ni t(SNR,M);% Efficientize the algorithm using the Campello's algorithm [bits_alloc,e nergy_alloc]= campello_algo(bits_alloc,e nergy_alloc,e nergytable,total_bits, num_subc,M ); _ _ _ - -ComputeSNR.m : Give n the subcarrier gains, this simple fun ctio n gen erates the SNR values of each cha nn el (each sin gular value on each tone is a separate cha nn el).fun cti on SNR = ComputeSNR(subcar_ga ins,no ise,gap)SNR = abs((subcar_ga in s.A 2)./( noise*gap));% Calculate the En ergy required% Update the BitSubChan chow_algo.m : Apply Chow's algorithm to gen erate a particular bit and en ergy allocati on.% Chow's Algorithm% ..........................% This is based on the paper by Chow et al titled%% A Practical Discrete Multit one Tran sceiver Loadi ng Algorithm% for Data Tran smissi on over Spectrally Shaped Chann els .I EEE Tra ns% on Communications. Vol. 43, No 2/3/4, pp. 773-775, Feb/Mar/Apr 1995fun cti on [bits_alloc, en ergy_alloc] = chow_algo(SNR, num_subc,M) for i = 1:n um_subc% Assuming each of the subchannels has a flat fading, we get initial estimate% of the bits for each subcha nnel tempbits = log2(1 + abs(SNR(i))); % bits per two dime nsion.rou ndtempbits = roun d(tempbits); % round the bitsif (rou ndtempbits > 8)% Limit them betwee n 2 and 15 rou ndtempbits = 8;endif (mod(rou ndtempbits,2)== 1 & rou ndtempbits ~= 1) roundtempbits = roundtempbits -1;endif rou ndtempbits> 0 for the subcha nnelenergy_alloc(i) = (2A roundtempbits-1)/SNR(i);elseen ergy_alloc(i) = 0;endbits_alloc(i) = roun dtempbits;end % end of fun cti on En ergyTable In it.m: Give n the SNR values, form a table of en ergy in creme nts for each cha nn el.fun cti onen ergytable = En ergyTablel ni t(SNR,M);% In puts: subcar_ga ins : Subcarrier Gains% M : max Con stellati on Size % Gap : Gap of the system % Noise : Noise Power % Outputs: % en ergytable : En ergytable % Based on the Subcarrier Gai ns, we calculate the en ergy % in creme nt required by each subcarrier for tran smitt ing % 1,2 ,4 ,6,8 bits.% En ergy = 2A(i-1)/subcar_ga ins;bit anden ergy % ........................................................................................%subcar_ga ins = (subcar_ga in s.A 2)/(Gap*Noise);en ergytable = abs((1./SNR)'*(2.A([i :M+1]-1)));% In crease the en ergy value for con stellati on size of more tha n M to% a very high value so that it is not assig ned.en ergytable(:,M+1) = lnf*on es(size(e nergytable(:,M+1)));for i = 3:2:Men ergytable(:,i) = (en ergytable(:,i) +en ergytable(:,i+1))/2;en ergytable(:,i+1) = en ergytable(:,i);end%en ergytable = [on es(1,size(e nergytable,1))' en ergytable];campello algo.m : Apply Campello's algorithm to con verge to the optimal en ergy allocati on for the give n cha nnel con diti ons.% campello_algo.m% .......................% This function is used by Campello's algorithm to allocate bits andfor% each subcha nnel optimally.fun cti on [bits_alloc, en ergy_alloc]=campello_algo(bits_alloc,e nergy_alloc,e nergytable,total_bits, num_subc,M) _ _ _ - -bt = sum(bits_alloc);% We can't tran smit more tha n M*(Number of subcha nn el) bitsif total_bits > M*n um_subctotal_bits = M*n um_subc;endwhile (bt ~= total_bits)if (bt > total_bits)max_val = 0;max_i nd = ceil(ra nd(1)* num_subc);for i = 1:n um_subcif bits_alloc(i) ~= 0temp = en ergytable(i,bits_alloc(i));a uniqueelsetemp = 0;endif (temp > max_val)max_val = temp;max_i nd = i;endendif (bits_alloc(max_i nd) > 0) bits_alloc(max_i nd) = bits_alloc(max_i nd) -1; en ergy_alloc(max_i nd) = en ergy_alloc(max_i nd) - max_val; bt = bt-1;endelsemin_val = Inf;min_ind = ceil(ra nd(1)* num_subc);for i = 1:n um_subcif bits_alloc(i) ~=0 & bits_alloc(i) <9temp = en ergytable(i,bits_alloc(i) + 1);elsetemp = Inf;endif (temp < min_val)min_val = temp;min_i nd = i;endendif (bits_alloc(min_i nd) < 8)bits_alloc(min_i nd) = bits_alloc(min_i nd) +1;if (min_val==i nf)min_val = en ergytable(min_i nd,bits_alloc(min_i nd));enden ergy_alloc(min_i nd) = en ergy_alloc(min_i nd) +min_val;bt = bt+1;endendendfor i = 1:le ngth(bits_alloc)if (mod(bits_alloc(i),2) == 1 & bits_alloc(i) ~=1)[bits_alloc,e nergy_alloc]=ResolvetheLastBit(bits_alloc,e nergy_alloc,i,e nergytable, num_subc);endendResolvetheLastBit.m : An optimal bit-loading of the last bit requires optimizati on.fun cti on [bits_alloc, en ergy_alloc]=ResolvetheLastBit(bits_alloc,e nergy_alloc,i ndex,e nergytable, num_subc)max_val = 0;for i = 1:n um_subcif (i ~= index & bits_alloc(i) == 1)if bits_alloc(i) ~= 0 temp = energytable(i,bits_alloc(i)) ;endif (temp > max_val) max_val = temp;max_ind = i;end end end min_val = Inf;for i = 1:num_subcif (i~= index & bits_alloc(i) == 1) if bits_alloc(i) ~=0temp = energytable(i,bits_alloc(i) + 1); end if (temp < min_val)min_val = temp;min_ind = i;endendend if (min_val < max_val)bits_alloc(min_ind) = bits_alloc(min_ind) + 1; bits_alloc(index) = bits_alloc(index) - 1;energy_alloc(index) = energy_alloc(index) - min_val;elsebits_alloc(max_ind) = bits_alloc(max_ind) - 1;bits_alloc(index) = bits_alloc(index) + 1;energy_alloc(index) = energy_alloc(index) + max_val;end。
OFDM的matlab仿真Matlab,Matrix Laboratory的简称,是美国Mathworks公司于1984年推出的数值计算机仿真软件,经过不断的发展和完善,如今已成为覆盖多个学科、具有超强数值计算能力和仿真分析能力的软件。
Matlab应用较为简单,用大家非常熟悉的数学表达式来表达问题和求解方法。
它把计算、图示和编程集成到一个环境中,用起来非常方便。
同时,Matlab具有很强的开放性和适应性,在保持内核不变的情况下,Matlab推出了适合不同学科的工具箱,如图像处理工具箱,小波分析工具箱、信号处理工具箱、神经网络工具箱等,极大地方便了不同学科的研究工作。
Matlab强大的绘图功能,简单的命令形式,使其越来越受到国内外科技人员的青睐,得到越来越广泛的应用。
一. MATLAB的特点一种语言之所以如此迅速地普及,显示出如此旺盛的生命力,是由于它有着不同于其它语言的特点。
正如同Fortran和C等高级语言使人们摆脱了需要直接对计算机硬件资源进行操作一样,被称为第4代计算机语言的MATLAB,利用其丰富的函数资源,使编程人员从繁琐的程序代码中解放出来。
1.功能强大MATLAB具有功能强劲的工具箱,其包含两个部分:核心部分和各种可选的工具箱。
核心部分中,有数百个核心内部函数。
其工具箱又可分为两类:功能性工具箱和学科性工具箱。
功能性工具箱主要用来扩充其符号计算功能、图示建模仿真功能、文字处理功能以及与硬件实时交互功能。
功能性工具箱能用于多种学科,而学科性工具箱是专业性比较强的,例如control toolbox,image processing toolbox,signal processing toolbox 等。
这些工具箱都是由该领域内的学术水平很高的专家编写的,所以用户无需编写自己学科范围内的基础程序,就能够直接进行高、精、尖的研究。
2. 界面友好,编程效率高MATLAB突出的特点就是简洁。
第一章绪论1.1简述OFDM是一种特殊的多载波传输方案,它可以被看作是一种调制技术,也可以被当作一种复用技术。
多载波传输把数据流分解成若干子比特流,这样每个子数据流将具有低得多的比特速率,用这样的低比特率形成的低速率多状态符号再去调制相应的子载波,就构成多个低速率符号并行发送的传输系统。
正交频分复用是对多载波调制(MCM,Multi-Carrier Modulation)的一种改进。
它的特点是各子载波相互正交,所以扩频调制后的频谱可以相互重叠,不但减小了子载波间的干扰,还大大提高了频谱利用率。
符号间干扰是多径衰落信道宽带传输的主要问题,多载波调制技术包括正交频分复用(OFDM)是解决这一难题中最具前景的方法和技术。
利用OFDM技术和IFFT方式的数字实现更适宜于多径影响较为显著的环境,如高速WLAN 和数字视频广播DVB等。
OFDM作为一种高效传输技术备受关注,并已成为第4代移动通信的核心技术。
如果进行OFDM系统的研究,建立一个完整的OFDM 系统是必要的。
本文在简要介绍了OFDM 基本原理后,基于MATLAB构建了一个完整的OFDM动态仿真系统。
1.2 OFDM基本原理概述1.2.1 OFDM的产生和发展OFDM的思想早在20世纪60年代就已经提出,由于使用模拟滤波器实现起来的系统复杂度较高,所以一直没有发展起来。
在20世纪70年代,提出用离散傅里叶变换(DFT)实现多载波调制,为OFDM的实用化奠定了理论基础;从此以后,OFDM在移动通信中的应用得到了迅猛的发展。
OFDM系统收发机的典型框图如图1.1所示,发送端将被传输的数字信号转换成子载波幅度和相位的映射,并进行离散傅里叶变换(IDFT)将数据的频谱表达式变换到时域上。
IFFT变换与IDFT变换的作用相同,只是有更高的计算效基于MATLAB实现OFDM的仿真率,所以适用于所有的应用系统。
其中,上半部分对应于发射机链路,下半部分对应于接收机链路。
由于FFT操作类似于IFFT,因此发射机和接收机可以使用同一硬件设备。
当然,这种复杂性的节约则意味着接收发机不能同时进行发送和接收操作。
接收端进行发送相反的操作,将射频(RF,Radio Frequency)信号与基带信号进行混频处理,并用FFT变换分解频域信号。
子载波幅度和相位被采集出来并转换回数字信号。
IFFT和FFT互为反变换,选择适当的变换将信号接收或发送。
但信号独立于系统时,FFT变换和IFFT变换可以被交替使用。
1.2.2 串并变换数据传输的典型形式是串行数据流,符号被连续传输,每一个数据符号的频谱可占据整个可以利用的带宽。
但在并行数据传输系统中,许多符号同时传输,减少了那些在串行系统中出现的问题。
在OFDM系统中,每个传输符号速率的大小大约在几十bit/s到几十kbit/s之间,所以必须进行串并变换,将输入串行比特流转换成为可以传输的OFDM符号。
由于调试模式可以自适应调节,所以每个子载波的调制模式是可以变化的,因为而每个子载波可传输的比特数也是可以变化的,所以串并变换需要分配给每个子载波数据段的长度是不一样的。
在接收端执行相反的过程,从各个子载波出来的数据长度不一样。
在接收端执行相反的过程,从各个子载波处来的数据被转换回原来的串行数据。
当一个OFDM符号在多径无线信道中传输时,频率选择性衰落会导致某几组子载波收到相当大的的衰减,从而引起比特错误。
这些在信道频率响应的零点会造成在邻近的子载波上发射的信息受到破坏,导致在每个符号中出现一连串的比特错误。
与一大串错误连续出现的情况相比较,大多数前向纠错编码(FEC,Forward Error Correction)在错误分布均与的情况下会工作得更有效。
所以,为了提高系统的性能,大多数系统采用数据加扰作为串并变换工作的一部分。
这可以通过把每个连续的数据比特随机地分配到各个子载波上来实现。
在接收机端,进行一个对应的逆过程解出信号。
这样,不仅可以还原出数据比特原来的顺序,同时还可以分散由于信号衰落引起的连串的比特错误使其在时间上近似均匀分布。
这种将比特错误位置的随机化可以提高前向纠错编码(FEC)的性能,并且系统的总的性能也得到改善。
1.2.3 子载波调制正交频分复用(OFDM)技术就是在频域内将给定信道分成许多正交子信道,在每个子信道上使用一个子载波进行调制,并且各子载波并行传输。
尽管总的信道是非平坦的,具有频率选择性,但是每个子信道是相对平坦的,在每个子信道上进行的是窄带传输,信号带宽小于信道的相应带宽,因此大大消除了信号波形间的干扰。
而且子信道的载波相互正交,一个OFDM符号包括多个经过PSK调制或QAM调制的子载波的合成信号,每个子载波的频谱相互重叠,从而又提高了频谱利用率。
用N 表示子载波个数,T 表示OFDM 符号的持续时间,d i( i = 0 ,1 , …, N - 1)为分配给每个子信道的数据符号,f i为第i 个子载波的载波频率,从t = t s开始的OFDM符号的等效基带信号可表示为(模拟信号表示式) :基于MATLAB 实现OFDM 的仿真s(t)的实部和虚部分别对应于OFDM 符号的同相分量和正交分量,在实际系统中可分别与相应子载波的余弦分量和正弦分量相乘,构成最终的子信道。
其相应的数字表示式如下:令 t s = 0 ,采样速率为 N/ T ,则发送速率的第 k ( k =:0 ,1 , …, N - 1)个采样表示为:∑-===1)/2exp()/()(N ti N ik j d N kT s k s π (1-2)显然式上式恰好为IDFT 的表达式,可知OFDM 的调制和解调可以通过 IDFT 和DFT 或(IFFT 和FFT )来实现。
如图1.2所示,在一个OFDM 符号内包含四个载波的实例。
其中,所有的子载波都具有相同的幅度和相位,但在实际应用中,根据数据符号的调制方式,每个子载波都有相同的幅度和相位是不可能的。
从图1.2可以看出每个子载波在一个OFDM 符号周期内都包含整数倍个周期,而且各个相邻的子载波之间相差1个周期。
这一特性可以用来解释子载波之间的正交性,即:⎰⎩⎨⎧≠==Ton nm n m dt j t j T 01)exp()exp(/1n ωω(1-3)如对式1-3中的第j 个子载波进行调制,然后在时间长度T 内进行积分,即:()()⎰∑⎰∑=⎪⎪⎭⎫ ⎝⎛--=-+--=-=-=js N i i s s sN i i s j d dt t t T j i d T dtt t T i T t t d t t T j Tb )(j2exp /1)(/2j exp )(/2j exp /1ˆ1010πππ根据对式1-4可以看到,对第J 个子载波进行解调可以恢复出期望的符号。
而对其他载波来说,由于积分间隔内,频率差别(I-J)/T 可以产生整数倍个周期,所以积分结果为零。
这种正交性还可以从频率角度来解释。
根据式1-2 ,每个OFDM 符号在其周期T 内包含多个非零子载波。
因此其频谱可以看作是周期为T 的矩形脉冲的频谱与一组位于各个子载波频率上的δ函数的卷积。
矩形脉冲频谱幅度值为sinc(ƒT)函数,这种函数的零点出现在频率为1/T 整数倍的位置上。
[]ss s s N ts s i t T t t t s T t t t t t T i j T t t rect d t s +><=+≤≤---=∑-=或1t 0)()(/2exp )2/()(π图1.2 OFDM载波图1.3 OFDM子载波频谱这种现象可以参见图1.3,图中给出了相互覆盖的各个子信道内经过矩形波形成型得到的符号的sinc函数频谱。
在每个子载波频率最大值处,所有其他子信道的频谱值恰好为零。
因为在对OFDM符号进行解调过程中,需要计算这些点上所对应的每个子载波频率的最大值,所以可以从多个相互重叠的子信道中提基于MATLAB 实现OFDM 的仿真取每一个子信道的符号,而不会受到其他子信道的干扰。
从图 1.3可以看出,OFDM 符号频谱实际上可以满足奈奎斯特准则,即多个子信道频谱之间不存在相互干扰。
因此这种一个子信道频谱出现最大值而其他信道频谱为零点的特点可以避免载波间的干扰(ICI )的出现。
1.2.4 DFT 的实现傅里叶变换将时域与频域联系在一起,傅里叶变换的形式有几种,选择哪种形式的傅里叶也变化由工作的具体环境决定。
大多数信号处理使用DFT 。
DFT 是常规变换的一种变化形式,信号在时域和频域上均抽样。
由DFT 的定义,时间上波形连续重复,因此导致频域上频谱的连续重复。
快速傅里叶变换(FFT )仅是计算应用的一种快速数学方法,由于其高效性,使OFDM 技术发展迅速。
对于N 比较大的系统来说,式1-1中的OFDM 复等效基带信号可以采用离散傅里叶逆变换(IDFT )方法来实现。
为了叙述的简洁,可以令式1-1中的s t =0,并且忽略矩形函数,对于信号s(t)以T/N 的速率进行抽样,即令t=kT/N (k=0,1,...,N-1),则得到:∑-=-≤≤==1)10()/2exp()/(N ii k N k N ik j d N kT s s π (1-5)可以看到k S 等效为对d i 进行IDFT 运算。
同样在接收端,为了恢复出原来的数据符号d i ,可以对s k 进行逆变换,即DFT 得到:)10()/2exp(1-≤≤-=∑-=N i N ik j s d N ik i π(1-6)根据以上分析可以看到,OFDM 系统的调制和解调可以分别由IDFT 和DFT 来代替。
通过N 点的IDFT 运算,把频域数据符号d i 变换为时域数据符号k S ,经过射频载波调制之后,发送到无线信道中。
其中每个IDFT 输出的数据符号k s 都是由所有子载波信号经过叠加而生成的,即对连续的多个经过调制的子载波的叠加信号进行得到的。
在OFDM 系统的实际运用中,可以采用更加方便快捷的IFFT/FFT 。
N 点DFT 运算需要实施N 2复数乘法运算,而IFFT 可以显著地降低运算的复杂程度。
对于常用的基-2IFFT 算法来说,其复数乘法次数进仅为(N/2)log2(N/2)。
1.2.5 保护间隔、循环前缀应用OFDM的一个重要原因在于它可以有效地对抗多径时延扩展。
把输入数据流串并变换到N个并行子信道中,使得每一个调制子载波的数据周期可以扩大为原来数据符号周期的N倍。
为了最大限度的消除符号间干扰,可以在每个OFDM符号之间插入保护间隔(GI),而且该保护间隔长度T g一般要大于无线信道中的最大时延扩展,这样一个符号的多径分量就不会对下一个符号造成干扰。
在这段保护间隔可以不插入任何信号,即是一段空白的传输时段。