用MATLAB做4fsk
发布网友
发布时间:2022-04-25 12:07
我来回答
共2个回答
热心网友
时间:2024-11-02 07:38
x=sqrt(2Eb/Tb)*cos2*π*fi*t;f0=1;f1=4;
t=0:2*pi/99:Tb;
cp=[];mod=[];bit=[];
for n=1:length(x);
if x(n)==0;
cp1=ones(1,100);c=sin(f0*t);
bit1=zeros(1,100);
else x(n)==1;
cp1=ones(1,100);c=sin(f1*t);
bit1=ones(1,100);
end
cp=[cp cp1];mod=[mod c];bit=[bit bit1];
end
fsk=cp.*mod;
plot(bit,'r*:');
grid on;hold on
plot(fsk,'b+:');
SNRindB1=0:1:12;
SNRindB2=0:0.1:12;
for i=1:length(SNRindB1)
simu_err_prb(i)=snr2ps5_11(SNRindB1(i));
end;
for i=1:length(SNRindB2)
SNR=exp(SNRindB2(i)*log(10)/10);
theo_err_prb(i)=Qfunct(sqrt(SNR));
end;
semilogy(SNRindB1,simu_err_prb,'*');
hold
semilogy(SNRindB2,theo_err_prb);
legend('仿真结果','理论曲线')
function [p]=snr2ps5_11(snr_in_dB)
E=1;
SNR=exp(snr_in_dB*log(10)/10);
sgma=E/sqrt(2*SNR);
N=10000;
for i=1:N, %产生二进制数据源
temp=rand;
if (temp<0.5),
dsource(i)=0;
else
dsource(i)=1;
end
end
%检测、计算差错概率
numoferr=0;
for i=1:N,
n0=gausamp(sgma);
n1=gausamp(sgma);
if(dsource(i)==0),
r0=E+n0;
r1=n1;
else
r1=E+n1;
r0=n0;
end
if(r0>r1),
decis=0;
else
decis=1;
end
if(decis~=dsource(i))
numoferr=numoferr+1;
end
end
p=numoferr/N;
function [y]=Qfunct(x)
y=(1/2)*erfc(x/sqrt(2));
%高斯样本的产生
function x=gausamp(sgma)
x=sqrt(sgma)*randn;
%Q函数的计算
function [y]=Qfunct(x)
y=(1/2)*erfc(x/sqrt(2));
热心网友
时间:2024-11-02 07:38
x=sqrt(2Eb/Tb)*cos2*π*fi*t;f0=1;f1=4;
t=0:2*pi/99:Tb;
cp=[];mod=[];bit=[];
for
n=1:length(x);
if
x(n)==0;
cp1=ones(1,100);c=sin(f0*t);
bit1=zeros(1,100);
else
x(n)==1;
cp1=ones(1,100);c=sin(f1*t);
bit1=ones(1,100);
end
cp=[cp
cp1];mod=[mod
c];bit=[bit
bit1];
end
fsk=cp.*mod;
plot(bit,'r*:');
grid
on;hold
on
plot(fsk,'b+:');
SNRindB1=0:1:12;
SNRindB2=0:0.1:12;
for
i=1:length(SNRindB1)
simu_err_prb(i)=snr2ps5_11(SNRindB1(i));
end;
for
i=1:length(SNRindB2)
SNR=exp(SNRindB2(i)*log(10)/10);
theo_err_prb(i)=Qfunct(sqrt(SNR));
end;
semilogy(SNRindB1,simu_err_prb,'*');
hold
semilogy(SNRindB2,theo_err_prb);
legend('仿真结果','理论曲线')
function
[p]=snr2ps5_11(snr_in_dB)
E=1;
SNR=exp(snr_in_dB*log(10)/10);
sgma=E/sqrt(2*SNR);
N=10000;
for
i=1:N,
%产生二进制数据源
temp=rand;
if
(temp<0.5),
dsource(i)=0;
else
dsource(i)=1;
end
end
%检测、计算差错概率
numoferr=0;
for
i=1:N,
n0=gausamp(sgma);
n1=gausamp(sgma);
if(dsource(i)==0),
r0=E+n0;
r1=n1;
else
r1=E+n1;
r0=n0;
end
if(r0>r1),
decis=0;
else
decis=1;
end
if(decis~=dsource(i))
numoferr=numoferr+1;
end
end
p=numoferr/N;
function
[y]=Qfunct(x)
y=(1/2)*erfc(x/sqrt(2));
%高斯样本的产生
function
x=gausamp(sgma)
x=sqrt(sgma)*randn;
%Q函数的计算
function
[y]=Qfunct(x)
y=(1/2)*erfc(x/sqrt(2));