¸½Â¼³ÌÐò£ºclearall;closeall;fprintf('OFDMÐŵÀ¹À¼Æ·ÂÕæ\n\n');carrier_count=64;%-----------Ôز¨ÊýÄ¿num_symbol=50;%--------------OFDM·ûºÅ¸öÊýGuard=8;%--------------------Ñ»·Ç°×ºpilot_Inter=8;%--------------µ¼Æµ¼ä¸ômodulation_mode=16;%---------µ÷ÖÆ·½Ê½SNR=[0:2:20];%-------------ÐÅÔë±ÈÈ¡ÖµNumLoop=15;%-----------------Ñ»·´ÎÊýnum_bit_err=zeros(length(SNR),NumLoop);num_bit_err_dft=zeros(length(SNR),NumLoop);num_bit_err_ls=zeros(length(SNR),NumLoop);MSE=zeros(length(SNR),NumLoop);MSE1=zeros(length(SNR),NumLoop);MSE2=zeros(length(SNR),NumLoop);%%%%%%%%%%%%%%%%%%%%%%%Ö÷³ÌÐòÑ»·%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%forc1=1:length(SNR)fprintf('\n\n\n·ÂÕæÐÅÔë±ÈΪ%f\n\n',SNR(c1));fornum1=1:NumLoop%---------------²úÉú·¢Ë͵ÄËæ»úÐòÁСª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª-BitsLen=carrier_count*num_symbol;BitsTx=randint(1,BitsLen);%---------------·ûºÅµ÷ÖÆ---------------------------------------Modulated_Sequence=qammod(BitsTx,modulation_mode);%---------------µ¼Æµ¸ñʽ---------------------------------------pilot_len=carrier_count;pilot_symbols=round(rand(1,pilot_len));fori=1:pilot_lenifpilot_symbols(1,i)==0pilot_symbols(1,i)=pilot_symbols(1,i)-1;elsepilot_symbols(1,i)=pilot_symbols(1,i);endendpilot_symbols=pilot_symbols';%----------------¼ÆË㵼ƵºÍÊý¾ÝÊýÄ¿----------------------------num_pilot=ceil(num_symbol/pilot_Inter);ifrem(num_symbol,pilot_Inter)==0num_pilot=num_pilot+1;endnum_data=num_symbol+num_pilot;%----------------µ¼ÆµÎ»ÖüÆËã----------------------------------pilot_Indx=zeros(1,num_pilot);Data_Indx=zeros(1,num_pilot*(pilot_Inter+1));fori=1:num_pilot-1pilot_Indx(1,i)=(i-1)*(pilot_Inter+1)+1;endpilot_Indx(1,num_pilot)=num_data;forj=0:num_pilotData_Indx(1,(1+j*pilot_Inter):(j+1)*pilot_Inter)=(2+j*(pilot_Inter+1)):((j+1)*(pilot_Inter+1));endData_Indx=Data_Indx(1,1:num_symbol);%----------------µ¼Æµ²åÈë-------------------------------------piloted_ofdm_syms=zeros(carrier_count,num_data);piloted_ofdm_syms(:,Data_Indx)=reshape(Modulated_Sequence,carrier_count,num_symbol);piloted_ofdm_syms(:,pilot_Indx)=repmat(pilot_symbols,1,num_pilot);%----------------IFFT±ä»»¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ªtime_signal=sqrt(carrier_count)*ifft(piloted_ofdm_syms);%----------------¼ÓÑ»·Ç°×º------------------------------------add_cyclic_signal=[time_signal((carrier_count-Guard+1:carrier_count),:);time_signal];Tx_data_trans=reshape(add_cyclic_signal,1,(carrier_count+Guard)*num_data);%----------------ÐŵÀ´¦Àí--------------------------------------Tx_signal_power=sum(abs(Tx_data_trans(:)).^2)/length(Tx_data_trans(:));noise_var=Tx_signal_power/(10^(SNR(c1)/10));Rx_data=awgn(Tx_data_trans,SNR(c1),'measured');%----------------ÐźŽÓÊÕ¡¢È¥Ñ»·Ç°×º¡¢FFT±ä»»-----------------Rx_signal=reshape(Rx_data,(carrier_count+Guard),num_data);Rx_signal_matrix=zeros(carrier_count,num_data);Rx_signal_matrix=Rx_signal(Guard+1:end,:);Rx_carriers=fft(Rx_signal_matrix)/sqrt(carrier_count);%----------------µ¼ÆµºÍÊý¾ÝÌáÈ¡--------------------------------Rx_pilot=Rx_carriers(:,pilot_Indx);Rx_fre_data=Rx_carriers(:,Data_Indx);%----------------µ¼ÆµÎ»ÖÃÐŵÀÏìÓ¦LS¹À¼Æ------------------------pilot_patt=repmat(pilot_symbols,1,num_pilot);pilot_esti=Rx_pilot./pilot_patt;%----------------LS¹À¼ÆµÄÏßÐÔ²åÖµ¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ªint_len=pilot_Indx;len=1:num_data;forii=1:carrier_countchannel_H_ls(ii,:)=interp1(int_len,pilot_esti(ii,1:(num_pilot)),len,'linear');endchannel_H_data_ls=channel_H_ls(:,Data_Indx);%----------------LS¹À¼ÆÖз¢ËÍÊý¾ÝµÄ¹À¼ÆÖµ----------------------Tx_data_estimate_ls=Rx_fre_data.*conj(channel_H_data_ls)./(abs(channel_H_data_ls).^2);%----------------DFT¹À¼Æ--------------------------------------Tx_pilot_estimate_ifft=ifft(pilot_esti);padding_zero=zeros(1024,7);Tx_pilot_estimate_ifft_padding_zero=[Tx_pilot_estimate_ifft;padding_zero];Tx_pilot_estimate_dft=fft(Tx_pilot_estimate_ifft_padding_zero);%----------------DFT¹À¼ÆµÄÏßÐÔ²åÖµ¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ªint_len=pilot_Indx;len=1:num_data;forii=1:carrier_countchannel_H_dft(ii,:)=interp1(int_len,Tx_pilot_estimate_dft(ii,1:(num_pilot)),len,'linear');endchannel_H_data_dft=channel_H_dft(:,Data_Indx);%----------------DFT¹À¼ÆÖз¢ËÍÊý¾ÝµÄ¹À¼ÆÖµ----------------------Tx_data_estimate_dft=Rx_fre_data.*conj(channel_H_data_dft)./(abs(channel_H_data_dft).^2);%----------------DFT·ûºÅ½âµ÷------------------------------------demod_in_dft=Tx_data_estimate_dft(:).';demod_out_dft=qamdemod(demod_in_dft,modulation_mode);%----------------LS·ûºÅ½âµ÷------------------------------------demod_in_ls=Tx_data_estimate_ls(:).';demod_out_ls=qamdemod(demod_in_ls,modulation_mode);%----------------ÎóÂëÂʵļÆËã----------------------------------fori=1:length(BitsTx)ifdemod_out_dft(i)~=BitsTx(i)num_bit_err_dft(c1,num1)=num_bit_err_dft(c1,num1)+1;endifdemod_out_ls(i)~=BitsTx(i)num_bit_err_ls(c1,num1)=num_bit_err_ls(c1,num1)+1;endendendendBER_dft=mean(num_bit_err_dft.')/length(BitsTx);BER_ls=mean(num_bit_err_ls.')/length(BitsTx);%%%%%%%%%%%%%%%%%%%a%%%%%%%%Ö÷³ÌÐòÑ»·»»½áÊø%%%%%%%%%%%%%%%%%%%%%%%%%%%%figuresemilogy(SNR,BER_dft,'-mp',SNR,BER_ls,'-k+');title(