📄 bpsk.m
字号:
% bpsk.m
% Simulation program to realize BPSK transmission system
%
% 这个程序仿真了数字信号的BPSK调制及相关解调,
% 传输信道为加性高斯白噪声信道(AWGN)
%******************** Preparation part **********************
sr=256000.0; % Symbol rate
ml=1; % Number of modulation levels
br=sr.*ml; % Bit rate (=symbol rate in this case)
nd = 1000; % Number of symbols that simulates in each loop
ebn0=3; % Eb/N0,dBW
IPOINT=8; % Number of oversamples
%******************** Data generation ********************************
indata=rand(1,nd)>0.5; % rand: built in function
%******************** BPSK Modulation ***********************
data1=indata.*2-1; % convert(0,1) to (-1,1)
data2=zeros(1,nd*IPOINT); % oversample data1,initiation
data2(1:IPOINT:1+IPOINT*(nd-1))=data1; % set the date from data1 every 8 samples
%****************** Attenuation Calculation *****************
spow=sum(data2.*data2)/nd; % average symbol power
npow=spow*sr/br*10.^(-ebn0/10); % noise power
attn=sqrt(0.5*npow); % the attenuation of AWGN noise
%************ Add White Gaussian Noise (AWGN) ***************
inoise=randn(1,length(data2)).*attn; % randn: built in function
data3=data2+inoise;
data4=data3(1:IPOINT:IPOINT*nd-1);
%******************** BPSK Demodulation *********************
outdata=data4>0;
%********************** Output result ***************************
% 输入、输出比特流的图形对比
x=0:nd-1;
plot(x,indata,'b*-',x,outdata,'r-')
h=legend('indata','outdata');
set(gca,'ytick',[-1:2])
axis equal tight([0 inf 0 1])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -