www.pudn.com > BFSK.rar > bfsk.m, change:2015-12-03,size:1603b


clear;clc; 
nsymbol=100000; 
fc=5e6; 
fs=200e6; 
nsamp=fs/fc; 
f1=10e6;f2=20e6; 
EbN0=0:10; 
t=0:1/fs:(1/fc-1/fs); 
rand0=randi([0 1],1,nsymbol); 
asym=ones(1,fs/fc); 
asym1=asym.*cos(2*pi*f1*t); 
asym2=asym.*cos(2*pi*f2*t);%可以保证相位连续 
msg0=(rand0'*asym1+(~rand0)'*asym2)'; 
msg=reshape(msg0,1,nsymbol*nsamp); 
 
 
%fp=12e6;fs=15e6;Rp=1;As=30;fp衰减开始频率,fs衰减结束频率,RS衰减-3db增益,AS衰减-单位增益分贝,这是低通 
%[N,wc]=buttord(fp,fs,Rp,As,'s')%计算率波器的阶数和3dB截止频率 
%[B,A]=butter(N,wc,'s');%计算滤波器系统函数分子分母多项式 
 
 
[b1,a1]=butter(2,[5e6,15e6]*2/fs);%设计巴特沃斯带通滤波器,10e6信号通过,3阶,系数为a1,b1 
[b2,a2]=butter(2,[15e6,25e6]*2/fs);%设计巴特沃斯带通滤波器,20e6信号通过,3阶,系数为a2,b2 
[b3,a3]=butter(2,15e6/fs);%设计巴特沃斯低通滤波器, 
[b4,a4]=butter(2,25e6/fs);%设计巴特沃斯低通滤波器,20e6HZ信号通过 
t1=repmat(t,1,nsymbol); 
for i=0:10 
msg1=awgn(real(msg),EbN0(i+1)-10*log10(nsamp/2),'measured'); 
sg1=filter(b1,a1,msg1);%10e6带通 
sg2=filter(b2,a2,msg1);%20e6带通 
sag1=2*sg1.*cos(2*pi*f1*t1);%10e6HZ信号通过相乘器 
sag2=2*sg2.*cos(2*pi*f2*t1);%20e6HZ信号通过相乘器 
sag3= filter(b3,a3,sag1);%10e6HZ信号通过该LPF 
sag4= filter(b4,a4,sag2);%20e6HZ信号通过该LPF 
decmsg=zeros(1,nsymbol); 
c=sag3-sag4; 
msg2=reshape(c,40,100000); 
msg2=msg2(40,:); 
indx1=find(msg2>=0); 
decmsg(indx1)=1; 
[err,ber(i+1)]=biterr(rand0,decmsg); 
end; 
%Pe=berawgn(EbN0,'fsk',2,'nondiff'); 
Pe=berawgn(EbN0,'fsk',2,'noncoherent'); 
semilogy(EbN0,ber,'ko',EbN0,Pe,'b-.',EbN0,(qfunc(sqrt(10.^(EbN0/10))))); 
legend('方波2FSK仿真','方波2FSK理论','BOA最佳接收理论');