Matlab简单的OFDM仿真信道估计有BER曲线.docx
- 文档编号:10696806
- 上传时间:2023-02-22
- 格式:DOCX
- 页数:14
- 大小:177.95KB
Matlab简单的OFDM仿真信道估计有BER曲线.docx
《Matlab简单的OFDM仿真信道估计有BER曲线.docx》由会员分享,可在线阅读,更多相关《Matlab简单的OFDM仿真信道估计有BER曲线.docx(14页珍藏版)》请在冰豆网上搜索。
Matlab简单的OFDM仿真信道估计有BER曲线
clearall;
closeall;
fprintf('\nOFDM仿真\n\n');
%%
%参数定义%
%%
IFFT_bin_length=1024;carrier_count=200;
bits_per_symbol=2;symbols_per_carrier=50;
%子载波数200
%位数/符号2
%符号数/载波50
%训练符号数10
%循环前缀长度T/4(作者注明)All-zeroCP
%调制方式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));%坐标:
(1to200)+156,157--356
conjugate_carriers=IFFT_bin_length-carriers+2;%坐标:
1024-
(157:
356)+2=1026-(157:
356)=(869:
670)
%构造共轭时间-载波矩阵,以便应用所谓的RCC,ReducedComputationalComplexity算法,即ifft之后结果为实数
%Definetheconjugatetime-carriermatrix
%也可以用flipdim函数构造对称共轭矩阵
%%
%信号发
射%
%%%out=rand(1,baseband_out_length);
%baseband_out1=round(out);
%baseband_out2=floor(out*2);
%baseband_out3=ceil(out*2)-1;
%baseband_out4=randint(1,baseband_out_length);
%四种生成发送的二进制序列的方法,任取一种产生要发送的二进制序列
%if(baseband_out1==baseband_out2&baseband_out1==baseband_out3)
%fprintf('TransmissionSequenceGenerated\n\n');
%baseband_out=baseband_out1;
%else
%fprintf('CheckCode!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
\n\n');
%end
%验证四种生成发送的二进制序列的方法
baseband_out=round(rand(1,baseband_out_length));convert_matrixreshape(baseband_out,bits_per_symbol,length(baseband_out)/bits_per_symbol);
fork=1length(baseband_out)/bits_per_symbol),modulo_baseband(k)=0;
fori=1:
bits_per_symbol
modulo_baseband(k)=modulo_baseband(k)+convert_matrix(i,k)*
2A(bits_per_symbol-i);
end
end
%每2个比特转化为整数0至3
%采用'left-msb'方式
%%Testbylavabin
%Abuilt-infunctionofdirectlychangebinarybitsintodecimalnumbers
%%convert_matrix1zeros(length(baseband_out)/bits_per_symbol,bits_per_symbol);
%convert_matrix1=convert_matrix';
%Test_convert_matrix1bi2de(convert_matrix1,bits_per_symbol,'left-msb');
%Test_convert_matrix2bi2de(convert_matrix1,bits_per_symbol,'right-msb');
%函数说明:
%BI2DEConvertbinaryvectorstodecimalnumbers.
%D=BI2DE(B)convertsabinaryvectorBtoadecimalvalueD.WhenB
is
%amatrix,theconversionisperformedrow-wiseandtheoutputDisa
%columnvectorofdecimalvalues.Thedefaultorientationofthebinary
%inputisRight-MSB;thefirstelementinBrepresentstheleastsignificantbit.
%if(modulo_baseband==Test_convert_matrix1')
%fprintf('modulo_baseband=Test_convert_matrix1\n\n\n');
%elseif(modulo_baseband==Test_convert_matrix2')
%fprintf('modulo_baseband=Test_convert_matrix2\n\n\n');
%else
%fprintf('modulo_baseband~=anyTest_convert_matrix\n\n\n');
%end
%end
%wegettheresult"modulo_baseband=Test_convert_matrix1".
%carrier_matrix
reshape(modulo_baseband,carrier_count,symbols_per_carrier)';%生成时间-载波矩阵
%%
%QDPSK调制%
%%carrier_matrix=[zeros(1,carrier_count);carrier_matrix];%添加一个差分调制的初始相位,为0fori=2symbols_per_carrier+1)
carrier_matrix(i,=rem(carrier_matrix(i,+carrier_matrix(i-1,,2Abits_per_symbol);%差分调制
end
carrier_matrix=carrier_matrix*((2*pi)/(2Abits_per_symbol));%产
生差分相位
[X,Y]=pol2cart(carrier_matrix,
ones(size(carrier_matrix,1),size(carrier_matrix,2)));%由极坐标向复
数坐标转化第一参数为相位第二参数为幅度
%Carrier_matrixcontainsallthephaseinformationandalltheamplitudesarethesame‘1'.
complex_carrier_matrix=complex(X,Y);
%添加训练序列'
training_symbols=[1jj1-1-j-j-11jj1-1-j-j-11jj1-1
-j-j-11jj1-1-j-j-11jj1-1...
-j-j-11jj1-1-j-j-11jj1-1-j-j-11jj1-1-j-j-11
jj1-1-j-j-11jj1-1-j-j-1...
1jj1-1-j-j-11jj1-1-j-j-11jj1-1-j-j-11jj1-1
-j-j-11jj1-1-j-j-11jj1...
-1-j-j-11jj1-1-j-j-11jj1-1-j-j-11jj1-1-j-j-1
1jj1-1-j-j-11jj1-1-j-j...
-11jj1-1-j-j-11jj1-1-j-j-11jj1-1-j-j-11jj1
-1-j-j-1];%25times"1jj1",25times"-1-j-j-1",totally200symbolsasarow
training_symbols=cat(1,training_symbols,training_symbols);
training_symbols=cat(1,training_symbols,training_symbols);%
Productionof4rowsoftraining_symbolscomplex_carrier_matrix=cat(1,training_symbols,
complex_carrier_matrix);%训练序列与数据合并
%block-typepilotsymbols
IFFT_modulation=zeros(4+symbols_per_carrier+1,IFFT_bin_length);
%Herearowvectorofzerosisbetweentrainingsymbolsanddatasymbols!
!
!
%4trainingsymbolsand1zerosymbol
%everyOFDMsymboltakesarowof"IFFT_modulation"
IFFT_modulation(:
carriers)=complex_carrier_matrix;
IFFT_modulation(:
conjugate_carriers)=conj(complex_carrier_matrix)
%
%Testbylavabin--Findtheindicesofzeros
%index_of_zeros=zeros(symbols_per_carrier,IFFT_bin_length2*carrier_count);
%IFFT_modulation1=zeros(4+symbols_per_carrier+1,IFFT_bin_length);%IFFT_modulation2=zeros(4+symbols_per_carrier+1,IFFT_bin_length);%IFFT_modulation1(6:
symbols_per_carrier+5,IFFT_modulation(6:
symbols_per_carrier+5,==0;
%fori=1:
symbols_per_carrier%index_of_zeros(i,=find(IFFT_modulation1(i+5,==1);
%end
%
time_wave_matrix=ifft(IFFT_modulation');%进行IFFT操作
time_wave_matrix=time_wave_matrix';%IfXisamatrix,ifftreturnstheinverseFouriertransformofeachcolumnofthematrix.
fori=1:
4+symbols_per_carrier+1
windowed_time_wave_matrix(i,:
)=real(time_wave_matrix(i,:
))end
%gettherealpartoftheresultofIFFT
%这一步可以省略,因为IFFT结果都是实数
%由此可以看出,只是取了IFFT之后载波上的点,并未进行CP的复制和添加end
ofdm_modulation=reshape(windowed_time_wave_matrix',1,IFFT_bin_length*(4+symbols_per_carrier+1));
%P2Soperation
%
%Testbylavabin
%Anotherwayofmatrixtransition
%ofdm_modulation_tmp=windowed_time_wave_matrix.';%ofdm_modulation_test=ofdm_modulation_tmp(';
%if(ofdm_modulation_test==ofdm_modulation)
%fprintf('ofdm_modulation_test==ofdm_modulation\n\n\n');
%else
%fprintf('ofdm_modulation_test~=ofdm_modulation\n\n\n');
%end
%Wegettheresult"ofdm_modulation_test==ofdm_modulation".
%
Tx_data=ofdm_modulation;
%%
%信道模拟%
%%d1=4;a1=0.2;d2=5;a2=0.3;d3=6;a3=0.4;d4=7;a4=0.5;%信道模拟
copy1=zeros(size(Tx_data));
fori=1+d1:
length(Tx_data)copy1(i)=a1*Tx_data(i-d1);
end
copy2=zeros(size(Tx_data));
fori=1+d2:
length(Tx_data)
copy2(i)=a2*Tx_data(i-d2);
end
copy3=zeros(size(Tx_data));
fori=1+d3:
length(Tx_data)
copy3(i)=a3*Tx_data(i-d3);
end
copy4=zeros(size(Tx_data));
fori=1+d4:
length(Tx_data)
copy4(i)=a4*Tx_data(i-d4);
end
Tx_data=Tx_data+copy1+copy2+copy3+copy4;%4multi-pathsTx_signal_power=var(Tx_data);
foridx=1:
length(SNR)%montecarlo仿真模拟
linear_SNR=10A(SNR(idx)/10);
noise_sigma=Tx_signal_power/linear_SNR;noise_scale_factor=sqrt(noise_sigma);
noise=randn(1,length(Tx_data))*noise_scale_factor;
Rx_Data=Tx_data+noise;
%%
%信号接收%
%%
Rx_Data_matrix=reshape(Rx_Data,IFFT_bin_length,4+symbols_per_carrier+1);
Rx_spectrum=fft(Rx_Data_matrix);
%SupposeprecisesynchronazitionbetweenTxandRxRx_carriers=Rx_spectrum(carriers,:
)';
Rx_training_symbols=Rx_carriers((1:
4),:
);
Rx_carriers=Rx_carriers((5:
55),:
);
%%
信道估
%计%
%%
Rx_training_symbols=Rx_training_symbols./training_symbols;
Rx_training_symbols_deno=Rx_training_symbols42;
Rx_training_symbols_deno=
Rx_training_symbols_deno(1,+Rx_training_symbols_deno(2,+Rx_training_symbols_deno(3,+Rx_training_symbols_deno(4,;
Rx_training_symbols_nume=Rx_training_symbols(1,:
)
+Rx_training_symbols(2,:
)+Rx_training_symbols(3,:
)
+Rx_training_symbols(4,:
);
Rx_training_symbols_nume=conj(Rx_training_symbols_nume);
%取4个向量的导频符号是为了进行平均优化
%都是针对“行向量”即单个的OFDM符号进行操作
%原理:
寻求1/H,对FFT之后的数据进行频域补偿
%1/H=conj(H)/HA2because屮2=H*conj(H)
Rx_training_symbols=
Rx_training_symbols_nume./Rx_training_symbols_deno;
Rx_training_symbols=
Rx_training_symbols_nume./Rx_training_symbols_deno;
Rx_training_symbols_2=cat(1,
Rx_training_symbols,Rx_training_symbols);
Rx_training_symbols_4=cat(1,
Rx_training_symbols_2,Rx_training_symbols_2);
Rx_training_symbols_8=cat(1,
Rx_training_symbols_4,Rx_training_symbols_4);
cat(1,
Rx_training_symbols_8,
cat(1,
Rx_training_symbols_16,
cat(1,
Rx_training_symbols_32,
cat(1,
Rx_training_symbols_48,
cat(1,
Rx_training_symbols_16
Rx_training_symbols_8);
Rx_training_symbols_32
Rx_training_symbols_16);
Rx_training_symbols_48
Rx_training_symbols_16);
Rx_training_symbols_50
Rx_training_symbols_2);Rx_training_symbols
进行频域单抽头均衡
Rx_training_symbols_50,Rx_training_symbols);
Rx_carriers=Rx_training_symbols.*Rx_carriers;%Rx_phase=angle(Rx_carriers)*(180/pi);phase_negative=find(Rx_phase<0);
%TestofUsing
"rem"
%Rx_phase1=Rx_phase;
%Rx_phase2=Rx_phase;
%Rx_phase1(phase_negative)=rem(Rx_phase1(phase_negative)+360,360);%Rx_phase2(phase_negative)=Rx_phase2(phase_negative)+360;
%ifRx_phase2(phase_negative)==Rx_phase1(phase_negative)
%fprintf('\nThereisnoneedusingreminnegativephasetransition.\n')
%else
%fprintf('\nWeneedtousereminnegativephasetransition.\n')
%end
%
Rx_phase(phase_negative)=rem(Rx_phase(phase_negative)+360,360);%把负的相位转化为正的相位
Rx_decoded_phase=diff(Rx_phase);
%这也是为什么要在前面加上初始相位的原因
%“Herearowvectorofzerosisbetweentrainingsymbolsanddatasymbols!
!
!
”
phase_negative=find(Rx_decoded_phase<0);
Rx_decoded_phase(phase_negative)=rem(Rx_decoded_phase(phase_negative)
+360,360);%再次把负的相位转化为正的相位
%%
%QDPSK解调%
%%base_phase=360/2Abits_per_symbol;
delta_phase=base_phase/2;
Rx_decoded_symbols=
zeros(size(Rx_
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Matlab 简单 OFDM 仿真 信道 估计 BER 曲线