📄 main.m
字号:
% qpsk_fading.m
%
% Simulation program to realize QPSK transmission system
% (under four path fading)
%
% Programmed by BangzengHe
%
%******************** 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 = 20; % Number of symbols that simulates in each loop
ebn0=10; % Eb/N0
IPOINT=10; % Number of oversamples
%************************* 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
%******************* Fading initialization ********************
% Time resolution
tstp=1/sr/IPOINT;
% Arrival time for each multipath normalized by tstp
% In this simulation four-path Rayleigh fading are considered
itau = [0, 2, 3, 4];
% Mean power for each multipath normalized by direct wave.
% In this simulation four-path Rayleigh fading are considered.
% This means that the second path is -10dB less than the first direct path.
dlvl = [0 ,10 ,20 ,25];
% Number of waves to generate fading for each multipath.
% In this simulation four-path Rayleigh fading are considered.
% In normal case, more than six waves are needed to generate Rayleigh fading
n0=[6,7,6,7];
% Initial Phase of delayed wave
% In this simulation four-path Rayleigh fading are considered.
th1=[0.0,0.0,0.0,0.0];
% Number of fading counter to skip (50us/0.5us)
% In this case we assume to skip 50 us
itnd0=nd*IPOINT*100;
% Initial value of fading counter
% In this simulation four-path Rayleigh fading are considered.
% Therefore four fading counter are needed.
itnd1=[1000,2000, 3000, 4000];
% Number of directwave + Number of delayed wave
% In this simulation four-path Rayleigh fading are considered
now1=4;
% Maximum Doppler frequency [Hz]
% You can insert your favorite value
fd=200;
% You can decide two mode to simulate fading by changing the variable flat
% flat : flat fading or not
% (1->flat (only amplitude is fluctuated),0->nomal(phase and amplitude are fluctutated)
flat =1;
%******************** START CALCULATION *************************************
nloop=100;
for iii=1:nloop
%*************************** Data generation ********************************
data1=rand(1,nd*ml)>0.5; % rand: built in function
[data2] = oversamp( data1, nd , IPOINT) ;
%*************************** QPSK Modulation ********************************
[ich,qch]=qpskmod(data1,1,nd,ml);
[ich1,qch1]= compoversamp(ich,qch,length(ich),IPOINT);
[ich2,qch2]= compconv(ich1,qch1,xh);
%**************************** Attenuation Calculation ***********************
spow=sum(ich2.*ich2+qch2.*qch2)/nd; % sum: built in function
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn); % sqrt: built in function
%********************** Fading channel **********************
% Generated data are fed into a fading simulator
[ifade,qfade]=sefade(ich2,qch2,itau,dlvl,th1,n0,itnd1,now1,length(ich2),tstp,fd,flat);
% Updata fading counter
itnd1 = itnd1+ itnd0;
%********************* Add White Gaussian Noise (AWGN) **********************
[ich3,qch3]= comb(ifade,qfade,attn);% add white gaussian noise
[ich4,qch4]= compconv(ich3,qch3,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);
[data3] = oversamp( demodata, nd , IPOINT) ;
figure(7);
plot(ich2,qch2);
title('signal constellation before the Rayleigh channel');
hold on;
figure(8);
plot(ifade,qfade);
title('signal constellation after the Rayheigh channel');
hold on;
end
%********************** Output result ***************************
figure(1);
plot(data2);
axis([0 200 -0.5 1.5]);
title('source signal');
xlabel('Time');
T=1; % symbol duration
delta_T=T/(nd*ml); % sampling interval
t=-0.5*T+delta_T:delta_T:0.5*T; % time axis
N=length(t); % number of samples
for i=1:N, % calculation of raised cosine pulse
g_T(i)=data1(i);
end;
G_T=abs(fft(g_T)); % spectrum of g_T
f=-0.5/delta_T:1/(delta_T*(N-1)):0.5/delta_T;
figure(2);
% plot(f,fftshift(G_T));
psd(G_T);
[Pxx,fr]=psd(G_T);
plot(fr-0.5,fftshift(Pxx));
figure(3);
plot(ich2);
title('modulated signal');
xlabel('Time');
figure(4);
psd(ich2);
[Pxx,fr]=psd(ich2);
plot(fr-0.5,fftshift(Pxx));
figure(5);
plot(ich4);
title('AWGN channel output signal');
xlabel('Time');
figure(6);
psd(ich4);
[Pxx,fr]=psd(ich4);
%pause;
plot(fr-0.5,fftshift(Pxx));
%******************** end of file ***************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -