⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ofdm_awgn.m

📁 文件夹“AWGN”说明了系统误码率在均衡前后随SNR增加的变化。 (1)绘制误码率曲线。运行m文件:main_picture,调用主函数:ofdm_AWGN。 (2)绘制星座点图。运行m文件:sn
💻 M
📖 第 1 页 / 共 2 页
字号:
%--------------------------------------------------------------------------
%pause
%figure
%subplot(2,1,1)
%stairs(t2,S);
%ylim([-1.5 1.5])
%X = xlabel('Time [S]');
%Y = ylabel('Amplitude [V]');
%title('发送端 映射后')

% plot(real(S),imag(S),'ob')
% hold on
% xlim([-1.5 1.5])
% ylim([-1.5 1.5])
% %X = xlabel('Time [S]');
% %Y = ylabel('Amplitude [V]');
% plot(real(Rx_S),imag(Rx_S),'*r')
% hold off

%t6 = linspace (0,nf*(TC+TP),length(Rx_S));
%subplot(2,1,2)
%stairs(t6,Rx_S);
%ylim([-1.5 1.5])
%X = xlabel('Time [S]');
%Y = ylabel('Amplitude [V]');
%title('接收端 对应处')
%**************************************************************************
%                                  解映射
%**************************************************************************
[demo_bits1] = deyinshe(Rx_S,ml);
%--------------------------------------------------------------------------
%                         解映射后画图程序
%--------------------------------------------------------------------------

%pause
%figure
%subplot(2,1,1)
%stairs(t1,ge_bits);
%ylim([-0.3 1.5])
%X = xlabel('Time [S]');
%Y = ylabel('Amplitude [V]');
%title('发送的信号')

% t7 = linspace (0,nf*(TC+TP),length(demo_bits1));
% subplot(2,1,2)
% stairs(t7,demo_bits1);
% ylim([-0.3 1.5])
% X = xlabel('Time [S]');
% Y = ylabel('Amplitude [V]');
% title('接收到的信号')





%*************************************************************************
%                        比较部分:均衡后
%*************************************************************************

%**************************************************************************
%                         把nf个符号按顺序排列
%**************************************************************************
Rx_X = Rx_XM';
%*********************************************************************
%                          LMS EQULIZATION
%*********************************************************************
numPoints =ifftlen;


x=Rx_XM';
d=ifft_data ;

w = [];
y = [];
in = []; 
e = []; % error, final result to be computed

wo=[0.0000001];
w = repmat(wo,numTaps+1,1) + i*repmat(wo,numTaps+1,1);
%w = zeros(numTaps+1,1) + i*zeros(numTaps+1,1);
y = zeros(1,numPoints) ;
e = zeros(1,numPoints) ;

% LMS Adaptation
for n  = numTaps+1 : numPoints
    % select part of training input
    in = x(n : -1 : n-numTaps) ;
    y(n) = w'*in;        
    % compute error
    e(n) = d(n)-y(n);
    % update taps
    w = w + Mu*( real(e(n)*conj(in)) - i*imag(e(n)*conj(in)) );
    %w = w + Mu*( real(conj(e(n))*(in)) - i*imag(conj(e(n))*(in)) );
    %w=w+Mu*in*e(n);%抽头系数w调整
end

% Plot results
% pause
% figure;
% semilogy(abs(e));
% title(['LMS Adaptation Learning Curve Using Mu = ', num2str(Mu)]);
% xlabel('Iteration Number');
% ylabel('Output Estimation Error in dB');
%***********************************************************************; 
%pause
%subplot(2,1,1)
%plot(real(d),imag(d))
%title('System output') ;
%xlabel('Samples')
%ylabel('True  output')
%subplot(2,1,2)
%plot(real(y),imag(y),'r');
%title('System output') ;
%xlabel('Samples')
%ylabel('estimated output')


%pause
%figure
% g=real(w);
% k=imag(w);
% plot(w, 'r*')
% legend('Actual weights')
% title('Comparison of the actual weights and the estimated weights') ;

Rx_X(:)=y(:);
%**************************************************************************
%                           串并转换
%**************************************************************************
nc = floor(length(Rx_X)/FS_cp);
Rx_X = reshape(Rx_X,FS_cp,nc);
Rx_ch = zeros(NFFT,nc);
%************************************************************************* 
%                          去循环前缀 
%**************************************************************************
for m = 1:nc
   Rx_C_cp = Rx_X(:,m);
   if ncp>0
        Rx_C = zeros(over*NFFT,1);
        Rx_C(:) = Rx_C_cp(over*ncp+1:length(Rx_C_cp));
    else
        Rx_C = Rx_C_cp;
    end
%********************************************************************   
%                       FFT 
%********************************************************************
    %FS = 4*NFFT;
    Rx_C = Rx_C/sqrt(FS);
    Rx_Czp = fft(Rx_C,FS);
    %disp(Rx_Czp);
%**************************************************************************
%                              还原过采样
%**************************************************************************
    Rx_c0 = zeros(NFFT,1);    
    %up2 = floor(NFFT/2);
    %down2 = NFFT-n1;
    Rx_c0(1:up2) = Rx_Czp(1:up2);
    Rx_c0(up2+1:NFFT) = Rx_Czp(FS-down2+1:FS); 
    Rx_ch(:,m)=Rx_c0(:);
end
%**************************************************************************
%                         去掉128中间的0
%**************************************************************************
    Rx_S0 = zeros(numcarrier,nf);
    %up1 = floor(numcarrier/2);
    %down1 = numcarrier-nf;
    Rx_S0(1:up1,:) = Rx_ch(1:up1,:);
    Rx_S0(numcarrier-down1+1:numcarrier,:) = Rx_ch(NFFT-down1+1:NFFT,:);
%**************************************************************************
%                               并串转换
%**************************************************************************
Rx_S = reshape(Rx_S0,1,numcarrier*nf);
%Rx_S = sign(Rx_S);
%--------------------------------------------------------------------------
%                         FFT后画图程序
%--------------------------------------------------------------------------
%pause
%figure
%subplot(2,1,1)
%stairs(t2,S); 

% figure
% plot(real(S),imag(S),'ob')
% hold on
% xlim([-1.5 1.5])
% ylim([-1.5 1.5])
% X = xlabel('Time [S]');
% Y = ylabel('Amplitude [V]');
% plot(real(Rx_S),imag(Rx_S),'*r')
% title('发送端 映射后')

%t6 = linspace (0,nf*(TC+TP),length(Rx_S));
%subplot(2,1,2)
%stairs(t6,Rx_S);
%ylim([-1.5 1.5])
%X = xlabel('Time [S]');
%Y = ylabel('Amplitude [V]');
%title('接收端 对应处')
%**************************************************************************
%                                  解映射
%**************************************************************************
[demo_bits2] = deyinshe(Rx_S,ml);
%--------------------------------------------------------------------------
%                         接收到的信号画图程序
%--------------------------------------------------------------------------
%pause
%figure
%subplot(2,1,1)
%stairs(t1,ge_bits);
%ylim([-0.3 1.5])
%X = xlabel('Time [S]');
%Y = ylabel('Amplitude [V]');
%title('发送的信号')

%t7 = linspace (0,nf*(TC+TP),length(demo_bits2));
%subplot(2,1,2)
%stairs(t7,demo_bits2);
%ylim([-0.3 1.5])
%X = xlabel('Time [S]');
%Y = ylabel('Amplitude [V]');
%title('接收到的信号')

%erro_un(i)= sum(abs(demo_bits1-ge_bits));
%erro_eq(i)= sum(abs(demo_bits2-ge_bits));

 %end
%erro_un
%erro_eq
% plot(erro_un ,'b+')
%xlim([0 i+1]);
%ylim([-numbits/10 numbits])
%hold on
%plot(erro_eq  , 'r*')
%legend('unequ','equ')
%**************************************************************************
%                                误码率计算
%**************************************************************************
% instantaneous number of error and data

eob2=sum(abs(demo_bits1-ge_bits));  %  sum : built in function
eob3=sum(abs(demo_bits2-ge_bits));  %  sum : built in function
nob2=length(ge_bits);  %  length : built in function

% cumulative the number of error and data in eob and nob

eob=eob+eob2;
eob_equ=eob_equ+eob3;
nob=nob+nob2;

% calculating PER

if eob2~=0  
   eop=eop+1;
else
   eop=eop;
end   
   eop;
   nop=nop+1;
    
end

%********************** Output result ***************************

per=eop/nop;
ber=eob/nob;
ber_equ=eob_equ/nob;
BER(lll)=ber;
BER_EQU(lll)=ber_equ;
PER(lll)=per;
lll=lll+1;
fprintf('%f\t%e\t%e\t\n\t\n',snrdb,ber,ber_equ,per);
fid=fopen('P&Bofdm.dat','a');
fprintf(fid,'%f\t%e\t%e\t\n\t\n',snrdb,ber,ber_equ,per);
fclose(fid);
end
 
% plot(real(S),imag(S),'ob')
% hold on
% xlim([-1.5 1.5])
% ylim([-1.5 1.5])
% %X = xlabel('Time [S]');
% %Y = ylabel('Amplitude [V]');
% plot(real(Rx_S),imag(Rx_S),'*r')
% hold off

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -