clc;
clear all ;
close all;
global N_sc;
N_sc=256;%有效数据的子载波数
BitperSymbol=4; %每符号的比特数
DataSymlength=22; %传输的符号数 512
Data_Bitlength=DataSymlength*N_sc*BitperSymbol;
%% 产生数据信号 ------------(X_Data)
Y_BitSource=round(rand(1,DataSymlength*BitperSymbol*N_sc)); s
ysym=bi2de(reshape(Y_BitSource',BitperSymbol,length(Y_BitSource)/BitperSymbol).','left-msb'); % 十进制数
graycode=[0 1 3 2 4 5 7 6 12 13 15 14 8 9 11 10]; %格雷码编码规则
nsg=graycode(ysym+1); %将随机数映射成格雷码
%% ------------------------------------------串并变换-----ysym---------------------------
Y_input=reshape(nsg,N_sc/4,[]);
%% -----------------------------------------MQMAM调制-------------------------
hI = modem.qammod(2^BitperSymbol);
hII = modem.qamdemod(2^BitperSymbol);
Y_Data = modulate(hI,Y_input); % 复数
% figure (1)
% plot(Y_Data,'*r'); %画接收信号的星座图
% axis([-4, 4, -4, 4]);
% grid on
%% 自共轭
%% Hermitian对称
%% -----------------------------------DCO信号调整---------------------------------------
NumLoop=length(Y_Data(1,:));
SymIFFT_Y = zeros(130,NumLoop);
SymIFFTtmptmp_Y = zeros(130,NumLoop);
SymIFFTtmp_Y = reshape(Y_Data,64,NumLoop);
SymIFFTtmptmp_Y(1,:) = SymIFFT_Y(1,:); % 实数
SymIFFTtmptmp_Y(2:65,:) = SymIFFTtmp_Y; % 实数
SymIFFTtmptmp_Y(66,:)=SymIFFT_Y(66,:);
SymIFFTtmptmp_Y(65+1,:) = SymIFFT_Y(65+1,:);
SymIFFTtmptmp_Y(65+2:65*2,:) = flipdim(conj(SymIFFTtmptmp_Y(2:65,:)),1);
%% ---------------------------------------------ifft变换-------------------------
Y1_ifft_output=ifft(SymIFFTtmptmp_Y);
%% ---------------------------------------------DCO偏置--------------------------
Y1_ifft_output_D=std2(Y1_ifft_output);
U=2.15;%偏置系数
% U=1.9;%偏置系数
Din_y=U*sqrt(Y1_ifft_output_D);
Din=Din_y*ones(130,NumLoop);
Y1_ifft_output_y=Y1_ifft_output+Din;
Y1_ifft_output_y(find(Y1_ifft_output_y<0))=0;
si=1;
s1=zeros(1,snr_shu+1);
s2=zeros(1,snr_shu+1);
%% ---------------------------------------------------------------------------信道----------------------------------------
for snr = 0:1:snr_shu;
for num = 100;
% snr=10;
ofdm_sig_y=awgn(Y1_ifft_output_y, snr,'measured' );
%% ----------------------------------------------DCO去偏置-------------------------------------
ofdm_sig_y_1=ofdm_sig_y-Din;
%% --------------------------------------------FFT运算-------------------------------------
RY1_QAMSymbol=fft(ofdm_sig_y_1);
%% ---------------------------------反Hermitian对称----------------------
%% DCO
SymEqtmp1_y=zeros(64,NumLoop);
SymEqtmp1_y_1= RY1_QAMSymbol(2:65,:);
%% ---------MQAM解调------------
%% DCO
DY1_int = demodulate(hII,SymEqtmp1_y_1);
nsg1=graycode(DY1_int+1);
% nsg1_1=reshape(nsg1,[],1);
DY1_Bit = de2bi(nsg1,'left-msb');
nsg2=graycode(y_2+1);
DY1_Bit_1 = de2bi(nsg2,'left-msb');
%% 并串变换
DY1_Bit_chuan=reshape(DY1_Bit',1,[]);
DY1_Bit_chuan_1=reshape(DY1_Bit_1',1,[]);
%% BER计算
%% DCO
L1=length(DY1_Bit_chuan_1); L2=length(Y_BitSource);
% Y_input_ceshi=Y_BitSource(L2-L1+1:L2);
% DY1_Bit_ceshi=DY1_Bit_chuan(L2-L1+1:L2);
Y_input_ceshi=Y_BitSource;
DY1_Bit_ceshi=DY1_Bit_chuan;
% [number_of_errors_y,bit_error_rate_y]=biterr(DY1_Bit_chuan_3,DY1_Bit_ceshi);
[number_of_errors_y,bit_error_rate_y]=biterr(Y_input_ceshi,DY1_Bit_ceshi);
xlbf=DY1_Bit_chuan(1:L2-L1);
DY1_Bit_ceshi_1=[xlbf DY1_Bit_chuan_1];
% DY1_Bit_ceshi_1=DY1_Bit_chuan_1;
[number_of_errors_y_1,bit_error_rate_y_1]=biterr(Y_input_ceshi,DY1_Bit_ceshi_1);
- 1
- 2
前往页