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

📄 bpsk.m

📁 上传一个bpsk信号matlab源代码
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Programmed by Oh Joon
%

%******************** Preparation part *************************************
clear all;
sr=256000.0; % Symbol rate
ml=1;        % ml:Number of modulation levels (BPSK:ml=1)
br=sr .* ml; % Bit rate
nd = 100;   % Number of symbols that simulates in each loop
IPOINT=8;    % Number of oversamples

%******************* Filter initialization ********************

irfn=21;     % Number of filter taps          
alfs=0.5;    % Rolloff factor
[xh] = hrollfcoef(irfn,IPOINT,sr,alfs,1);   %Transmitter filter coefficients  
[xh2] = hrollfcoef(irfn,IPOINT,sr,alfs,0);  %Receiver filter coefficients

%******************** START CALCULATION *********************
%nloop=1000;  % Number of simulation loops

nloop=100;
Eb_N0=0:10; % Eb/No

for i=1:length(Eb_N0)
%ber = 0;
noe = 0;    % Number of error data
nod = 0;    % Number of transmitted data
%total = 0;
Eb = Eb_N0;
for iii=1:nloop
    
%******************** Data generation ********************************  

	data=rand(1,nd)>0.5;  % rand: built in function
    
%******************** BPSK Modulation ***********************  

    data1=data.*2-1;
	[data2] = oversamp( data1, nd , IPOINT) ;
	data3 = conv(data2,xh);  % conv: built in function
     
%****************** Attenuation Calculation *****************
	
    spow=sum(data3.*data3)/nd;
	attn=0.5*spow*sr/br*10.^(-Eb_N0(i)/10);
	attn=sqrt(attn);
   
%********************** Fading channel **********************

  % Generated data are fed into a fading simulator
  % In the case of BPSK, only Ich data are fed into fading counter
  % [ifade,qfade]=sefade(data3,zeros(1,length(data3)),itau,dlvl,th1,n0,itnd1,now1,length(data3),tstp,fd,flat);
  
  % Updata fading counter
  %itnd1 = itnd1+ itnd0;

%************ Add White Gaussian Noise (AWGN) ***************
	
    inoise=randn(1,length(data3)).*attn;  % randn: built in function
	data4=data3+inoise;
	data5=conv(data4,xh2);  % conv: built in function

	sampl=irfn*IPOINT+1;
	data6 = data5(sampl:8:8*nd+sampl-1);
    
%******************** BPSK Demodulation *********************

    demodata=data6 > 0;

%******************** Bit Error Rate (BER) ******************

    noe2=sum(abs(data-demodata));  % sum: built in function
	nod2=length(data);  % length: built in function
	noe=noe+noe2;
	nod=nod+nod2;

    
    %ber = noe/nod;
    %total = total+ noe/nod;
    
    
end % for iii=1:nloop   
    ber(i) = noe/nod;
    %Avg_BER(i) = total/nloop;
    %Q function
    Qx=(1/2)*erfc((10.^(Eb/10))/sqrt(2));

end % for i=1:20
%********************** Output result ***************************

%semilogy(Eb_N0,ber);
figure;
semilogy(Eb_N0, ber, 'bo-',Eb_N0,Qx,'rx-');
xlabel('Eb/No (dB)'); ylabel('BER');
title('Performence of BPSK');
axis([0 10 1E-4 1]);
legend('BPSK AWGN (Simulation)','BPSK AWGN (Theory)');
grid on;


%******************** end of file ***************************
 

⌨️ 快捷键说明

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