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

📄 qpsk_rayleigh.asv

📁 这是一个误码率QPSK的仿真的文件,很有用的哦!快来看一看!
💻 ASV
字号:
% qpsk_rayleigh.m
%
% Simulation program to realize QPSK transmission system over Rayleigh channel
%
clear;
clc;

%******************** Preparation part *************************************
sr=256000.0;    % Symbol rate
ml=2;           % ml:Number of modulation levels (BPSK:ml=1, QPSK:ml=2, 16QAM:ml=4)
br=sr.*ml;      % Bit rate
nd=100;         % Number of symbols that simulates in each loop
IPOINT=8;       % Number of oversamples
sample2=32;

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

irfn=21;                  % Number of 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=100;  % Max number of simulation loops
noe = 0;    % Number of error data
nod = 0;    % Number of transmitted data

for ebn0=0:2:24   % Eb/N0
for iii=1:nloop
    
%*************************** Data generation ********************************  
	
    data=rand(1,nd*ml)>0.5;  % rand: built in function
    data1=2.*data-1;
    for i=1
%*************************** QPSK Modulation ********************************  

    [ich,qch]=qpskmod(data1,1,nd,ml);
	[ich1,qch1]= compoversamp(ich,qch,length(ich),IPOINT); 
	[ich2,qch2]= compconv(ich1,qch1,xh); 
     
%****************************Add signals to carriers*********************

ich_sample2=oversample2(ich2,sample2);
qch_sample2=oversample2(qch2,sample2);

%Frequency of carriers is 4 times as large as 
%that of singnals after oversample(IPOINT=8)
cos_carrier=cos((8*pi/sample2)*[1:length(ich_sample2)]);
sin_carrier=sin((8*pi/sample2)*[1:length(qch_sample2)]);
                   
ich_sample2=ich_sample2.*cos_carrier;
qch_sample2=qch_sample2.*sin_carrier;

%*************************** Fading Channel ******************************
    
    [ifade,qfade]=rayleigh(ich_sample2,qch_sample2);

%**************************** Attenuation Calculation ***********************
   
   spow=sum(ifade.*ifade+qfade.*qfade)/nd;  % sum: built in function
   attn=0.5*spow*sr/br*10.^(-ebn0/10);
   attn=sqrt(attn);
    
%********************* Add White Gaussian Noise (AWGN) **********************
   
    [ich31,qch31]= comb(ifade,qfade,attn);
    
%********************Resume signals from carriers**************************

    ich32=ich31.*cos_carrier;
    qch32=qch31.*sin_carrier;
    
    %butterworth filter(cut-off frequency is chosen as same as carrier)
    [b,a]=butter(10,0.1);
    
    %filter the signals
    ich3=filter(b,a,ich32);
    qch3=filter(b,a,qch32);
    
    %resume dada from oversampled signals every 32 points
    ich3_data=ich3(1:sample2:length(ich3));
    qch3_data=qch3(1:sample2:length(qch3));
    
    [ich4,qch4]= compconv(ich3_data,qch3_data,xh2);

    syncpoint=irfn*IPOINT+1;
    ich5=ich4(syncpoint:IPOINT:length(ich4));
    qch5=qch4(syncpoint:IPOINT:length(qch4));
        
%**************************** QPSK Demodulation *****************************

    [demodata]=qpskdemod(ich5,qch5,1,nd,ml);

%************************** 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;

%************************Check if noe>=100******************************

    if noe>=10
        flag=1;
        break;
   end
	
end % for iii=1:nloop    

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

    ber = noe/nod;
    fprintf('%d\t%e\n',ebn0,noe/nod);  % fprintf: built in function
    
    noe = 0;    
    nod = 0;
end % for  ebn0=0:2:20 
%*********************Plot the data of the last loop**************

figure(1);

subplot(2,2,1);
plot(data(1:10),'c');
title('基带信号');
subplot(2,2,2);
p1=spectrum(data,256');
plot(p1,'c');
title('基带信号功率谱');

subplot(2,2,3);
plot(ich_sample2,'b');
title('已调信号(信道I)');
subplot(2,2,4);
p2=spectrum(ich_sample2,256);
plot(p2,'b');
title('已调信号(信道I)功率谱 ');

figure(2);

subplot(2,2,1);
plot(ich31,'k');
title('接收信号(信道I)');
subplot(2,2,2);
p3=spectrum(ich31,256);
plot(p3,'k');
title('接收信号(信道I)功率谱');

subplot(2,2,3);
plot(demodata(1:10),'g');
title('解调信号(前10周期)');
subplot(2,2,4);
p4=spectrum(demodata,256);
plot(p4,'g');
title('解调信号功率谱');

figure(3);
plot(ich, qch,'b+');
title('经信道传输前信号的星座图');

figure(4);
plot(ifade,qfade,'b+');
title('经信道传输后信号的星座图');

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

⌨️ 快捷键说明

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